2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2020,2021, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 # Perform Python installation discovery early and in one place, for consistency.
37 if($<VERSION_GREATER_EQUAL:${CMAKE_VERSION},"3.18">)
38 # With embedded packages in this repository, the module-scoped default behavior of
39 # FindPython3 version/component requirements and artifact specification is likely
40 # confusing (at best) or leading to bad logic (at worst).
41 # https://cmake.org/cmake/help/latest/module/FindPython3.html#artifacts-specification
42 option(Python3_ARTIFACTS_INTERACTIVE TRUE
43 "Make artifacts specification global and cached.")
44 elseif(NOT FIND_PACKAGE_MESSAGE_DETAILS_Python3)
45 # On first run, check whether the user has triggered the behavior described above.
46 if (Python3_EXECUTABLE
48 OR Python3_DOTNET_LAUNCHER
50 OR Python3_INCLUDE_DIR
51 OR Python3_NumPy_INCLUDE_DIR)
53 "Specifying FindPython3 artifacts may complicate consistent Python detection "
54 "in projects bundled with GROMACS. See "
55 "https://cmake.org/cmake/help/latest/module/FindPython3.html#artifacts-specification"
60 # Note: If necessary, the Python location can be hinted with Python3_ROOT_DIR
61 # For additional parameters affecting Python installation discovery, see
62 # https://cmake.org/cmake/help/latest/module/FindPython3.html#hints
63 if(FIND_PACKAGE_MESSAGE_DETAILS_Python3)
64 # Keep quiet on subsequent runs of cmake
65 set(Python3_FIND_QUIETLY ON)
66 set(PythonInterp_FIND_QUIETLY ON)
68 if (NOT Python3_FIND_STRATEGY)
69 # If the user provides a hint for the Python installation with Python3_ROOT_DIR,
70 # prevent FindPython3 from overriding the choice with a newer Python version
71 # when CMP0094 is set to OLD.
72 set(Python3_FIND_STRATEGY LOCATION)
74 if(NOT Python3_FIND_VIRTUALENV)
75 # We advocate using Python venvs to manage package availability, so by default
76 # we want to preferentially discover user-space software.
77 set(Python3_FIND_VIRTUALENV FIRST)
79 find_package(Python3 3.7 COMPONENTS Interpreter Development)
80 if (GMX_PYTHON_PACKAGE AND (NOT Python3_FOUND OR NOT Python3_Development_FOUND))
81 message(FATAL_ERROR "Could not locate Python development requirements. \
82 Provide appropriate CMake hints or set GMX_PYTHON_PACKAGE=OFF")
85 # Provide hints for other Python detection that may occur later.
87 # Other components, such as pybind and googletest, may expect the
88 # PYTHON_EXECUTABLE variable from pre-3.12 FindPythonInterp.cmake.
89 if (Python3_Interpreter_FOUND)
90 set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE} CACHE FILEPATH "Location hint for Python interpreter.")
92 # We've already generated all of the output we need, even though other subcomponents
93 # may call find_package(PythonInterp) later on.
94 set(Python3_FIND_QUIETLY ON)
95 set(PythonInterp_FIND_QUIETLY ON)
96 # Older versions of FindPythonLibs and FindPythonInterp might not search for
97 # Python newer than 3.7 by default. (as of CMake 3.9)
98 # Note that this hint is not used by the newer FindPython module we rely on above.
99 set(Python_ADDITIONAL_VERSIONS 3.8 3.9 3.10)