Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some errors on macOS + fully static build #15

Open
shakfu opened this issue Jul 15, 2023 · 7 comments
Open

Fixed some errors on macOS + fully static build #15

shakfu opened this issue Jul 15, 2023 · 7 comments

Comments

@shakfu
Copy link

shakfu commented Jul 15, 2023

Hi,

As I wanted to include the csound~ external in a standalone, I've been spending some time on a recent fork with the initial objective of getting it to work for me on macOS and also to create a relocatable external (not dependent on local ~/Library/Frameworks/Csound64.framework

To that end, I've made some progress and I think some of it would be worth contributing back to the project in a PR at some point if I get past some frustrating windows compilation issues (windows is not my platform of choice -- I'd appreciate some advice if possible).

In any case, here's a brief list of the changes so:

  • Converted to Max Package with regular cross-platform structure

  • Added max-sdk-base as git submodule

  • Added Makefile frontend for simplified macOS builds

  • Fixed macOS compilation errors related to deprecated apis (dropped carbon and rewrote Launch code) and also made a few general code improvements (complete diff here):

    • Removed all using namespace std statements and converted unqualified terms to qualified, and renamed byte in definitions.h to csbyte because there were name collisions between std::byte (added in c++ 17) and former.

    • Dropped use of auto_ptr in csound~.cpp, which was removed in c++17, : converted to std::unique_ptr.

    • Dropped some deprecated or obsolete api usage, for exampleFSRef -> CFURLRef

  • Added Build variants with associated scripts:

    • macOS - local build: non-relocatable, dynamically linked to local csound library or framework

    • macOS - hybrid build: relocatable with static csound + dynamic dependencies

    • macOS - release build: relocatable 100% static build using vcpkg.

    • windows - NOT complete due to residual linking errors but with updated cmake build...

fork: https://github.com/shakfu/csound_tilde

@shakfu shakfu changed the title Fork to fix errors on macOS + fully static build Fix some errors on macOS + fully static build Jul 15, 2023
@shakfu shakfu changed the title Fix some errors on macOS + fully static build Fixed some errors on macOS + fully static build Jul 15, 2023
@kunstmusik
Copy link
Member

I don't think there's anyone really maintaining this at the moment, so it's really nice to see an update! When you're ready please setup a PR and I or someone else can look at merging code in.

@shakfu
Copy link
Author

shakfu commented Jul 15, 2023

Thanks for your reply, Stephen.

I'd be happy to contribute a PR at some point. In fact, on the macOS side, I'm pretty much almost done with my changes. It's just the windows build is a bit of pain since I haven't developed on Windows for quite a while.

Anyway, let's see how it goes.

@iainctduncan
Copy link
Collaborator

With regard to maintenance and general plans for Max, I have plans (after defending) to update my port of the Lazzarini csound object for PD, which is over at: https://github.com/iainctduncan/csound_max. It is a much more minimal version that uses the Csound API only.

I would like to get that working on Apple Silicon, and perhaps also port the midi functionality that is not in there yet from Victor's version. But this one is much more complicated!

@shakfu
Copy link
Author

shakfu commented Jul 15, 2023

Funnily enough, I also have an ancillary repo for testing common build improvements to both csound externals.

@iainctduncan
Copy link
Collaborator

iainctduncan commented Jul 15, 2023

I'd love to chat about teaming up to improve the csound_max external after I'm done my defense (July 24th)! Feel free to email me off github.

@shakfu
Copy link
Author

shakfu commented Jul 16, 2023

@kunstmusik I'm struggling with linking csound with csound_tilde on windows, as I'm using MSVC for the time being but the errors are mostly to do with runtime library linking issues vis-a-vis libcsound.

On csound's CMakeList.txt, I found the option of MinGW compilation, and also some useful info about MSVC compilation configuration:

if(WIN32 AND NOT MSVC)
    if(EXISTS "C:/MinGW/include")
        include_directories(C:/MinGW/include)
    else()
        MESSAGE(STATUS "MinGW include dir not found.")
    endif()
    set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--add-stdcall-alias")
endif()

if(WIN32)
    set(CMAKE_SHARED_LIBRARY_PREFIX "")
    set(CMAKE_SHARED_MODULE_PREFIX "")

    set(CSOUND_WINDOWS_LIBRARIES
        advapi32
        comctl32
        comdlg32
        glu32
        kernel32
        odbc32
        odbccp32
        ole32
        oleaut32
        shell32
        user32
        uuid
        winmm
        winspool
        ws2_32
        wsock32)

    if(MSVC)
        # Experimented with flags but did not make change performance results
        #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi /fp:fast /arch:AVX2")
        #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Oi /fp:fast /arch:AVX2")

        # Replace the default CRT linkage from dynamic (MD) to static (MT)
        if(STATIC_CRT STREQUAL "ON")
            foreach(flag_var
                CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_DEBUG
                CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
                CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
                string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
            endforeach()
            message(STATUS "Using static CRT linkage /MT")
        endif()
    else()
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mstackrealign -static-libgcc -static")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign -static-libstdc++ -static-libgcc -static")
        set_target_properties(${CSOUNDLIB} PROPERTIES LINK_FLAGS "-static-libstdc++ -static-libgcc -static")
        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static")
    endif()
endif()

It would be useful to know which compiler is used for the default csound binary builds that are currently available for download on csound's website in case I am trying to link csound_tilde compiled using MSVC to a libcsound compiled with MinGW (see stackoverflow case)

@shakfu
Copy link
Author

shakfu commented Jul 16, 2023

No worries, I found the answer in the csound docs in csound/platform/README.md:

Visual Studio via CMake is the supported build platform for Windows with Csound. MSYS or Cygwin may no longer work and are not actively maintained. System dependencies for Windows can be installed with Chocolately or Scoop. VCPKG is used as the 3rd party library dependency manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants