Skip to content

Move away from deprecated FindPythonInterp and FindPythonLibs #511

@anderkve

Description

@anderkve

Our cmake system currently uses the cmake modules

to detect Python and store all relevant paths in cmake variables like PYTHON_EXECUTABLE, PYTHON_LIBRARIES, etc.

These cmake modules have been deprecated since cmake version 3.12, so we should update our cmake system to rather use the new module

This new module stores the information in variables with different names, such as Python3_EXECUTABLE, Python3_LIBRARIES, etc.

So I think what is needed is to update this part of our main CMakeLists.txt file,

gambit/CMakeLists.txt

Lines 121 to 153 in fb7f22a

# Check for Python interpreter.
# We also need to search for PythonLibs before letting pybind11 look for them,
# otherwise it seems to get it wrong. Also, we need to add versions of python
# greater than 3.3 manually, for compatibility with CMake 2.8.12.
# If pybind11 is ditched, do not worry about PythonLibs
set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11)
find_package(PythonInterp 3) # We require Python 3.
if(PYTHONINTERP_FOUND)
if(NOT DITCH_PYBIND)
find_package(PythonLibs 3) # We require Python 3.
endif()
else()
message(FATAL_ERROR "\nPython 3 was not found, but it is required by GAMBIT. \nIf you need to set the path to the Python interpreter manually, "
"please use -D PYTHON_EXECUTABLE=path/to/preferred/python.")
endif()
message("${BoldYellow} Using Python interpreter version ${PYTHON_VERSION_STRING} for build.${ColourReset}")
if(PYTHONLIBS_FOUND)
message("${BoldYellow} Using Python libraries version ${PYTHONLIBS_VERSION_STRING} for Python backend support.${ColourReset}")
# Remove trailing non-numeric characters from version
string(REGEX REPLACE "[a-zA-Z]" "" PYTHONLIBS_VERSION_STRING_CLEAN ${PYTHONLIBS_VERSION_STRING})
if (NOT "${PYTHON_VERSION_STRING}" STREQUAL "${PYTHONLIBS_VERSION_STRING_CLEAN}")
message("${BoldRed} NOTE: You are using different Python versions for the interpreter and the libraries!${ColourReset}\n"
" In principle this should be fine, as the interpreter is only used for building GAMBIT, and the\n"
" libraries are only used for providing support for Python backends at runtime. However, if you\n"
" have matching versions installed, you can make this message go away by manually setting the \n"
" following variables when you invoke cmake:\n"
" PYTHON_LIBRARY\n"
" PYTHON_INCLUDE_DIR\n"
" PYTHON_EXECUTABLE\n"
" Make sure to clean out your build dir before reconfiguring with these variables set.")
endif()
endif()

to use the new modules in the find_package(...) calls and then update the relevant variable names everywhere in our cmake system.

Or, maybe we just want to copy the values from the new variables (e.g. Python3_EXECUTABLE) to the old variable name (e.g. PYTHON_EXECUTABLE) so that all other code using these variable names can remain unchanged? Any thoughts on this, @ChrisJChang, @ajueid, @pstoecker?

Metadata

Metadata

Assignees

Labels

2 Core pointsA core task that should be possible to tackle without prior Core experienceCoreCore group taskbuild

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions