1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
|
# Load Conan
if ( ${_OPT}conan_allow_prebuilt_binaries )
set( CONAN_REMOTE https://artifactory.audacityteam.org/artifactory/api/conan/audacity-binaries )
else()
set( CONAN_REMOTE https://artifactory.audacityteam.org/artifactory/api/conan/audacity-recipes )
endif()
if( ${_OPT}conan_force_build_dependencies )
set( CONAN_BUILD_MODE BUILD all )
else()
set( CONAN_BUILD_MODE BUILD missing )
endif()
if( ${_OPT}conan_enabled )
include( conan )
conan_check()
# Conan will fail to detect the compiler in case /usr/bin/cc or /usr/bin/cxx are passed
# CMake will set CC and CXX variables, breaking the correct detection of compiler.
# However, we can safely unset them before running Conan, because we only care for
# the build tools environment here
if( DEFINED ENV{CC} )
set( OLD_CC $ENV{CC} )
unset( ENV{CC} )
endif()
if( DEFINED ENV{CXX} )
set( OLD_CXX $ENV{CXX} )
unset( ENV{CXX} )
endif()
execute_process( COMMAND ${CONAN_CMD} profile new audacity_build --detect --force )
# Conan will not detect compiler runtime
if(MSVC)
_get_msvc_ide_version(msvc_version_for_profile)
execute_process( COMMAND ${CONAN_CMD} profile update settings.compiler="Visual Studio" audacity_build )
execute_process( COMMAND ${CONAN_CMD} profile update settings.compiler.version="${msvc_version_for_profile}" audacity_build )
execute_process( COMMAND ${CONAN_CMD} profile update settings.compiler.runtime=MD audacity_build )
execute_process( COMMAND ${CONAN_CMD} profile update settings.compiler.cppstd=17 audacity_build )
endif()
if( DEFINED OLD_CC )
set( ENV{CC} ${OLD_CC} )
endif()
if( DEFINED OLD_CXX )
set( ENV{CXX} ${OLD_CXX} )
endif()
set(ENV{CONAN_REVISIONS_ENABLED} 1)
conan_add_remote(NAME audacity
URL ${CONAN_REMOTE}
VERIFY_SSL True
INDEX 0
)
conan_add_remote(NAME conan-center-cache
URL https://artifactory.audacityteam.org/artifactory/api/conan/conancenter
VERIFY_SSL True
INDEX 1
)
endif()
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
PKG_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
)
PKG_CONFIG accepts a list of possible package configurations.
add_conan_lib will iterate over it one by one until the library is found.
]]
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 "ALLOW_FIND_PACKAGE" )
set ( allow_find_package on )
elseif ( opt STREQUAL "CONAN_OPTIONS" )
set( list_mode on )
set( current_var "conan_package_options" )
elseif ( opt STREQUAL "PKG_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 OR NOT ${_OPT}conan_enabled )
set( sysopt "system" )
string( PREPEND option_desc "system (if available), " )
if( ${_OPT}conan_enabled )
set( default "${${_OPT}lib_preference}" )
else()
set( default "system" )
endif()
else()
set( default "local" )
endif()
if( ${_OPT}conan_enabled )
set( localopt "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} ${localopt} ${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" OR NOT ${_OPT}conan_enabled )
if( pkg_config_options )
foreach(variant ${pkg_config_options})
pkg_check_modules( PKG_${package} ${variant} )
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} ${interface_name} )
return()
endif()
endforeach()
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 OR NOT ${_OPT}conan_enabled )
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 -> ./${_SHARED_PROXY_BASE}/${build_type} @ keep_path=False"
IMPORTS "lib, *.dll -> ./${_SHARED_PROXY_BASE}/${build_type} @ keep_path=False"
IMPORTS "lib, *.dylib -> ./${_SHARED_PROXY_BASE}/${build_type} @ keep_path=False"
IMPORTS "lib, *.so* -> ./${_SHARED_PROXY_BASE}/${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" )
if( MACOS_ARCHITECTURE STREQUAL "x86_64" )
set( CONAN_MACOS_ARCHITECTURE "x86_64" )
else()
set( CONAN_MACOS_ARCHITECTURE "armv8" )
endif()
list( APPEND settings "arch=${CONAN_MACOS_ARCHITECTURE}" )
list( APPEND settings "os.version=${CMAKE_OSX_DEPLOYMENT_TARGET}" )
# This line is required to workaround the conan bug #8025
# https://github.com/conan-io/conan/issues/8025
# Without it, libjpeg-turbo will fail to cross-compile on AppleSilicon macs
set(ENV{CONAN_CMAKE_SYSTEM_NAME} "Darwin")
set(ENV{CONAN_CMAKE_SYSTEM_PROCESSOR} ${MACOS_ARCHITECTURE})
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 .
${CONAN_BUILD_MODE}
PROFILE_BUILD audacity_build
SETTINGS_HOST ${settings}
)
endfunction()
macro( resolve_conan_dependencies )
if( ${_OPT}conan_enabled )
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)
mark_as_advanced(${package}_DIR)
if (NOT ${package}_FOUND)
message( FATAL_ERROR "Failed to find the conan package ${package}" )
endif()
endforeach()
endif()
file(GLOB dependency_helpers "${AUDACITY_MODULE_PATH}/dependencies/*.cmake")
foreach(f ${dependency_helpers})
include(${f})
endforeach()
endmacro()
macro ( find_required_package package_name system_package_name )
find_package ( ${package_name} QUIET ${ARGN} )
if ( NOT ${package_name}_FOUND )
if (CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
message( FATAL_ERROR "Error: ${package_name} is required")
else()
message( FATAL_ERROR "Error: ${package_name} is required.\nPlease install it with using command like:\n\t\$ sudo apt install ${system_package_name}" )
endif()
endif()
endmacro()
|