Advertisement
dev_kongor

conan install through cmake

Feb 12th, 2020
952
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cmake_minimum_required(VERSION 3.16)
  2. project(conan_test)
  3.  
  4. function(conan_install file_out)
  5.     set(CONAN_CMAKE_MODULE_DIR_PATH "${CMAKE_BINARY_DIR}/ConanFiles")
  6.     set(CONAN_PROFILES_DIR_PATH "${CMAKE_SOURCE_DIR}/profiles")
  7.  
  8.     set(CONAN_FILE_DIR "${CMAKE_SOURCE_DIR}")
  9.     set(CONAN_FILE_PATH "${CMAKE_SOURCE_DIR}/conanfile.txt")
  10.  
  11.     set(CONAN_CMAKE_MODULE_MULTI_PATH   "${CONAN_CMAKE_MODULE_DIR_PATH}/conanbuildinfo_multi.cmake")
  12.     set(CONAN_CMAKE_MODULE_RELEASE_PATH "${CONAN_CMAKE_MODULE_DIR_PATH}/conanbuildinfo_release.cmake")
  13.     set(CONAN_CMAKE_MODULE_DEBUG_PATH   "${CONAN_CMAKE_MODULE_DIR_PATH}/conanbuildinfo_debug.cmake")
  14.  
  15.     message(STATUS ${CONAN_FILE_PATH} " - " ${CONAN_CMAKE_MODULE_MULTI_PATH})
  16.     if(NOT EXISTS ${CONAN_CMAKE_MODULE_MULTI_PATH}
  17.         OR "${CONAN_FILE_PATH}" IS_NEWER_THAN "${CONAN_CMAKE_MODULE_MULTI_PATH}"
  18.         OR "${CONAN_FILE_PATH}" IS_NEWER_THAN "${CONAN_CMAKE_MODULE_RELEASE_PATH}"
  19.         OR "${CONAN_FILE_PATH}" IS_NEWER_THAN "${CONAN_CMAKE_MODULE_DEBUG_PATH}")
  20.  
  21.         message(STATUS "Installing dependencies...")
  22.         file(REMOVE_RECURSE "${CONAN_CMAKE_MODULE_DIR_PATH}")
  23.         function(conan_install_profile profile)
  24.             message(STATUS "Installing dependencies for profile: ${profile}")
  25.             execute_process(
  26.                 OUTPUT_QUIET ERROR_VARIABLE error_out
  27.                 COMMAND conan install "${CONAN_FILE_DIR}"
  28.                     -if "${CONAN_CMAKE_MODULE_DIR_PATH}"
  29.                     --profile "${CONAN_PROFILES_DIR_PATH}/${profile}"
  30.                     )
  31.             if (error_out)
  32.                 message(FATAL_ERROR "Failed to install conan dependencies for profile: ${profile}\n${error_out}")
  33.             endif()
  34.             message(STATUS "Installing dependencies for profile: ${profile} -- done")
  35.         endfunction()
  36.         conan_install_profile(release)
  37.         conan_install_profile(debug)
  38.  
  39.     else()
  40.         message(STATUS "Conan configuration allready exists - using it")
  41.     endif()
  42.  
  43.     set(${file_out} ${CONAN_CMAKE_MODULE_MULTI_PATH} PARENT_SCOPE)
  44. endfunction()
  45.  
  46. conan_install(CONAN_CMAKE_FILE)
  47. include(${CONAN_CMAKE_FILE})
  48. unset(CONAN_CMAKE_FILE)
Advertisement
RAW Paste Data Copied
Advertisement