Skip to content

Commit d573266

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 5f750c8 commit d573266

File tree

11 files changed

+41
-41
lines changed

11 files changed

+41
-41
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})
@@ -127,7 +127,7 @@ macro(ctkMacroBuildLibWrapper)
127127
endif()
128128
endif()
129129
add_library(${lib_name}PythonQt ${MY_WRAPPER_LIBRARY_TYPE} ${KIT_PYTHONQT_SRCS})
130-
target_link_libraries(${lib_name}PythonQt ${lib_name} ${my_EXTRA_PYTHON_LIBRARIES})
130+
target_link_libraries(${lib_name}PythonQt ${lib_name} ${my_EXTRA_Python3_LIBRARIES})
131131
if(MY_WRAPPER_LIBRARY_TYPE STREQUAL "STATIC")
132132
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64-bit
133133
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
@@ -148,15 +148,15 @@ function(_ctk_add_compile_python_directories_target target)
148148
set(_compileall_code "${_compileall_code}\nctk_compile_file('${tgt}', force=1)")
149149
endforeach()
150150

151-
if(NOT PYTHONINTERP_FOUND)
152-
find_package(PythonInterp REQUIRED)
151+
if(NOT Python3_Interpreter_FOUND)
152+
find_package(Python3 COMPONENTS Interpreter REQUIRED)
153153
endif()
154-
if(NOT PYTHONLIBS_FOUND)
155-
find_package(PythonLibs REQUIRED)
154+
if(NOT Python3_Development_FOUND)
155+
find_package(Python3 COMPONENTS Development REQUIRED)
156156
endif()
157157

158158
# Extract python lib path
159-
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
159+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
160160
get_filename_component(PYTHON_LIBRARY_PATH "${PYTHON_LIBRARY}" PATH)
161161

162162
# 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}
@@ -193,6 +193,6 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
193193
if(NOT PYTHONQT_FOUND)
194194
message(FATAL_ERROR "error: PythonQt package is required to build ${TARGET}PythonQt")
195195
endif()
196-
include_directories(${PYTHON_INCLUDE_DIRS} ${PYTHONQT_INCLUDE_DIR})
196+
include_directories(${Python3_INCLUDE_DIRS} ${PYTHONQT_INCLUDE_DIR})
197197

198198
endmacro()

CMake/ctk_compile_python_scripts.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ else()
9393
endif()
9494

9595
execute_process(
96-
COMMAND "@PYTHON_EXECUTABLE@" "@compile_all_script@"
96+
COMMAND "@Python3_EXECUTABLE@" "@compile_all_script@"
9797
RESULT_VARIABLE result_var
9898
)
9999
if(NOT result_var STREQUAL 0)

CMakeExternals/PythonQt.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ if(NOT DEFINED PYTHONQT_INSTALL_DIR)
7373
endif()
7474

7575
# Python is required
76-
if(NOT PYTHONLIBS_FOUND)
77-
find_package(PythonLibs)
78-
if(NOT PYTHONLIBS_FOUND)
76+
if(NOT Python3_Development_FOUND)
77+
find_package(Python3 COMPONENTS Development)
78+
if(NOT Python3_Development_FOUND)
7979
message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
8080
endif()
8181
endif()
8282

83-
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
83+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
8484
if(CTK_QT_VERSION VERSION_EQUAL "5")
8585
set(revision_tag 37b0d31e5d313f5682f774bd8d5d41f5018a2ce9) # patched-v3.6.1-2025-06-13-a2687828e
8686
else()
@@ -145,7 +145,7 @@ set(PythonQt_DIR ${PYTHONQT_INSTALL_DIR})
145145
mark_as_superbuild(
146146
VARS
147147
PYTHONQT_INSTALL_DIR:PATH
148-
PYTHON_EXECUTABLE:FILEPATH # FindPythonInterp expects PYTHON_EXECUTABLE variable to be defined
148+
Python3_EXECUTABLE:FILEPATH # FindPythonInterp expects Python3_EXECUTABLE variable to be defined
149149
PYTHON_INCLUDE_DIR:PATH # FindPythonQt expects PYTHON_INCLUDE_DIR variable to be defined
150150
PYTHON_INCLUDE_DIR2:PATH
151151
PYTHON_LIBRARY:FILEPATH # FindPythonQt expects PYTHON_LIBRARY variable to be defined

CMakeExternals/VTK.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@ if(NOT DEFINED VTK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
6868
if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
6969

7070
if(NOT DEFINED VTK_PYTHON_VERSION)
71-
set(VTK_PYTHON_VERSION ${PYTHON_VERSION_MAJOR})
71+
set(VTK_PYTHON_VERSION ${Python3_VERSION_MAJOR})
7272
endif()
73-
if(NOT "${VTK_PYTHON_VERSION}" STREQUAL "${PYTHON_VERSION_MAJOR}")
74-
message(FATAL_ERROR "error: VTK_PYTHON_VERSION [${VTK_PYTHON_VERSION}] is expected to match PYTHON_VERSION_MAJOR [${PYTHON_VERSION_MAJOR}]")
73+
if(NOT "${VTK_PYTHON_VERSION}" STREQUAL "${Python3_VERSION_MAJOR}")
74+
message(FATAL_ERROR "error: VTK_PYTHON_VERSION [${VTK_PYTHON_VERSION}] is expected to match Python3_VERSION_MAJOR [${Python3_VERSION_MAJOR}]")
7575
endif()
76-
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
76+
set(Python3_EXECUTABLE ${Python3_EXECUTABLE})
7777
set(Python3_INCLUDE_DIR ${PYTHON_INCLUDE_DIR})
7878
set(Python3_LIBRARY ${PYTHON_LIBRARY})
7979
find_package(Python3 COMPONENTS Interpreter Development)
8080

81-
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
81+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
8282
list(APPEND additional_vtk_cmakevars
8383
-DVTK_PYTHON_VERSION:STRING=${VTK_PYTHON_VERSION}
8484
# FindPythonInterp, FindPythonLibs
85-
-DPYTHON_EXECUTABLE:PATH=${PYTHON_EXECUTABLE}
85+
-DPython3_EXECUTABLE:PATH=${Python3_EXECUTABLE}
8686
-DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR}
8787
-DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
8888
-DPYTHON_DEBUG_LIBRARIES:FILEPATH=${PYTHON_DEBUG_LIBRARIES}

CMakeLists.txt

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

881881
# Check if dependencies are satisfied
882882
if(CTK_LIB_Scripting/Python/Core)
883-
if(NOT PYTHONINTERP_FOUND)
884-
find_package(PythonInterp)
885-
if(NOT PYTHONINTERP_FOUND)
886-
message(FATAL_ERROR "PYTHON_EXECUTABLE variable should be set to build CTK_LIB_Scripting/Python")
883+
if(NOT Python3_Interpreter_FOUND)
884+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
885+
if(NOT Python3_Interpreter_FOUND)
886+
message(FATAL_ERROR "Python3_EXECUTABLE variable should be set to build CTK_LIB_Scripting/Python")
887887
endif()
888888
endif()
889-
if(NOT PYTHONLIBS_FOUND)
890-
find_package(PythonLibs)
891-
if(NOT PYTHONLIBS_FOUND)
892-
message(FATAL_ERROR "PYTHON_LIBRARIES and PYTHON_INCLUDE_DIRS should be set to build CTK_LIB_Scripting/Python")
889+
if(NOT Python3_Development_FOUND)
890+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
891+
if(NOT Python3_Development_FOUND)
892+
message(FATAL_ERROR "Python3_LIBRARIES and Python3_INCLUDE_DIRS should be set to build CTK_LIB_Scripting/Python")
893893
endif()
894894
endif()
895895
endif()

Libs/Scripting/Python/Core/CMakeLists.txt

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

4242
# Target libraries - See CMake/ctkFunctionGetTargetLibraries.cmake
4343
# The following macro will read the target libraries from the file 'target_libraries.cmake'
44-
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
44+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
4545
ctkFunctionGetTargetLibraries(KIT_target_libraries)
4646

4747
ctkMacroBuildLib(

Libs/Visualization/VTK/Core/CMakeLists.txt

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

105105
if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
106106
include_directories(
107-
${PYTHON_INCLUDE_DIRS}
107+
${Python3_INCLUDE_DIRS}
108108
${PYTHONQT_INCLUDE_DIR}
109109
)
110110
endif()
@@ -203,7 +203,7 @@ endif()
203203
if(${VTK_VERSION} VERSION_LESS "8.90")
204204

205205
if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
206-
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
206+
ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY)
207207
list(APPEND VTK_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES})
208208
if(${VTK_VERSION_MAJOR} GREATER 5)
209209
list(APPEND VTK_LIBRARIES vtkWrappingPythonCore)

0 commit comments

Comments
 (0)