csound / csound_tilde

csound~ object for Max
GNU Lesser General Public License v3.0
17 stars 3 forks source link

Fixed some errors on macOS + fully static build #15

Open shakfu opened 1 year ago

shakfu commented 1 year ago

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:

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

kunstmusik commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

iainctduncan commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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.