From ca713bc6411a003a37b948c6250d622e333fecfd Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Wed, 8 Apr 2020 19:04:36 +0200 Subject: [PATCH] Improve finding python with cmake >= 3.12.0 --- tools/FindPythonLibsNew.cmake | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/FindPythonLibsNew.cmake b/tools/FindPythonLibsNew.cmake index 9ea6036e33..a5a2f09fe0 100644 --- a/tools/FindPythonLibsNew.cmake +++ b/tools/FindPythonLibsNew.cmake @@ -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.