Mercurial > thymian
comparison cmake/conan.cmake @ 0:a4671277546c tip
created the repository for the thymian project
| author | ferencd |
|---|---|
| date | Tue, 17 Aug 2021 11:19:54 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a4671277546c |
|---|---|
| 1 # The MIT License (MIT) | |
| 2 | |
| 3 # Copyright (c) 2018 JFrog | |
| 4 | |
| 5 # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 6 # of this software and associated documentation files (the "Software"), to deal | |
| 7 # in the Software without restriction, including without limitation the rights | |
| 8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 9 # copies of the Software, and to permit persons to whom the Software is | |
| 10 # furnished to do so, subject to the following conditions: | |
| 11 | |
| 12 # The above copyright notice and this permission notice shall be included in all | |
| 13 # copies or substantial portions of the Software. | |
| 14 | |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| 16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| 17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| 18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| 21 # SOFTWARE. | |
| 22 | |
| 23 | |
| 24 | |
| 25 # This file comes from: https://github.com/conan-io/cmake-conan. Please refer | |
| 26 # to this repository for issues and documentation. | |
| 27 | |
| 28 # Its purpose is to wrap and launch Conan C/C++ Package Manager when cmake is called. | |
| 29 # It will take CMake current settings (os, compiler, compiler version, architecture) | |
| 30 # and translate them to conan settings for installing and retrieving dependencies. | |
| 31 | |
| 32 # It is intended to facilitate developers building projects that have conan dependencies, | |
| 33 # but it is only necessary on the end-user side. It is not necessary to create conan | |
| 34 # packages, in fact it shouldn't be use for that. Check the project documentation. | |
| 35 | |
| 36 | |
| 37 include(CMakeParseArguments) | |
| 38 | |
| 39 function(_get_msvc_ide_version result) | |
| 40 set(${result} "" PARENT_SCOPE) | |
| 41 if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) | |
| 42 set(${result} 8 PARENT_SCOPE) | |
| 43 elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600) | |
| 44 set(${result} 9 PARENT_SCOPE) | |
| 45 elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700) | |
| 46 set(${result} 10 PARENT_SCOPE) | |
| 47 elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800) | |
| 48 set(${result} 11 PARENT_SCOPE) | |
| 49 elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900) | |
| 50 set(${result} 12 PARENT_SCOPE) | |
| 51 elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910) | |
| 52 set(${result} 14 PARENT_SCOPE) | |
| 53 elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920) | |
| 54 set(${result} 15 PARENT_SCOPE) | |
| 55 elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930) | |
| 56 set(${result} 16 PARENT_SCOPE) | |
| 57 else() | |
| 58 message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]") | |
| 59 endif() | |
| 60 endfunction() | |
| 61 | |
| 62 function(conan_cmake_settings result) | |
| 63 #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER}) | |
| 64 #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER_ID}) | |
| 65 #message(STATUS "VERSION " ${CMAKE_CXX_COMPILER_VERSION}) | |
| 66 #message(STATUS "FLAGS " ${CMAKE_LANG_FLAGS}) | |
| 67 #message(STATUS "LIB ARCH " ${CMAKE_CXX_LIBRARY_ARCHITECTURE}) | |
| 68 #message(STATUS "BUILD TYPE " ${CMAKE_BUILD_TYPE}) | |
| 69 #message(STATUS "GENERATOR " ${CMAKE_GENERATOR}) | |
| 70 #message(STATUS "GENERATOR WIN64 " ${CMAKE_CL_64}) | |
| 71 | |
| 72 message(STATUS "Conan: Automatic detection of conan settings from cmake") | |
| 73 | |
| 74 parse_arguments(${ARGV}) | |
| 75 | |
| 76 if(ARGUMENTS_BUILD_TYPE) | |
| 77 set(_CONAN_SETTING_BUILD_TYPE ${ARGUMENTS_BUILD_TYPE}) | |
| 78 elseif(CMAKE_BUILD_TYPE) | |
| 79 set(_CONAN_SETTING_BUILD_TYPE ${CMAKE_BUILD_TYPE}) | |
| 80 else() | |
| 81 message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)") | |
| 82 endif() | |
| 83 | |
| 84 string(TOUPPER ${_CONAN_SETTING_BUILD_TYPE} _CONAN_SETTING_BUILD_TYPE_UPPER) | |
| 85 if (_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "DEBUG") | |
| 86 set(_CONAN_SETTING_BUILD_TYPE "Debug") | |
| 87 elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELEASE") | |
| 88 set(_CONAN_SETTING_BUILD_TYPE "Release") | |
| 89 elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELWITHDEBINFO") | |
| 90 set(_CONAN_SETTING_BUILD_TYPE "RelWithDebInfo") | |
| 91 elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "MINSIZEREL") | |
| 92 set(_CONAN_SETTING_BUILD_TYPE "MinSizeRel") | |
| 93 endif() | |
| 94 | |
| 95 if(ARGUMENTS_ARCH) | |
| 96 set(_CONAN_SETTING_ARCH ${ARGUMENTS_ARCH}) | |
| 97 endif() | |
| 98 #handle -s os setting | |
| 99 if(CMAKE_SYSTEM_NAME) | |
| 100 #use default conan os setting if CMAKE_SYSTEM_NAME is not defined | |
| 101 set(CONAN_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}) | |
| 102 if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") | |
| 103 set(CONAN_SYSTEM_NAME Macos) | |
| 104 endif() | |
| 105 set(CONAN_SUPPORTED_PLATFORMS Windows Linux Macos Android iOS FreeBSD WindowsStore) | |
| 106 list (FIND CONAN_SUPPORTED_PLATFORMS "${CONAN_SYSTEM_NAME}" _index) | |
| 107 if (${_index} GREATER -1) | |
| 108 #check if the cmake system is a conan supported one | |
| 109 set(_CONAN_SETTING_OS ${CONAN_SYSTEM_NAME}) | |
| 110 else() | |
| 111 message(FATAL_ERROR "cmake system ${CONAN_SYSTEM_NAME} is not supported by conan. Use one of ${CONAN_SUPPORTED_PLATFORMS}") | |
| 112 endif() | |
| 113 endif() | |
| 114 | |
| 115 get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES) | |
| 116 if (";${_languages};" MATCHES ";CXX;") | |
| 117 set(LANGUAGE CXX) | |
| 118 set(USING_CXX 1) | |
| 119 elseif (";${_languages};" MATCHES ";C;") | |
| 120 set(LANGUAGE C) | |
| 121 set(USING_CXX 0) | |
| 122 else () | |
| 123 message(FATAL_ERROR "Conan: Neither C or C++ was detected as a language for the project. Unabled to detect compiler version.") | |
| 124 endif() | |
| 125 | |
| 126 if (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU) | |
| 127 # using GCC | |
| 128 # TODO: Handle other params | |
| 129 string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) | |
| 130 list(GET VERSION_LIST 0 MAJOR) | |
| 131 list(GET VERSION_LIST 1 MINOR) | |
| 132 set(COMPILER_VERSION ${MAJOR}.${MINOR}) | |
| 133 if(${MAJOR} GREATER 4) | |
| 134 set(COMPILER_VERSION ${MAJOR}) | |
| 135 endif() | |
| 136 set(_CONAN_SETTING_COMPILER gcc) | |
| 137 set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) | |
| 138 if (USING_CXX) | |
| 139 conan_cmake_detect_unix_libcxx(_LIBCXX) | |
| 140 set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) | |
| 141 endif () | |
| 142 elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang) | |
| 143 # using AppleClang | |
| 144 string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) | |
| 145 list(GET VERSION_LIST 0 MAJOR) | |
| 146 list(GET VERSION_LIST 1 MINOR) | |
| 147 set(_CONAN_SETTING_COMPILER apple-clang) | |
| 148 set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) | |
| 149 if (USING_CXX) | |
| 150 conan_cmake_detect_unix_libcxx(_LIBCXX) | |
| 151 set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) | |
| 152 endif () | |
| 153 elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang) | |
| 154 string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) | |
| 155 list(GET VERSION_LIST 0 MAJOR) | |
| 156 list(GET VERSION_LIST 1 MINOR) | |
| 157 set(_CONAN_SETTING_COMPILER clang) | |
| 158 set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) | |
| 159 if(APPLE) | |
| 160 cmake_policy(GET CMP0025 APPLE_CLANG_POLICY_ENABLED) | |
| 161 if(NOT APPLE_CLANG_POLICY_ENABLED) | |
| 162 message(STATUS "Conan: APPLE and Clang detected. Assuming apple-clang compiler. Set CMP0025 to avoid it") | |
| 163 set(_CONAN_SETTING_COMPILER apple-clang) | |
| 164 endif() | |
| 165 endif() | |
| 166 if(${_CONAN_SETTING_COMPILER} STREQUAL clang AND ${MAJOR} GREATER 7) | |
| 167 set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}) | |
| 168 endif() | |
| 169 if (USING_CXX) | |
| 170 conan_cmake_detect_unix_libcxx(_LIBCXX) | |
| 171 set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) | |
| 172 endif () | |
| 173 elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL MSVC) | |
| 174 set(_VISUAL "Visual Studio") | |
| 175 _get_msvc_ide_version(_VISUAL_VERSION) | |
| 176 if("${_VISUAL_VERSION}" STREQUAL "") | |
| 177 message(FATAL_ERROR "Conan: Visual Studio not recognized") | |
| 178 else() | |
| 179 set(_CONAN_SETTING_COMPILER ${_VISUAL}) | |
| 180 set(_CONAN_SETTING_COMPILER_VERSION ${_VISUAL_VERSION}) | |
| 181 endif() | |
| 182 | |
| 183 if(NOT _CONAN_SETTING_ARCH) | |
| 184 if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64") | |
| 185 set(_CONAN_SETTING_ARCH x86_64) | |
| 186 elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM") | |
| 187 message(STATUS "Conan: Using default ARM architecture from MSVC") | |
| 188 set(_CONAN_SETTING_ARCH armv6) | |
| 189 elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86") | |
| 190 set(_CONAN_SETTING_ARCH x86) | |
| 191 else () | |
| 192 message(FATAL_ERROR "Conan: Unknown MSVC architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]") | |
| 193 endif() | |
| 194 endif() | |
| 195 | |
| 196 conan_cmake_detect_vs_runtime(_vs_runtime) | |
| 197 message(STATUS "Conan: Detected VS runtime: ${_vs_runtime}") | |
| 198 set(_CONAN_SETTING_COMPILER_RUNTIME ${_vs_runtime}) | |
| 199 | |
| 200 if (CMAKE_GENERATOR_TOOLSET) | |
| 201 set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) | |
| 202 elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja")) | |
| 203 set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) | |
| 204 endif() | |
| 205 else() | |
| 206 message(FATAL_ERROR "Conan: compiler setup not recognized") | |
| 207 endif() | |
| 208 | |
| 209 # If profile is defined it is used | |
| 210 if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ARGUMENTS_DEBUG_PROFILE) | |
| 211 set(_APPLIED_PROFILES ${ARGUMENTS_DEBUG_PROFILE}) | |
| 212 elseif(CMAKE_BUILD_TYPE STREQUAL "Release" AND ARGUMENTS_RELEASE_PROFILE) | |
| 213 set(_APPLIED_PROFILES ${ARGUMENTS_RELEASE_PROFILE}) | |
| 214 elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND ARGUMENTS_RELWITHDEBINFO_PROFILE) | |
| 215 set(_APPLIED_PROFILES ${ARGUMENTS_RELWITHDEBINFO_PROFILE}) | |
| 216 elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" AND ARGUMENTS_MINSIZEREL_PROFILE) | |
| 217 set(_APPLIED_PROFILES ${ARGUMENTS_MINSIZEREL_PROFILE}) | |
| 218 elseif(ARGUMENTS_PROFILE) | |
| 219 set(_APPLIED_PROFILES ${ARGUMENTS_PROFILE}) | |
| 220 endif() | |
| 221 | |
| 222 foreach(ARG ${_APPLIED_PROFILES}) | |
| 223 set(_SETTINGS ${_SETTINGS} -pr ${ARG}) | |
| 224 endforeach() | |
| 225 | |
| 226 if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL") | |
| 227 set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version | |
| 228 compiler.runtime compiler.libcxx compiler.toolset) | |
| 229 endif() | |
| 230 | |
| 231 # Automatic from CMake | |
| 232 foreach(ARG ${ARGUMENTS_PROFILE_AUTO}) | |
| 233 string(TOUPPER ${ARG} _arg_name) | |
| 234 string(REPLACE "." "_" _arg_name ${_arg_name}) | |
| 235 if(_CONAN_SETTING_${_arg_name}) | |
| 236 set(_SETTINGS ${_SETTINGS} -s ${ARG}=${_CONAN_SETTING_${_arg_name}}) | |
| 237 endif() | |
| 238 endforeach() | |
| 239 | |
| 240 foreach(ARG ${ARGUMENTS_SETTINGS}) | |
| 241 set(_SETTINGS ${_SETTINGS} -s ${ARG}) | |
| 242 endforeach() | |
| 243 | |
| 244 message(STATUS "Conan: Settings= ${_SETTINGS}") | |
| 245 | |
| 246 set(${result} ${_SETTINGS} PARENT_SCOPE) | |
| 247 endfunction() | |
| 248 | |
| 249 | |
| 250 function(conan_cmake_detect_unix_libcxx result) | |
| 251 # Take into account any -stdlib in compile options | |
| 252 get_directory_property(compile_options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS) | |
| 253 | |
| 254 # Take into account any _GLIBCXX_USE_CXX11_ABI in compile definitions | |
| 255 get_directory_property(defines DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS) | |
| 256 foreach(define ${defines}) | |
| 257 if(define MATCHES "_GLIBCXX_USE_CXX11_ABI") | |
| 258 if(define MATCHES "^-D") | |
| 259 set(compile_options ${compile_options} "${define}") | |
| 260 else() | |
| 261 set(compile_options ${compile_options} "-D${define}") | |
| 262 endif() | |
| 263 endif() | |
| 264 endforeach() | |
| 265 | |
| 266 execute_process( | |
| 267 COMMAND ${CMAKE_COMMAND} -E echo "#include <string>" | |
| 268 COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM - | |
| 269 OUTPUT_VARIABLE string_defines | |
| 270 ) | |
| 271 | |
| 272 if(string_defines MATCHES "#define __GLIBCXX__") | |
| 273 # Allow -D_GLIBCXX_USE_CXX11_ABI=ON/OFF as argument to cmake | |
| 274 if(DEFINED _GLIBCXX_USE_CXX11_ABI) | |
| 275 if(_GLIBCXX_USE_CXX11_ABI) | |
| 276 set(${result} libstdc++11 PARENT_SCOPE) | |
| 277 return() | |
| 278 else() | |
| 279 set(${result} libstdc++ PARENT_SCOPE) | |
| 280 return() | |
| 281 endif() | |
| 282 endif() | |
| 283 | |
| 284 if(string_defines MATCHES "#define _GLIBCXX_USE_CXX11_ABI 1\n") | |
| 285 set(${result} libstdc++11 PARENT_SCOPE) | |
| 286 else() | |
| 287 # Either the compiler is missing the define because it is old, and so | |
| 288 # it can't use the new abi, or the compiler was configured to use the | |
| 289 # old abi by the user or distro (e.g. devtoolset on RHEL/CentOS) | |
| 290 set(${result} libstdc++ PARENT_SCOPE) | |
| 291 endif() | |
| 292 else() | |
| 293 set(${result} libc++ PARENT_SCOPE) | |
| 294 endif() | |
| 295 endfunction() | |
| 296 | |
| 297 function(conan_cmake_detect_vs_runtime result) | |
| 298 string(TOUPPER ${CMAKE_BUILD_TYPE} build_type) | |
| 299 set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS) | |
| 300 foreach(variable ${variables}) | |
| 301 string(REPLACE " " ";" flags ${${variable}}) | |
| 302 foreach (flag ${flags}) | |
| 303 if(${flag} STREQUAL "/MD" OR ${flag} STREQUAL "/MDd" OR ${flag} STREQUAL "/MT" OR ${flag} STREQUAL "/MTd") | |
| 304 string(SUBSTRING ${flag} 1 -1 runtime) | |
| 305 set(${result} ${runtime} PARENT_SCOPE) | |
| 306 return() | |
| 307 endif() | |
| 308 endforeach() | |
| 309 endforeach() | |
| 310 if(${build_type} STREQUAL "DEBUG") | |
| 311 set(${result} "MDd" PARENT_SCOPE) | |
| 312 else() | |
| 313 set(${result} "MD" PARENT_SCOPE) | |
| 314 endif() | |
| 315 endfunction() | |
| 316 | |
| 317 | |
| 318 macro(parse_arguments) | |
| 319 set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS) | |
| 320 set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND) | |
| 321 set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE | |
| 322 PROFILE REQUIRES OPTIONS IMPORTS SETTINGS BUILD ENV GENERATORS PROFILE_AUTO | |
| 323 INSTALL_ARGS) | |
| 324 cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | |
| 325 endmacro() | |
| 326 | |
| 327 function(conan_cmake_install) | |
| 328 # Calls "conan install" | |
| 329 # Argument BUILD is equivalant to --build={missing, PkgName,...} or | |
| 330 # --build when argument is 'BUILD all' (which builds all packages from source) | |
| 331 # Argument CONAN_COMMAND, to specify the conan path, e.g. in case of running from source | |
| 332 # cmake does not identify conan as command, even if it is +x and it is in the path | |
| 333 parse_arguments(${ARGV}) | |
| 334 | |
| 335 if(CONAN_CMAKE_MULTI) | |
| 336 set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake_multi) | |
| 337 else() | |
| 338 set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake) | |
| 339 endif() | |
| 340 | |
| 341 set(CONAN_BUILD_POLICY "") | |
| 342 foreach(ARG ${ARGUMENTS_BUILD}) | |
| 343 if(${ARG} STREQUAL "all") | |
| 344 set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build) | |
| 345 break() | |
| 346 else() | |
| 347 set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build=${ARG}) | |
| 348 endif() | |
| 349 endforeach() | |
| 350 if(ARGUMENTS_CONAN_COMMAND) | |
| 351 set(CONAN_CMD ${ARGUMENTS_CONAN_COMMAND}) | |
| 352 else() | |
| 353 conan_check(REQUIRED) | |
| 354 endif() | |
| 355 set(CONAN_OPTIONS "") | |
| 356 if(ARGUMENTS_CONANFILE) | |
| 357 set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE}) | |
| 358 # A conan file has been specified - apply specified options as well if provided | |
| 359 foreach(ARG ${ARGUMENTS_OPTIONS}) | |
| 360 set(CONAN_OPTIONS ${CONAN_OPTIONS} -o=${ARG}) | |
| 361 endforeach() | |
| 362 else() | |
| 363 set(CONANFILE ".") | |
| 364 endif() | |
| 365 if(ARGUMENTS_UPDATE) | |
| 366 set(CONAN_INSTALL_UPDATE --update) | |
| 367 endif() | |
| 368 if(ARGUMENTS_NO_IMPORTS) | |
| 369 set(CONAN_INSTALL_NO_IMPORTS --no-imports) | |
| 370 endif() | |
| 371 set(CONAN_INSTALL_FOLDER "") | |
| 372 if(ARGUMENTS_INSTALL_FOLDER) | |
| 373 set(CONAN_INSTALL_FOLDER -if=${ARGUMENTS_INSTALL_FOLDER}) | |
| 374 endif() | |
| 375 foreach(ARG ${ARGUMENTS_GENERATORS}) | |
| 376 set(CONAN_GENERATORS ${CONAN_GENERATORS} -g=${ARG}) | |
| 377 endforeach() | |
| 378 foreach(ARG ${ARGUMENTS_ENV}) | |
| 379 set(CONAN_ENV_VARS ${CONAN_ENV_VARS} -e=${ARG}) | |
| 380 endforeach() | |
| 381 set(conan_args install ${CONANFILE} ${settings} ${CONAN_ENV_VARS} ${CONAN_GENERATORS} ${CONAN_BUILD_POLICY} ${CONAN_INSTALL_UPDATE} ${CONAN_INSTALL_NO_IMPORTS} ${CONAN_OPTIONS} ${CONAN_INSTALL_FOLDER} ${ARGUMENTS_INSTALL_ARGS}) | |
| 382 | |
| 383 string (REPLACE ";" " " _conan_args "${conan_args}") | |
| 384 message(STATUS "Conan executing: ${CONAN_CMD} ${_conan_args}") | |
| 385 | |
| 386 if(ARGUMENTS_OUTPUT_QUIET) | |
| 387 execute_process(COMMAND ${CONAN_CMD} ${conan_args} | |
| 388 RESULT_VARIABLE return_code | |
| 389 OUTPUT_VARIABLE conan_output | |
| 390 ERROR_VARIABLE conan_output | |
| 391 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | |
| 392 else() | |
| 393 execute_process(COMMAND ${CONAN_CMD} ${conan_args} | |
| 394 RESULT_VARIABLE return_code | |
| 395 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | |
| 396 endif() | |
| 397 | |
| 398 if(NOT "${return_code}" STREQUAL "0") | |
| 399 message(FATAL_ERROR "Conan install failed='${return_code}'") | |
| 400 endif() | |
| 401 | |
| 402 endfunction() | |
| 403 | |
| 404 | |
| 405 function(conan_cmake_setup_conanfile) | |
| 406 parse_arguments(${ARGV}) | |
| 407 if(ARGUMENTS_CONANFILE) | |
| 408 get_filename_component(_CONANFILE_NAME ${ARGUMENTS_CONANFILE} NAME) | |
| 409 # configure_file will make sure cmake re-runs when conanfile is updated | |
| 410 configure_file(${ARGUMENTS_CONANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk) | |
| 411 file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk) | |
| 412 else() | |
| 413 conan_cmake_generate_conanfile(${ARGV}) | |
| 414 endif() | |
| 415 endfunction() | |
| 416 | |
| 417 function(conan_cmake_generate_conanfile) | |
| 418 # Generate, writing in disk a conanfile.txt with the requires, options, and imports | |
| 419 # specified as arguments | |
| 420 # This will be considered as temporary file, generated in CMAKE_CURRENT_BINARY_DIR) | |
| 421 parse_arguments(${ARGV}) | |
| 422 set(_FN "${CMAKE_CURRENT_BINARY_DIR}/conanfile.txt") | |
| 423 | |
| 424 file(WRITE ${_FN} "[generators]\ncmake\n\n[requires]\n") | |
| 425 foreach(ARG ${ARGUMENTS_REQUIRES}) | |
| 426 file(APPEND ${_FN} ${ARG} "\n") | |
| 427 endforeach() | |
| 428 | |
| 429 file(APPEND ${_FN} ${ARG} "\n[options]\n") | |
| 430 foreach(ARG ${ARGUMENTS_OPTIONS}) | |
| 431 file(APPEND ${_FN} ${ARG} "\n") | |
| 432 endforeach() | |
| 433 | |
| 434 file(APPEND ${_FN} ${ARG} "\n[imports]\n") | |
| 435 foreach(ARG ${ARGUMENTS_IMPORTS}) | |
| 436 file(APPEND ${_FN} ${ARG} "\n") | |
| 437 endforeach() | |
| 438 endfunction() | |
| 439 | |
| 440 | |
| 441 macro(conan_load_buildinfo) | |
| 442 if(CONAN_CMAKE_MULTI) | |
| 443 set(_CONANBUILDINFO conanbuildinfo_multi.cmake) | |
| 444 else() | |
| 445 set(_CONANBUILDINFO conanbuildinfo.cmake) | |
| 446 endif() | |
| 447 if(ARGUMENTS_INSTALL_FOLDER) | |
| 448 set(_CONANBUILDINFOFOLDER ${ARGUMENTS_INSTALL_FOLDER}) | |
| 449 else() | |
| 450 set(_CONANBUILDINFOFOLDER ${CMAKE_CURRENT_BINARY_DIR}) | |
| 451 endif() | |
| 452 # Checks for the existence of conanbuildinfo.cmake, and loads it | |
| 453 # important that it is macro, so variables defined at parent scope | |
| 454 if(EXISTS "${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}") | |
| 455 message(STATUS "Conan: Loading ${_CONANBUILDINFO}") | |
| 456 include(${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}) | |
| 457 else() | |
| 458 message(FATAL_ERROR "${_CONANBUILDINFO} doesn't exist in ${CMAKE_CURRENT_BINARY_DIR}") | |
| 459 endif() | |
| 460 endmacro() | |
| 461 | |
| 462 | |
| 463 macro(conan_cmake_run) | |
| 464 parse_arguments(${ARGV}) | |
| 465 | |
| 466 if(CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE AND NOT CONAN_EXPORTED | |
| 467 AND NOT ARGUMENTS_BUILD_TYPE) | |
| 468 set(CONAN_CMAKE_MULTI ON) | |
| 469 message(STATUS "Conan: Using cmake-multi generator") | |
| 470 else() | |
| 471 set(CONAN_CMAKE_MULTI OFF) | |
| 472 endif() | |
| 473 | |
| 474 if(NOT CONAN_EXPORTED) | |
| 475 conan_cmake_setup_conanfile(${ARGV}) | |
| 476 if(CONAN_CMAKE_MULTI) | |
| 477 foreach(CMAKE_BUILD_TYPE "Release" "Debug") | |
| 478 set(ENV{CONAN_IMPORT_PATH} ${CMAKE_BUILD_TYPE}) | |
| 479 conan_cmake_settings(settings ${ARGV}) | |
| 480 conan_cmake_install(SETTINGS ${settings} ${ARGV}) | |
| 481 endforeach() | |
| 482 set(CMAKE_BUILD_TYPE) | |
| 483 else() | |
| 484 conan_cmake_settings(settings ${ARGV}) | |
| 485 conan_cmake_install(SETTINGS ${settings} ${ARGV}) | |
| 486 endif() | |
| 487 endif() | |
| 488 | |
| 489 if (NOT ARGUMENTS_NO_LOAD) | |
| 490 conan_load_buildinfo() | |
| 491 endif() | |
| 492 | |
| 493 if(ARGUMENTS_BASIC_SETUP) | |
| 494 foreach(_option CMAKE_TARGETS KEEP_RPATHS NO_OUTPUT_DIRS) | |
| 495 if(ARGUMENTS_${_option}) | |
| 496 if(${_option} STREQUAL "CMAKE_TARGETS") | |
| 497 list(APPEND _setup_options "TARGETS") | |
| 498 else() | |
| 499 list(APPEND _setup_options ${_option}) | |
| 500 endif() | |
| 501 endif() | |
| 502 endforeach() | |
| 503 conan_basic_setup(${_setup_options}) | |
| 504 endif() | |
| 505 endmacro() | |
| 506 | |
| 507 macro(conan_check) | |
| 508 # Checks conan availability in PATH | |
| 509 # Arguments REQUIRED and VERSION are optional | |
| 510 # Example usage: | |
| 511 # conan_check(VERSION 1.0.0 REQUIRED) | |
| 512 message(STATUS "Conan: checking conan executable") | |
| 513 set(options REQUIRED) | |
| 514 set(oneValueArgs VERSION) | |
| 515 cmake_parse_arguments(CONAN "${options}" "${oneValueArgs}" "" ${ARGN}) | |
| 516 | |
| 517 find_program(CONAN_CMD conan) | |
| 518 if(NOT CONAN_CMD AND CONAN_REQUIRED) | |
| 519 message(FATAL_ERROR "Conan executable not found!") | |
| 520 endif() | |
| 521 message(STATUS "Conan: Found program ${CONAN_CMD}") | |
| 522 execute_process(COMMAND ${CONAN_CMD} --version | |
| 523 OUTPUT_VARIABLE CONAN_VERSION_OUTPUT | |
| 524 ERROR_VARIABLE CONAN_VERSION_OUTPUT) | |
| 525 message(STATUS "Conan: Version found ${CONAN_VERSION_OUTPUT}") | |
| 526 | |
| 527 if(DEFINED CONAN_VERSION) | |
| 528 string(REGEX MATCH ".*Conan version ([0-9]+\.[0-9]+\.[0-9]+)" FOO | |
| 529 "${CONAN_VERSION_OUTPUT}") | |
| 530 if(${CMAKE_MATCH_1} VERSION_LESS ${CONAN_VERSION}) | |
| 531 message(FATAL_ERROR "Conan outdated. Installed: ${CMAKE_MATCH_1}, \ | |
| 532 required: ${CONAN_VERSION}. Consider updating via 'pip \ | |
| 533 install conan==${CONAN_VERSION}'.") | |
| 534 endif() | |
| 535 endif() | |
| 536 endmacro() | |
| 537 | |
| 538 function(conan_add_remote) | |
| 539 # Adds a remote | |
| 540 # Arguments URL and NAME are required, INDEX and COMMAND are optional | |
| 541 # Example usage: | |
| 542 # conan_add_remote(NAME bincrafters INDEX 1 | |
| 543 # URL https://api.bintray.com/conan/bincrafters/public-conan) | |
| 544 set(oneValueArgs URL NAME INDEX COMMAND) | |
| 545 cmake_parse_arguments(CONAN "" "${oneValueArgs}" "" ${ARGN}) | |
| 546 | |
| 547 if(DEFINED CONAN_INDEX) | |
| 548 set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}") | |
| 549 endif() | |
| 550 if(CONAN_COMMAND) | |
| 551 set(CONAN_CMD ${CONAN_COMMAND}) | |
| 552 else() | |
| 553 conan_check(REQUIRED) | |
| 554 endif() | |
| 555 message(STATUS "Conan: Adding ${CONAN_NAME} remote repository (${CONAN_URL})") | |
| 556 execute_process(COMMAND ${CONAN_CMD} remote add ${CONAN_NAME} ${CONAN_URL} | |
| 557 ${CONAN_INDEX_ARG} -f) | |
| 558 endfunction() |
