From ca20152e5143dccc586cc9d090dfc41938ef29fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 27 Sep 2023 10:06:03 +0200 Subject: [PATCH] findDependencies.cmake: use `FindPython` instead of deprecated `FindPythonInterp` (#5485) This fixes the following warning with CMake 3.27: ``` CMake Warning (dev) at cmake/findDependencies.cmake:42 (find_package): Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules are removed. Run "cmake --help-policy CMP0148" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Call Stack (most recent call first): CMakeLists.txt:15 (include) This warning is for project developers. Use -Wno-dev to suppress it. ``` --- cmake/findDependencies.cmake | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake index da6d63975..90b7c137e 100644 --- a/cmake/findDependencies.cmake +++ b/cmake/findDependencies.cmake @@ -39,13 +39,23 @@ endif() set(CMAKE_INCLUDE_CURRENT_DIR ON) -find_package(PythonInterp 3 QUIET) -if (NOT PYTHONINTERP_FOUND) - set(PYTHONINTERP_FOUND "") - find_package(PythonInterp 2.7 QUIET) - if (NOT PYTHONINTERP_FOUND AND NOT USE_MATCHCOMPILER_OPT STREQUAL "Off") +if (CMAKE_VERSION VERSION_EQUAL "3.12" OR CMAKE_VERSION VERSION_GREATER "3.12") + find_package(Python COMPONENTS Interpreter) + if (NOT Python_Interpreter_FOUND) message(WARNING "No python interpreter found. Therefore, the match compiler is switched off.") set(USE_MATCHCOMPILER_OPT "Off") + else() + set(PYTHON_EXECUTABLE ${Python_EXECUTABLE}) + endif() +else() + find_package(PythonInterp 3 QUIET) + if (NOT PYTHONINTERP_FOUND) + set(PYTHONINTERP_FOUND "") + find_package(PythonInterp 2.7 QUIET) + if (NOT PYTHONINTERP_FOUND AND NOT USE_MATCHCOMPILER_OPT STREQUAL "Off") + message(WARNING "No python interpreter found. Therefore, the match compiler is switched off.") + set(USE_MATCHCOMPILER_OPT "Off") + endif() endif() endif()