Update CMake requirement to 3.16.3
[alexxy/gromacs.git] / cmake / gmxPythonDiscovery.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
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.
8 #
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.
13 #
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.
18 #
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.
23 #
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.
31 #
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.
34
35 # Perform Python installation discovery early and in one place, for consistency.
36 #
37 # Note: If necessary, the Python location can be hinted with Python3_ROOT_DIR
38 # For additional parameters affecting Python installation discovery, see
39 # https://cmake.org/cmake/help/latest/module/FindPython3.html#hints
40 if(FIND_PACKAGE_MESSAGE_DETAILS_Python3)
41     # Keep quiet on subsequent runs of cmake
42     set(Python3_FIND_QUIETLY ON)
43     set(PythonInterp_FIND_QUIETLY ON)
44 endif()
45 if (NOT Python3_FIND_STRATEGY)
46     # If the user provides a hint for the Python installation with Python3_ROOT_DIR,
47     # prevent FindPython3 from overriding the choice with a newer Python version
48     # when CMP0094 is set to OLD.
49     set(Python3_FIND_STRATEGY LOCATION)
50 endif ()
51 if(NOT Python3_FIND_VIRTUALENV)
52     # We advocate using Python venvs to manage package availability, so by default
53     # we want to preferentially discover user-space software.
54     set(Python3_FIND_VIRTUALENV FIRST)
55 endif()
56 if(GMX_PYTHON_PACKAGE)
57     find_package(Python3 3.6 COMPONENTS Interpreter Development)
58     if (NOT Python3_FOUND OR NOT Python3_Development_FOUND)
59         message(FATAL_ERROR "Could not locate Python development requirements. \
60                 Provide appropriate CMake hints or set GMX_PYTHON_PACKAGE=OFF")
61     endif ()
62 else()
63     find_package(Python3 3.6 COMPONENTS Interpreter)
64 endif()
65
66 # Provide hints for other Python detection that may occur later.
67 #
68 # Other components, such as pybind and googletest, may expect the
69 # PYTHON_EXECUTABLE variable from pre-3.12 FindPythonInterp.cmake.
70 if (Python3_Interpreter_FOUND)
71     set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE} CACHE FILEPATH "Location hint for Python interpreter.")
72 endif ()
73 # We've already generated all of the output we need, even though other subcomponents
74 # may call find_package(PythonInterp) later on.
75 set(Python3_FIND_QUIETLY ON)
76 set(PythonInterp_FIND_QUIETLY ON)
77 # Older versions of FindPythonLibs and FindPythonInterp might not search for
78 # Python newer than 3.7 by default. (as of CMake 3.9)
79 # Note that this hint is not used by the newer FindPython module we rely on above.
80 set(Python_ADDITIONAL_VERSIONS 3.8 3.9 3.10)