conan.cmake 37 KB

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