Debian Codegraph @

cmake/tribits/core/package_arch/TribitsFindPythonInterp.cmake

raw
1 # @HEADER
2 # *****************************************************************************
3 # TriBITS: Tribal Build, Integrate, and Test System
4 #
5 # Copyright 2013-2016 NTESS and the TriBITS contributors.
6 # SPDX-License-Identifier: BSD-3-Clause
7 # *****************************************************************************
8 # @HEADER
9
10
11 # TriBITS Wrapper for finding Python (or not) for a TriBITS project.
12 macro(tribits_find_python_interp)
13 if (${PROJECT_NAME}_REQUIRES_PYTHON)
14 set(${PROJECT_NAME}_USES_PYTHON TRUE)
15 endif()
16 if ("${${PROJECT_NAME}_USES_PYTHON}" STREQUAL "")
17 # Unless the project tells us they can use Python or not, let's go ahead
18 # and look for Python in case some packages want to use it.
19 set(${PROJECT_NAME}_USES_PYTHON TRUE)
20 endif()
21 if (${PROJECT_NAME}_USES_PYTHON)
22 tribits_find_python()
23 print_var(Python3_EXECUTABLE)
24 if (${PROJECT_NAME}_REQUIRES_PYTHON AND Python3_EXECUTABLE STREQUAL "")
25 message_wrapper(FATAL_ERROR "Error, Python3_EXECUTABLE='' but"
26 " ${PROJECT_NAME}_REQUIRES_PYTHON=${${PROJECT_NAME}_REQUIRES_PYTHON}!" )
27 endif()
28 else()
29 message_wrapper("-- " "NOTE: Skipping check for Python because"
30 " ${PROJECT_NAME}_USES_PYTHON='${${PROJECT_NAME}_USES_PYTHON}'")
31 endif()
32 endmacro()
33
34
35 # Find Python executable which is needed for dependency file building
36 macro(tribits_find_python)
37 tribits_find_python_set_python3_find_version()
38 tribits_find_python_backward_compatible_python_executable()
39 tribits_find_python_find_python3()
40 endmacro()
41
42
43 macro(tribits_find_python_set_python3_find_version)
44 # Get minimum version of Python to find
45 set(${PROJECT_NAME}_Python3_FIND_VERSION_MIN "3.6")
46 if ("${${PROJECT_NAME}_Python3_FIND_VERSION_DEFAULT}" STREQUAL "")
47 set(${PROJECT_NAME}_Python3_FIND_VERSION_DEFAULT
48 "${${PROJECT_NAME}_Python3_FIND_VERSION_MIN}")
49 endif()
50 advanced_set(${PROJECT_NAME}_Python3_FIND_VERSION
51 ${${PROJECT_NAME}_Python3_FIND_VERSION_DEFAULT}
52 CACHE STRING
53 "Default version of Python to find (must be ${${PROJECT_NAME}_Python3_FIND_VERSION_DEFAULT} or greater")
54 if (${PROJECT_NAME}_Python3_FIND_VERSION VERSION_LESS
55 "${${PROJECT_NAME}_Python3_FIND_VERSION_MIN}"
56 )
57 message_wrapper(FATAL_ERROR "Error,"
58 " ${PROJECT_NAME}_Python3_FIND_VERSION=${${PROJECT_NAME}_Python3_FIND_VERSION} < ${${PROJECT_NAME}_Python3_FIND_VERSION_MIN}"
59 " is not allowed!" )
60 endif()
61 endmacro()
62
63
64 macro(tribits_find_python_backward_compatible_python_executable)
65 # Provide backward compatibility for user setting PYTHON_EXECUTABLE
66 if ((NOT "${PYTHON_EXECUTABLE}" STREQUAL "") AND ("${Python3_EXECUTABLE}" STREQUAL ""))
67 tribits_deprecated("Python3_EXECUTABLE being set by default to PYTHON_EXECUTABLE = '${PYTHON_EXECUTABLE}' is deprecated!")
68 set(Python3_EXECUTABLE "${PYTHON_EXECUTABLE}" CACHE FILEPATH
69 "Set by default to PYTHON_EXECUTABLE!")
70 endif()
71 endmacro()
72
73
74 macro(tribits_find_python_find_python3)
75 # Find Python3
76 if (${PROJECT_NAME}_REQUIRES_PYTHON)
77 set(Python3_REQUIRED_ARG "REQUIRED")
78 else()
79 set(Python3_REQUIRED_ARG "")
80 endif()
81 set(FIND_Python3_ARGS
82 Python3 ${${PROJECT_NAME}_Python3_FIND_VERSION} ${Python3_REQUIRED_ARG})
83 if(DEFINED Python3_EXECUTABLE)
84 # Already defined (even if it is set to empty), so no need to call anything!
85 elseif (TRIBITS_FIND_PYTHON_UNITTEST)
86 set(Python3_EXECUTABLE ${Python3_EXECUTABLE_UNITTEST_VAL})
87 else()
88 find_package(${FIND_Python3_ARGS})
89 endif()
90 endmacro()
91
92
93