From 8517b549f44eb41c93eb1c448de176ad4172f083 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Tue, 21 May 2019 16:10:43 +0200 Subject: FindPython: Add policy to manage lookup stratgey default. --- Help/manual/cmake-policies.7.rst | 1 + Help/policy/CMP0094.rst | 22 ++++++++++++++++++++++ Help/release/dev/FindPython-CMP0094.rst | 5 +++++ Help/release/dev/FindPython-FIND_STRATEGY.rst | 5 +++++ Modules/FindPython.cmake | 4 +++- Modules/FindPython/Support.cmake | 14 ++++++++++++-- Modules/FindPython2.cmake | 4 +++- Modules/FindPython3.cmake | 4 +++- Source/cmPolicies.h | 4 ++++ 9 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 Help/policy/CMP0094.rst create mode 100644 Help/release/dev/FindPython-CMP0094.rst create mode 100644 Help/release/dev/FindPython-FIND_STRATEGY.rst diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index 8d35b86..1d023cb 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -57,6 +57,7 @@ Policies Introduced by CMake 3.15 .. toctree:: :maxdepth: 1 + CMP0094: FindPython3, FindPython2 and FindPython use LOCATION for lookup strategy. CMP0093: FindBoost reports Boost_VERSION in x.y.z format. CMP0092: MSVC warning flags are not in CMAKE_{C,CXX}_FLAGS by default. CMP0091: MSVC runtime library flags are selected by an abstraction. diff --git a/Help/policy/CMP0094.rst b/Help/policy/CMP0094.rst new file mode 100644 index 0000000..836f30f --- /dev/null +++ b/Help/policy/CMP0094.rst @@ -0,0 +1,22 @@ +CMP0094 +------- + +Modules :module:`FindPython3`, :module:`FindPython2` and :module:`FindPython` +use ``LOCATION`` for lookup strategy. + +Starting with CMake 3.15, Modules :module:`FindPython3`, :module:`FindPython2` +and :module:`FindPython` set value ``LOCATION`` for, respectively, variables +``Python3_FIND_STRATEGY``, ``Python2_FIND_STRATEGY`` and +``Python_FIND_STRATEGY``. This policy provides compatibility with projects that +expect the legacy behavior. + +The ``OLD`` behavior for this policy set value ``VERSION`` for variables +``Python3_FIND_STRATEGY``, ``Python2_FIND_STRATEGY`` and +``Python_FIND_STRATEGY``. + +This policy was introduced in CMake version 3.15. Use the +:command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly. +Unlike many policies, CMake version |release| does *not* warn +when this policy is not set and simply uses the ``OLD`` behavior. + +.. include:: DEPRECATED.txt diff --git a/Help/release/dev/FindPython-CMP0094.rst b/Help/release/dev/FindPython-CMP0094.rst new file mode 100644 index 0000000..43442fc --- /dev/null +++ b/Help/release/dev/FindPython-CMP0094.rst @@ -0,0 +1,5 @@ +FindPython-CMP0094 +------------------ + +* Modules :module:`FindPython3`, :module:`FindPython2` and :module:`FindPython` + have changed default strategy for lookup. See policy :policy:`CMP0094`. diff --git a/Help/release/dev/FindPython-FIND_STRATEGY.rst b/Help/release/dev/FindPython-FIND_STRATEGY.rst new file mode 100644 index 0000000..1d06e04 --- /dev/null +++ b/Help/release/dev/FindPython-FIND_STRATEGY.rst @@ -0,0 +1,5 @@ +FindPython-FIND_STRATEGY +------------------------ + +* Modules :module:`FindPython3`, :module:`FindPython2` and :module:`FindPython` + gain a new way to control lookup strategy. diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake index d368ecc..59c286d 100644 --- a/Modules/FindPython.cmake +++ b/Modules/FindPython.cmake @@ -144,9 +144,11 @@ Hints * ``VERSION``: Try to find the most recent version in all specified locations. - This is the default. + This is the default if policy :policy:`CMP0094` is undefined or set to + ``OLD``. * ``LOCATION``: Stops lookup as soon as a version satisfying version constraints is founded. + This is the default if policy :policy:`CMP0094` is set to ``NEW``. ``Python_FIND_REGISTRY`` On Windows the ``Python_FIND_REGISTRY`` variable determine the order diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 4ba0b0f..bb2f60d 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -5,8 +5,14 @@ # This file is a "template" file used by various FindPython modules. # +cmake_policy (GET CMP0094 _${_PYTHON_PREFIX}_LOOKUP_POLICY) + cmake_policy (VERSION 3.7) +if (_${_PYTHON_PREFIX}_LOOKUP_POLICY) + cmake_policy (SET CMP0094 ${_${_PYTHON_PREFIX}_LOOKUP_POLICY}) +endif() + # # Initial configuration # @@ -316,13 +322,17 @@ if (${_PYTHON_PREFIX}_FIND_VERSION_COUNT GREATER 1) endif() # Define lookup strategy -set (_${_PYTHON_PREFIX}_FIND_STRATEGY "VERSION") +if (_${_PYTHON_PREFIX}_LOOKUP_POLICY STREQUAL "NEW") + set (_${_PYTHON_PREFIX}_FIND_STRATEGY "LOCATION") +else() + set (_${_PYTHON_PREFIX}_FIND_STRATEGY "VERSION") +endif() if (DEFINED ${_PYTHON_PREFIX}_FIND_STRATEGY) if (NOT ${_PYTHON_PREFIX}_FIND_STRATEGY MATCHES "^(VERSION|LOCATION)$") message (AUTHOR_WARNING "Find${_PYTHON_PREFIX}: ${${_PYTHON_PREFIX}_FIND_STRATEGY}: invalid value for '${_PYTHON_PREFIX}_FIND_STRATEGY'. 'VERSION' or 'LOCATION' expected.") set (_${_PYTHON_PREFIX}_FIND_STRATEGY "VERSION") else() - set (_${_PYTHON_PREFIX}_FIND_STRATEGY "${${_PYTHON_PREFIX}_FIND_STRATEGY}") + set (_${_PYTHON_PREFIX}_FIND_STRATEGY "${${_PYTHON_PREFIX}_FIND_STRATEGY}") endif() endif() diff --git a/Modules/FindPython2.cmake b/Modules/FindPython2.cmake index eea4d29..8a633e0 100644 --- a/Modules/FindPython2.cmake +++ b/Modules/FindPython2.cmake @@ -145,9 +145,11 @@ Hints * ``VERSION``: Try to find the most recent version in all specified locations. - This is the default. + This is the default if policy :policy:`CMP0094` is undefined or set to + ``OLD``. * ``LOCATION``: Stops lookup as soon as a version satisfying version constraints is founded. + This is the default if policy :policy:`CMP0094` is set to ``NEW``. ``Python2_FIND_REGISTRY`` On Windows the ``Python2_FIND_REGISTRY`` variable determine the order diff --git a/Modules/FindPython3.cmake b/Modules/FindPython3.cmake index 5e42732..2867326 100644 --- a/Modules/FindPython3.cmake +++ b/Modules/FindPython3.cmake @@ -145,9 +145,11 @@ Hints * ``VERSION``: Try to find the most recent version in all specified locations. - This is the default. + This is the default if policy :policy:`CMP0094` is undefined or set to + ``OLD``. * ``LOCATION``: Stops lookup as soon as a version satisfying version constraints is founded. + This is the default if policy :policy:`CMP0094` is set to ``NEW``. ``Python3_FIND_REGISTRY`` On Windows the ``Python3_FIND_REGISTRY`` variable determine the order diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 4bb4c53..b705119 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -275,6 +275,10 @@ class cmMakefile; "MSVC warning flags are not in CMAKE__FLAGS by default.", 3, \ 15, 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0093, "FindBoost reports Boost_VERSION in x.y.z format.", \ + 3, 15, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0094, \ + "FindPython3, FindPython2 and FindPyton use " \ + "LOCATION for lookup strategy.", \ 3, 15, 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) -- cgit v0.12