From 4bb1225e467a55561da774c053d4056b6f165661 Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Sat, 27 Aug 2022 23:31:56 +0100 Subject: [PATCH 01/14] Enable building Sf2 Player with MSVC --- .github/workflows/build.yml | 2 +- CMakeLists.txt | 8 +- cmake/modules/FindFluidSynth.cmake | 134 +++++++++++++++++++++++++++++ plugins/Sf2Player/CMakeLists.txt | 19 ++-- plugins/Sf2Player/Sf2Player.cpp | 11 ++- 5 files changed, 159 insertions(+), 15 deletions(-) create mode 100644 cmake/modules/FindFluidSynth.cmake diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bdcdeb7d76d..9cdb7d10222 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -223,7 +223,7 @@ jobs: - name: Install dependencies run: | vcpkg install --triplet ${{ matrix.arch }}-windows --recurse ` - fftw3 libsamplerate libsndfile lilv lv2 sdl2 + fftw3 fluidsynth[sndfile] libsamplerate libsndfile lilv lv2 sdl2 - name: Set up build environment uses: ilammy/msvc-dev-cmd@d8610e2b41c6d0f0c3b4c46dad8df0fd826c68e1 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index 0453c169b0b..a67ee846fad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -496,14 +496,14 @@ ENDIF() # check for Fluidsynth IF(WANT_SF2) - PKG_CHECK_MODULES(FLUIDSYNTH fluidsynth>=1.0.7) - IF(FLUIDSYNTH_FOUND) + find_package(FluidSynth 1.0.7) + if(FluidSynth_FOUND) SET(LMMS_HAVE_FLUIDSYNTH TRUE) SET(STATUS_FLUIDSYNTH "OK") - ELSE(FLUIDSYNTH_FOUND) + else() SET(STATUS_FLUIDSYNTH "not found, libfluidsynth-dev (or similar)" "is highly recommended") - ENDIF(FLUIDSYNTH_FOUND) + endif() ENDIF(WANT_SF2) # check for libgig diff --git a/cmake/modules/FindFluidSynth.cmake b/cmake/modules/FindFluidSynth.cmake new file mode 100644 index 00000000000..259ddf96ac4 --- /dev/null +++ b/cmake/modules/FindFluidSynth.cmake @@ -0,0 +1,134 @@ +# Copyright (c) 2022 Dominic Clark +# +# Redistribution and use is allowed according to the terms of the New BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +# Return if we already have FluidSynth +if(TARGET fluidsynth) + set(FluidSynth_FOUND 1) + return() +endif() + +# Attempt to find FluidSynth using PkgConfig +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_check_modules(FLUIDSYNTH_PKG fluidsynth) +endif() + +# Find the library and headers using the results from PkgConfig as a guide +find_path(FluidSynth_INCLUDE_DIR + NAMES "fluidsynth.h" + HINTS ${FLUIDSYNTH_PKG_INCLUDE_DIRS} +) + +find_library(FluidSynth_LIBRARY + NAMES "fluidsynth" + HINTS ${FLUIDSYNTH_PKG_LIBRARY_DIRS} +) + +# Given a library in vcpkg, find appropriate debug and release versions. If only +# one version exists, it is used as the release version, and the debug version +# is not set. +function(_get_vcpkg_library_configs _release_out _debug_out _library) + # We want to do all operations within the vcpkg directory + file(RELATIVE_PATH _lib_relative "${VCPKG_INSTALLED_DIR}" "${_library}") + + # Return early if we're not using vcpkg + if(IS_ABSOLUTE _lib_relative OR _lib_relative MATCHES "^\\.\\./") + set("${_release_out}" "${_library}" PARENT_SCOPE) + return() + endif() + + string(REPLACE "/" ";" _path_bits "${_lib_relative}") + + # Determine whether we were given the debug or release version + list(FIND _path_bits "debug" _debug_index) + if(_debug_index EQUAL -1) + # We have the release version, so use it + set(_release_lib "${_library}") + + # Try to find a debug version too + list(FIND _path_bits "lib" _lib_index) + if(_lib_index GREATER_EQUAL 0) + list(INSERT _path_bits "${_lib_index}" "debug") + list(INSERT _path_bits 0 "${VCPKG_INSTALLED_DIR}") + string(REPLACE ";" "/" _debug_lib "${_path_bits}") + + if(NOT EXISTS "${_debug_lib}") + # Debug version does not exist - only use given version + unset(_debug_lib) + endif() + endif() + else() + # We have the debug version, so try to find a release version too + list(REMOVE_AT _path_bits "${_debug_index}") + list(INSERT _path_bits 0 "${VCPKG_INSTALLED_DIR}") + string(REPLACE ";" "/" _release_lib "${_path_bits}") + + if(NOT EXISTS "${_release_lib}") + # Release version does not exist - only use given version + set(_release_lib "${_library}") + else() + # Release version exists, so use given version as debug + set(_debug_lib "${_library}") + endif() + endif() + + # Set output variables appropriately + if(_debug_lib) + set("${_release_out}" "${_release_lib}" PARENT_SCOPE) + set("${_debug_out}" "${_debug_lib}" PARENT_SCOPE) + else() + set("${_release_out}" "${_release_lib}" PARENT_SCOPE) + unset("${_debug_out}" PARENT_SCOPE) + endif() +endfunction() + +if(FluidSynth_INCLUDE_DIR AND FluidSynth_LIBRARY) + add_library(fluidsynth SHARED IMPORTED) + set_target_properties(fluidsynth PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${FluidSynth_INCLUDE_DIR}" + ) + if(WIN32) + if(VCPKG_INSTALLED_DIR) + _get_vcpkg_library_configs(FluidSynth_IMPLIB_RELEASE FluidSynth_IMPLIB_DEBUG "${FluidSynth_LIBRARY}") + else() + set(FluidSynth_IMPLIB_RELEASE "${FluidSynth_LIBRARY}") + endif() + if(FluidSynth_IMPLIB_DEBUG) + set_target_properties(fluidsynth PROPERTIES + IMPORTED_IMPLIB_RELEASE "${FluidSynth_IMPLIB_RELEASE}" + IMPORTED_IMPLIB_DEBUG "${FluidSynth_IMPLIB_DEBUG}" + ) + else() + set_target_properties(fluidsynth PROPERTIES + IMPORTED_IMPLIB "${FluidSynth_IMPLIB_RELEASE}" + ) + endif() + else() + set_target_properties(fluidsynth PROPERTIES + IMPORTED_LOCATION "${FluidSynth_LIBRARY}" + ) + endif() + + if(EXISTS "${FluidSynth_INCLUDE_DIR}/fluidsynth/version.h") + file(STRINGS + "${FluidSynth_INCLUDE_DIR}/fluidsynth/version.h" + _version_string + REGEX "^#[\t ]*define[\t ]+FLUIDSYNTH_VERSION[\t ]+\".*\"" + ) + string(REGEX REPLACE + "^.*FLUIDSYNTH_VERSION[\t ]+\"([^\"]*)\".*$" + "\\1" + FluidSynth_VERSION_STRING + "${_version_string}" + ) + unset(_version_string) + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(FluidSynth + REQUIRED_VARS FluidSynth_LIBRARY FluidSynth_INCLUDE_DIR + VERSION_VAR FluidSynth_VERSION_STRING +) diff --git a/plugins/Sf2Player/CMakeLists.txt b/plugins/Sf2Player/CMakeLists.txt index be21c0cf2ec..4679a94bda3 100644 --- a/plugins/Sf2Player/CMakeLists.txt +++ b/plugins/Sf2Player/CMakeLists.txt @@ -1,8 +1,13 @@ if(LMMS_HAVE_FLUIDSYNTH) - INCLUDE(BuildPlugin) - INCLUDE_DIRECTORIES(${FLUIDSYNTH_INCLUDE_DIRS} ${SAMPLERATE_INCLUDE_DIRS}) - LINK_DIRECTORIES(${FLUIDSYNTH_LIBRARY_DIRS} ${SAMPLERATE_LIBRARY_DIRS}) - LINK_LIBRARIES(${FLUIDSYNTH_LIBRARIES} ${SAMPLERATE_LIBRARIES}) - BUILD_PLUGIN(sf2player Sf2Player.cpp Sf2Player.h PatchesDialog.cpp PatchesDialog.h PatchesDialog.ui MOCFILES Sf2Player.h PatchesDialog.h UICFILES PatchesDialog.ui EMBEDDED_RESOURCES *.png) -endif(LMMS_HAVE_FLUIDSYNTH) - + include(BuildPlugin) + include_directories(${SAMPLERATE_INCLUDE_DIRS}) + link_directories(${SAMPLERATE_LIBRARY_DIRS}) + link_libraries(${SAMPLERATE_LIBRARIES}) + build_plugin(sf2player + Sf2Player.cpp Sf2Player.h PatchesDialog.cpp PatchesDialog.h PatchesDialog.ui + MOCFILES Sf2Player.h PatchesDialog.h + UICFILES PatchesDialog.ui + EMBEDDED_RESOURCES *.png + ) + target_link_libraries(sf2player fluidsynth) +endif() diff --git a/plugins/Sf2Player/Sf2Player.cpp b/plugins/Sf2Player/Sf2Player.cpp index dae94a33212..e339473d099 100644 --- a/plugins/Sf2Player/Sf2Player.cpp +++ b/plugins/Sf2Player/Sf2Player.cpp @@ -282,7 +282,7 @@ void Sf2Instrument::loadFile( const QString & _file ) fluid_preset_t preset; fluid_preset_t *pCurPreset = &preset; #else - fluid_preset_t *pCurPreset; + fluid_preset_t *pCurPreset = nullptr; #endif if ( ( pCurPreset = fluid_sfont_iteration_next_wrapper( pSoundFont, pCurPreset ) ) ) { @@ -475,7 +475,7 @@ QString Sf2Instrument::getCurrentPatchName() fluid_preset_t preset; fluid_preset_t *pCurPreset = &preset; #else - fluid_preset_t *pCurPreset; + fluid_preset_t *pCurPreset = nullptr; #endif while ((pCurPreset = fluid_sfont_iteration_next_wrapper(pSoundFont, pCurPreset))) { @@ -676,8 +676,13 @@ void Sf2Instrument::noteOn( Sf2PluginData * n ) // get list of current voice IDs so we can easily spot the new // voice after the fluid_synth_noteon() call const int poly = fluid_synth_get_polyphony( m_synth ); - fluid_voice_t * voices[poly]; +#ifndef _MSC_VER + fluid_voice_t* voices[poly]; unsigned int id[poly]; +#else + const auto voices = static_cast(_alloca(poly * sizeof(fluid_voice_t*))); + const auto id = static_cast(_alloca(poly * sizeof(unsigned int))); +#endif fluid_synth_get_voicelist( m_synth, voices, poly, -1 ); for( int i = 0; i < poly; ++i ) { From a529a1de3902b1aea454b6b3c5fb2aa9df8c6441 Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Sun, 28 Aug 2022 15:43:09 +0100 Subject: [PATCH 02/14] Enable building Mallets with MSVC The rawwaves directory is not yet installed; a more general fix is required to handle MinGW too. --- .github/workflows/build.yml | 3 ++- CMakeLists.txt | 32 ++++++++++++++++++-------- cmake/modules/FindSTK.cmake | 37 ++++++++++++++++-------------- plugins/Stk/Mallets/CMakeLists.txt | 12 ++++++---- plugins/Stk/Mallets/Mallets.cpp | 6 ++--- plugins/Stk/Mallets/Mallets.h | 2 +- 6 files changed, 56 insertions(+), 36 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9cdb7d10222..94ba0af7b8c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -223,7 +223,8 @@ jobs: - name: Install dependencies run: | vcpkg install --triplet ${{ matrix.arch }}-windows --recurse ` - fftw3 fluidsynth[sndfile] libsamplerate libsndfile lilv lv2 sdl2 + fftw3 fluidsynth[sndfile] libsamplerate libsndfile libstk lilv lv2 ` + sdl2 - name: Set up build environment uses: ilammy/msvc-dev-cmd@d8610e2b41c6d0f0c3b4c46dad8df0fd826c68e1 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index a67ee846fad..6b85360e292 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,6 +202,27 @@ CHECK_CXX_SOURCE_COMPILES( LMMS_HAVE_SF_COMPLEVEL ) +# Search for a target in a package using config mode first, then fall back to +# module mode. This allows us to use the package's own CMake configuration files +# if available. +# We use this macro instead of the CMAKE_FIND_PACKAGE_PREFER_CONFIG variable +# since some packages on some systems provide a config file that doesn't create +# a target, and some packages have unusual config file names. +macro(find_target_prefer_config PACKAGE_NAME TARGET_NAME) + if("${ARGC}" GREATER 2) + # Handle optional third argument specifying a config name different from + # the module name + find_package("${ARGV2}" CONFIG QUIET) + set("${PACKAGE_NAME}_FOUND" "${${ARGV2}_FOUND}") + else() + find_package("${PACKAGE_NAME}" CONFIG QUIET) + endif() + if(NOT TARGET "${TARGET_NAME}") + unset("${PACKAGE_NAME}_FOUND") + find_package("${PACKAGE_NAME}" MODULE) + endif() +endmacro() + IF(WANT_LV2) IF(PKG_CONFIG_FOUND) PKG_CHECK_MODULES(LV2 lv2) @@ -300,14 +321,7 @@ IF(WANT_SDL) # Don't look for SDL2main SET(SDL2_BUILDING_LIBRARY TRUE) - # Search for SDL2 using config mode first, then fall back to module mode. - # This allows us to use SDL2's own CMake configuration files if available. - FIND_PACKAGE(SDL2 CONFIG QUIET) - IF(NOT TARGET SDL2::SDL2) - UNSET(SDL2_FOUND) - FIND_PACKAGE(SDL2 MODULE) - ENDIF() - + find_target_prefer_config(SDL2 SDL2::SDL2) IF(SDL2_FOUND) SET(LMMS_HAVE_SDL TRUE) SET(LMMS_HAVE_SDL2 TRUE) @@ -343,7 +357,7 @@ ENDIF() # check for Stk IF(WANT_STK) - FIND_PACKAGE(STK) + find_target_prefer_config(STK unofficial::libstk::libstk unofficial-libstk) IF(STK_FOUND) SET(LMMS_HAVE_STK TRUE) SET(STATUS_STK "OK") diff --git a/cmake/modules/FindSTK.cmake b/cmake/modules/FindSTK.cmake index 6c2f16de4c6..756257d5b27 100644 --- a/cmake/modules/FindSTK.cmake +++ b/cmake/modules/FindSTK.cmake @@ -1,20 +1,23 @@ -FIND_PATH(STK_INCLUDE_DIR Stk.h /usr/include/stk /usr/local/include/stk ${CMAKE_INSTALL_PREFIX}/include/stk ${CMAKE_FIND_ROOT_PATH}/include/stk) +find_path(STK_INCLUDE_DIR + NAMES stk/Stk.h + PATH /usr/include/stk /usr/local/include/stk "${CMAKE_INSTALL_PREFIX}/include/stk" "${CMAKE_FIND_ROOT_PATH}/include/stk" +) -FIND_LIBRARY(STK_LIBRARY NAMES stk PATH /usr/lib /usr/local/lib ${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_FIND_ROOT_PATH}/lib) +find_library(STK_LIBRARY + NAMES stk + PATH /usr/lib /usr/local/lib "${CMAKE_INSTALL_PREFIX}/lib" "${CMAKE_FIND_ROOT_PATH}/lib" +) -IF (STK_INCLUDE_DIR AND STK_LIBRARY) - SET(STK_FOUND TRUE) -ENDIF (STK_INCLUDE_DIR AND STK_LIBRARY) - - -IF (STK_FOUND) - IF (NOT STK_FIND_QUIETLY) - MESSAGE(STATUS "Found STK: ${STK_LIBRARY}") - SET(HAVE_STK TRUE) - ENDIF (NOT STK_FIND_QUIETLY) -ELSE (STK_FOUND) - IF (STK_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find STK") - ENDIF (STK_FIND_REQUIRED) -ENDIF (STK_FOUND) +if(STK_INCLUDE_DIR AND STK_LIBRARY) + # Yes, this target name is hideous, but it matches that provided by vcpkg + add_library(unofficial::libstk::libstk UNKNOWN IMPORTED) + set_target_properties(unofficial::libstk::libstk PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${STK_INCLUDE_DIR}" + IMPORTED_LOCATION "${STK_LIBRARY}" + ) +endif() +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(STK + REQUIRED_VARS STK_LIBRARY STK_INCLUDE_DIR +) diff --git a/plugins/Stk/Mallets/CMakeLists.txt b/plugins/Stk/Mallets/CMakeLists.txt index a2b5ddf1dc0..77b7afff222 100644 --- a/plugins/Stk/Mallets/CMakeLists.txt +++ b/plugins/Stk/Mallets/CMakeLists.txt @@ -1,5 +1,7 @@ -INCLUDE(BuildPlugin) -INCLUDE_DIRECTORIES("${STK_INCLUDE_DIR}") -LINK_LIBRARIES(${STK_LIBRARY}) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions") -BUILD_PLUGIN(malletsstk Mallets.cpp Mallets.h MOCFILES Mallets.h EMBEDDED_RESOURCES artwork.png logo.png) +include(BuildPlugin) +build_plugin(malletsstk + Mallets.cpp Mallets.h + MOCFILES Mallets.h + EMBEDDED_RESOURCES artwork.png logo.png +) +target_link_libraries(malletsstk unofficial::libstk::libstk) diff --git a/plugins/Stk/Mallets/Mallets.cpp b/plugins/Stk/Mallets/Mallets.cpp index 6dcd8f56388..8b61e208d6c 100644 --- a/plugins/Stk/Mallets/Mallets.cpp +++ b/plugins/Stk/Mallets/Mallets.cpp @@ -30,9 +30,9 @@ #include #include -#include "BandedWG.h" -#include "ModalBar.h" -#include "TubeBell.h" +#include +#include +#include #include "AudioEngine.h" #include "ConfigManager.h" diff --git a/plugins/Stk/Mallets/Mallets.h b/plugins/Stk/Mallets/Mallets.h index 4d5aed28812..f66ac25d011 100644 --- a/plugins/Stk/Mallets/Mallets.h +++ b/plugins/Stk/Mallets/Mallets.h @@ -27,7 +27,7 @@ #ifndef _MALLET_H #define _MALLET_H -#include "Instrmnt.h" +#include #include "ComboBox.h" #include "Instrument.h" From 7490e9e45ea441ec7087e59d11c0ab07998dc464 Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Mon, 29 Aug 2022 21:30:05 +0100 Subject: [PATCH 03/14] Support PortAudio with MSVC --- .github/workflows/build.yml | 2 +- CMakeLists.txt | 8 ++-- cmake/modules/FindPortaudio.cmake | 61 +++++++++++++++++-------------- src/CMakeLists.txt | 11 +++--- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 94ba0af7b8c..8362c024b8b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -224,7 +224,7 @@ jobs: run: | vcpkg install --triplet ${{ matrix.arch }}-windows --recurse ` fftw3 fluidsynth[sndfile] libsamplerate libsndfile libstk lilv lv2 ` - sdl2 + portaudio sdl2 - name: Set up build environment uses: ilammy/msvc-dev-cmd@d8610e2b41c6d0f0c3b4c46dad8df0fd826c68e1 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b85360e292..6276bf5da84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -371,14 +371,14 @@ ENDIF(WANT_STK) # check for PortAudio IF(WANT_PORTAUDIO) - FIND_PACKAGE(Portaudio) - IF(PORTAUDIO_FOUND) + find_target_prefer_config(Portaudio portaudio portaudio) + IF(Portaudio_FOUND) SET(LMMS_HAVE_PORTAUDIO TRUE) SET(STATUS_PORTAUDIO "OK") - ELSE(PORTAUDIO_FOUND) + ELSE() SET(STATUS_PORTAUDIO "not found, please install portaudio19-dev (or similar, version >= 1.9) " "if you require PortAudio support") - ENDIF(PORTAUDIO_FOUND) + ENDIF() ENDIF(WANT_PORTAUDIO) # check for libsoundio diff --git a/cmake/modules/FindPortaudio.cmake b/cmake/modules/FindPortaudio.cmake index bb6bdf48b24..3c0fb8fd0bc 100644 --- a/cmake/modules/FindPortaudio.cmake +++ b/cmake/modules/FindPortaudio.cmake @@ -1,36 +1,41 @@ -# - Try to find Portaudio -# Once done this will define -# -# PORTAUDIO_FOUND - system has Portaudio -# PORTAUDIO_INCLUDE_DIRS - the Portaudio include directory -# PORTAUDIO_LIBRARIES - Link these to use Portaudio -# PORTAUDIO_DEFINITIONS - Compiler switches required for using Portaudio -# -# Copyright (c) 2006 Andreas Schneider +# Copyright (c) 2022 Dominic Clark # # Redistribution and use is allowed according to the terms of the New BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# +# Return if we already have PortAudio +if(TARGET portaudio) + set(Portaudio_FOUND 1) + return() +endif() + +# Attempt to find PortAudio using PkgConfig, if we have it +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PORTAUDIO_PKG portaudio-2.0) +endif() -if (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) - # in cache already - set(PORTAUDIO_FOUND TRUE) -else (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) - include(FindPkgConfig) - pkg_check_modules(PORTAUDIO portaudio-2.0) - if (PORTAUDIO_FOUND) - if (NOT Portaudio_FIND_QUIETLY) - message(STATUS "Found Portaudio: ${PORTAUDIO_LIBRARIES}") - endif (NOT Portaudio_FIND_QUIETLY) - else (PORTAUDIO_FOUND) - if (Portaudio_FIND_REQUIRED) - message(FATAL_ERROR "Could not find Portaudio") - endif (Portaudio_FIND_REQUIRED) - endif (PORTAUDIO_FOUND) +# Find the library and headers using the results from PkgConfig as a guide +find_library(Portaudio_LIBRARY + NAMES "portaudio" + HINTS ${PORTAUDIO_PKG_LIBRARY_DIRS} +) - # show the PORTAUDIO_INCLUDE_DIRS and PORTAUDIO_LIBRARIES variables only in the advanced view - mark_as_advanced(PORTAUDIO_INCLUDE_DIRS PORTAUDIO_LIBRARIES) +find_path(Portaudio_INCLUDE_DIR + NAMES "portaudio.h" + HINTS ${PORTAUDIO_PKG_INCLUDE_DIRS} +) -endif (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) +# Create an imported target for PortAudio if we succeeded in finding it. +if(Portaudio_LIBRARY AND Portaudio_INCLUDE_DIR) + add_library(portaudio UNKNOWN IMPORTED) + set_target_properties(portaudio PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Portaudio_INCLUDE_DIR}" + IMPORTED_LOCATION "${Portaudio_LIBRARY}" + ) +endif() +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Portaudio + REQUIRED_VARS Portaudio_LIBRARY Portaudio_INCLUDE_DIR +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f8a0dfcb8c..d081ab86689 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,7 +55,7 @@ ADD_GEN_QRC(LMMS_RCC_OUT lmms.qrc # Paths relative to lmms executable FILE(RELATIVE_PATH LIB_DIR_RELATIVE "/${BIN_DIR}" "/${LIB_DIR}") FILE(RELATIVE_PATH PLUGIN_DIR_RELATIVE "/${BIN_DIR}" "/${PLUGIN_DIR}") -ADD_DEFINITIONS(-DLIB_DIR="${LIB_DIR_RELATIVE}" -DPLUGIN_DIR="${PLUGIN_DIR_RELATIVE}" ${PULSEAUDIO_DEFINITIONS} ${PORTAUDIO_DEFINITIONS}) +ADD_DEFINITIONS(-DLIB_DIR="${LIB_DIR_RELATIVE}" -DPLUGIN_DIR="${PLUGIN_DIR_RELATIVE}" ${PULSEAUDIO_DEFINITIONS}) INCLUDE_DIRECTORIES( ${JACK_INCLUDE_DIRS} ${SAMPLERATE_INCLUDE_DIRS} @@ -75,10 +75,6 @@ IF(LMMS_HAVE_WEAKJACK) ADD_DEFINITIONS(-DUSE_WEAK_JACK=1 -DNO_JACK_METADATA=1) ENDIF() -IF(NOT ("${PORTAUDIO_INCLUDE_DIR}" STREQUAL "")) - INCLUDE_DIRECTORIES("${PORTAUDIO_INCLUDE_DIR}") -ENDIF() - IF(NOT ("${PULSEAUDIO_INCLUDE_DIR}" STREQUAL "")) INCLUDE_DIRECTORIES("${PULSEAUDIO_INCLUDE_DIR}") ENDIF() @@ -170,13 +166,16 @@ if(LMMS_HAVE_LIBRT) list(APPEND EXTRA_LIBRARIES "rt") endif() +if(LMMS_HAVE_PORTAUDIO) + list(APPEND EXTRA_LIBRARIES portaudio) +endif() + SET(LMMS_REQUIRED_LIBS ${LMMS_REQUIRED_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${QT_LIBRARIES} ${ASOUND_LIBRARY} ${SDL_LIBRARY} ${SDL2_LIBRARY} - ${PORTAUDIO_LIBRARIES} ${SOUNDIO_LIBRARY} ${SNDIO_LIBRARIES} ${PULSEAUDIO_LIBRARIES} From 671e0e65f00b5c35d65d8340c041008a3fcaef9d Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Tue, 30 Aug 2022 10:04:02 +0100 Subject: [PATCH 04/14] Set sndio status for Windows builds --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6276bf5da84..7720ae9bf7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,7 @@ IF(LMMS_BUILD_WIN32) SET(STATUS_ALSA "") SET(STATUS_PULSEAUDIO "") SET(STATUS_SOUNDIO "") + SET(STATUS_SNDIO "") SET(STATUS_WINMM "OK") SET(STATUS_APPLEMIDI "") ELSE(LMMS_BUILD_WIN32) From bade02d41000787db77b2d1e489ce5950822944a Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Wed, 31 Aug 2022 22:40:44 +0100 Subject: [PATCH 05/14] Clean up FindSDL2.cmake * Remove change log * Remove SDL2main target * Remove debug code * Convert commands to lowercase * Remove arguments from else/endif * Tweak formatting --- cmake/modules/FindSDL2.cmake | 135 ++++++++--------------------------- 1 file changed, 28 insertions(+), 107 deletions(-) diff --git a/cmake/modules/FindSDL2.cmake b/cmake/modules/FindSDL2.cmake index 513578813a2..879d23c0fac 100644 --- a/cmake/modules/FindSDL2.cmake +++ b/cmake/modules/FindSDL2.cmake @@ -1,60 +1,20 @@ # This module defines # SDL2::SDL2, a target providing SDL2 itself -# SDL2::SDL2main, a target providing an entry point for applications # SDL2_LIBRARY, the name of the library to link against # SDL2_FOUND, if false, do not try to link to SDL2 # SDL2_INCLUDE_DIR, where to find SDL.h # -# This module responds to the the flag: -# SDL2_BUILDING_LIBRARY -# If this is defined, then no SDL2::SDL2main target will be created because -# only applications need main(). -# Otherwise, it is assumed you are building an application and this -# module will attempt to locate and set the the proper link flags -# as part of the SDL2::SDL2main target. -# -# Don't forget to include SDLmain.h and SDLmain.m your project for the -# OS X framework based version. (Other versions link to -lSDL2main which -# this module will try to find on your behalf.) Also for OS X, this -# module will automatically add the -framework Cocoa on your behalf. -# -# -# Additional Note: If you see an empty SDL2_LIBRARY in your configuration, it -# means CMake did not find your SDL2 library (SDL2.dll, libsdl2.so, -# SDL2.framework, etc). -# Set SDL2_LIBRARY to point to your SDL2 library, and configure again. -# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value -# as appropriate. -# -# -# Modified by Dominic Clark. -# Added modern CMake targets to match those SDL2 itself uses. +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. # # $SDL2DIR is an environment variable that would # correspond to the ./configure --prefix=$SDL2DIR # used in building SDL2. -# l.e.galup 9-20-02 -# -# Modified by Eric Wing. -# Added code to assist with automated building by using environmental variables -# and providing a more controlled/consistent search behavior. -# Added new modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). -# Also corrected the header search path to follow "proper" SDL guidelines. -# Added a search for SDL2main which is needed by some platforms. -# Added a search for threads which is needed by some platforms. -# Added needed compile switches for MinGW. # -# On OSX, this will prefer the Framework version (if found) over others. -# People will have to manually change the cache values of -# SDL2_LIBRARY to override this selection or set the CMake environment -# CMAKE_INCLUDE_PATH to modify the search paths. +# Modified by Eric Wing, l.e.galup, and Dominic Clark # -# Note that the header path has changed from SDL2/SDL.h to just SDL.h -# This needed to change because "proper" SDL convention -# is #include "SDL.h", not . This is done for portability -# reasons because not all systems place things in SDL2/ (see FreeBSD). - #============================================================================= # Copyright 2003-2009 Kitware, Inc. # @@ -68,9 +28,7 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -# message("") - -SET(SDL2_SEARCH_PATHS +set(SDL2_SEARCH_PATHS ~/Library/Frameworks /Library/Frameworks /usr/local @@ -82,9 +40,9 @@ SET(SDL2_SEARCH_PATHS ${SDL2_PATH} ) -FIND_PATH(SDL2_INCLUDE_DIR SDL.h - HINTS - $ENV{SDL2DIR} +find_path(SDL2_INCLUDE_DIR + NAMES SDL.h + HINTS $ENV{SDL2DIR} PATH_SUFFIXES SDL2 include/SDL2 include PATHS ${SDL2_SEARCH_PATHS} ) @@ -95,83 +53,46 @@ else() set(PATH_SUFFIXES lib/x86 lib) endif() -FIND_LIBRARY(SDL2_LIBRARY +find_library(SDL2_LIBRARY NAMES SDL2 - HINTS - $ENV{SDL2DIR} + HINTS $ENV{SDL2DIR} PATH_SUFFIXES ${PATH_SUFFIXES} PATHS ${SDL2_SEARCH_PATHS} ) -IF(NOT SDL2_BUILDING_LIBRARY) - IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") - # Non-OS X framework versions expect you to also dynamically link to - # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms - # seem to provide SDL2main for compatibility even though they don't - # necessarily need it. - FIND_LIBRARY(SDL2MAIN_LIBRARY - NAMES SDL2main - HINTS - $ENV{SDL2DIR} - PATH_SUFFIXES ${PATH_SUFFIXES} - PATHS ${SDL2_SEARCH_PATHS} - ) - ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") -ENDIF(NOT SDL2_BUILDING_LIBRARY) - # SDL2 may require threads on your system. # The Apple build may not need an explicit flag because one of the # frameworks may already provide it. # But for non-OSX systems, I will use the CMake Threads package. -IF(NOT APPLE) - FIND_PACKAGE(Threads) -ENDIF(NOT APPLE) - -# MinGW needs an additional link flag, -mwindows -# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows -IF(MINGW) - SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW") -ENDIF(MINGW) +if(NOT APPLE) + find_package(Threads) +endif() -IF(SDL2_LIBRARY) - ADD_LIBRARY(SDL2::SDL2 UNKNOWN IMPORTED) - SET_TARGET_PROPERTIES(SDL2::SDL2 PROPERTIES +if(SDL2_LIBRARY) + add_library(SDL2::SDL2 UNKNOWN IMPORTED) + set_target_properties(SDL2::SDL2 PROPERTIES IMPORTED_LOCATION "${SDL2_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" ) # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. - IF(APPLE) - SET_PROPERTY(TARGET SDL2::SDL2 APPEND PROPERTY + if(APPLE) + set_property(TARGET SDL2::SDL2 APPEND PROPERTY INTERFACE_LINK_OPTIONS "-framework Cocoa" ) - ENDIF(APPLE) + endif() # For threads, as mentioned Apple doesn't need this. # In fact, there seems to be a problem if I used the Threads package # and try using this line, so I'm just skipping it entirely for OS X. - IF(NOT APPLE AND Threads_FOUND) - SET_PROPERTY(TARGET SDL2::SDL2 APPEND PROPERTY + if(NOT APPLE AND Threads_FOUND) + set_property(TARGET SDL2::SDL2 APPEND PROPERTY INTERFACE_LINK_LIBRARIES "Threads::Threads" ) - ENDIF(NOT APPLE AND Threads_FOUND) -ENDIF(SDL2_LIBRARY) + endif() +endif() -IF(NOT SDL2_BUILDING_LIBRARY AND SDL2MAIN_LIBRARY) - ADD_LIBRARY(SDL2::SDL2main STATIC IMPORTED) - SET_TARGET_PROPERTIES(SDL2::SDL2main PROPERTIES - IMPORTED_LOCATION "${SDL2MAIN_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" - ) - IF(MINGW) - SET_PROPERTY(TARGET SDL2::SDL2main APPEND PROPERTY - INTERFACE_LINK_OPTIONS "${MINGW32_LIBRARY}" - ) - ENDIF(MINGW) -ENDIF(NOT SDL2_BUILDING_LIBRARY AND SDL2MAIN_LIBRARY) - -# message("") - -INCLUDE(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL2 + REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR +) From 1593b67b46eeec883e62dec3b2f6b316d4b06872 Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Thu, 1 Sep 2022 18:18:09 +0100 Subject: [PATCH 06/14] Move config mode logic from CMakeLists to modules --- CMakeLists.txt | 30 +------- cmake/modules/FindPortaudio.cmake | 55 +++++++------- cmake/modules/FindSDL2.cmake | 114 ++++++++++++++++-------------- cmake/modules/FindSTK.cmake | 37 ++++++---- 4 files changed, 117 insertions(+), 119 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7720ae9bf7a..025edf3b005 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,27 +203,6 @@ CHECK_CXX_SOURCE_COMPILES( LMMS_HAVE_SF_COMPLEVEL ) -# Search for a target in a package using config mode first, then fall back to -# module mode. This allows us to use the package's own CMake configuration files -# if available. -# We use this macro instead of the CMAKE_FIND_PACKAGE_PREFER_CONFIG variable -# since some packages on some systems provide a config file that doesn't create -# a target, and some packages have unusual config file names. -macro(find_target_prefer_config PACKAGE_NAME TARGET_NAME) - if("${ARGC}" GREATER 2) - # Handle optional third argument specifying a config name different from - # the module name - find_package("${ARGV2}" CONFIG QUIET) - set("${PACKAGE_NAME}_FOUND" "${${ARGV2}_FOUND}") - else() - find_package("${PACKAGE_NAME}" CONFIG QUIET) - endif() - if(NOT TARGET "${TARGET_NAME}") - unset("${PACKAGE_NAME}_FOUND") - find_package("${PACKAGE_NAME}" MODULE) - endif() -endmacro() - IF(WANT_LV2) IF(PKG_CONFIG_FOUND) PKG_CHECK_MODULES(LV2 lv2) @@ -319,10 +298,7 @@ ENDIF(WANT_CARLA) # check for SDL2 IF(WANT_SDL) - # Don't look for SDL2main - SET(SDL2_BUILDING_LIBRARY TRUE) - - find_target_prefer_config(SDL2 SDL2::SDL2) + FIND_PACKAGE(SDL2) IF(SDL2_FOUND) SET(LMMS_HAVE_SDL TRUE) SET(LMMS_HAVE_SDL2 TRUE) @@ -358,7 +334,7 @@ ENDIF() # check for Stk IF(WANT_STK) - find_target_prefer_config(STK unofficial::libstk::libstk unofficial-libstk) + FIND_PACKAGE(STK) IF(STK_FOUND) SET(LMMS_HAVE_STK TRUE) SET(STATUS_STK "OK") @@ -372,7 +348,7 @@ ENDIF(WANT_STK) # check for PortAudio IF(WANT_PORTAUDIO) - find_target_prefer_config(Portaudio portaudio portaudio) + FIND_PACKAGE(Portaudio) IF(Portaudio_FOUND) SET(LMMS_HAVE_PORTAUDIO TRUE) SET(STATUS_PORTAUDIO "OK") diff --git a/cmake/modules/FindPortaudio.cmake b/cmake/modules/FindPortaudio.cmake index 3c0fb8fd0bc..f9c7699f451 100644 --- a/cmake/modules/FindPortaudio.cmake +++ b/cmake/modules/FindPortaudio.cmake @@ -3,36 +3,39 @@ # Redistribution and use is allowed according to the terms of the New BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# Return if we already have PortAudio -if(TARGET portaudio) - set(Portaudio_FOUND 1) - return() -endif() +# Try config mode if possible +find_package(portaudio CONFIG QUIET) -# Attempt to find PortAudio using PkgConfig, if we have it -find_package(PkgConfig QUIET) -if(PKG_CONFIG_FOUND) - pkg_check_modules(PORTAUDIO_PKG portaudio-2.0) -endif() - -# Find the library and headers using the results from PkgConfig as a guide -find_library(Portaudio_LIBRARY - NAMES "portaudio" - HINTS ${PORTAUDIO_PKG_LIBRARY_DIRS} -) +if(TARGET portaudio) + # Extract details for find_package_handle_standard_args + get_target_property(Portaudio_LIBRARY portaudio LOCATION) + get_target_property(Portaudio_INCLUDE_DIR portaudio INTERFACE_INCLUDE_DIRECTORIES) +else() + # Attempt to find PortAudio using PkgConfig, if we have it + find_package(PkgConfig QUIET) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PORTAUDIO_PKG portaudio-2.0) + endif() -find_path(Portaudio_INCLUDE_DIR - NAMES "portaudio.h" - HINTS ${PORTAUDIO_PKG_INCLUDE_DIRS} -) + # Find the library and headers using the results from PkgConfig as a guide + find_library(Portaudio_LIBRARY + NAMES "portaudio" + HINTS ${PORTAUDIO_PKG_LIBRARY_DIRS} + ) -# Create an imported target for PortAudio if we succeeded in finding it. -if(Portaudio_LIBRARY AND Portaudio_INCLUDE_DIR) - add_library(portaudio UNKNOWN IMPORTED) - set_target_properties(portaudio PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${Portaudio_INCLUDE_DIR}" - IMPORTED_LOCATION "${Portaudio_LIBRARY}" + find_path(Portaudio_INCLUDE_DIR + NAMES "portaudio.h" + HINTS ${PORTAUDIO_PKG_INCLUDE_DIRS} ) + + # Create an imported target for PortAudio if we succeeded in finding it. + if(Portaudio_LIBRARY AND Portaudio_INCLUDE_DIR) + add_library(portaudio UNKNOWN IMPORTED) + set_target_properties(portaudio PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Portaudio_INCLUDE_DIR}" + IMPORTED_LOCATION "${Portaudio_LIBRARY}" + ) + endif() endif() include(FindPackageHandleStandardArgs) diff --git a/cmake/modules/FindSDL2.cmake b/cmake/modules/FindSDL2.cmake index 879d23c0fac..eb3b4e4677a 100644 --- a/cmake/modules/FindSDL2.cmake +++ b/cmake/modules/FindSDL2.cmake @@ -28,67 +28,77 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -set(SDL2_SEARCH_PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /sw # Fink - /opt/local # DarwinPorts - /opt/csw # Blastwave - /opt - ${SDL2_PATH} -) - -find_path(SDL2_INCLUDE_DIR - NAMES SDL.h - HINTS $ENV{SDL2DIR} - PATH_SUFFIXES SDL2 include/SDL2 include - PATHS ${SDL2_SEARCH_PATHS} -) +# Try config mode first - anything SDL2 itself provides is likely to be more +# reliable than our guesses. +find_package(SDL2 CONFIG QUIET) -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(PATH_SUFFIXES lib64 lib/x64 lib) -else() - set(PATH_SUFFIXES lib/x86 lib) -endif() +if(TARGET SDL2::SDL2) + # Extract details for find_package_handle_standard_args + get_target_property(SDL2_LIBRARY SDL2::SDL2 LOCATION) + get_target_property(SDL2_INCLUDE_DIR SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES) +else() + set(SDL2_SEARCH_PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ${SDL2_PATH} + ) -find_library(SDL2_LIBRARY - NAMES SDL2 - HINTS $ENV{SDL2DIR} - PATH_SUFFIXES ${PATH_SUFFIXES} - PATHS ${SDL2_SEARCH_PATHS} -) + find_path(SDL2_INCLUDE_DIR + NAMES SDL.h + HINTS $ENV{SDL2DIR} + PATH_SUFFIXES SDL2 include/SDL2 include + PATHS ${SDL2_SEARCH_PATHS} + ) -# SDL2 may require threads on your system. -# The Apple build may not need an explicit flag because one of the -# frameworks may already provide it. -# But for non-OSX systems, I will use the CMake Threads package. -if(NOT APPLE) - find_package(Threads) -endif() + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(PATH_SUFFIXES lib64 lib/x64 lib) + else() + set(PATH_SUFFIXES lib/x86 lib) + endif() -if(SDL2_LIBRARY) - add_library(SDL2::SDL2 UNKNOWN IMPORTED) - set_target_properties(SDL2::SDL2 PROPERTIES - IMPORTED_LOCATION "${SDL2_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" + find_library(SDL2_LIBRARY + NAMES SDL2 + HINTS $ENV{SDL2DIR} + PATH_SUFFIXES ${PATH_SUFFIXES} + PATHS ${SDL2_SEARCH_PATHS} ) - # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. - if(APPLE) - set_property(TARGET SDL2::SDL2 APPEND PROPERTY - INTERFACE_LINK_OPTIONS "-framework Cocoa" - ) + # SDL2 may require threads on your system. + # The Apple build may not need an explicit flag because one of the + # frameworks may already provide it. + # But for non-OSX systems, I will use the CMake Threads package. + if(NOT APPLE) + find_package(Threads) endif() - # For threads, as mentioned Apple doesn't need this. - # In fact, there seems to be a problem if I used the Threads package - # and try using this line, so I'm just skipping it entirely for OS X. - if(NOT APPLE AND Threads_FOUND) - set_property(TARGET SDL2::SDL2 APPEND PROPERTY - INTERFACE_LINK_LIBRARIES "Threads::Threads" + if(SDL2_LIBRARY) + add_library(SDL2::SDL2 UNKNOWN IMPORTED) + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" ) + + # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. + if(APPLE) + set_property(TARGET SDL2::SDL2 APPEND PROPERTY + INTERFACE_LINK_OPTIONS "-framework Cocoa" + ) + endif() + + # For threads, as mentioned Apple doesn't need this. + # In fact, there seems to be a problem if I used the Threads package + # and try using this line, so I'm just skipping it entirely for OS X. + if(NOT APPLE AND Threads_FOUND) + set_property(TARGET SDL2::SDL2 APPEND PROPERTY + INTERFACE_LINK_LIBRARIES "Threads::Threads" + ) + endif() endif() endif() diff --git a/cmake/modules/FindSTK.cmake b/cmake/modules/FindSTK.cmake index 756257d5b27..80ed0da42f8 100644 --- a/cmake/modules/FindSTK.cmake +++ b/cmake/modules/FindSTK.cmake @@ -1,20 +1,29 @@ -find_path(STK_INCLUDE_DIR - NAMES stk/Stk.h - PATH /usr/include/stk /usr/local/include/stk "${CMAKE_INSTALL_PREFIX}/include/stk" "${CMAKE_FIND_ROOT_PATH}/include/stk" -) +# Try config mode first +find_package(unofficial-libstk CONFIG QUIET) -find_library(STK_LIBRARY - NAMES stk - PATH /usr/lib /usr/local/lib "${CMAKE_INSTALL_PREFIX}/lib" "${CMAKE_FIND_ROOT_PATH}/lib" -) +if(TARGET unofficial::libstk::libstk) + # Extract details for find_package_handle_standard_args + get_target_property(STK_LIBRARY unofficial::libstk::libstk LOCATION) + get_target_property(STK_INCLUDE_DIR unofficial::libstk::libstk INTERFACE_INCLUDE_DIRECTORIES) +else() + find_path(STK_INCLUDE_DIR + NAMES stk/Stk.h + PATH /usr/include /usr/local/include "${CMAKE_INSTALL_PREFIX}/include" "${CMAKE_FIND_ROOT_PATH}/include" + ) -if(STK_INCLUDE_DIR AND STK_LIBRARY) - # Yes, this target name is hideous, but it matches that provided by vcpkg - add_library(unofficial::libstk::libstk UNKNOWN IMPORTED) - set_target_properties(unofficial::libstk::libstk PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${STK_INCLUDE_DIR}" - IMPORTED_LOCATION "${STK_LIBRARY}" + find_library(STK_LIBRARY + NAMES stk + PATH /usr/lib /usr/local/lib "${CMAKE_INSTALL_PREFIX}/lib" "${CMAKE_FIND_ROOT_PATH}/lib" ) + + if(STK_INCLUDE_DIR AND STK_LIBRARY) + # Yes, this target name is hideous, but it matches that provided by vcpkg + add_library(unofficial::libstk::libstk UNKNOWN IMPORTED) + set_target_properties(unofficial::libstk::libstk PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${STK_INCLUDE_DIR}" + IMPORTED_LOCATION "${STK_LIBRARY}" + ) + endif() endif() include(FindPackageHandleStandardArgs) From 0474791badcfa71b78b9aa4daa7458fe06b0bdbe Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Thu, 1 Sep 2022 18:28:34 +0100 Subject: [PATCH 07/14] Support LAME with MSVC --- cmake/modules/FindLame.cmake | 39 +++++++++++++++++++++++++++--------- src/CMakeLists.txt | 9 ++++----- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/cmake/modules/FindLame.cmake b/cmake/modules/FindLame.cmake index e5dc93bd5a7..bad06dd0853 100644 --- a/cmake/modules/FindLame.cmake +++ b/cmake/modules/FindLame.cmake @@ -1,16 +1,37 @@ # - Try to find LAME # Once done this will define # -# LAME_FOUND - system has liblame -# LAME_INCLUDE_DIRS - the liblame include directory -# LAME_LIBRARIES - The liblame libraries +# Lame_FOUND - system has liblame +# Lame_INCLUDE_DIRS - the liblame include directory +# Lame_LIBRARIES - The liblame libraries +# mp3lame::mp3lame - an imported target providing lame -find_path(LAME_INCLUDE_DIRS lame/lame.h) -find_library(LAME_LIBRARIES mp3lame) +find_package(mp3lame CONFIG QUIET) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Lame DEFAULT_MSG LAME_INCLUDE_DIRS LAME_LIBRARIES) +if(TARGET mp3lame::mp3lame) + # Extract details for find_package_handle_standard_args + get_target_property(Lame_LIBRARIES mp3lame::mp3lame LOCATION) + get_target_property(Lame_INCLUDE_DIRS mp3lame::mp3lame INTERFACE_INCLUDE_DIRECTORIES) +else() + find_path(Lame_INCLUDE_DIRS lame/lame.h) + find_library(Lame_LIBRARIES mp3lame) + + list(APPEND Lame_DEFINITIONS -DHAVE_LIBMP3LAME=1) + + mark_as_advanced(Lame_INCLUDE_DIRS Lame_LIBRARIES Lame_DEFINITIONS) -list(APPEND LAME_DEFINITIONS -DHAVE_LIBMP3LAME=1) + if(Lame_LIBRARIES AND Lame_INCLUDE_DIRS) + add_library(mp3lame::mp3lame UNKNOWN IMPORTED) -mark_as_advanced(LAME_INCLUDE_DIRS LAME_LIBRARIES LAME_DEFINITIONS) + set_target_properties(mp3lame::mp3lame PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Lame_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${Lame_DEFINITIONS}" + IMPORTED_LOCATION "${Lame_LIBRARIES}" + ) + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Lame + REQUIRED_VARS Lame_LIBRARIES Lame_INCLUDE_DIRS +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d081ab86689..bd543779fb0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -83,10 +83,6 @@ IF(NOT ("${OGGVORBIS_INCLUDE_DIR}" STREQUAL "")) INCLUDE_DIRECTORIES("${OGGVORBIS_INCLUDE_DIR}") ENDIF() -IF(NOT ("${LAME_INCLUDE_DIRS}" STREQUAL "")) - INCLUDE_DIRECTORIES("${LAME_INCLUDE_DIRS}") -ENDIF() - IF(NOT ("${LV2_INCLUDE_DIRS}" STREQUAL "")) INCLUDE_DIRECTORIES(${LV2_INCLUDE_DIRS}) ENDIF() @@ -170,6 +166,10 @@ if(LMMS_HAVE_PORTAUDIO) list(APPEND EXTRA_LIBRARIES portaudio) endif() +if(LMMS_HAVE_MP3LAME) + list(APPEND EXTRA_LIBRARIES mp3lame::mp3lame) +endif() + SET(LMMS_REQUIRED_LIBS ${LMMS_REQUIRED_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${QT_LIBRARIES} @@ -181,7 +181,6 @@ SET(LMMS_REQUIRED_LIBS ${LMMS_REQUIRED_LIBS} ${PULSEAUDIO_LIBRARIES} ${JACK_LIBRARIES} ${OGGVORBIS_LIBRARIES} - ${LAME_LIBRARIES} ${LV2_LIBRARIES} ${SUIL_LIBRARIES} ${LILV_LIBRARIES} From ae936965ce761268a1455e626cf6f58c58499f5c Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Thu, 1 Sep 2022 18:36:41 +0100 Subject: [PATCH 08/14] Use UNKNOWN imported library type for FluidSynth --- cmake/modules/FindFluidSynth.cmake | 32 +++++++++++++----------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/cmake/modules/FindFluidSynth.cmake b/cmake/modules/FindFluidSynth.cmake index 259ddf96ac4..f516d50c1fc 100644 --- a/cmake/modules/FindFluidSynth.cmake +++ b/cmake/modules/FindFluidSynth.cmake @@ -85,29 +85,25 @@ function(_get_vcpkg_library_configs _release_out _debug_out _library) endfunction() if(FluidSynth_INCLUDE_DIR AND FluidSynth_LIBRARY) - add_library(fluidsynth SHARED IMPORTED) + add_library(fluidsynth UNKNOWN IMPORTED) set_target_properties(fluidsynth PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FluidSynth_INCLUDE_DIR}" ) - if(WIN32) - if(VCPKG_INSTALLED_DIR) - _get_vcpkg_library_configs(FluidSynth_IMPLIB_RELEASE FluidSynth_IMPLIB_DEBUG "${FluidSynth_LIBRARY}") - else() - set(FluidSynth_IMPLIB_RELEASE "${FluidSynth_LIBRARY}") - endif() - if(FluidSynth_IMPLIB_DEBUG) - set_target_properties(fluidsynth PROPERTIES - IMPORTED_IMPLIB_RELEASE "${FluidSynth_IMPLIB_RELEASE}" - IMPORTED_IMPLIB_DEBUG "${FluidSynth_IMPLIB_DEBUG}" - ) - else() - set_target_properties(fluidsynth PROPERTIES - IMPORTED_IMPLIB "${FluidSynth_IMPLIB_RELEASE}" - ) - endif() + + if(VCPKG_INSTALLED_DIR) + _get_vcpkg_library_configs(FluidSynth_IMPLIB_RELEASE FluidSynth_IMPLIB_DEBUG "${FluidSynth_LIBRARY}") + else() + set(FluidSynth_IMPLIB_RELEASE "${FluidSynth_LIBRARY}") + endif() + + if(FluidSynth_IMPLIB_DEBUG) + set_target_properties(fluidsynth PROPERTIES + IMPORTED_LOCATION_RELEASE "${FluidSynth_IMPLIB_RELEASE}" + IMPORTED_LOCATION_DEBUG "${FluidSynth_IMPLIB_DEBUG}" + ) else() set_target_properties(fluidsynth PROPERTIES - IMPORTED_LOCATION "${FluidSynth_LIBRARY}" + IMPORTED_LOCATION "${FluidSynth_IMPLIB_RELEASE}" ) endif() From f655b2ceec5794da30e696b46e79a9bd9b35451a Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Thu, 1 Sep 2022 18:46:30 +0100 Subject: [PATCH 09/14] Move vcpkg config helper function to new module --- cmake/modules/FindFluidSynth.cmake | 59 +---------------------- cmake/modules/ImportedTargetHelpers.cmake | 57 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 cmake/modules/ImportedTargetHelpers.cmake diff --git a/cmake/modules/FindFluidSynth.cmake b/cmake/modules/FindFluidSynth.cmake index f516d50c1fc..fcc00cd7d0e 100644 --- a/cmake/modules/FindFluidSynth.cmake +++ b/cmake/modules/FindFluidSynth.cmake @@ -26,64 +26,6 @@ find_library(FluidSynth_LIBRARY HINTS ${FLUIDSYNTH_PKG_LIBRARY_DIRS} ) -# Given a library in vcpkg, find appropriate debug and release versions. If only -# one version exists, it is used as the release version, and the debug version -# is not set. -function(_get_vcpkg_library_configs _release_out _debug_out _library) - # We want to do all operations within the vcpkg directory - file(RELATIVE_PATH _lib_relative "${VCPKG_INSTALLED_DIR}" "${_library}") - - # Return early if we're not using vcpkg - if(IS_ABSOLUTE _lib_relative OR _lib_relative MATCHES "^\\.\\./") - set("${_release_out}" "${_library}" PARENT_SCOPE) - return() - endif() - - string(REPLACE "/" ";" _path_bits "${_lib_relative}") - - # Determine whether we were given the debug or release version - list(FIND _path_bits "debug" _debug_index) - if(_debug_index EQUAL -1) - # We have the release version, so use it - set(_release_lib "${_library}") - - # Try to find a debug version too - list(FIND _path_bits "lib" _lib_index) - if(_lib_index GREATER_EQUAL 0) - list(INSERT _path_bits "${_lib_index}" "debug") - list(INSERT _path_bits 0 "${VCPKG_INSTALLED_DIR}") - string(REPLACE ";" "/" _debug_lib "${_path_bits}") - - if(NOT EXISTS "${_debug_lib}") - # Debug version does not exist - only use given version - unset(_debug_lib) - endif() - endif() - else() - # We have the debug version, so try to find a release version too - list(REMOVE_AT _path_bits "${_debug_index}") - list(INSERT _path_bits 0 "${VCPKG_INSTALLED_DIR}") - string(REPLACE ";" "/" _release_lib "${_path_bits}") - - if(NOT EXISTS "${_release_lib}") - # Release version does not exist - only use given version - set(_release_lib "${_library}") - else() - # Release version exists, so use given version as debug - set(_debug_lib "${_library}") - endif() - endif() - - # Set output variables appropriately - if(_debug_lib) - set("${_release_out}" "${_release_lib}" PARENT_SCOPE) - set("${_debug_out}" "${_debug_lib}" PARENT_SCOPE) - else() - set("${_release_out}" "${_release_lib}" PARENT_SCOPE) - unset("${_debug_out}" PARENT_SCOPE) - endif() -endfunction() - if(FluidSynth_INCLUDE_DIR AND FluidSynth_LIBRARY) add_library(fluidsynth UNKNOWN IMPORTED) set_target_properties(fluidsynth PROPERTIES @@ -91,6 +33,7 @@ if(FluidSynth_INCLUDE_DIR AND FluidSynth_LIBRARY) ) if(VCPKG_INSTALLED_DIR) + include(ImportedTargetHelpers) _get_vcpkg_library_configs(FluidSynth_IMPLIB_RELEASE FluidSynth_IMPLIB_DEBUG "${FluidSynth_LIBRARY}") else() set(FluidSynth_IMPLIB_RELEASE "${FluidSynth_LIBRARY}") diff --git a/cmake/modules/ImportedTargetHelpers.cmake b/cmake/modules/ImportedTargetHelpers.cmake new file mode 100644 index 00000000000..87b3aeedc33 --- /dev/null +++ b/cmake/modules/ImportedTargetHelpers.cmake @@ -0,0 +1,57 @@ +# Given a library in vcpkg, find appropriate debug and release versions. If only +# one version exists, it is used as the release version, and the debug version +# is not set. +function(_get_vcpkg_library_configs _release_out _debug_out _library) + # We want to do all operations within the vcpkg directory + file(RELATIVE_PATH _lib_relative "${VCPKG_INSTALLED_DIR}" "${_library}") + + # Return early if we're not using vcpkg + if(IS_ABSOLUTE _lib_relative OR _lib_relative MATCHES "^\\.\\./") + set("${_release_out}" "${_library}" PARENT_SCOPE) + return() + endif() + + string(REPLACE "/" ";" _path_bits "${_lib_relative}") + + # Determine whether we were given the debug or release version + list(FIND _path_bits "debug" _debug_index) + if(_debug_index EQUAL -1) + # We have the release version, so use it + set(_release_lib "${_library}") + + # Try to find a debug version too + list(FIND _path_bits "lib" _lib_index) + if(_lib_index GREATER_EQUAL 0) + list(INSERT _path_bits "${_lib_index}" "debug") + list(INSERT _path_bits 0 "${VCPKG_INSTALLED_DIR}") + string(REPLACE ";" "/" _debug_lib "${_path_bits}") + + if(NOT EXISTS "${_debug_lib}") + # Debug version does not exist - only use given version + unset(_debug_lib) + endif() + endif() + else() + # We have the debug version, so try to find a release version too + list(REMOVE_AT _path_bits "${_debug_index}") + list(INSERT _path_bits 0 "${VCPKG_INSTALLED_DIR}") + string(REPLACE ";" "/" _release_lib "${_path_bits}") + + if(NOT EXISTS "${_release_lib}") + # Release version does not exist - only use given version + set(_release_lib "${_library}") + else() + # Release version exists, so use given version as debug + set(_debug_lib "${_library}") + endif() + endif() + + # Set output variables appropriately + if(_debug_lib) + set("${_release_out}" "${_release_lib}" PARENT_SCOPE) + set("${_debug_out}" "${_debug_lib}" PARENT_SCOPE) + else() + set("${_release_out}" "${_release_lib}" PARENT_SCOPE) + unset("${_debug_out}" PARENT_SCOPE) + endif() +endfunction() From c9dcc41a8f06cd59bd9106d5ea5aa95bf7a21b34 Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Mon, 5 Sep 2022 18:32:04 +0100 Subject: [PATCH 10/14] Fix Lame definitions --- cmake/modules/FindLame.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/FindLame.cmake b/cmake/modules/FindLame.cmake index bad06dd0853..c3fb09c5bf1 100644 --- a/cmake/modules/FindLame.cmake +++ b/cmake/modules/FindLame.cmake @@ -16,7 +16,7 @@ else() find_path(Lame_INCLUDE_DIRS lame/lame.h) find_library(Lame_LIBRARIES mp3lame) - list(APPEND Lame_DEFINITIONS -DHAVE_LIBMP3LAME=1) + list(APPEND Lame_DEFINITIONS HAVE_LIBMP3LAME=1) mark_as_advanced(Lame_INCLUDE_DIRS Lame_LIBRARIES Lame_DEFINITIONS) From d10b3347a7afb7f4ae92770417d640d5687ca902 Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Mon, 5 Sep 2022 18:33:14 +0100 Subject: [PATCH 11/14] Add version detection and MinGW hints to SDL2 --- cmake/modules/FindSDL2.cmake | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmake/modules/FindSDL2.cmake b/cmake/modules/FindSDL2.cmake index eb3b4e4677a..3bad1002ead 100644 --- a/cmake/modules/FindSDL2.cmake +++ b/cmake/modules/FindSDL2.cmake @@ -51,7 +51,7 @@ else() find_path(SDL2_INCLUDE_DIR NAMES SDL.h - HINTS $ENV{SDL2DIR} + HINTS $ENV{SDL2DIR} ${SDL2_INCLUDE_DIRS} PATH_SUFFIXES SDL2 include/SDL2 include PATHS ${SDL2_SEARCH_PATHS} ) @@ -64,7 +64,7 @@ else() find_library(SDL2_LIBRARY NAMES SDL2 - HINTS $ENV{SDL2DIR} + HINTS $ENV{SDL2DIR} ${SDL2_LIBDIR} PATH_SUFFIXES ${PATH_SUFFIXES} PATHS ${SDL2_SEARCH_PATHS} ) @@ -77,7 +77,7 @@ else() find_package(Threads) endif() - if(SDL2_LIBRARY) + if(SDL2_LIBRARY AND SDL2_INCLUDE_DIR) add_library(SDL2::SDL2 UNKNOWN IMPORTED) set_target_properties(SDL2::SDL2 PROPERTIES IMPORTED_LOCATION "${SDL2_LIBRARY}" @@ -99,10 +99,20 @@ else() INTERFACE_LINK_LIBRARIES "Threads::Threads" ) endif() + + if(EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") + file(READ "${SDL2_INCLUDE_DIR}/SDL_version.h" _sdl_version_h) + string(REGEX REPLACE ".*#[\t ]*define[\t ]+SDL_MAJOR_VERSION[\t ]+([0-9]+).*" "\\1" SDL2_VERSION_MAJOR "${_sdl_version_h}") + string(REGEX REPLACE ".*#[\t ]*define[\t ]+SDL_MINOR_VERSION[\t ]+([0-9]+).*" "\\1" SDL2_VERSION_MINOR "${_sdl_version_h}") + string(REGEX REPLACE ".*#[\t ]*define[\t ]+SDL_PATCHLEVEL[\t ]+([0-9]+).*" "\\1" SDL2_VERSION_PATCH "${_sdl_version_h}") + set(SDL2_VERSION "${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH}") + unset(_sdl_version_h) + endif() endif() endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR + VERSION_VAR SDL2_VERSION ) From 082e148ac9f8564ce6cc59bb8e8651dc11ec141c Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Tue, 6 Sep 2022 00:39:43 +0100 Subject: [PATCH 12/14] Set vcpkg host triplet Only build a single version of ports required by both host and target --- .github/workflows/build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8362c024b8b..b28f9690cfe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -222,7 +222,10 @@ jobs: set-env: ${{ matrix.arch == 'x86' }} - name: Install dependencies run: | - vcpkg install --triplet ${{ matrix.arch }}-windows --recurse ` + vcpkg install ` + --triplet=${{ matrix.arch }}-windows ` + --host-triplet=${{ matrix.arch }}-windows ` + --recurse ` fftw3 fluidsynth[sndfile] libsamplerate libsndfile libstk lilv lv2 ` portaudio sdl2 - name: Set up build environment From 726a3bdf996b08c6e61637b02102034e3feca01a Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Thu, 8 Sep 2022 20:23:43 +0100 Subject: [PATCH 13/14] Attempt to fix MinGW build errors --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 025edf3b005..f4adc98f8c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,14 @@ ENDIF(COMMAND CMAKE_POLICY) # Import of windows.h breaks min()/max() ADD_DEFINITIONS(-DNOMINMAX) +# Treating imported target headers as system includes can change the header +# search order if some targets have headers in the standard system include +# directories, which can cause some headers not to be found due to the way +# #include_next is used in the standard library. +if(MINGW) + set(CMAKE_NO_SYSTEM_FROM_IMPORTED TRUE) +endif() + INCLUDE(PluginList) INCLUDE(CheckSubmodules) INCLUDE(AddFileDependencies) From d178987855b00dc2c20b62d398639ca513b2efb2 Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Mon, 19 Sep 2022 13:16:57 +0100 Subject: [PATCH 14/14] Limit MinGW workaround to affected CMake versions --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f4adc98f8c8..ad419e2cbb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,11 +22,11 @@ ENDIF(COMMAND CMAKE_POLICY) # Import of windows.h breaks min()/max() ADD_DEFINITIONS(-DNOMINMAX) -# Treating imported target headers as system includes can change the header -# search order if some targets have headers in the standard system include -# directories, which can cause some headers not to be found due to the way -# #include_next is used in the standard library. -if(MINGW) +# CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES is not set correctly for MinGW until +# CMake 3.14.1, so avoid specifying system include directories on affected +# versions. Normal include directories are safe, since GCC ignores them if they +# are already in the built-in search path. +if(MINGW AND CMAKE_VERSION VERSION_LESS "3.14.1") set(CMAKE_NO_SYSTEM_FROM_IMPORTED TRUE) endif()