set(Python3_FIND_QUIETLY ON)
set(PythonInterp_FIND_QUIETLY ON)
endif()
-# Older CMake versions might not search for Python newer than 3.7.
-set(Python_ADDITIONAL_VERSIONS 3.8 3.9 3.10)
-# We advocate using Python venvs to manage package availability, so by default
-# we want to preferentially discover user-space software.
-set(Python3_FIND_REGISTRY LAST)
-# Make package discovery consistent with Unix behavior and our documented
-# suggestions for installing dependencies.
-set(CMAKE_FIND_FRAMEWORK LAST)
+if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
+ if (NOT Python3_FIND_STRATEGY)
+ # If the user provides a hint for the Python installation with Python3_ROOT_DIR,
+ # prevent FindPython3 from overriding the choice with a newer Python version
+ # when CMP0094 is set to OLD.
+ set(Python3_FIND_STRATEGY LOCATION)
+ endif ()
+ if(NOT Python3_FIND_VIRTUALENV)
+ # We advocate using Python venvs to manage package availability, so by default
+ # we want to preferentially discover user-space software.
+ set(Python3_FIND_VIRTUALENV FIRST)
+ endif()
+else()
+ if(NOT Python3_FIND_REGISTRY)
+ # We advocate using Python venvs to manage package availability, so by default
+ # we want to preferentially discover user-space software.
+ set(Python3_FIND_REGISTRY LAST)
+ endif()
+ # Make package discovery consistent with Unix behavior and our documented
+ # suggestions for installing dependencies.
+ set(CMAKE_FIND_FRAMEWORK LAST)
+endif ()
if(GMX_PYTHON_PACKAGE)
find_package(Python3 3.6 COMPONENTS Interpreter Development)
if (NOT Python3_FOUND OR NOT Python3_Development_FOUND)
else()
find_package(Python3 3.6 COMPONENTS Interpreter)
endif()
+
+# Provide hints for other Python detection that may occur later.
+#
# Other components, such as pybind and googletest, may expect the
# PYTHON_EXECUTABLE variable from pre-3.12 FindPythonInterp.cmake.
if (Python3_Interpreter_FOUND)
# may call find_package(PythonInterp) later on.
set(Python3_FIND_QUIETLY ON)
set(PythonInterp_FIND_QUIETLY ON)
+# Older versions of FindPythonLibs and FindPythonInterp might not search for
+# Python newer than 3.7 by default. (as of CMake 3.9)
+# Note that this hint is not used by the newer FindPython module we rely on above.
+set(Python_ADDITIONAL_VERSIONS 3.8 3.9 3.10)