conan1_deprecated.cmake 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. # The MIT License (MIT)
  2. # Copyright (c) 2018 JFrog
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. # The above copyright notice and this permission notice shall be included in all
  10. # copies or substantial portions of the Software.
  11. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. # SOFTWARE.
  18. # This file comes from: https://github.com/conan-io/cmake-conan. Please refer
  19. # to this repository for issues and documentation.
  20. # Its purpose is to wrap and launch Conan C/C++ Package Manager when cmake is called.
  21. # It will take CMake current settings (os, compiler, compiler version, architecture)
  22. # and translate them to conan settings for installing and retrieving dependencies.
  23. # It is intended to facilitate developers building projects that have conan dependencies,
  24. # but it is only necessary on the end-user side. It is not necessary to create conan
  25. # packages, in fact it shouldn't be use for that. Check the project documentation.
  26. # version: 0.17.0
  27. include(CMakeParseArguments)
  28. function(_get_msvc_ide_version result)
  29. set(${result} "" PARENT_SCOPE)
  30. # VisualStudioVersion is set by vcvars*.bat
  31. if(DEFINED ENV{VisualStudioVersion})
  32. string(REGEX MATCH "([0-9]+)\.0" _ $ENV{VisualStudioVersion})
  33. if(CMAKE_MATCH_COUNT EQUAL 1)
  34. set(${result} ${CMAKE_MATCH_1} PARENT_SCOPE)
  35. return()
  36. else()
  37. message(FATAL_ERROR "Conan: Unexpected env variable VisualStudioVersion format [$ENV{VisualStudioVersion}]")
  38. endif()
  39. endif()
  40. # fallback to MSVC_VERSION which is set only based on _MSC_VER and can differ from the really installed
  41. # Visual Studio version if non-standard toolset is used
  42. if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500)
  43. set(${result} 8 PARENT_SCOPE)
  44. elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600)
  45. set(${result} 9 PARENT_SCOPE)
  46. elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700)
  47. set(${result} 10 PARENT_SCOPE)
  48. elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800)
  49. set(${result} 11 PARENT_SCOPE)
  50. elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900)
  51. set(${result} 12 PARENT_SCOPE)
  52. elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910)
  53. set(${result} 14 PARENT_SCOPE)
  54. elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920)
  55. set(${result} 15 PARENT_SCOPE)
  56. elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930)
  57. set(${result} 16 PARENT_SCOPE)
  58. elseif(NOT MSVC_VERSION VERSION_LESS 1930 AND MSVC_VERSION VERSION_LESS 1940)
  59. set(${result} 17 PARENT_SCOPE)
  60. else()
  61. message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]")
  62. endif()
  63. endfunction()
  64. macro(_conan_detect_build_type)
  65. conan_parse_arguments(${ARGV})
  66. if(ARGUMENTS_BUILD_TYPE)
  67. set(_CONAN_SETTING_BUILD_TYPE ${ARGUMENTS_BUILD_TYPE})
  68. elseif(CMAKE_BUILD_TYPE)
  69. set(_CONAN_SETTING_BUILD_TYPE ${CMAKE_BUILD_TYPE})
  70. else()
  71. message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)")
  72. endif()
  73. string(TOUPPER ${_CONAN_SETTING_BUILD_TYPE} _CONAN_SETTING_BUILD_TYPE_UPPER)
  74. if (_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "DEBUG")
  75. set(_CONAN_SETTING_BUILD_TYPE "Debug")
  76. elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELEASE")
  77. set(_CONAN_SETTING_BUILD_TYPE "Release")
  78. elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELWITHDEBINFO")
  79. set(_CONAN_SETTING_BUILD_TYPE "RelWithDebInfo")
  80. elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "MINSIZEREL")
  81. set(_CONAN_SETTING_BUILD_TYPE "MinSizeRel")
  82. endif()
  83. endmacro()
  84. macro(_conan_check_system_name)
  85. #handle -s os setting
  86. if(CMAKE_SYSTEM_NAME AND NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
  87. #use default conan os setting if CMAKE_SYSTEM_NAME is not defined
  88. set(CONAN_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
  89. if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
  90. set(CONAN_SYSTEM_NAME Macos)
  91. message(STATUS "CMake-Conan: cmake_osx_deployment_target=${CMAKE_OSX_DEPLOYMENT_TARGET}")
  92. set(_CONAN_SETTING_OS_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
  93. endif()
  94. if(${CMAKE_SYSTEM_NAME} STREQUAL "QNX")
  95. set(CONAN_SYSTEM_NAME Neutrino)
  96. endif()
  97. set(CONAN_SUPPORTED_PLATFORMS Windows Linux Macos Android iOS FreeBSD WindowsStore WindowsCE watchOS tvOS FreeBSD SunOS AIX Arduino Emscripten Neutrino)
  98. list (FIND CONAN_SUPPORTED_PLATFORMS "${CONAN_SYSTEM_NAME}" _index)
  99. if (${_index} GREATER -1)
  100. #check if the cmake system is a conan supported one
  101. set(_CONAN_SETTING_OS ${CONAN_SYSTEM_NAME})
  102. else()
  103. message(FATAL_ERROR "cmake system ${CONAN_SYSTEM_NAME} is not supported by conan. Use one of ${CONAN_SUPPORTED_PLATFORMS}")
  104. endif()
  105. endif()
  106. endmacro()
  107. macro(_conan_check_language)
  108. get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
  109. if (";${_languages};" MATCHES ";CXX;")
  110. set(LANGUAGE CXX)
  111. set(USING_CXX 1)
  112. elseif (";${_languages};" MATCHES ";C;")
  113. set(LANGUAGE C)
  114. set(USING_CXX 0)
  115. else ()
  116. message(FATAL_ERROR "Conan: Neither C or C++ was detected as a language for the project. Unabled to detect compiler version.")
  117. endif()
  118. endmacro()
  119. macro(_conan_detect_compiler)
  120. conan_parse_arguments(${ARGV})
  121. if(ARGUMENTS_ARCH)
  122. set(_CONAN_SETTING_ARCH ${ARGUMENTS_ARCH})
  123. endif()
  124. if(USING_CXX)
  125. set(_CONAN_SETTING_COMPILER_CPPSTD ${CMAKE_CXX_STANDARD})
  126. endif()
  127. if (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU)
  128. # using GCC
  129. # TODO: Handle other params
  130. string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION})
  131. list(GET VERSION_LIST 0 MAJOR)
  132. list(GET VERSION_LIST 1 MINOR)
  133. set(COMPILER_VERSION ${MAJOR}.${MINOR})
  134. if(${MAJOR} GREATER 4)
  135. set(COMPILER_VERSION ${MAJOR})
  136. endif()
  137. set(_CONAN_SETTING_COMPILER gcc)
  138. set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION})
  139. if (USING_CXX)
  140. conan_cmake_detect_unix_libcxx(_LIBCXX)
  141. set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX})
  142. endif ()
  143. elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Intel)
  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(COMPILER_VERSION ${MAJOR}.${MINOR})
  148. set(_CONAN_SETTING_COMPILER intel)
  149. set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION})
  150. if (USING_CXX)
  151. conan_cmake_detect_unix_libcxx(_LIBCXX)
  152. set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX})
  153. endif ()
  154. elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang)
  155. # using AppleClang
  156. string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION})
  157. list(GET VERSION_LIST 0 MAJOR)
  158. list(GET VERSION_LIST 1 MINOR)
  159. set(_CONAN_SETTING_COMPILER apple-clang)
  160. set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR})
  161. if (USING_CXX)
  162. conan_cmake_detect_unix_libcxx(_LIBCXX)
  163. set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX})
  164. endif ()
  165. elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang
  166. AND NOT "${CMAKE_${LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC"
  167. AND NOT "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC")
  168. string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION})
  169. list(GET VERSION_LIST 0 MAJOR)
  170. list(GET VERSION_LIST 1 MINOR)
  171. set(_CONAN_SETTING_COMPILER clang)
  172. set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR})
  173. if(APPLE)
  174. cmake_policy(GET CMP0025 APPLE_CLANG_POLICY)
  175. if(NOT APPLE_CLANG_POLICY STREQUAL NEW)
  176. message(STATUS "Conan: APPLE and Clang detected. Assuming apple-clang compiler. Set CMP0025 to avoid it")
  177. set(_CONAN_SETTING_COMPILER apple-clang)
  178. endif()
  179. endif()
  180. if(${_CONAN_SETTING_COMPILER} STREQUAL clang AND ${MAJOR} GREATER 7)
  181. set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR})
  182. endif()
  183. if (USING_CXX)
  184. conan_cmake_detect_unix_libcxx(_LIBCXX)
  185. set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX})
  186. endif ()
  187. elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL MSVC
  188. OR (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang
  189. AND "${CMAKE_${LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC"
  190. AND "${CMAKE_${LANGUAGE}_SIMULATE_ID}" STREQUAL "MSVC"))
  191. set(_VISUAL "Visual Studio")
  192. _get_msvc_ide_version(_VISUAL_VERSION)
  193. if("${_VISUAL_VERSION}" STREQUAL "")
  194. message(FATAL_ERROR "Conan: Visual Studio not recognized")
  195. else()
  196. set(_CONAN_SETTING_COMPILER ${_VISUAL})
  197. set(_CONAN_SETTING_COMPILER_VERSION ${_VISUAL_VERSION})
  198. endif()
  199. if(NOT _CONAN_SETTING_ARCH)
  200. if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64")
  201. set(_CONAN_SETTING_ARCH x86_64)
  202. elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM")
  203. message(STATUS "Conan: Using default ARM architecture from MSVC")
  204. set(_CONAN_SETTING_ARCH armv6)
  205. elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86")
  206. set(_CONAN_SETTING_ARCH x86)
  207. else ()
  208. message(FATAL_ERROR "Conan: Unknown MSVC architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]")
  209. endif()
  210. endif()
  211. conan_cmake_detect_vs_runtime(_vs_runtime ${ARGV})
  212. message(STATUS "Conan: Detected VS runtime: ${_vs_runtime}")
  213. set(_CONAN_SETTING_COMPILER_RUNTIME ${_vs_runtime})
  214. if (CMAKE_GENERATOR_TOOLSET)
  215. set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET})
  216. elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja"))
  217. set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET})
  218. endif()
  219. else()
  220. message(FATAL_ERROR "Conan: compiler setup not recognized")
  221. endif()
  222. endmacro()
  223. function(conan_cmake_settings result)
  224. #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER})
  225. #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER_ID})
  226. #message(STATUS "VERSION " ${CMAKE_CXX_COMPILER_VERSION})
  227. #message(STATUS "FLAGS " ${CMAKE_LANG_FLAGS})
  228. #message(STATUS "LIB ARCH " ${CMAKE_CXX_LIBRARY_ARCHITECTURE})
  229. #message(STATUS "BUILD TYPE " ${CMAKE_BUILD_TYPE})
  230. #message(STATUS "GENERATOR " ${CMAKE_GENERATOR})
  231. #message(STATUS "GENERATOR WIN64 " ${CMAKE_CL_64})
  232. message(STATUS "Conan: Automatic detection of conan settings from cmake")
  233. conan_parse_arguments(${ARGV})
  234. _conan_detect_build_type(${ARGV})
  235. _conan_check_system_name()
  236. _conan_check_language()
  237. _conan_detect_compiler(${ARGV})
  238. # If profile is defined it is used
  239. if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ARGUMENTS_DEBUG_PROFILE)
  240. set(_APPLIED_PROFILES ${ARGUMENTS_DEBUG_PROFILE})
  241. elseif(CMAKE_BUILD_TYPE STREQUAL "Release" AND ARGUMENTS_RELEASE_PROFILE)
  242. set(_APPLIED_PROFILES ${ARGUMENTS_RELEASE_PROFILE})
  243. elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND ARGUMENTS_RELWITHDEBINFO_PROFILE)
  244. set(_APPLIED_PROFILES ${ARGUMENTS_RELWITHDEBINFO_PROFILE})
  245. elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" AND ARGUMENTS_MINSIZEREL_PROFILE)
  246. set(_APPLIED_PROFILES ${ARGUMENTS_MINSIZEREL_PROFILE})
  247. elseif(ARGUMENTS_PROFILE)
  248. set(_APPLIED_PROFILES ${ARGUMENTS_PROFILE})
  249. endif()
  250. foreach(ARG ${_APPLIED_PROFILES})
  251. set(_SETTINGS ${_SETTINGS} -pr=${ARG})
  252. endforeach()
  253. foreach(ARG ${ARGUMENTS_PROFILE_BUILD})
  254. conan_check(VERSION 1.24.0 REQUIRED DETECT_QUIET)
  255. set(_SETTINGS ${_SETTINGS} -pr:b=${ARG})
  256. endforeach()
  257. if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL")
  258. set(ARGUMENTS_PROFILE_AUTO arch os.version build_type compiler compiler.version
  259. compiler.runtime compiler.libcxx compiler.toolset)
  260. endif()
  261. # remove any manually specified settings from the autodetected settings
  262. foreach(ARG ${ARGUMENTS_SETTINGS})
  263. string(REGEX MATCH "[^=]*" MANUAL_SETTING "${ARG}")
  264. message(STATUS "Conan: ${MANUAL_SETTING} was added as an argument. Not using the autodetected one.")
  265. list(REMOVE_ITEM ARGUMENTS_PROFILE_AUTO "${MANUAL_SETTING}")
  266. endforeach()
  267. # Automatic from CMake
  268. foreach(ARG ${ARGUMENTS_PROFILE_AUTO})
  269. string(TOUPPER ${ARG} _arg_name)
  270. string(REPLACE "." "_" _arg_name ${_arg_name})
  271. if(_CONAN_SETTING_${_arg_name})
  272. set(_SETTINGS ${_SETTINGS} -s ${ARG}=${_CONAN_SETTING_${_arg_name}})
  273. endif()
  274. endforeach()
  275. foreach(ARG ${ARGUMENTS_SETTINGS})
  276. set(_SETTINGS ${_SETTINGS} -s ${ARG})
  277. endforeach()
  278. message(STATUS "Conan: Settings= ${_SETTINGS}")
  279. set(${result} ${_SETTINGS} PARENT_SCOPE)
  280. endfunction()
  281. function(conan_cmake_detect_unix_libcxx result)
  282. # Take into account any -stdlib in compile options
  283. get_directory_property(compile_options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS)
  284. string(GENEX_STRIP "${compile_options}" compile_options)
  285. # Take into account any _GLIBCXX_USE_CXX11_ABI in compile definitions
  286. get_directory_property(defines DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS)
  287. string(GENEX_STRIP "${defines}" defines)
  288. foreach(define ${defines})
  289. if(define MATCHES "_GLIBCXX_USE_CXX11_ABI")
  290. if(define MATCHES "^-D")
  291. set(compile_options ${compile_options} "${define}")
  292. else()
  293. set(compile_options ${compile_options} "-D${define}")
  294. endif()
  295. endif()
  296. endforeach()
  297. # add additional compiler options ala cmRulePlaceholderExpander::ExpandRuleVariable
  298. set(EXPAND_CXX_COMPILER ${CMAKE_CXX_COMPILER})
  299. if(CMAKE_CXX_COMPILER_ARG1)
  300. # CMake splits CXX="foo bar baz" into CMAKE_CXX_COMPILER="foo", CMAKE_CXX_COMPILER_ARG1="bar baz"
  301. # without this, ccache, winegcc, or other wrappers might lose all their arguments
  302. separate_arguments(SPLIT_CXX_COMPILER_ARG1 NATIVE_COMMAND ${CMAKE_CXX_COMPILER_ARG1})
  303. list(APPEND EXPAND_CXX_COMPILER ${SPLIT_CXX_COMPILER_ARG1})
  304. endif()
  305. if(CMAKE_CXX_COMPILE_OPTIONS_TARGET AND CMAKE_CXX_COMPILER_TARGET)
  306. # without --target= we may be calling the wrong underlying GCC
  307. list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${CMAKE_CXX_COMPILER_TARGET}")
  308. endif()
  309. if(CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN AND CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
  310. list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN}${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
  311. endif()
  312. if(CMAKE_CXX_COMPILE_OPTIONS_SYSROOT)
  313. # without --sysroot= we may find the wrong #include <string>
  314. if(CMAKE_SYSROOT_COMPILE)
  315. list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT_COMPILE}")
  316. elseif(CMAKE_SYSROOT)
  317. list(APPEND EXPAND_CXX_COMPILER "${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}")
  318. endif()
  319. endif()
  320. separate_arguments(SPLIT_CXX_FLAGS NATIVE_COMMAND ${CMAKE_CXX_FLAGS})
  321. if(CMAKE_OSX_SYSROOT)
  322. set(xcode_sysroot_option "--sysroot=${CMAKE_OSX_SYSROOT}")
  323. endif()
  324. execute_process(
  325. COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
  326. COMMAND ${EXPAND_CXX_COMPILER} ${SPLIT_CXX_FLAGS} -x c++ ${xcode_sysroot_option} ${compile_options} -E -dM -
  327. OUTPUT_VARIABLE string_defines
  328. )
  329. if(string_defines MATCHES "#define __GLIBCXX__")
  330. # Allow -D_GLIBCXX_USE_CXX11_ABI=ON/OFF as argument to cmake
  331. if(DEFINED _GLIBCXX_USE_CXX11_ABI)
  332. if(_GLIBCXX_USE_CXX11_ABI)
  333. set(${result} libstdc++11 PARENT_SCOPE)
  334. return()
  335. else()
  336. set(${result} libstdc++ PARENT_SCOPE)
  337. return()
  338. endif()
  339. endif()
  340. if(string_defines MATCHES "#define _GLIBCXX_USE_CXX11_ABI 1\n")
  341. set(${result} libstdc++11 PARENT_SCOPE)
  342. else()
  343. # Either the compiler is missing the define because it is old, and so
  344. # it can't use the new abi, or the compiler was configured to use the
  345. # old abi by the user or distro (e.g. devtoolset on RHEL/CentOS)
  346. set(${result} libstdc++ PARENT_SCOPE)
  347. endif()
  348. else()
  349. set(${result} libc++ PARENT_SCOPE)
  350. endif()
  351. endfunction()
  352. function(conan_cmake_detect_vs_runtime result)
  353. conan_parse_arguments(${ARGV})
  354. if(ARGUMENTS_BUILD_TYPE)
  355. set(build_type "${ARGUMENTS_BUILD_TYPE}")
  356. elseif(CMAKE_BUILD_TYPE)
  357. set(build_type "${CMAKE_BUILD_TYPE}")
  358. else()
  359. message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)")
  360. endif()
  361. if(build_type)
  362. string(TOUPPER "${build_type}" build_type)
  363. endif()
  364. if (DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
  365. if(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL MultiThreaded)
  366. set(${result} "MT" PARENT_SCOPE)
  367. elseif(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL MultiThreadedDebug)
  368. set(${result} "MTd" PARENT_SCOPE)
  369. elseif(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL MultiThreadedDLL)
  370. set(${result} "MD" PARENT_SCOPE)
  371. elseif(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL MultiThreadedDebugDLL)
  372. set(${result} "MDd" PARENT_SCOPE)
  373. elseif(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  374. if(${build_type} STREQUAL DEBUG)
  375. set(${result} "MTd" PARENT_SCOPE)
  376. else()
  377. set(${result} "MT" PARENT_SCOPE)
  378. endif()
  379. elseif(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
  380. if(${build_type} STREQUAL DEBUG)
  381. set(${result} "MDd" PARENT_SCOPE)
  382. else()
  383. set(${result} "MD" PARENT_SCOPE)
  384. endif()
  385. else()
  386. message(FATAL_ERROR "Incorrect CMAKE_MSVC_RUNTIME_LIBRARY value ${CMAKE_MSVC_RUNTIME_LIBRARY}")
  387. endif()
  388. return()
  389. endif()
  390. set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
  391. foreach(variable ${variables})
  392. if(NOT "${${variable}}" STREQUAL "")
  393. string(REPLACE " " ";" flags "${${variable}}")
  394. foreach (flag ${flags})
  395. if("${flag}" STREQUAL "/MD" OR "${flag}" STREQUAL "/MDd" OR "${flag}" STREQUAL "/MT" OR "${flag}" STREQUAL "/MTd")
  396. string(SUBSTRING "${flag}" 1 -1 runtime)
  397. set(${result} "${runtime}" PARENT_SCOPE)
  398. return()
  399. endif()
  400. endforeach()
  401. endif()
  402. endforeach()
  403. if("${build_type}" STREQUAL "DEBUG")
  404. set(${result} "MDd" PARENT_SCOPE)
  405. else()
  406. set(${result} "MD" PARENT_SCOPE)
  407. endif()
  408. endfunction()
  409. function(_collect_settings result)
  410. set(ARGUMENTS_PROFILE_AUTO arch os.version build_type compiler compiler.version
  411. compiler.runtime compiler.libcxx compiler.toolset
  412. compiler.cppstd)
  413. foreach(ARG ${ARGUMENTS_PROFILE_AUTO})
  414. string(TOUPPER ${ARG} _arg_name)
  415. string(REPLACE "." "_" _arg_name ${_arg_name})
  416. if(_CONAN_SETTING_${_arg_name})
  417. set(detected_setings ${detected_setings} ${ARG}=${_CONAN_SETTING_${_arg_name}})
  418. endif()
  419. endforeach()
  420. set(${result} ${detected_setings} PARENT_SCOPE)
  421. endfunction()
  422. function(conan_cmake_autodetect detected_settings)
  423. _conan_detect_build_type(${ARGV})
  424. _conan_check_system_name()
  425. _conan_check_language()
  426. _conan_detect_compiler(${ARGV})
  427. _collect_settings(collected_settings)
  428. set(${detected_settings} ${collected_settings} PARENT_SCOPE)
  429. endfunction()
  430. macro(conan_parse_arguments)
  431. set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS SKIP_STD)
  432. set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND)
  433. set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE
  434. PROFILE REQUIRES OPTIONS IMPORTS SETTINGS BUILD ENV GENERATORS PROFILE_AUTO
  435. INSTALL_ARGS CONFIGURATION_TYPES PROFILE_BUILD BUILD_REQUIRES)
  436. cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  437. endmacro()
  438. function(old_conan_cmake_install)
  439. # Calls "conan install"
  440. # Argument BUILD is equivalant to --build={missing, PkgName,...} or
  441. # --build when argument is 'BUILD all' (which builds all packages from source)
  442. # Argument CONAN_COMMAND, to specify the conan path, e.g. in case of running from source
  443. # cmake does not identify conan as command, even if it is +x and it is in the path
  444. conan_parse_arguments(${ARGV})
  445. if(CONAN_CMAKE_MULTI)
  446. set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake_multi)
  447. else()
  448. set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake)
  449. endif()
  450. set(CONAN_BUILD_POLICY "")
  451. foreach(ARG ${ARGUMENTS_BUILD})
  452. if(${ARG} STREQUAL "all")
  453. set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build)
  454. break()
  455. else()
  456. set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build=${ARG})
  457. endif()
  458. endforeach()
  459. if(ARGUMENTS_CONAN_COMMAND)
  460. set(CONAN_CMD ${ARGUMENTS_CONAN_COMMAND})
  461. else()
  462. conan_check(REQUIRED)
  463. endif()
  464. set(CONAN_OPTIONS "")
  465. if(ARGUMENTS_CONANFILE)
  466. if(IS_ABSOLUTE ${ARGUMENTS_CONANFILE})
  467. set(CONANFILE ${ARGUMENTS_CONANFILE})
  468. else()
  469. set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE})
  470. endif()
  471. else()
  472. set(CONANFILE ".")
  473. endif()
  474. foreach(ARG ${ARGUMENTS_OPTIONS})
  475. set(CONAN_OPTIONS ${CONAN_OPTIONS} -o=${ARG})
  476. endforeach()
  477. if(ARGUMENTS_UPDATE)
  478. set(CONAN_INSTALL_UPDATE --update)
  479. endif()
  480. if(ARGUMENTS_NO_IMPORTS)
  481. set(CONAN_INSTALL_NO_IMPORTS --no-imports)
  482. endif()
  483. set(CONAN_INSTALL_FOLDER "")
  484. if(ARGUMENTS_INSTALL_FOLDER)
  485. set(CONAN_INSTALL_FOLDER -if=${ARGUMENTS_INSTALL_FOLDER})
  486. endif()
  487. foreach(ARG ${ARGUMENTS_GENERATORS})
  488. set(CONAN_GENERATORS ${CONAN_GENERATORS} -g=${ARG})
  489. endforeach()
  490. foreach(ARG ${ARGUMENTS_ENV})
  491. set(CONAN_ENV_VARS ${CONAN_ENV_VARS} -e=${ARG})
  492. endforeach()
  493. 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})
  494. string (REPLACE ";" " " _conan_args "${conan_args}")
  495. message(STATUS "Conan executing: ${CONAN_CMD} ${_conan_args}")
  496. if(ARGUMENTS_OUTPUT_QUIET)
  497. execute_process(COMMAND ${CONAN_CMD} ${conan_args}
  498. RESULT_VARIABLE return_code
  499. OUTPUT_VARIABLE conan_output
  500. ERROR_VARIABLE conan_output
  501. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
  502. else()
  503. execute_process(COMMAND ${CONAN_CMD} ${conan_args}
  504. RESULT_VARIABLE return_code
  505. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
  506. endif()
  507. if(NOT "${return_code}" STREQUAL "0")
  508. message(FATAL_ERROR "Conan install failed='${return_code}'")
  509. endif()
  510. endfunction()
  511. function(conan_cmake_install)
  512. if(DEFINED CONAN_COMMAND)
  513. set(CONAN_CMD ${CONAN_COMMAND})
  514. else()
  515. conan_check(REQUIRED)
  516. endif()
  517. set(installOptions UPDATE NO_IMPORTS OUTPUT_QUIET ERROR_QUIET)
  518. set(installOneValueArgs PATH_OR_REFERENCE REFERENCE REMOTE LOCKFILE LOCKFILE_OUT LOCKFILE_NODE_ID INSTALL_FOLDER)
  519. set(installMultiValueArgs GENERATOR BUILD ENV ENV_HOST ENV_BUILD OPTIONS_HOST OPTIONS OPTIONS_BUILD PROFILE
  520. PROFILE_HOST PROFILE_BUILD SETTINGS SETTINGS_HOST SETTINGS_BUILD CONF)
  521. cmake_parse_arguments(ARGS "${installOptions}" "${installOneValueArgs}" "${installMultiValueArgs}" ${ARGN})
  522. foreach(arg ${installOptions})
  523. if(ARGS_${arg})
  524. set(${arg} ${${arg}} ${ARGS_${arg}})
  525. endif()
  526. endforeach()
  527. foreach(arg ${installOneValueArgs})
  528. if(DEFINED ARGS_${arg})
  529. if("${arg}" STREQUAL "REMOTE")
  530. set(flag "--remote")
  531. elseif("${arg}" STREQUAL "LOCKFILE")
  532. set(flag "--lockfile")
  533. elseif("${arg}" STREQUAL "LOCKFILE_OUT")
  534. set(flag "--lockfile-out")
  535. elseif("${arg}" STREQUAL "LOCKFILE_NODE_ID")
  536. set(flag "--lockfile-node-id")
  537. elseif("${arg}" STREQUAL "INSTALL_FOLDER")
  538. set(flag "--install-folder")
  539. endif()
  540. set(${arg} ${${arg}} ${flag} ${ARGS_${arg}})
  541. endif()
  542. endforeach()
  543. foreach(arg ${installMultiValueArgs})
  544. if(DEFINED ARGS_${arg})
  545. if("${arg}" STREQUAL "GENERATOR")
  546. set(flag "--generator")
  547. elseif("${arg}" STREQUAL "BUILD")
  548. set(flag "--build")
  549. elseif("${arg}" STREQUAL "ENV")
  550. set(flag "--env")
  551. elseif("${arg}" STREQUAL "ENV_HOST")
  552. set(flag "--env:host")
  553. elseif("${arg}" STREQUAL "ENV_BUILD")
  554. set(flag "--env:build")
  555. elseif("${arg}" STREQUAL "OPTIONS")
  556. set(flag "--options")
  557. elseif("${arg}" STREQUAL "OPTIONS_HOST")
  558. set(flag "--options:host")
  559. elseif("${arg}" STREQUAL "OPTIONS_BUILD")
  560. set(flag "--options:build")
  561. elseif("${arg}" STREQUAL "PROFILE")
  562. set(flag "--profile")
  563. elseif("${arg}" STREQUAL "PROFILE_HOST")
  564. set(flag "--profile:host")
  565. elseif("${arg}" STREQUAL "PROFILE_BUILD")
  566. set(flag "--profile:build")
  567. elseif("${arg}" STREQUAL "SETTINGS")
  568. set(flag "--settings")
  569. elseif("${arg}" STREQUAL "SETTINGS_HOST")
  570. set(flag "--settings:host")
  571. elseif("${arg}" STREQUAL "SETTINGS_BUILD")
  572. set(flag "--settings:build")
  573. elseif("${arg}" STREQUAL "CONF")
  574. set(flag "--conf")
  575. endif()
  576. list(LENGTH ARGS_${arg} numargs)
  577. foreach(item ${ARGS_${arg}})
  578. if(${item} STREQUAL "all" AND ${arg} STREQUAL "BUILD")
  579. set(${arg} "--build")
  580. break()
  581. endif()
  582. set(${arg} ${${arg}} ${flag} ${item})
  583. endforeach()
  584. endif()
  585. endforeach()
  586. if(DEFINED UPDATE)
  587. set(UPDATE --update)
  588. endif()
  589. if(DEFINED NO_IMPORTS)
  590. set(NO_IMPORTS --no-imports)
  591. endif()
  592. set(install_args install ${PATH_OR_REFERENCE} ${REFERENCE} ${UPDATE} ${NO_IMPORTS} ${REMOTE} ${LOCKFILE} ${LOCKFILE_OUT} ${LOCKFILE_NODE_ID} ${INSTALL_FOLDER}
  593. ${GENERATOR} ${BUILD} ${ENV} ${ENV_HOST} ${ENV_BUILD} ${OPTIONS} ${OPTIONS_HOST} ${OPTIONS_BUILD}
  594. ${PROFILE} ${PROFILE_HOST} ${PROFILE_BUILD} ${SETTINGS} ${SETTINGS_HOST} ${SETTINGS_BUILD} ${CONF})
  595. string(REPLACE ";" " " _install_args "${install_args}")
  596. message(STATUS "Conan executing: ${CONAN_CMD} ${_install_args}")
  597. if(ARGS_OUTPUT_QUIET)
  598. set(OUTPUT_OPT OUTPUT_QUIET)
  599. endif()
  600. if(ARGS_ERROR_QUIET)
  601. set(ERROR_OPT ERROR_QUIET)
  602. endif()
  603. execute_process(COMMAND ${CONAN_CMD} ${install_args}
  604. RESULT_VARIABLE return_code
  605. ${OUTPUT_OPT}
  606. ${ERROR_OPT}
  607. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
  608. if(NOT "${return_code}" STREQUAL "0")
  609. if (ARGS_ERROR_QUIET)
  610. message(WARNING "Conan install failed='${return_code}'")
  611. else()
  612. message(FATAL_ERROR "Conan install failed='${return_code}'")
  613. endif()
  614. endif()
  615. endfunction()
  616. function(conan_cmake_setup_conanfile)
  617. conan_parse_arguments(${ARGV})
  618. if(ARGUMENTS_CONANFILE)
  619. get_filename_component(_CONANFILE_NAME ${ARGUMENTS_CONANFILE} NAME)
  620. # configure_file will make sure cmake re-runs when conanfile is updated
  621. configure_file(${ARGUMENTS_CONANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk COPYONLY)
  622. file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk)
  623. else()
  624. conan_cmake_generate_conanfile(ON ${ARGV})
  625. endif()
  626. endfunction()
  627. function(conan_cmake_configure)
  628. conan_cmake_generate_conanfile(OFF ${ARGV})
  629. endfunction()
  630. # Generate, writing in disk a conanfile.txt with the requires, options, and imports
  631. # specified as arguments
  632. # This will be considered as temporary file, generated in CMAKE_CURRENT_BINARY_DIR)
  633. function(conan_cmake_generate_conanfile DEFAULT_GENERATOR)
  634. conan_parse_arguments(${ARGV})
  635. set(_FN "${CMAKE_CURRENT_BINARY_DIR}/conanfile.txt")
  636. file(WRITE ${_FN} "")
  637. if(DEFINED ARGUMENTS_REQUIRES)
  638. file(APPEND ${_FN} "[requires]\n")
  639. foreach(REQUIRE ${ARGUMENTS_REQUIRES})
  640. file(APPEND ${_FN} ${REQUIRE} "\n")
  641. endforeach()
  642. endif()
  643. if (DEFAULT_GENERATOR OR DEFINED ARGUMENTS_GENERATORS)
  644. file(APPEND ${_FN} "[generators]\n")
  645. if (DEFAULT_GENERATOR)
  646. file(APPEND ${_FN} "cmake\n")
  647. endif()
  648. if (DEFINED ARGUMENTS_GENERATORS)
  649. foreach(GENERATOR ${ARGUMENTS_GENERATORS})
  650. file(APPEND ${_FN} ${GENERATOR} "\n")
  651. endforeach()
  652. endif()
  653. endif()
  654. if(DEFINED ARGUMENTS_BUILD_REQUIRES)
  655. file(APPEND ${_FN} "[build_requires]\n")
  656. foreach(BUILD_REQUIRE ${ARGUMENTS_BUILD_REQUIRES})
  657. file(APPEND ${_FN} ${BUILD_REQUIRE} "\n")
  658. endforeach()
  659. endif()
  660. if(DEFINED ARGUMENTS_IMPORTS)
  661. file(APPEND ${_FN} "[imports]\n")
  662. foreach(IMPORTS ${ARGUMENTS_IMPORTS})
  663. file(APPEND ${_FN} ${IMPORTS} "\n")
  664. endforeach()
  665. endif()
  666. if(DEFINED ARGUMENTS_OPTIONS)
  667. file(APPEND ${_FN} "[options]\n")
  668. foreach(OPTION ${ARGUMENTS_OPTIONS})
  669. file(APPEND ${_FN} ${OPTION} "\n")
  670. endforeach()
  671. endif()
  672. endfunction()
  673. macro(conan_load_buildinfo)
  674. if(CONAN_CMAKE_MULTI)
  675. set(_CONANBUILDINFO conanbuildinfo_multi.cmake)
  676. else()
  677. set(_CONANBUILDINFO conanbuildinfo.cmake)
  678. endif()
  679. if(ARGUMENTS_INSTALL_FOLDER)
  680. set(_CONANBUILDINFOFOLDER ${ARGUMENTS_INSTALL_FOLDER})
  681. else()
  682. set(_CONANBUILDINFOFOLDER ${CMAKE_CURRENT_BINARY_DIR})
  683. endif()
  684. # Checks for the existence of conanbuildinfo.cmake, and loads it
  685. # important that it is macro, so variables defined at parent scope
  686. if(EXISTS "${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}")
  687. message(STATUS "Conan: Loading ${_CONANBUILDINFO}")
  688. include(${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO})
  689. else()
  690. message(FATAL_ERROR "${_CONANBUILDINFO} doesn't exist in ${CMAKE_CURRENT_BINARY_DIR}")
  691. endif()
  692. endmacro()
  693. macro(conan_cmake_run)
  694. conan_parse_arguments(${ARGV})
  695. if(ARGUMENTS_CONFIGURATION_TYPES AND NOT CMAKE_CONFIGURATION_TYPES)
  696. message(WARNING "CONFIGURATION_TYPES should only be specified for multi-configuration generators")
  697. elseif(ARGUMENTS_CONFIGURATION_TYPES AND ARGUMENTS_BUILD_TYPE)
  698. message(WARNING "CONFIGURATION_TYPES and BUILD_TYPE arguments should not be defined at the same time.")
  699. endif()
  700. if(CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE AND NOT CONAN_EXPORTED
  701. AND NOT ARGUMENTS_BUILD_TYPE)
  702. set(CONAN_CMAKE_MULTI ON)
  703. if (NOT ARGUMENTS_CONFIGURATION_TYPES)
  704. set(ARGUMENTS_CONFIGURATION_TYPES "Release;Debug")
  705. endif()
  706. message(STATUS "Conan: Using cmake-multi generator")
  707. else()
  708. set(CONAN_CMAKE_MULTI OFF)
  709. endif()
  710. if(NOT CONAN_EXPORTED)
  711. conan_cmake_setup_conanfile(${ARGV})
  712. if(CONAN_CMAKE_MULTI)
  713. foreach(CMAKE_BUILD_TYPE ${ARGUMENTS_CONFIGURATION_TYPES})
  714. set(ENV{CONAN_IMPORT_PATH} ${CMAKE_BUILD_TYPE})
  715. conan_cmake_settings(settings ${ARGV})
  716. old_conan_cmake_install(SETTINGS ${settings} ${ARGV})
  717. endforeach()
  718. set(CMAKE_BUILD_TYPE)
  719. else()
  720. conan_cmake_settings(settings ${ARGV})
  721. old_conan_cmake_install(SETTINGS ${settings} ${ARGV})
  722. endif()
  723. endif()
  724. if (NOT ARGUMENTS_NO_LOAD)
  725. conan_load_buildinfo()
  726. endif()
  727. if(ARGUMENTS_BASIC_SETUP)
  728. foreach(_option CMAKE_TARGETS KEEP_RPATHS NO_OUTPUT_DIRS SKIP_STD)
  729. if(ARGUMENTS_${_option})
  730. if(${_option} STREQUAL "CMAKE_TARGETS")
  731. list(APPEND _setup_options "TARGETS")
  732. else()
  733. list(APPEND _setup_options ${_option})
  734. endif()
  735. endif()
  736. endforeach()
  737. conan_basic_setup(${_setup_options})
  738. endif()
  739. endmacro()
  740. macro(conan_check)
  741. # Checks conan availability in PATH
  742. # Arguments REQUIRED, DETECT_QUIET and VERSION are optional
  743. # Example usage:
  744. # conan_check(VERSION 1.0.0 REQUIRED)
  745. set(options REQUIRED DETECT_QUIET)
  746. set(oneValueArgs VERSION)
  747. cmake_parse_arguments(CONAN "${options}" "${oneValueArgs}" "" ${ARGN})
  748. if(NOT CONAN_DETECT_QUIET)
  749. message(STATUS "Conan: checking conan executable")
  750. endif()
  751. find_program(CONAN_CMD conan)
  752. if(NOT CONAN_CMD AND CONAN_REQUIRED)
  753. message(FATAL_ERROR "Conan executable not found! Please install conan.")
  754. endif()
  755. if(NOT CONAN_DETECT_QUIET)
  756. message(STATUS "Conan: Found program ${CONAN_CMD}")
  757. endif()
  758. execute_process(COMMAND ${CONAN_CMD} --version
  759. RESULT_VARIABLE return_code
  760. OUTPUT_VARIABLE CONAN_VERSION_OUTPUT
  761. ERROR_VARIABLE CONAN_VERSION_OUTPUT)
  762. if(NOT "${return_code}" STREQUAL "0")
  763. message(FATAL_ERROR "Conan --version failed='${return_code}'")
  764. endif()
  765. if(NOT CONAN_DETECT_QUIET)
  766. string(STRIP "${CONAN_VERSION_OUTPUT}" _CONAN_VERSION_OUTPUT)
  767. message(STATUS "Conan: Version found ${_CONAN_VERSION_OUTPUT}")
  768. endif()
  769. if(DEFINED CONAN_VERSION)
  770. string(REGEX MATCH ".*Conan version ([0-9]+\\.[0-9]+\\.[0-9]+)" FOO
  771. "${CONAN_VERSION_OUTPUT}")
  772. if(${CMAKE_MATCH_1} VERSION_LESS ${CONAN_VERSION})
  773. message(FATAL_ERROR "Conan outdated. Installed: ${CMAKE_MATCH_1}, \
  774. required: ${CONAN_VERSION}. Consider updating via 'pip \
  775. install conan==${CONAN_VERSION}'.")
  776. endif()
  777. endif()
  778. endmacro()
  779. function(conan_add_remote)
  780. # Adds a remote
  781. # Arguments URL and NAME are required, INDEX, COMMAND and VERIFY_SSL are optional
  782. # Example usage:
  783. # conan_add_remote(NAME bincrafters INDEX 1
  784. # URL https://api.bintray.com/conan/bincrafters/public-conan
  785. # VERIFY_SSL True)
  786. set(oneValueArgs URL NAME INDEX COMMAND VERIFY_SSL)
  787. cmake_parse_arguments(CONAN "" "${oneValueArgs}" "" ${ARGN})
  788. if(DEFINED CONAN_INDEX)
  789. set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}")
  790. endif()
  791. if(DEFINED CONAN_COMMAND)
  792. set(CONAN_CMD ${CONAN_COMMAND})
  793. else()
  794. conan_check(REQUIRED DETECT_QUIET)
  795. endif()
  796. set(CONAN_VERIFY_SSL_ARG "True")
  797. if(DEFINED CONAN_VERIFY_SSL)
  798. set(CONAN_VERIFY_SSL_ARG ${CONAN_VERIFY_SSL})
  799. endif()
  800. message(STATUS "Conan: Adding ${CONAN_NAME} remote repository (${CONAN_URL}) verify ssl (${CONAN_VERIFY_SSL_ARG})")
  801. execute_process(COMMAND ${CONAN_CMD} remote add ${CONAN_NAME} ${CONAN_INDEX_ARG} -f ${CONAN_URL} ${CONAN_VERIFY_SSL_ARG}
  802. RESULT_VARIABLE return_code)
  803. if(NOT "${return_code}" STREQUAL "0")
  804. message(FATAL_ERROR "Conan remote failed='${return_code}'")
  805. endif()
  806. endfunction()
  807. macro(conan_config_install)
  808. # install a full configuration from a local or remote zip file
  809. # Argument ITEM is required, arguments TYPE, SOURCE, TARGET and VERIFY_SSL are optional
  810. # Example usage:
  811. # conan_config_install(ITEM https://github.com/conan-io/cmake-conan.git
  812. # TYPE git SOURCE source-folder TARGET target-folder VERIFY_SSL false)
  813. set(oneValueArgs ITEM TYPE SOURCE TARGET VERIFY_SSL)
  814. set(multiValueArgs ARGS)
  815. cmake_parse_arguments(CONAN "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  816. find_program(CONAN_CMD conan)
  817. if(NOT CONAN_CMD AND CONAN_REQUIRED)
  818. message(FATAL_ERROR "Conan executable not found!")
  819. endif()
  820. if(DEFINED CONAN_VERIFY_SSL)
  821. set(CONAN_VERIFY_SSL_ARG "--verify-ssl=${CONAN_VERIFY_SSL}")
  822. endif()
  823. if(DEFINED CONAN_TYPE)
  824. set(CONAN_TYPE_ARG "--type=${CONAN_TYPE}")
  825. endif()
  826. if(DEFINED CONAN_ARGS)
  827. set(CONAN_ARGS_ARGS "--args=\"${CONAN_ARGS}\"")
  828. endif()
  829. if(DEFINED CONAN_SOURCE)
  830. set(CONAN_SOURCE_ARGS "--source-folder=${CONAN_SOURCE}")
  831. endif()
  832. if(DEFINED CONAN_TARGET)
  833. set(CONAN_TARGET_ARGS "--target-folder=${CONAN_TARGET}")
  834. endif()
  835. set (CONAN_CONFIG_INSTALL_ARGS ${CONAN_VERIFY_SSL_ARG}
  836. ${CONAN_TYPE_ARG}
  837. ${CONAN_ARGS_ARGS}
  838. ${CONAN_SOURCE_ARGS}
  839. ${CONAN_TARGET_ARGS})
  840. message(STATUS "Conan: Installing config from ${CONAN_ITEM}")
  841. execute_process(COMMAND ${CONAN_CMD} config install ${CONAN_ITEM} ${CONAN_CONFIG_INSTALL_ARGS}
  842. RESULT_VARIABLE return_code)
  843. if(NOT "${return_code}" STREQUAL "0")
  844. message(FATAL_ERROR "Conan config failed='${return_code}'")
  845. endif()
  846. endmacro()