python/CMakeLists.txt: rework Python development files detection master
authorYegor Yefremov <yegorslists@googlemail.com>
Mon, 23 Jun 2025 12:44:13 +0000 (14:44 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 30 Jun 2025 11:28:35 +0000 (13:28 +0200)
Both the FindPythonInterp and FindPythonLibs modules were removed. Use
find_package(Python3 COMPONENTS Interpreter Development) to find both
the interpreter and the library.

The old modules have been deprecated since CMake 3.12.

Resolves the following warning:

CMake Warning (dev) at python/CMakeLists.txt:11 (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.

python/CMakeLists.txt

index d496c3f..d312fae 100644 (file)
@@ -8,12 +8,11 @@ else ()
         set(SWIG_FOUND TRUE)
     endif ()
 endif ()
-find_package(PythonInterp REQUIRED)
-find_package(PythonLibs REQUIRED)
+find_package(Python3 COMPONENTS Interpreter Development)
 
 include(UseSWIG)
 include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src)
-include_directories(${PYTHON_INCLUDE_DIRS})
+include_directories(${Python3_INCLUDE_DIRS})
 link_directories(${CMAKE_CURRENT_BINARY_DIR}/../src)
 
 if (DOCUMENTATION)
@@ -32,7 +31,7 @@ endif ()
 
 set_target_properties(pyftdi1 PROPERTIES NO_SONAME ON)
 
-execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print( sysconfig.get_path( 'platlib', vars={'platbase': '${CMAKE_INSTALL_PREFIX}'} ) )"
+execute_process(COMMAND ${Python3_EXECUTABLE} -c "import sysconfig; print( sysconfig.get_path( 'platlib', vars={'platbase': '${CMAKE_INSTALL_PREFIX}'} ) )"
         OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
         OUTPUT_STRIP_TRAILING_WHITESPACE)
 
@@ -55,7 +54,7 @@ if (DOCUMENTATION)
 
     # generate .i from doxygen .xml
     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
-            COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n
+            COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n
             ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml
             ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
             COMMENT "Generating ftdi1_doc.i from ftdi_8c.xml"