Skip to content

Commit

Permalink
Change to find_package(Python3), set Python3_EXECUTABLE to PYTHON_EXE…
Browse files Browse the repository at this point in the history
…CUTABLE (TriBITSPub#610)

Change from calling deprecated find_package(PythonInterp) to call
find_package(Python3).  To maintain backward compatibility for external users,
set Python3_EXECUTABLE to PYTHON_EXECUTABLE if the former is unset and the
later is set.

The rest of TriBITS will need to be refactored to absorb this.
  • Loading branch information
bartlettroscoe committed Oct 3, 2024
1 parent 46f0df5 commit 7364e52
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions tribits/core/package_arch/TribitsFindPythonInterp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,20 @@

# Find Python executable which is needed for dependency file building
macro(tribits_find_python)
set(PythonInterp_FIND_VERSION_MIN "2.6")
if ("${PythonInterp_FIND_VERSION_DEFAULT}" STREQUAL "")
set(PythonInterp_FIND_VERSION_DEFAULT "${PythonInterp_FIND_VERSION_MIN}")
if ((NOT "${PYTHON_EXECUTABLE}" STREQUAL "") AND ("${Python3_EXECUTABLE}" STREQUAL ""))
tribits_deprecated("Python3_EXECUTABLE being set by default to PYTHON_EXECUTABLE = '${PYTHON_EXECUTABLE}' is deprecated!")
set(Python3_EXECUTABLE "${PYTHON_EXECUTABLE}" CACHE FILEPATH
"Set by default to PYTHON_EXECUTABLE!")
endif()
advanced_set(PythonInterp_FIND_VERSION ${PythonInterp_FIND_VERSION_DEFAULT}
CACHE STRING
"Default version of Python to find (must be ${PythonInterp_FIND_VERSION_DEFAULT} or greater")
if (PythonInterp_FIND_VERSION VERSION_LESS "${PythonInterp_FIND_VERSION_MIN}")
message_wrapper(FATAL_ERROR "Error,"
" PythonInterp_FIND_VERSION=${PythonInterp_FIND_VERSION} < ${PythonInterp_FIND_VERSION_MIN}"
" is not allowed!" )
endif()
advanced_set(PythonInterp_MUST_BE_FOUND FALSE CACHE BOOL "Require Python to be found or not.")
if (${PROJECT_NAME}_REQUIRES_PYTHON)
set(PythonInterp_REQUIRED_ARG "REQUIRED")
set(Python3_REQUIRED_ARG "REQUIRED")
else()
set(PythonInterp_REQUIRED_ARG "")
set(Python3_REQUIRED_ARG "")
endif()
set(FIND_PythonInterp_ARGS PythonInterp ${PythonInterp_REQUIRED_ARG})
if (TRIBITS_FIND_PYTHON_UNITTEST)
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE_UNITTEST_VAL})
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE_UNITTEST_VAL})
else()
find_package(${FIND_PythonInterp_ARGS})
find_package(Python3 ${Python3_REQUIRED_ARG})
endif()
endmacro()

Expand All @@ -48,9 +39,9 @@ macro(tribits_find_python_interp)
endif()
if (${PROJECT_NAME}_USES_PYTHON)
tribits_find_python()
print_var(PYTHON_EXECUTABLE)
if (${PROJECT_NAME}_REQUIRES_PYTHON AND PYTHON_EXECUTABLE STREQUAL "")
message_wrapper(FATAL_ERROR "Error, PYTHON_EXECUTABLE='' but"
print_var(Python3_EXECUTABLE)
if (${PROJECT_NAME}_REQUIRES_PYTHON AND Python3_EXECUTABLE STREQUAL "")
message_wrapper(FATAL_ERROR "Error, Python3_EXECUTABLE='' but"
" ${PROJECT_NAME}_REQUIRES_PYTHON=${${PROJECT_NAME}_REQUIRES_PYTHON}!" )
endif()
else()
Expand Down

0 comments on commit 7364e52

Please sign in to comment.