Skip to content

Commit 6ccdd70

Browse files
CMake: Use FindPython instead of FindPythonInterp
Fixes warning: CMake Warning (dev) at CMakeLists.txt:337 (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.
1 parent 5e4add3 commit 6ccdd70

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,27 @@ endif()
332332

333333
# Check for Python
334334
# PythonCCS requires Python v2.x and is the only target that uses this
335-
# With CMake 3.12+ we could use FindPython() here
336335
set(CMK_HAS_PYTHON 0)
337336
set(CMK_PYTHON_VERSION "")
338337
set(CMK_BUILD_PYTHON "")
339338

340-
set(Python_ADDITIONAL_VERSIONS 2)
341-
find_package(PythonInterp)
339+
if(CMAKE_VERSION VERSION_GREATER 3.12 OR CMAKE_VERSION VERSION_EQUAL 3.12)
340+
find_package(Python2 COMPONENTS Interpreter)
341+
if(Python2_FOUND)
342+
set(CMK_PYTHON_VERSION_MAJOR ${Python2_VERSION_MAJOR})
343+
set(CMK_PYTHON_VERSION_MINOR ${Python2_VERSION_MINOR})
344+
endif()
345+
else()
346+
set(Python_ADDITIONAL_VERSIONS 2)
347+
find_package(PythonInterp)
348+
if(PYTHONINTERP_FOUND)
349+
set(CMK_PYTHON_VERSION_MAJOR ${PYTHON_VERSION_MAJOR})
350+
set(CMK_PYTHON_VERSION_MINOR ${PYTHON_VERSION_MINOR})
351+
endif()
352+
endif()
342353

343-
if(PYTHONINTERP_FOUND)
344-
set(__MY_PYTHON_VER "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
354+
if(CMK_PYTHON_VERSION_MAJOR)
355+
set(__MY_PYTHON_VER "${CMK_PYTHON_VERSION_MAJOR}.${CMK_PYTHON_VERSION_MINOR}")
345356
check_include_file(python${__MY_PYTHON_VER}/Python.h __MY_HAS_PYTHONH)
346357
if(__MY_HAS_PYTHONH)
347358
set(CMK_HAS_PYTHON 1)

src/libs/ck-libs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ add_custom_command(
168168
# pythonCCS
169169

170170
if(CMK_BUILD_PYTHON)
171-
if(PYTHON_VERSION_MAJOR EQUAL 2) # pythonCCS needs Python 2.x
171+
if(CMK_PYTHON_VERSION_MAJOR EQUAL 2) # pythonCCS needs Python 2.x
172172
set(pythonCCS-h-sources pythonCCS/PythonCCS.h pythonCCS/PythonCCS-client.h)
173173

174174
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/include/pythonIncludes.h CONTENT

0 commit comments

Comments
 (0)