-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use cmake policy instead of minimum #53
base: master
Are you sure you want to change the base?
Conversation
Policy correctly scopes the changes to the Config file, rather than applying the change to the rest of the user's code when called from inside `find_package` or `find_dependency`.
message(FATAL_ERROR "CMake >= 3.0.0 required") | ||
endif() | ||
cmake_policy(PUSH) | ||
cmake_policy(VERSION 3.0.0...3.27) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmake_policy(VERSION 3.0.0...3.27) | |
cmake_policy(VERSION 3.8.0...3.27) |
@@ -1,10 +1,18 @@ | |||
# -------------------------------------------------------------------------------------- # | |||
|
|||
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessary
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.8) | ||
message(FATAL_ERROR "CMake >= 3.0.0 required") | ||
endif() | ||
if(CMAKE_VERSION VERSION_LESS "3.0.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this 3.0.0 and not 3.8.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated usage mirrors the CMake-generated Targets.cmake file: assertions to check for the rough CMake version, then a scoped policy change for the file itself.
I suspect cmake does this for better backward compatibility with old versions: each successive test requires newer features. If you look at the cmake-generated Targets from any installation you'll see the same assertions in the same order.
This is a follow-up to #51 and is related to some nasty obscure side effects of the policy alteration by the previous implementation, seen in celeritas-project/celeritas#1573.
It's unusual to use
cmake_minimum_required
in a package config file, since it can alter policy scope elsewhere (depending, of course, on the policy that's been set). Thecmake_policy
command correctly scopes the changes to the Config file, rather than applying the change to the rest of the user's code when called from insidefind_package
orfind_dependency
.The updated usage mirrors the CMake-generated
Targets.cmake
file: assertions to check for the rough CMake version, then a scoped policy change for the file itself.