Skip to content

Improve finding python with cmake >= 3.12.0 #2156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions tools/FindPythonLibsNew.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,29 @@ if(PYTHONLIBS_FOUND AND PYTHON_MODULE_EXTENSION)
return()
endif()

if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set(PythonLibsNew_FIND_MODULE "PythonInterp")
else()
set(PythonLibsNew_FIND_MODULE "Python")
endif()

# Use the Python interpreter to find the libs.
if(PythonLibsNew_FIND_REQUIRED)
find_package(PythonInterp ${PythonLibsNew_FIND_VERSION} REQUIRED)
find_package(${PythonLibsNew_FIND_MODULE} ${PythonLibsNew_FIND_VERSION} REQUIRED)
else()
find_package(PythonInterp ${PythonLibsNew_FIND_VERSION})
find_package(${PythonLibsNew_FIND_MODULE} ${PythonLibsNew_FIND_VERSION})
endif()

if(NOT PYTHONINTERP_FOUND)
if(NOT (PYTHONINTERP_FOUND OR ${PythonLibsNew_FIND_MODULE}_FOUND))
set(PYTHONLIBS_FOUND FALSE)
set(PythonLibsNew_FOUND FALSE)
return()
endif()

if(NOT PYTHONINTERP_FOUND)
set(PYTHON_EXECUTABLE "${${PythonLibsNew_FIND_MODULE}_EXECUTABLE}")
endif()

# According to http://stackoverflow.com/questions/646518/python-how-to-detect-debug-interpreter
# testing whether sys has the gettotalrefcount function is a reliable, cross-platform
# way to detect a CPython debug interpreter.
Expand Down