Skip to content

Commit

Permalink
Merge pull request #517 from ssrobins/check-conan-version
Browse files Browse the repository at this point in the history
Check required Conan version
  • Loading branch information
memsharded authored May 21, 2023
2 parents d296a90 + 7d39630 commit f49e229
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions conan_support.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
set(CONAN_MINIMUM_VERSION 2.0.2)


function(detect_os OS)
# it could be cross compilation
message(STATUS "CMake-Conan: cmake_system_name=${CMAKE_SYSTEM_NAME}")
Expand Down Expand Up @@ -163,10 +166,48 @@ function(conan_install)
endfunction()


function(conan_get_version conan_command conan_current_version)
execute_process(
COMMAND ${conan_command} --version
OUTPUT_VARIABLE conan_output
RESULT_VARIABLE conan_result
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(conan_result)
message(FATAL_ERROR "CMake-Conan: Error when trying to run Conan")
endif()

string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" conan_version ${conan_output})
set(${conan_current_version} ${conan_version} PARENT_SCOPE)
endfunction()


function(conan_version_check)
set(options )
set(oneValueArgs MINIMUM CURRENT)
set(multiValueArgs )
cmake_parse_arguments(CONAN_VERSION_CHECK
"${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT CONAN_VERSION_CHECK_MINIMUM)
message(FATAL_ERROR "CMake-Conan: Required parameter MINIMUM not set!")
endif()
if(NOT CONAN_VERSION_CHECK_CURRENT)
message(FATAL_ERROR "CMake-Conan: Required parameter CURRENT not set!")
endif()

if(CONAN_VERSION_CHECK_CURRENT VERSION_LESS CONAN_VERSION_CHECK_MINIMUM)
message(FATAL_ERROR "CMake-Conan: Conan version must be ${CONAN_VERSION_CHECK_MINIMUM} or later")
endif()
endfunction()


macro(conan_provide_dependency package_name)
get_property(CONAN_INSTALL_SUCCESS GLOBAL PROPERTY CONAN_INSTALL_SUCCESS)
if(NOT CONAN_INSTALL_SUCCESS)
find_program(CONAN_COMMAND "conan" REQUIRED)
conan_get_version(${CONAN_COMMAND} CONAN_CURRENT_VERSION)
conan_version_check(MINIMUM ${CONAN_MINIMUM_VERSION} CURRENT ${CONAN_CURRENT_VERSION})
message(STATUS "CMake-Conan: first find_package() found. Installing dependencies with Conan")
conan_profile_detect_default()
detect_host_profile(${CMAKE_BINARY_DIR}/conan_host_profile)
Expand Down

0 comments on commit f49e229

Please sign in to comment.