mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-16 15:41:11 +02:00
Add the first Conan-based dependecies
add_conan_lib cmake function is defined, that allows to add a dependency using Conan with two possible system fallbacks: 1. pkg_check_modules is invoked, if `PGK_CONFIG ...` is present 2. find_package is invoked if `FIND_PACKAGE_OPTIONS` is present and `pkg_check_modules` has failed If `ALWAYS_ALLOW_CONAN_FALLBACK` is present - `obey_system_dependencies` will be ignored for the package Currently, the following dependencies are retrieved using Conan: * zlib * expat * wxwidgets * libmp3lame * libid3tag * libmad The last three libraries are included in this commit, as they depend on zlib. Properly pass **arch** and **os.version** to Conan
This commit is contained in:
269
cmake-proxies/cmake-modules/AudacityDependencies.cmake
Normal file
269
cmake-proxies/cmake-modules/AudacityDependencies.cmake
Normal file
@@ -0,0 +1,269 @@
|
||||
# Load Conan
|
||||
include( conan )
|
||||
|
||||
conan_add_remote(NAME audacity
|
||||
URL https://artifactory.audacityteam.org/artifactory/api/conan/conan-local
|
||||
VERIFY_SSL True
|
||||
)
|
||||
|
||||
set( CONAN_BUILD_REQUIRES )
|
||||
set( CONAN_REQUIRES )
|
||||
set( CONAN_PACKAGE_OPTIONS )
|
||||
set( CONAN_ONLY_DEBUG_RELEASE )
|
||||
set( CONAN_CONFIG_OPTIONS )
|
||||
set( CONAN_RESOLVE_LIST )
|
||||
|
||||
# Add a Conan dependency
|
||||
# Example usage:
|
||||
# add_conan_lib(
|
||||
# wxWdidget
|
||||
# wxwidgets/3.1.3-audacity
|
||||
# OPTION_NAME wxwidgets
|
||||
# SYMBOL WXWIDGET
|
||||
# REQUIRED
|
||||
# ALWAYS_ALLOW_CONAN_FALLBACK
|
||||
# PGK_CONFIG "wxwidgets >= 3.1.3"
|
||||
# FIND_PACKAGE_OPTIONS COMPONENTS adv base core html qa xml
|
||||
# INTERFACE_NAME wxwidgets::wxwidgets
|
||||
# HAS_ONLY_DEBUG_RELEASE
|
||||
# CONAN_OPTIONS
|
||||
# wxwidgets:shared=True
|
||||
# )
|
||||
|
||||
|
||||
function (add_conan_lib package conan_package_name )
|
||||
# Extract the list of packages from the function args
|
||||
list( SUBLIST ARGV 2 -1 options )
|
||||
|
||||
set( list_mode on )
|
||||
set( current_var "conan_package_options" )
|
||||
|
||||
set( option_name_base ${package} )
|
||||
set( allow_find_package off )
|
||||
set( find_package_options )
|
||||
set( conan_package_options )
|
||||
set( required off )
|
||||
set( pkg_config_options )
|
||||
set( system_only ${${_OPT}obey_system_dependencies})
|
||||
set( interface_name "${package}::${package}")
|
||||
|
||||
# Parse function arguments
|
||||
|
||||
foreach( opt IN LISTS options )
|
||||
if( opt STREQUAL "FIND_PACKAGE_OPTIONS" )
|
||||
set( list_mode on )
|
||||
set( allow_find_package on )
|
||||
set( current_var "find_package_options" )
|
||||
elseif ( opt STREQUAL "CONAN_OPTIONS" )
|
||||
set( list_mode on )
|
||||
set( current_var "conan_package_options" )
|
||||
elseif ( opt STREQUAL "PGK_CONFIG" )
|
||||
set( list_mode on )
|
||||
set( current_var "pkg_config_options" )
|
||||
elseif ( opt STREQUAL "OPTION_NAME" )
|
||||
set( list_mode off )
|
||||
set( current_var "option_name_base" )
|
||||
elseif ( opt STREQUAL "SYMBOL" )
|
||||
set( list_mode off )
|
||||
set( current_var "symbol" )
|
||||
elseif ( opt STREQUAL "INTERFACE_NAME" )
|
||||
set( list_mode off )
|
||||
set( current_var "interface_name" )
|
||||
elseif ( opt STREQUAL "REQUIRED" )
|
||||
set( required on )
|
||||
elseif ( opt STREQUAL "ALWAYS_ALLOW_CONAN_FALLBACK" )
|
||||
set( system_only off )
|
||||
elseif ( opt STREQUAL "HAS_ONLY_DEBUG_RELEASE" )
|
||||
set ( only_debug_release on )
|
||||
else()
|
||||
if( list_mode )
|
||||
list( APPEND ${current_var} ${opt} )
|
||||
else()
|
||||
set (${current_var} ${opt})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if( NOT DEFINED symbol )
|
||||
string( TOUPPER "${option_name_base}" symbol)
|
||||
endif()
|
||||
|
||||
# Generate CMake option
|
||||
set( option_name ${_OPT}use_${option_name_base} )
|
||||
|
||||
set( option_desc "local" )
|
||||
|
||||
if( pkg_config_options OR allow_find_package )
|
||||
set( sysopt "system" )
|
||||
string( PREPEND option_desc "system (if available), " )
|
||||
set( default "${${_OPT}lib_preference}" )
|
||||
else()
|
||||
set( default "local" )
|
||||
endif()
|
||||
|
||||
if( NOT required )
|
||||
set( reqopt "off" )
|
||||
string( APPEND option_desc ", off" )
|
||||
endif()
|
||||
|
||||
cmd_option( ${option_name}
|
||||
"Use ${option_name_base} library [${option_desc}]"
|
||||
"${default}"
|
||||
STRINGS ${sysopt} "local" ${reqopt}
|
||||
)
|
||||
|
||||
# Early bail out
|
||||
if( ${option_name} STREQUAL "off" )
|
||||
|
||||
message( STATUS "========== ${option_name_base} 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 )
|
||||
|
||||
if ( TARGET "${package}" )
|
||||
return()
|
||||
endif()
|
||||
|
||||
if( ${option_name} STREQUAL "system" )
|
||||
if( pkg_config_options )
|
||||
pkg_check_modules( PKG_${package} ${pkg_config_options} )
|
||||
|
||||
if( PKG_${package}_FOUND )
|
||||
message( STATUS "Using '${package}' system library" )
|
||||
|
||||
# Create the target interface library
|
||||
add_library( ${interface_name} INTERFACE IMPORTED GLOBAL)
|
||||
|
||||
# Retrieve the package information
|
||||
get_package_interface( PKG_${package} )
|
||||
|
||||
# And add it to our target
|
||||
target_include_directories( ${interface_name} INTERFACE ${INCLUDES} )
|
||||
target_link_libraries( ${interface_name} INTERFACE ${LIBRARIES} )
|
||||
|
||||
message(STATUS "Added inteface ${interface_name} ${INCLUDES} ${LIBRARIES}")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if( allow_find_package )
|
||||
find_package( ${package} QUIET ${find_package_options} )
|
||||
|
||||
if ( ${package}_FOUND )
|
||||
message( STATUS "Using '${package}' system library" )
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if( system_only )
|
||||
message( FATAL_ERROR "Failed to find the system package ${package}" )
|
||||
else()
|
||||
set( ${option_name} "local" )
|
||||
set_property( CACHE ${option_name} PROPERTY VALUE "local" )
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list( APPEND CONAN_REQUIRES ${conan_package_name} )
|
||||
list( APPEND CONAN_PACKAGE_OPTIONS ${conan_package_options} )
|
||||
list( APPEND CONAN_RESOLVE_LIST ${package} )
|
||||
|
||||
if ( only_debug_release )
|
||||
message( STATUS "${package} only has Debug and Release versions" )
|
||||
list( APPEND CONAN_ONLY_DEBUG_RELEASE ${package})
|
||||
endif()
|
||||
|
||||
set( CONAN_REQUIRES ${CONAN_REQUIRES} PARENT_SCOPE )
|
||||
set( CONAN_PACKAGE_OPTIONS ${CONAN_PACKAGE_OPTIONS} PARENT_SCOPE )
|
||||
set( CONAN_RESOLVE_LIST ${CONAN_RESOLVE_LIST} PARENT_SCOPE )
|
||||
set( CONAN_ONLY_DEBUG_RELEASE ${CONAN_ONLY_DEBUG_RELEASE} PARENT_SCOPE )
|
||||
|
||||
message (STATUS "Adding Conan dependency ${package}")
|
||||
endfunction()
|
||||
|
||||
macro( set_conan_vars_to_parent )
|
||||
set( CONAN_REQUIRES ${CONAN_REQUIRES} PARENT_SCOPE )
|
||||
set( CONAN_PACKAGE_OPTIONS ${CONAN_PACKAGE_OPTIONS} PARENT_SCOPE )
|
||||
set( CONAN_RESOLVE_LIST ${CONAN_RESOLVE_LIST} PARENT_SCOPE )
|
||||
set( CONAN_BUILD_REQUIRES ${CONAN_BUILD_REQUIRES} PARENT_SCOPE )
|
||||
set( CONAN_ONLY_DEBUG_RELEASE ${CONAN_ONLY_DEBUG_RELEASE} PARENT_SCOPE )
|
||||
endmacro()
|
||||
|
||||
function ( _conan_install build_type )
|
||||
conan_cmake_configure (
|
||||
REQUIRES ${CONAN_REQUIRES}
|
||||
GENERATORS cmake_find_package_multi
|
||||
BUILD_REQUIRES ${CONAN_BUILD_REQUIRES}
|
||||
${CONAN_CONFIG_OPTIONS}
|
||||
IMPORTS "bin, *.dll -> ./bin/shared/${build_type} @ keep_path=False"
|
||||
IMPORTS "lib, *.dll -> ./bin/shared/${build_type} @ keep_path=False"
|
||||
IMPORTS "lib, *.dylib -> ./lib/shared/${build_type} @ keep_path=False"
|
||||
IMPORTS "lib, *.so* -> ./lib/shared/${build_type} @ keep_path=False"
|
||||
OPTIONS ${CONAN_PACKAGE_OPTIONS}
|
||||
)
|
||||
|
||||
message(STATUS "Configuring packages for ${build_type}")
|
||||
|
||||
conan_cmake_autodetect(settings BUILD_TYPE ${build_type})
|
||||
|
||||
if( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
|
||||
# We have no AppleSilicon support yet
|
||||
list( APPEND settings "arch=x86_64" )
|
||||
list (APPEND settings "os.version=${CMAKE_OSX_DEPLOYMENT_TARGET}")
|
||||
endif()
|
||||
|
||||
if (build_type MATCHES "MinSizeRel|RelWithDebInfo")
|
||||
message(STATUS "Release only libraries: ${CONAN_ONLY_DEBUG_RELEASE}")
|
||||
|
||||
foreach( package ${CONAN_ONLY_DEBUG_RELEASE} )
|
||||
list( APPEND settings "${package}:build_type=Release")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
|
||||
conan_cmake_install(PATH_OR_REFERENCE .
|
||||
BUILD missing
|
||||
SETTINGS ${settings}
|
||||
)
|
||||
endfunction()
|
||||
|
||||
macro( resolve_conan_dependencies )
|
||||
message(STATUS
|
||||
"Executing Conan: \
|
||||
REQUIRES ${CONAN_REQUIRES}
|
||||
GENERATORS cmake_find_package_multi
|
||||
BUILD_REQUIRES ${CONAN_BUILD_REQUIRES}
|
||||
${CONAN_CONFIG_OPTIONS}
|
||||
OPTIONS ${CONAN_PACKAGE_OPTIONS}
|
||||
")
|
||||
|
||||
if(MSVC OR XCODE)
|
||||
foreach(TYPE ${CMAKE_CONFIGURATION_TYPES})
|
||||
_conan_install(${TYPE})
|
||||
endforeach()
|
||||
else()
|
||||
_conan_install(${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
|
||||
list( REMOVE_DUPLICATES CONAN_REQUIRES )
|
||||
|
||||
foreach( package ${CONAN_RESOLVE_LIST} )
|
||||
message(STATUS "Resolving Conan library ${package}")
|
||||
|
||||
find_package(${package} CONFIG)
|
||||
|
||||
if (NOT ${package}_FOUND)
|
||||
message( FATAL_ERROR "Failed to find the conan package ${package}" )
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
file(GLOB dependency_helpers "${AUDACITY_MODULE_PATH}/dependencies/*.cmake")
|
||||
|
||||
foreach(f ${dependency_helpers})
|
||||
include(${f})
|
||||
endforeach()
|
||||
endmacro()
|
Reference in New Issue
Block a user