Use CMake 3.12+ facilities for detecting Python.
[alexxy/gromacs.git] / cmake / gmxPythonDiscovery.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2020, 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 # Older CMake versions might not search for Python newer than 3.7.
46 set(Python_ADDITIONAL_VERSIONS 3.8)
47 # We advocate using Python venvs to manage package availability, so by default
48 # we want to preferentially discover user-space software.
49 set(Python3_FIND_REGISTRY LAST)
50 # Make package discovery consistent with Unix behavior and our documented
51 # suggestions for installing dependencies.
52 set(CMAKE_FIND_FRAMEWORK LAST)
53 if(GMX_PYTHON_PACKAGE)
54     find_package(Python3 3.6 COMPONENTS Interpreter Development)
55     if (NOT Python3_FOUND OR NOT Python3_Development_FOUND)
56         message(FATAL_ERROR "Could not locate Python development requirements. \
57                 Provide appropriate CMake hints or set GMX_PYTHON_PACKAGE=OFF")
58     endif ()
59 else()
60     find_package(Python3 3.6 COMPONENTS Interpreter)
61 endif()
62 # Other components, such as pybind and googletest, may expect the
63 # PYTHON_EXECUTABLE variable from pre-3.12 FindPythonInterp.cmake.
64 if (Python3_Interpreter_FOUND)
65     set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE} CACHE FILEPATH "Location hint for Python interpreter.")
66 endif ()
67 # We've already generated all of the output we need, even though other subcomponents
68 # may call find_package(PythonInterp) later on.
69 set(Python3_FIND_QUIETLY ON)
70 set(PythonInterp_FIND_QUIETLY ON)