#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2020, by the GROMACS development team, led by
+# Copyright (c) 2020,2021, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
# the research papers on the package. Check out http://www.gromacs.org.
# Perform Python installation discovery early and in one place, for consistency.
-#
+
+if($<VERSION_GREATER_EQUAL:${CMAKE_VERSION},"3.18">)
+ # With embedded packages in this repository, the module-scoped default behavior of
+ # FindPython3 version/component requirements and artifact specification is likely
+ # confusing (at best) or leading to bad logic (at worst).
+ # https://cmake.org/cmake/help/latest/module/FindPython3.html#artifacts-specification
+ option(Python3_ARTIFACTS_INTERACTIVE TRUE
+ "Make artifacts specification global and cached.")
+elseif(NOT FIND_PACKAGE_MESSAGE_DETAILS_Python3)
+ # On first run, check whether the user has triggered the behavior described above.
+ if (Python3_EXECUTABLE
+ OR Python3_COMPILER
+ OR Python3_DOTNET_LAUNCHER
+ OR Python3_LIBRARY
+ OR Python3_INCLUDE_DIR
+ OR Python3_NumPy_INCLUDE_DIR)
+ message(WARNING
+ "Specifying FindPython3 artifacts may complicate consistent Python detection "
+ "in projects bundled with GROMACS. See "
+ "https://cmake.org/cmake/help/latest/module/FindPython3.html#artifacts-specification"
+ )
+ endif ()
+endif()
+
# Note: If necessary, the Python location can be hinted with Python3_ROOT_DIR
# For additional parameters affecting Python installation discovery, see
# https://cmake.org/cmake/help/latest/module/FindPython3.html#hints
set(Python3_FIND_QUIETLY ON)
set(PythonInterp_FIND_QUIETLY ON)
endif()
-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)
+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(GMX_PYTHON_PACKAGE)
- find_package(Python3 3.6 COMPONENTS Interpreter Development)
- if (NOT Python3_FOUND OR NOT Python3_Development_FOUND)
- message(FATAL_ERROR "Could not locate Python development requirements. \
- Provide appropriate CMake hints or set GMX_PYTHON_PACKAGE=OFF")
- endif ()
-else()
- find_package(Python3 3.6 COMPONENTS Interpreter)
+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()
+find_package(Python3 3.7 COMPONENTS Interpreter Development)
+if (GMX_PYTHON_PACKAGE AND (NOT Python3_FOUND OR NOT Python3_Development_FOUND))
+ message(FATAL_ERROR "Could not locate Python development requirements. \
+ Provide appropriate CMake hints or set GMX_PYTHON_PACKAGE=OFF")
+endif ()
# Provide hints for other Python detection that may occur later.
#