| 1 |
set(find_package_file "${CMAKE_BINARY_DIR}/find_package_include.cmake") |
| 2 |
file(WRITE ${find_package_file} "# Generated dependecies list\n") |
| 3 |
|
| 4 |
#[[ |
| 5 |
`audacity_find_package` emulates the behavior of `find_package` but |
| 6 |
add some Audaicity-specific logic to it. |
| 7 |
|
| 8 |
Directly supported find_package options: |
| 9 |
|
| 10 |
* REQUIRED |
| 11 |
* QUIET |
| 12 |
|
| 13 |
Other options can be passed to the `find_package` call by passing |
| 14 |
FIND_PACKAGE_OPTIONS before them. |
| 15 |
|
| 16 |
Additionally, the following options are supported: |
| 17 |
|
| 18 |
* CONAN_PACKAGE_NAME - name of the package in Conan. If not specified, |
| 19 |
the name of the package is assumed to be the lowercase of the CMake package name. |
| 20 |
* OPTION_NAME - name of the option to enable/disable the package. If not specified, |
| 21 |
the name of the option is assumed to be the lowercase of the CMake package name. |
| 22 |
|
| 23 |
Call to `audacity_find_package` will create the `option` with the name |
| 24 |
audacity_use_<OPTION_NAME>. If REQUIRED is not specified, the option will allow |
| 25 |
to disable the package. If Conan is enabled, the option will allow `local` state. |
| 26 |
In all the cases the option allows `system` state. By default, the option is set |
| 27 |
to audacity_lib_preference value. |
| 28 |
|
| 29 |
If the option is set to `local`, the package will be enabled when running Conan. |
| 30 |
|
| 31 |
If the option is not set to `off`, the package will be searched using `find_package`. |
| 32 |
|
| 33 |
Usage: |
| 34 |
|
| 35 |
audacity_find_package( |
| 36 |
<package_name> |
| 37 |
[REQUIRED] |
| 38 |
[QUIET] |
| 39 |
[FIND_PACKAGE_OPTIONS <find_package_options>] |
| 40 |
[CONAN_PACKAGE_NAME <conan_package_name>] |
| 41 |
[OPTION_NAME <option_name>] |
| 42 |
) |
| 43 |
]] |
| 44 |
function(audacity_find_package package_name) |
| 45 |
set(options REQUIRED QUIET) |
| 46 |
set(one_value_args VERSION CONAN_PACKAGE_NAME OPTION_NAME) |
| 47 |
set(multi_value_args FIND_PACKAGE_OPTIONS) |
| 48 |
cmake_parse_arguments(audacity_find_package "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) |
| 49 |
|
| 50 |
#message(FATAL_ERROR "${package_name} R ${audicity_find_package_REQUIRED} Q ${audicity_find_package_QUIET} V ${audicity_find_package_VERSION} C ${audicity_find_package_CONAN_PACKAGE_NAME} O ${audicity_find_package_OPTION} F ${audicity_find_package_FIND_PACKAGE_OPTIONS}") |
| 51 |
|
| 52 |
if(NOT audacity_find_package_OPTION_NAME) |
| 53 |
string(TOLOWER "${package_name}" audacity_find_package_OPTION_NAME) |
| 54 |
endif() |
| 55 |
|
| 56 |
if(NOT audacity_find_package_CONAN_PACKAGE_NAME) |
| 57 |
string(TOLOWER "${package_name}" audacity_find_package_CONAN_PACKAGE_NAME) |
| 58 |
endif() |
| 59 |
|
| 60 |
set( option_name ${_OPT}use_${audacity_find_package_OPTION_NAME} ) |
| 61 |
|
| 62 |
set( option_desc "local" ) |
| 63 |
|
| 64 |
set( sysopt "system" ) |
| 65 |
string( PREPEND option_desc "system (if available), " ) |
| 66 |
|
| 67 |
if( ${_OPT}conan_enabled ) |
| 68 |
set( default "${${_OPT}lib_preference}" ) |
| 69 |
else() |
| 70 |
set( default "system" ) |
| 71 |
endif() |
| 72 |
|
| 73 |
if( ${_OPT}conan_enabled ) |
| 74 |
set( localopt "local" ) |
| 75 |
endif() |
| 76 |
|
| 77 |
if( NOT audacity_find_package_REQUIRED ) |
| 78 |
set( reqopt "off" ) |
| 79 |
string( APPEND option_desc ", off" ) |
| 80 |
endif() |
| 81 |
|
| 82 |
cmd_option( ${option_name} |
| 83 |
"Use ${option_name_base} library [${option_desc}]" |
| 84 |
"${default}" |
| 85 |
STRINGS ${sysopt} ${localopt} ${reqopt} |
| 86 |
) |
| 87 |
|
| 88 |
string( TOUPPER "${audacity_find_package_OPTION_NAME}" symbol) |
| 89 |
|
| 90 |
if( ${option_name} STREQUAL "off" ) |
| 91 |
message( STATUS "========== ${package_name} is disabled ==========" ) |
| 92 |
set( USE_${symbol} OFF CACHE INTERNAL "" FORCE ) |
| 93 |
list(APPEND conan_package_options "-o" "use_${audacity_find_package_CONAN_PACKAGE_NAME}=False") |
| 94 |
return() |
| 95 |
endif() |
| 96 |
|
| 97 |
set( USE_${symbol} ON CACHE INTERNAL "" FORCE ) |
| 98 |
|
| 99 |
if( audacity_find_package_REQUIRED ) |
| 100 |
set(audacity_find_package_REQUIRED "REQUIRED") |
| 101 |
else() |
| 102 |
set(audacity_find_package_REQUIRED "") |
| 103 |
endif() |
| 104 |
|
| 105 |
if( audacity_find_package_QUIET ) |
| 106 |
set(audacity_find_package_QUIET "QUIET") |
| 107 |
else() |
| 108 |
set(audacity_find_package_QUIET "") |
| 109 |
endif() |
| 110 |
|
| 111 |
string( |
| 112 |
JOIN " " find_package_string "find_package(" ${package_name} |
| 113 |
${audacity_find_package_VERSION} |
| 114 |
${audacity_find_package_REQUIRED} |
| 115 |
${audacity_find_package_QUIET} |
| 116 |
${audacity_find_package_FIND_PACKAGE_OPTIONS} |
| 117 |
")\n" |
| 118 |
) |
| 119 |
|
| 120 |
file(APPEND ${find_package_file} "${find_package_string}") |
| 121 |
|
| 122 |
if( ${option_name} STREQUAL "local" ) |
| 123 |
message( STATUS "========== Using Conan version of ${package_name} ==========" ) |
| 124 |
list(APPEND conan_package_options "use_${audacity_find_package_CONAN_PACKAGE_NAME}=True") |
| 125 |
else() |
| 126 |
message( STATUS "========== Using system version of ${package_name} ==========" ) |
| 127 |
endif() |
| 128 |
|
| 129 |
if(conan_package_options) |
| 130 |
set(conan_package_options ${conan_package_options} PARENT_SCOPE) |
| 131 |
mark_as_advanced(${package_name}_DIR) |
| 132 |
mark_as_advanced(${audacity_find_package_OPTION_NAME}_DIR) |
| 133 |
mark_as_advanced(${audacity_find_package_CONAN_PACKAGE_NAME}_DIR) |
| 134 |
endif() |
| 135 |
endfunction() |
| 136 |
|
| 137 |
# Process the list of the 3d party libraries |
| 138 |
include (DependenciesList) |
| 139 |
|
| 140 |
# If conan is enabled, run conan_runner.py |
| 141 |
if( ${_OPT}conan_enabled ) |
| 142 |
# Deduce the build type |
| 143 |
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) |
| 144 |
|
| 145 |
if( is_multi_config ) |
| 146 |
set(_build_types ${CMAKE_CONFIGURATION_TYPES}) |
| 147 |
else() |
| 148 |
set(_build_types ${CMAKE_BUILD_TYPE}) |
| 149 |
endif() |
| 150 |
|
| 151 |
set(_conan_args) |
| 152 |
|
| 153 |
# Force the packages rebuld, if needed |
| 154 |
if( ${_OPT}conan_force_build_dependencies ) |
| 155 |
list(APPEND _conan_args "--force-build") |
| 156 |
endif() |
| 157 |
|
| 158 |
if( NOT ${_OPT}conan_allow_prebuilt_binaries ) |
| 159 |
list(APPEND _conan_args "--disallow-prebuilt") |
| 160 |
endif() |
| 161 |
|
| 162 |
# Deduce the target architecture |
| 163 |
if( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) |
| 164 |
set( _target_arch ${MACOS_ARCHITECTURE} ) |
| 165 |
elseif( MSVC ) |
| 166 |
set( _target_arch ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID} ) |
| 167 |
else() |
| 168 |
set( _target_arch "${CMAKE_SYSTEM_PROCESSOR}" ) |
| 169 |
endif() |
| 170 |
|
| 171 |
# Enable Conan download cache, if needed |
| 172 |
if( ${_OPT}conan_download_cache ) |
| 173 |
list(APPEND _conan_args "--download-cache" ${${_OPT}conan_download_cache} ) |
| 174 |
endif() |
| 175 |
|
| 176 |
if( ${_OPT}conan_build_profile) |
| 177 |
list(APPEND _conan_args "--build-profile" ${${_OPT}conan_build_profile} ) |
| 178 |
endif() |
| 179 |
|
| 180 |
if( ${_OPT}conan_host_profile) |
| 181 |
list(APPEND _conan_args "--host-profile" ${${_OPT}conan_host_profile} ) |
| 182 |
endif() |
| 183 |
|
| 184 |
# Set the libraries installation directory (Linux only, ignored on other platforms) |
| 185 |
if( _PKGLIB ) |
| 186 |
list(APPEND _conan_args "--lib-dir" ${_PKGLIB} ) |
| 187 |
endif() |
| 188 |
|
| 189 |
if( MIN_MACOS_VERSION ) |
| 190 |
list(APPEND _conan_args "--min-os-version" ${MIN_MACOS_VERSION} ) |
| 191 |
endif() |
| 192 |
|
| 193 |
execute_process( |
| 194 |
COMMAND ${PYTHON} "${CMAKE_SOURCE_DIR}/conan/conan_runner.py" |
| 195 |
--build-dir ${CMAKE_BINARY_DIR} |
| 196 |
--compiler ${CMAKE_CXX_COMPILER_ID} |
| 197 |
--compiler-version ${CMAKE_CXX_COMPILER_VERSION} |
| 198 |
--build-types ${_build_types} |
| 199 |
--target-arch ${_target_arch} |
| 200 |
--build-arch ${CMAKE_HOST_SYSTEM_PROCESSOR} |
| 201 |
${_conan_args} |
| 202 |
-o ${conan_package_options} |
| 203 |
|
| 204 |
RESULT_VARIABLE conan_result |
| 205 |
COMMAND_ECHO STDOUT |
| 206 |
) |
| 207 |
|
| 208 |
if( conan_result ) |
| 209 |
message( FATAL_ERROR "Conan failed to install dependencies (${conan_result}) ${PYTHON}" ) |
| 210 |
endif() |
| 211 |
|
| 212 |
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) |
| 213 |
endif() |
| 214 |
|
| 215 |
if( ${_OPT}conan_enabled ) |
| 216 |
set( _file_name "${CMAKE_BINARY_DIR}/generators/pre-find-package.cmake" ) |
| 217 |
|
| 218 |
if( EXISTS "${_file_name}" ) |
| 219 |
message(STATUS "Including ${_file_name}") |
| 220 |
include( ${_file_name} ) |
| 221 |
endif() |
| 222 |
endif() |
| 223 |
# Resolve the dependencies |
| 224 |
include(${find_package_file}) |
| 225 |
|
| 226 |
# Monkey-patch some targets to make the names consistent |
| 227 |
file(GLOB dependency_helpers "${AUDACITY_MODULE_PATH}/dependencies/*.cmake") |
| 228 |
|
| 229 |
foreach(f ${dependency_helpers}) |
| 230 |
include(${f}) |
| 231 |
endforeach() |
| 232 |
|
| 233 |
if( ${_OPT}conan_enabled ) |
| 234 |
set( _file_name "${CMAKE_BINARY_DIR}/generators/post-find-package.cmake" ) |
| 235 |
if( EXISTS "${_file_name}" ) |
| 236 |
message(STATUS "Including ${_file_name}") |
| 237 |
include( ${_file_name} ) |
| 238 |
endif() |
| 239 |
endif() |