conan.cmake 37 KB

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