Skip to content

Commit 3ce57f4

Browse files
committed
COMP: Update to find_package(Python3)
The FindPythonInterp and FindPythonLibs modules are removed. These modules have been deprecated since CMake 3.12. CMake 3.27 and above prefer to not provide the modules. This policy provides compatibility for projects that have not been ported away from them. Projects using the FindPythonInterp and/or FindPythonLibs modules should be updated to use one of their replacements: FindPython3 FindPython2 FindPython
1 parent 6781a25 commit 3ce57f4

File tree

10 files changed

+40
-34
lines changed

10 files changed

+40
-34
lines changed

CMake/ctkBlockCheckDependencies.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ set(${Log4Qt_enabling_variable}_INCLUDE_DIRS Log4Qt_INCLUDE_DIRS)
7575
set(${Log4Qt_enabling_variable}_FIND_PACKAGE_CMD Log4Qt)
7676

7777
set(PythonQt_enabling_variable PYTHONQT_LIBRARIES)
78-
set(${PythonQt_enabling_variable}_INCLUDE_DIRS PYTHONQT_INCLUDE_DIR PYTHON_INCLUDE_DIRS)
78+
set(${PythonQt_enabling_variable}_INCLUDE_DIRS PYTHONQT_INCLUDE_DIR Python3_INCLUDE_DIRS)
7979
set(${PythonQt_enabling_variable}_FIND_PACKAGE_CMD PythonQt)
8080

8181
set(QtSOAP_enabling_variable QtSOAP_LIBRARIES)

CMake/ctkMacroBuildLibWrapper.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ macro(ctkMacroBuildLibWrapper)
9595
# Since the PythonQt decorator depends on PythonQt, Python and VTK, let's link against
9696
# these ones to avoid complaints of MSVC
9797
# Note: "LINK_DIRECTORIES" has to be invoked before "ADD_LIBRARY"
98-
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
99-
set(my_EXTRA_PYTHON_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES})
98+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
99+
set(my_EXTRA_Python3_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES})
100100

101101
# Does a header having the expected filename exists ?
102102
string(REGEX REPLACE "^CTK" "ctk" lib_name_lc_ctk ${lib_name})
@@ -122,7 +122,7 @@ macro(ctkMacroBuildLibWrapper)
122122
list(APPEND KIT_PYTHONQT_SRCS ${DECORATOR_HEADER})
123123
endif()
124124
add_library(${lib_name}PythonQt ${MY_WRAPPER_LIBRARY_TYPE} ${KIT_PYTHONQT_SRCS})
125-
target_link_libraries(${lib_name}PythonQt ${lib_name} ${my_EXTRA_PYTHON_LIBRARIES})
125+
target_link_libraries(${lib_name}PythonQt ${lib_name} ${my_EXTRA_Python3_LIBRARIES})
126126
if(MY_WRAPPER_LIBRARY_TYPE STREQUAL "STATIC")
127127
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64-bit
128128
set_target_properties(${lib_name}PythonQt PROPERTIES COMPILE_FLAGS "-fPIC")

CMake/ctkMacroCompilePythonScript.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ function(_ctk_add_compile_python_directories_target target keep_only_pyc)
164164
endif()
165165
endforeach()
166166

167-
if(NOT PYTHONINTERP_FOUND)
168-
find_package(PythonInterp REQUIRED)
167+
if(NOT Python3_Interpreter_FOUND)
168+
find_package(Python3 COMPONENTS Interpreter REQUIRED)
169169
endif()
170-
if(NOT PYTHONLIBS_FOUND)
171-
find_package(PythonLibs REQUIRED)
170+
if(NOT Python3_Development_FOUND)
171+
find_package(Python3 COMPONENTS Development REQUIRED)
172172
endif()
173173

174174
# Extract python lib path
175-
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
175+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
176176
get_filename_component(PYTHON_LIBRARY_PATH "${PYTHON_LIBRARY}" PATH)
177177

178178
# Configure cmake script associated with the custom command

CMake/ctkMacroWrapPythonQt.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
6262
# TODO: this find package seems not to work when called form a superbuild, but the call is needed
6363
# in general to find the python interpreter. In CTK, the toplevel CMakeLists.txt does the find
6464
# package so this is a no-op. Other uses of this file may need to have this call so it is still enabled.
65-
if(NOT PYTHONINTERP_FOUND)
66-
find_package(PythonInterp)
67-
if(NOT PYTHONINTERP_FOUND)
68-
message(FATAL_ERROR "PYTHON_EXECUTABLE not specified or inexistent when calling ctkMacroWrapPythonQt")
65+
if(NOT Python3_Interpreter_FOUND)
66+
find_package(Python3 COMPONENTS Interpreter)
67+
if(NOT Python3_Interpreter_FOUND)
68+
message(FATAL_ERROR "Python3_EXECUTABLE not specified or inexistent when calling ctkMacroWrapPythonQt")
6969
endif()
7070
endif()
7171

@@ -157,7 +157,7 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
157157
DEPENDS
158158
${SOURCES_TO_WRAP}
159159
${CTK_CMAKE_DIR}/ctkWrapPythonQt.py
160-
COMMAND ${PYTHON_EXECUTABLE} ${CTK_CMAKE_DIR}/ctkWrapPythonQt.py
160+
COMMAND ${Python3_EXECUTABLE} ${CTK_CMAKE_DIR}/ctkWrapPythonQt.py
161161
--target=${TARGET}
162162
--namespace=${WRAPPING_NAMESPACE}
163163
--output-dir=${CMAKE_CURRENT_BINARY_DIR}/${wrap_int_dir} ${extra_args}
@@ -188,6 +188,6 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
188188
if(NOT PYTHONQT_FOUND)
189189
message(FATAL_ERROR "error: PythonQt package is required to build ${TARGET}PythonQt")
190190
endif()
191-
include_directories(${PYTHON_INCLUDE_DIRS} ${PYTHONQT_INCLUDE_DIR})
191+
include_directories(${Python3_INCLUDE_DIRS} ${PYTHONQT_INCLUDE_DIR})
192192

193193
endmacro()

CMake/ctk_compile_python_scripts.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ else()
9595
endif()
9696

9797
execute_process(
98-
COMMAND "@PYTHON_EXECUTABLE@" "@compile_all_script@"
98+
COMMAND "@Python3_EXECUTABLE@" "@compile_all_script@"
9999
RESULT_VARIABLE result_var
100100
)
101101
if(NOT result_var STREQUAL 0)

CMakeExternals/PythonQt.cmake

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ if(NOT DEFINED PYTHONQT_INSTALL_DIR)
7575
endif()
7676

7777
# Python is required
78-
if(NOT PYTHONLIBS_FOUND)
79-
find_package(PythonLibs)
80-
if(NOT PYTHONLIBS_FOUND)
78+
if(NOT Python3_Development_FOUND)
79+
find_package(Python3 COMPONENTS Development)
80+
if(NOT Python3_Development_FOUND)
8181
message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
8282
endif()
8383
endif()
@@ -88,6 +88,12 @@ if(NOT DEFINED PYTHONQT_INSTALL_DIR)
8888
set(Python3_LIBRARY_DEBUG ${PYTHON_LIBRARY})
8989
set(Python3_LIBRARY_RELEASE ${PYTHON_LIBRARY})
9090
find_package(Python3 COMPONENTS Development REQUIRED)
91+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
92+
if(CTK_QT_VERSION VERSION_EQUAL "5")
93+
set(revision_tag c128afb1b72488e1c21b1cb0205b795b268b45d0) # patched-v3.6.1-2025-09-30-f4769f190
94+
else()
95+
message(FATAL_ERROR "Support for Qt${CTK_QT_VERSION} is not implemented")
96+
endif()
9197

9298
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
9399

@@ -299,7 +305,7 @@ set(PythonQt_DIR ${PYTHONQT_INSTALL_DIR})
299305
mark_as_superbuild(
300306
VARS
301307
PYTHONQT_INSTALL_DIR:PATH
302-
PYTHON_EXECUTABLE:FILEPATH # FindPythonInterp expects PYTHON_EXECUTABLE variable to be defined
308+
Python3_EXECUTABLE:FILEPATH # FindPythonInterp expects Python3_EXECUTABLE variable to be defined
303309
PYTHON_INCLUDE_DIR:PATH # FindPythonQt expects PYTHON_INCLUDE_DIR variable to be defined
304310
PYTHON_INCLUDE_DIR2:PATH
305311
PYTHON_LIBRARY:FILEPATH # FindPythonQt expects PYTHON_LIBRARY variable to be defined

CMakeExternals/VTK.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ if(NOT DEFINED VTK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
6767

6868
if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
6969

70-
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
70+
set(Python3_EXECUTABLE ${Python3_EXECUTABLE})
7171
set(Python3_INCLUDE_DIR ${PYTHON_INCLUDE_DIR})
7272
set(Python3_LIBRARY ${PYTHON_LIBRARY})
7373
set(Python3_LIBRARY_DEBUG ${PYTHON_LIBRARY})
7474
set(Python3_LIBRARY_RELEASE ${PYTHON_LIBRARY})
7575
find_package(Python3 COMPONENTS Interpreter Development)
7676

77-
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
77+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
7878
list(APPEND additional_vtk_cmakevars
7979
# FindPythonInterp, FindPythonLibs
80-
-DPYTHON_EXECUTABLE:PATH=${PYTHON_EXECUTABLE}
80+
-DPython3_EXECUTABLE:PATH=${Python3_EXECUTABLE}
8181
-DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR}
8282
-DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
8383
-DPYTHON_DEBUG_LIBRARIES:FILEPATH=${PYTHON_DEBUG_LIBRARIES}

CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -944,16 +944,16 @@ endif()
944944

945945
# Check if dependencies are satisfied
946946
if(CTK_LIB_Scripting/Python/Core)
947-
if(NOT PYTHONINTERP_FOUND)
948-
find_package(PythonInterp)
949-
if(NOT PYTHONINTERP_FOUND)
950-
message(FATAL_ERROR "PYTHON_EXECUTABLE variable should be set to build CTK_LIB_Scripting/Python")
947+
if(NOT Python3_Interpreter_FOUND)
948+
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
949+
if(NOT Python3_Interpreter_FOUND)
950+
message(FATAL_ERROR "Python3_EXECUTABLE variable should be set to build CTK_LIB_Scripting/Python")
951951
endif()
952952
endif()
953-
if(NOT PYTHONLIBS_FOUND)
954-
find_package(PythonLibs)
955-
if(NOT PYTHONLIBS_FOUND)
956-
message(FATAL_ERROR "PYTHON_LIBRARIES and PYTHON_INCLUDE_DIRS should be set to build CTK_LIB_Scripting/Python")
953+
if(NOT Python3_Development_FOUND)
954+
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
955+
if(NOT Python3_Development_FOUND)
956+
message(FATAL_ERROR "Python3_LIBRARIES and Python3_INCLUDE_DIRS should be set to build CTK_LIB_Scripting/Python")
957957
endif()
958958
endif()
959959
endif()

Libs/Scripting/Python/Core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ configure_file(
3636

3737
# Target libraries - See CMake/ctkFunctionGetTargetLibraries.cmake
3838
# The following macro will read the target libraries from the file 'target_libraries.cmake'
39-
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
39+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
4040
ctkFunctionGetTargetLibraries(KIT_target_libraries)
4141

4242
ctkMacroBuildLib(

Libs/Visualization/VTK/Core/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ endif()
9898

9999
if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
100100
include_directories(
101-
${PYTHON_INCLUDE_DIRS}
101+
${Python3_INCLUDE_DIRS}
102102
${PYTHONQT_INCLUDE_DIR}
103103
)
104104
endif()
@@ -192,7 +192,7 @@ endif()
192192
if(${VTK_VERSION} VERSION_LESS "8.90")
193193

194194
if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
195-
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
195+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
196196
list(APPEND VTK_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES})
197197
if(${VTK_VERSION_MAJOR} GREATER 5)
198198
list(APPEND VTK_LIBRARIES vtkWrappingPythonCore)

0 commit comments

Comments
 (0)