Skip to content

Commit

Permalink
conan-provider.cmake: introduce a new policy scope, set min cmake ver…
Browse files Browse the repository at this point in the history
…sion

cmake has the notion of "policy scopes" to limit the scope of the policies.
this patch introduces a module-level policy scope and sets the minimum
required cmake version to 3.24, so the cmake features depend on policy settings
such as `if(... IN_LIST ...)` behaves as expected even if the consuming project
does not declare a cmake minimum version requirement. also, this change now
enforces the version requirement so the code would fail immediately if the
cmake version is less than the minimum.
  • Loading branch information
xmkg committed Jun 3, 2024
1 parent 8036ecf commit fd4abcb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@

set(CONAN_MINIMUM_VERSION 2.0.5)

# Create a new policy scope and set the minimum required cmake version so the
# features behind a policy setting like if(... IN_LIST ...) behaves as expected
# even if the parent project does not specify a minimum cmake version before the
# first project() call.
# (see: https://cmake.org/cmake/help/latest/variable/CMAKE_PROJECT_TOP_LEVEL_INCLUDES.html)
#
# The policy-affecting calls like cmake_policy(SET...) or `cmake_minimum_required` only
# affects the current policy scope, i.e. between the PUSH and POP in this case.
#
# https://cmake.org/cmake/help/book/mastering-cmake/chapter/Policies.html#the-policy-stack
cmake_policy(PUSH)
cmake_minimum_required(VERSION 3.24)

function(detect_os OS OS_API_LEVEL OS_SDK OS_SUBSYSTEM OS_VERSION)
# it could be cross compilation
Expand Down Expand Up @@ -647,3 +659,5 @@ if(NOT _cmake_program)
get_filename_component(PATH_TO_CMAKE_BIN "${CMAKE_COMMAND}" DIRECTORY)
set(PATH_TO_CMAKE_BIN "${PATH_TO_CMAKE_BIN}" CACHE INTERNAL "Path where the CMake executable is")
endif()

cmake_policy(POP)

0 comments on commit fd4abcb

Please sign in to comment.