diff --git a/CMakeLists.txt b/CMakeLists.txt index b6b57acf0..0e6b05f47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -384,6 +384,12 @@ macro( get_package_interface package ) ) endmacro() +# Set the cache and context value +macro( set_cache_value var value ) + set( ${var} "${value}" ) + set_property( CACHE ${var} PROPERTY VALUE "${value}" ) +endmacro() + # Set the given property and its config specific brethren to the same value function( set_target_property_all target property value ) set_target_properties( "${target}" PROPERTIES "${property}" "${value}" ) @@ -393,6 +399,51 @@ function( set_target_property_all target property value ) endforeach() endfunction() +# Taken from wxWidgets and modified for Audcaity +# +# cmd_option( [default] [STRINGS strings]) +# The default is ON if third parameter isn't specified +function( cmd_option name desc ) + cmake_parse_arguments( OPTION "" "" "STRINGS" ${ARGN} ) + + if( ARGC EQUAL 2 ) + if( OPTION_STRINGS ) + list( GET OPTION_STRINGS 1 default ) + else() + set( default ON ) + endif() + else() + set( default ${OPTION_UNPARSED_ARGUMENTS} ) + endif() + + if( OPTION_STRINGS ) + set( cache_type STRING ) + else() + set( cache_type BOOL ) + endif() + + set( ${name} "${default}" CACHE ${cache_type} "${desc}" ) + if( OPTION_STRINGS ) + set_property( CACHE ${name} PROPERTY STRINGS ${OPTION_STRINGS} ) + + # Check valid value + set( value_is_valid FALSE ) + set( avail_values ) + foreach( opt ${OPTION_STRINGS} ) + if( ${name} STREQUAL opt ) + set( value_is_valid TRUE ) + break() + endif() + string( APPEND avail_values " ${opt}" ) + endforeach() + if( NOT value_is_valid ) + message( FATAL_ERROR "Invalid value \"${${name}}\" for option ${name}. Valid values are: ${avail_values}" ) + endif() + endif() + + set( ${name} "${${name}}" PARENT_SCOPE ) +endfunction() + # Add our children add_subdirectory( "cmake-proxies" ) add_subdirectory( "help" ) diff --git a/cmake-proxies/CMakeLists.txt b/cmake-proxies/CMakeLists.txt index 273eb70d3..25b431869 100644 --- a/cmake-proxies/CMakeLists.txt +++ b/cmake-proxies/CMakeLists.txt @@ -1,6 +1,9 @@ - -# Allow user to globally set the system library preference -option( ${_OPT}prefer_system_libs "Use system libraries if available" YES ) +# Allow user to globally set the library preference +cmd_option( ${_OPT}lib_preference + "Library preference [system (if available), local]" + "system" + STRINGS "system" "local" +) # # Add individual library targets @@ -31,23 +34,8 @@ function( addlib dir name symbol required check ) set( TARGET ${dir} ) set( TARGET_ROOT ${libsrc}/${dir} ) - # If the target is required, then it's always enabled. Otherwise, - # give the user the option to enable/disable it. - set( enable ${_OPT}enable_${name} ) - if( required ) - set( ${enable} YES ) - else() - option( ${enable} "Enable ${name} library" ON ) - endif() - - # Let the Audacity target know that this library will be used. - set( USE_${symbol} ${${enable}} CACHE INTERNAL USE_${symbol} ) - - # Bail if the target isn't enabled. - if( NOT ${enable} ) - message( STATUS "========== ${name} disabled ==========" ) - return() - endif() + # Define the option name + set( use ${_OPT}use_${name} ) # If we're not checking for system or local here, then let the # target config handle the rest. @@ -56,30 +44,54 @@ function( addlib dir name symbol required check ) return() endif() - # Only present the system library option if pkg-config was found and - # a package has been specified. Otherwise, the local library will - # be used unconditionally. - set( system ${_OPT}use_system_${name} ) - if( PkgConfig_FOUND AND packages ) - option( ${system} "Use ${name} system library if available" ${${_OPT}prefer_system_libs} ) + # If the target isn't required, allow the user to select which one + # to use or disable it entirely + set( desc "local" ) + if( packages ) + set( sysopt "system" ) + string( PREPEND desc "system (if available), " ) + set( default "${${_OPT}lib_preference}" ) else() - set( ${system} NO ) + set( default "local" ) endif() + if( NOT required ) + set( reqopt "off" ) + string( APPEND desc ", off" ) + endif() + + cmd_option( ${use} + "Use ${name} library [${desc}]" + "${default}" + STRINGS ${sysopt} "local" ${reqopt} + ) + + # Bail if the target will not be used + if( ${use} STREQUAL "off" ) + message( STATUS "========== ${name} disabled ==========" ) + + set( USE_${symbol} OFF CACHE INTERNAL "" FORCE ) + + return() + endif() + + # Let the Audacity target know that this library will be used + set( USE_${symbol} ON CACHE INTERNAL "" FORCE ) + message( STATUS "========== Configuring ${name} ==========" ) - # Check for the system package if the user prefers it. - if( ${system} ) + # Check for the system package(s) if the user prefers it + if( ${use} STREQUAL "system" ) # Look them up - pkg_check_modules( ${TARGET} ${packages} ) - if( ${TARGET}_FOUND ) + pkg_check_modules( PKG_${TARGET} ${packages} ) + if( PKG_${TARGET}_FOUND ) message( STATUS "Using '${name}' system library" ) # Create the target interface library add_library( ${TARGET} INTERFACE IMPORTED GLOBAL ) # Retrieve the package information - get_package_interface( ${TARGET} ) + get_package_interface( PKG_${TARGET} ) # And add it to our target target_include_directories( ${TARGET} INTERFACE ${INCLUDES} ) @@ -87,11 +99,14 @@ function( addlib dir name symbol required check ) target_link_directories( ${TARGET} INTERFACE ${LINKDIRS} ) target_link_options( ${TARGET} INTERFACE ${LOPTS} ) target_link_libraries( ${TARGET} INTERFACE ${LIBRARIES} ) + else() + set( ${use} "local" ) + set_property( CACHE ${use} PROPERTY VALUE "local" ) endif() endif() - # User want the local package or the system one wasn't found - if( NOT ${TARGET}_FOUND ) + # User wants the local package or the system one wasn't found + if( ${use} STREQUAL "local" ) message( STATUS "Using '${name}' local library" ) # Pull in the target config diff --git a/cmake-proxies/ffmpeg/CMakeLists.txt b/cmake-proxies/ffmpeg/CMakeLists.txt index 40d121aa4..0d387d35e 100644 --- a/cmake-proxies/ffmpeg/CMakeLists.txt +++ b/cmake-proxies/ffmpeg/CMakeLists.txt @@ -11,39 +11,52 @@ def_vars() message( STATUS "========== Configuring ${name} ==========" ) -# Let the Audacity target know we're using ffmpeg -set( USE_${symbol} ON CACHE INTERNAL USE_${symbol} ) - -# Add the system/local option -option( ${_OPT}use_system_${name} "Use ${name} system library if available" ${${_OPT}prefer_system_libs} ) - -# Look up the system packages if the user wants them -if( ${_OPT}use_system_${name} ) - # Provide an option that determines if the libraries are loaded - # dynamically at run time or statically linked at build time - option( ${_OPT}disable_dynamic_${name} "Disable dynamic loading of ${name} libraries" NO) - - # Look them up - pkg_check_modules( ${TARGET} ${packages} ) -else() - # Make sure to reset in case user reconfigures between local/system - set( ${_OPT}disable_dynamic_${name} NO CACHE INTERNAL "" ) +# We can only (possibly) link to it if we have pkg-config +if( PkgConfig_FOUND ) + set( opt "linked" ) + set( desc "linked, " ) endif() -# If the system packages were found -if( ${TARGET}_FOUND ) - message( STATUS "Using '${name}' system library" ) +# FFmpeg is either dynamically loaded, linked to, or off +cmd_option( ${_OPT}use_ffmpeg + "Use ffmpeg library [loaded, ${desc}off]" + "loaded" + STRINGS "loaded" ${opt} "off" +) - # Pull in the package settings - get_package_interface( ${TARGET} ) +# Deteremine if it will be turned off, linked to, or loaded +if( ${_OPT}use_ffmpeg STREQUAL "off" ) + message( STATUS "Disabling '${name}' library" ) else() - message( STATUS "Using '${name}' local library" ) + # Let the Audacity target know that this library will be used. + set( USE_${symbol} ON CACHE INTERNAL USE_${symbol} ) - # Otherwise define the local settings - list( APPEND INCLUDES - INTERFACE - ${TARGET_ROOT} - ) + # Only need to look up the package if we're linking to it + set( isdyn YES ) + if( ${_OPT}use_ffmpeg STREQUAL "linked" ) + pkg_check_modules( ${TARGET} ${packages} ) + + # Set up for link if it was found + if( ${TARGET}_FOUND ) + message( STATUS "Linking '${name}' library during build" ) + + # Pull in the package settings + get_package_interface( ${TARGET} ) + + # Not dynamic + set( isdyn NO ) + endif() + endif() + + # Pull in the local includes if we're dynamically loading + if( isdyn ) + message( STATUS "Will dynamically load '${name}' library at runtime" ) + + list( APPEND INCLUDES + INTERFACE + ${TARGET_ROOT} + ) + endif() endif() # And add the settings to the target diff --git a/cmake-proxies/libsndfile/sndfile.h.in b/cmake-proxies/libsndfile/sndfile.h.in index 3777e5f59..f486f0424 100644 --- a/cmake-proxies/libsndfile/sndfile.h.in +++ b/cmake-proxies/libsndfile/sndfile.h.in @@ -29,6 +29,7 @@ /* This is the version 1.0.X header file. */ #define SNDFILE_1 +#include #include #include diff --git a/cmake-proxies/portaudio-v19/CMakeLists.txt b/cmake-proxies/portaudio-v19/CMakeLists.txt index 43e1e5e98..f79affcd7 100644 --- a/cmake-proxies/portaudio-v19/CMakeLists.txt +++ b/cmake-proxies/portaudio-v19/CMakeLists.txt @@ -7,23 +7,48 @@ set( CMAKE_MODULE_PATH ${TARGET_ROOT}/cmake_support ) # Define the platform specific interface options if( CMAKE_SYSTEM_NAME MATCHES "Windows" ) - option( ${_OPT}use_pa_ds "Enable the portaudio DirectSound interface if available" YES ) - option( ${_OPT}use_pa_wasapi "Enable the portaudio WASAPI interface if available" YES ) - option( ${_OPT}use_pa_wmme "Enable the portaudio WMME interface if available" YES ) + cmd_option( + ${_OPT}use_pa_ds + "Use the portaudio DirectSound interface if available" + YES + ) + cmd_option( + ${_OPT}use_pa_wasapi + "Use the portaudio WASAPI interface if available" + YES + ) + cmd_option( + ${_OPT}use_pa_wmme + "Use the portaudio WMME interface if available" + YES + ) elseif( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) - option( ${_OPT}use_pa_coreaudio "Enable the portaudio CoreAudio interface if available" YES ) + cmd_option( + ${_OPT}use_pa_coreaudio + "Use the portaudio CoreAudio interface if available" + YES + ) elseif( CMAKE_SYSTEM_NAME MATCHES "Linux|FreeBSD" ) - option( ${_OPT}use_pa_alsa "Enable the portaudio ALSA interface if available" YES ) + cmd_option( + ${_OPT}use_pa_alsa + "Use the portaudio ALSA interface if available" + YES + ) + if( ${_OPT}use_pa_alsa ) find_package( ALSA ) if( NOT ALSA_FOUND ) - set( ${_OPT}use_pa_alsa NO CACHE INTERNAL "" ) + set_cache_value( ${_OPT}use_pa_alsa NO ) endif() endif() endif() # Look for OSS if the user wants it -option( ${_OPT}use_pa_oss "Use the OSS audio interface if available" YES ) +cmd_option( + ${_OPT}use_pa_oss + "Use the OSS audio interface if available" + YES +) if( ${_OPT}use_pa_oss ) find_path( OSS_INCLUDE NAMES sys/soundcard.h ) mark_as_advanced( FORCE OSS_INCLUDE ) @@ -40,25 +65,23 @@ if( ${_OPT}use_pa_oss ) endif() if( NOT OSS_INCLUDE_DIRS ) - set( ${_OPT}use_pa_oss NO CACHE INTERNAL "" ) + set_cache_value( ${_OPT}use_pa_oss NO ) endif() endif() -# Look for JACK if the user wants it -option( ${_OPT}use_pa_jack "Use the JACK audio interface if available" YES ) -if( ${_OPT}use_pa_jack ) - # Provide an option that determines if the libraries are loaded - # dynamically at run time or statically linked at build time - option( ${_OPT}disable_dynamic_jack "Disable dynamic loading of JACK libraries" YES ) +# JACK can be dynamically loaded, linked to, or off +cmd_option( ${_OPT}use_pa_jack + "Use the JACK audio interface if available [loaded, linked, off]" + "linked" + STRINGS "loaded" "linked" "off" +) +if( NOT ${_OPT}use_pa_jack STREQUAL "off" ) # Find it find_package( Jack ) if( NOT JACK_FOUND) - set( ${_OPT}use_pa_jack NO CACHE INTERNAL "" ) + set_cache_value( ${_OPT}use_pa_jack "off" ) endif() -else() - # Make sure to reset in case user reconfigures later - set( ${_OPT}disable_dynamic_jack NO CACHE INTERNAL "" ) endif() list( APPEND SOURCES @@ -116,7 +139,7 @@ list( APPEND SOURCES ${TARGET_ROOT}/src/hostapi/oss/pa_unix_oss.c > - $<$: + $<$>: ${TARGET_ROOT}/src/hostapi/jack/pa_jack.c ${TARGET_ROOT}/src/hostapi/jack/pa_jack_dynload.c > @@ -150,7 +173,7 @@ list( APPEND INCLUDES ${OSS_INCLUDE_DIRS} > - $<$: + $<$>: ${TARGET_ROOT}/src/hostapi/jack ${JACK_INCLUDE_DIRS} > @@ -186,11 +209,11 @@ list( APPEND DEFINES HAVE_SYS_SOUNDCARD_H=1 > - $<$: + $<$>: PA_USE_JACK=1 > - $<$>: + $<$: PA_DYNAMIC_JACK=1 > ) @@ -205,7 +228,7 @@ list( APPEND LIBRARIES ${OSS_LIBRARIES} > - $<$: + $<$>: ${JACK_LIBRARIES} > ) diff --git a/cmake-proxies/wxWidgets/CMakeLists.txt b/cmake-proxies/wxWidgets/CMakeLists.txt index bf23dd52c..3c80ee24b 100644 --- a/cmake-proxies/wxWidgets/CMakeLists.txt +++ b/cmake-proxies/wxWidgets/CMakeLists.txt @@ -6,8 +6,13 @@ def_vars() message( STATUS "========== Configuring ${name} ==========" ) -option( ${_OPT}use_system_${name} "Use ${name} system library if available" ${${_OPT}prefer_system_libs} ) -if( ${_OPT}use_system_${name} ) +cmd_option( ${_OPT}use_wxwidgets + "Use ${name} library [system (if available), local]" + "${audacity_lib_preference}" + STRINGS "system" "local" +) + +if( ${_OPT}use_wxwidgets STREQUAL "system" ) find_package(wxWidgets) endif() @@ -53,8 +58,6 @@ if( wxWidgets_FOUND ) else() message( STATUS "Using local '${name}' library" ) - set( ${_OPT}use_system_${name} OFF CACHE BOOL "Prefer ${name} system library if available" FORCE ) - set( WXWIN $ENV{WXWIN} ) if( "${WXWIN}" STREQUAL "" ) # XXX: Look into importing instead of adding to this project @@ -118,7 +121,7 @@ else() ) # Do NOT split the generator expressions across multiple lines here. - # CMake appears to have a bug and doesn't see to handle it correctly + # CMake appears to have a bug and doesn't seem to handle it correctly # for target link libraries. set( LIBRARIES adv diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1b2fb434..067d2eb37 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1072,11 +1072,19 @@ if( CMAKE_VERSION VERSION_GREATER_EQUAL "3.16" AND NOT CCACHE_PROGRAM ) endif() # Handle Ladspa option -option( ${_OPT}enable_ladspa "Enable LADSPA plug-in support" ON ) -set( USE_LADSPA ${${_OPT}enable_ladspa} ) +cmd_option( + ${_OPT}use_ladspa + "Use LADSPA plug-in support [on, off]" + ON +) +set( USE_LADSPA ${${_OPT}use_ladspa} ) # Handle VST option -option( ${_OPT}enable_vst "Enable VST2 plug-in support" ON ) +cmd_option( + ${_OPT}use_vst + "Use VST2 plug-in support [on, off]" + ON +) set( USE_VST ${${_OPT}enable_vst} ) set( AUDACITY_NAME "Audacity" ) @@ -1119,7 +1127,7 @@ if( CMAKE_SYSTEM_NAME MATCHES "Windows" ) configure_file( audacity_config.h.in private/configwin.h ) # Copy over the wxWidgets DLLs - if( use_system_wxwidgets ) + if( ${_OPT}use_wxwidgets STREQUAL "system" ) set( wxlibs "$ENV{WXWIN}" ) else() set( wxlibs "${CMAKE_BINARY_DIR}" ) @@ -1144,7 +1152,7 @@ if( CMAKE_SYSTEM_NAME MATCHES "Windows" ) DEL ${dlls} ) IF %1 EQU xyzzy ( - FOR /F %%i IN ('DUMPBIN /DEPENDENTS \"%2\"\\%3 ^| FIND \" wx\"') DO ( + FOR /F %%i IN ('DUMPBIN /DEPENDENTS \"%2\"\\%3 ^| findstr /B \"/C: wx\"') DO ( ECHO %%i >>\"${dlls}\" CALL %0 xyzzy \"${libdir}\" %%i ) @@ -1172,7 +1180,11 @@ elseif( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) set( _EXE "Audacity" ) # Handle Audio Units option - option( ${_OPT}enable_audiounits "Enable Audio Unit plug-in support" ON ) + cmd_option( + ${_OPT}enable_audiounits + "Enable Audio Unit plug-in support" + ON + ) set( USE_AUDIO_UNITS ${${_OPT}enable_audiounits} ) set_target_properties( @@ -1296,7 +1308,7 @@ elseif( CMAKE_SYSTEM_NAME MATCHES "Linux|FreeBSD" ) configure_file( audacity.desktop.in ${_INTDIR}/audacity.desktop ) # Create the script to copy required wxWidgets libraries - if( NOT use_system_wxwidgets ) + if( ${_OPT}use_wxwidgets STREQUAL "local" ) file( WRITE "${_INTDIR}/copy_libs.sh" "for lib in \$(ldd ${_EXEDIR}/${_EXE} | awk '/libwx/{print \$1}') do