From 33b59cfb9a5aa2e5f061a2843077a40dbbdf1a3c Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Mon, 6 Oct 2025 10:24:59 -0500 Subject: [PATCH 1/2] COMP: Add python3-dev to package requirements. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1f7b16a6c..940bc85cd4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,7 @@ jobs: if: ${{ matrix.qt-major-version == 5 }} run: | sudo apt-get install -y \ + python3-dev \ qtbase5-dev \ qtmultimedia5-dev \ qttools5-dev \ From 907409507910d4843daaa65cc9d1a61975adef9a Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Mon, 23 Jun 2025 12:02:50 -0500 Subject: [PATCH 2/2] 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 --- CMake/ctkBlockCheckDependencies.cmake | 2 +- CMake/ctkMacroBuildLibWrapper.cmake | 6 +++--- CMake/ctkMacroCompilePythonScript.cmake | 10 +++++----- CMake/ctkMacroWrapPythonQt.cmake | 12 ++++++------ CMake/ctk_compile_python_scripts.cmake.in | 2 +- CMakeExternals/PythonQt.cmake | 10 +++++----- CMakeExternals/VTK.cmake | 6 +++--- CMakeLists.txt | 16 ++++++++-------- Libs/Scripting/Python/Core/CMakeLists.txt | 2 +- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/CMake/ctkBlockCheckDependencies.cmake b/CMake/ctkBlockCheckDependencies.cmake index fe3c9a1297..ac6f3ae82d 100644 --- a/CMake/ctkBlockCheckDependencies.cmake +++ b/CMake/ctkBlockCheckDependencies.cmake @@ -90,7 +90,7 @@ set(${Log4Qt_enabling_variable}_INCLUDE_DIRS Log4Qt_INCLUDE_DIRS) set(${Log4Qt_enabling_variable}_FIND_PACKAGE_CMD Log4Qt) set(PythonQt_enabling_variable PYTHONQT_LIBRARIES) -set(${PythonQt_enabling_variable}_INCLUDE_DIRS PYTHONQT_INCLUDE_DIR PYTHON_INCLUDE_DIRS) +set(${PythonQt_enabling_variable}_INCLUDE_DIRS PYTHONQT_INCLUDE_DIR Python3_INCLUDE_DIRS) set(${PythonQt_enabling_variable}_FIND_PACKAGE_CMD PythonQt) set(QtSOAP_enabling_variable QtSOAP_LIBRARIES) diff --git a/CMake/ctkMacroBuildLibWrapper.cmake b/CMake/ctkMacroBuildLibWrapper.cmake index de843fcc89..4f719a733c 100644 --- a/CMake/ctkMacroBuildLibWrapper.cmake +++ b/CMake/ctkMacroBuildLibWrapper.cmake @@ -95,8 +95,8 @@ macro(ctkMacroBuildLibWrapper) # Since the PythonQt decorator depends on PythonQt, Python and VTK, let's link against # these ones to avoid complaints of MSVC # Note: "LINK_DIRECTORIES" has to be invoked before "ADD_LIBRARY" - ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY) - set(my_EXTRA_PYTHON_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES}) + ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY) + set(my_EXTRA_Python3_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES}) # Does a header having the expected filename exists ? string(REGEX REPLACE "^CTK" "ctk" lib_name_lc_ctk ${lib_name}) @@ -122,7 +122,7 @@ macro(ctkMacroBuildLibWrapper) list(APPEND KIT_PYTHONQT_SRCS ${DECORATOR_HEADER}) endif() add_library(${lib_name}PythonQt ${MY_WRAPPER_LIBRARY_TYPE} ${KIT_PYTHONQT_SRCS}) - target_link_libraries(${lib_name}PythonQt ${lib_name} ${my_EXTRA_PYTHON_LIBRARIES}) + target_link_libraries(${lib_name}PythonQt ${lib_name} ${my_EXTRA_Python3_LIBRARIES}) if(MY_WRAPPER_LIBRARY_TYPE STREQUAL "STATIC") if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64-bit set_target_properties(${lib_name}PythonQt PROPERTIES COMPILE_FLAGS "-fPIC") diff --git a/CMake/ctkMacroCompilePythonScript.cmake b/CMake/ctkMacroCompilePythonScript.cmake index b734a3ea4a..5fb27ae947 100644 --- a/CMake/ctkMacroCompilePythonScript.cmake +++ b/CMake/ctkMacroCompilePythonScript.cmake @@ -164,15 +164,15 @@ function(_ctk_add_compile_python_directories_target target keep_only_pyc) endif() endforeach() - if(NOT PYTHONINTERP_FOUND) - find_package(PythonInterp REQUIRED) + if(NOT Python3_Interpreter_FOUND) + find_package(Python3 COMPONENTS Interpreter REQUIRED) endif() - if(NOT PYTHONLIBS_FOUND) - find_package(PythonLibs REQUIRED) + if(NOT Python3_Development_FOUND) + find_package(Python3 COMPONENTS Development REQUIRED) endif() # Extract python lib path - ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY) + ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY) get_filename_component(PYTHON_LIBRARY_PATH "${PYTHON_LIBRARY}" PATH) # Configure cmake script associated with the custom command diff --git a/CMake/ctkMacroWrapPythonQt.cmake b/CMake/ctkMacroWrapPythonQt.cmake index d6a410143f..076cab9099 100644 --- a/CMake/ctkMacroWrapPythonQt.cmake +++ b/CMake/ctkMacroWrapPythonQt.cmake @@ -62,10 +62,10 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W # TODO: this find package seems not to work when called form a superbuild, but the call is needed # in general to find the python interpreter. In CTK, the toplevel CMakeLists.txt does the find # package so this is a no-op. Other uses of this file may need to have this call so it is still enabled. - if(NOT PYTHONINTERP_FOUND) - find_package(PythonInterp) - if(NOT PYTHONINTERP_FOUND) - message(FATAL_ERROR "PYTHON_EXECUTABLE not specified or inexistent when calling ctkMacroWrapPythonQt") + if(NOT Python3_Interpreter_FOUND) + find_package(Python3 COMPONENTS Interpreter) + if(NOT Python3_Interpreter_FOUND) + message(FATAL_ERROR "Python3_EXECUTABLE not specified or inexistent when calling ctkMacroWrapPythonQt") endif() endif() @@ -157,7 +157,7 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W DEPENDS ${SOURCES_TO_WRAP} ${CTK_CMAKE_DIR}/ctkWrapPythonQt.py - COMMAND ${PYTHON_EXECUTABLE} ${CTK_CMAKE_DIR}/ctkWrapPythonQt.py + COMMAND ${Python3_EXECUTABLE} ${CTK_CMAKE_DIR}/ctkWrapPythonQt.py --target=${TARGET} --namespace=${WRAPPING_NAMESPACE} --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 if(NOT PYTHONQT_FOUND) message(FATAL_ERROR "error: PythonQt package is required to build ${TARGET}PythonQt") endif() - include_directories(${PYTHON_INCLUDE_DIRS} ${PYTHONQT_INCLUDE_DIR}) + include_directories(${Python3_INCLUDE_DIRS} ${PYTHONQT_INCLUDE_DIR}) endmacro() diff --git a/CMake/ctk_compile_python_scripts.cmake.in b/CMake/ctk_compile_python_scripts.cmake.in index 470b0bad36..cc38aea16c 100644 --- a/CMake/ctk_compile_python_scripts.cmake.in +++ b/CMake/ctk_compile_python_scripts.cmake.in @@ -95,7 +95,7 @@ else() endif() execute_process( - COMMAND "@PYTHON_EXECUTABLE@" "@compile_all_script@" + COMMAND "@Python3_EXECUTABLE@" "@compile_all_script@" RESULT_VARIABLE result_var ) if(NOT result_var STREQUAL 0) diff --git a/CMakeExternals/PythonQt.cmake b/CMakeExternals/PythonQt.cmake index db528d9aae..7b56ebcbb7 100644 --- a/CMakeExternals/PythonQt.cmake +++ b/CMakeExternals/PythonQt.cmake @@ -75,9 +75,9 @@ if(NOT DEFINED PYTHONQT_INSTALL_DIR) endif() # Python is required - if(NOT PYTHONLIBS_FOUND) - find_package(PythonLibs) - if(NOT PYTHONLIBS_FOUND) + if(NOT Python3_Development_FOUND) + find_package(Python3 COMPONENTS Development) + if(NOT Python3_Development_FOUND) message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}") endif() endif() @@ -89,7 +89,7 @@ if(NOT DEFINED PYTHONQT_INSTALL_DIR) set(Python3_LIBRARY_RELEASE ${PYTHON_LIBRARY}) find_package(Python3 COMPONENTS Development REQUIRED) - ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY) + ctkFunctionExtractOptimizedLibrary(Python3_LIBRARY PYTHON_LIBRARY) set(revision_tag 74dcd675e1515324cd7467a328d63dd25d263679) # patched-v4.1.0-2026-06-05-9992368e9 if(${proj}_REVISION_TAG) @@ -299,7 +299,7 @@ set(PythonQt_DIR ${PYTHONQT_INSTALL_DIR}) mark_as_superbuild( VARS PYTHONQT_INSTALL_DIR:PATH - PYTHON_EXECUTABLE:FILEPATH # FindPythonInterp expects PYTHON_EXECUTABLE variable to be defined + Python3_EXECUTABLE:FILEPATH # FindPythonInterp expects Python3_EXECUTABLE variable to be defined PYTHON_INCLUDE_DIR:PATH # FindPythonQt expects PYTHON_INCLUDE_DIR variable to be defined PYTHON_INCLUDE_DIR2:PATH PYTHON_LIBRARY:FILEPATH # FindPythonQt expects PYTHON_LIBRARY variable to be defined diff --git a/CMakeExternals/VTK.cmake b/CMakeExternals/VTK.cmake index 90a3fd57c1..8b8c7723b0 100644 --- a/CMakeExternals/VTK.cmake +++ b/CMakeExternals/VTK.cmake @@ -62,17 +62,17 @@ if(NOT DEFINED VTK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}) if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK) - set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) + set(Python3_EXECUTABLE ${Python3_EXECUTABLE}) set(Python3_INCLUDE_DIR ${PYTHON_INCLUDE_DIR}) set(Python3_LIBRARY ${PYTHON_LIBRARY}) set(Python3_LIBRARY_DEBUG ${PYTHON_LIBRARY}) set(Python3_LIBRARY_RELEASE ${PYTHON_LIBRARY}) find_package(Python3 COMPONENTS Interpreter Development) - ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY) + ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY) list(APPEND additional_vtk_cmakevars # FindPythonInterp, FindPythonLibs - -DPYTHON_EXECUTABLE:PATH=${PYTHON_EXECUTABLE} + -DPython3_EXECUTABLE:PATH=${Python3_EXECUTABLE} -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} -DPYTHON_DEBUG_LIBRARIES:FILEPATH=${PYTHON_DEBUG_LIBRARIES} diff --git a/CMakeLists.txt b/CMakeLists.txt index be708cfba2..bc83ff485c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -965,16 +965,16 @@ endif() # Check if dependencies are satisfied if(CTK_LIB_Scripting/Python/Core) - if(NOT PYTHONINTERP_FOUND) - find_package(PythonInterp) - if(NOT PYTHONINTERP_FOUND) - message(FATAL_ERROR "PYTHON_EXECUTABLE variable should be set to build CTK_LIB_Scripting/Python") + if(NOT Python3_Interpreter_FOUND) + find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + if(NOT Python3_Interpreter_FOUND) + message(FATAL_ERROR "Python3_EXECUTABLE variable should be set to build CTK_LIB_Scripting/Python") endif() endif() - if(NOT PYTHONLIBS_FOUND) - find_package(PythonLibs) - if(NOT PYTHONLIBS_FOUND) - message(FATAL_ERROR "PYTHON_LIBRARIES and PYTHON_INCLUDE_DIRS should be set to build CTK_LIB_Scripting/Python") + if(NOT Python3_Development_FOUND) + find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + if(NOT Python3_Development_FOUND) + message(FATAL_ERROR "Python3_LIBRARIES and Python3_INCLUDE_DIRS should be set to build CTK_LIB_Scripting/Python") endif() endif() endif() diff --git a/Libs/Scripting/Python/Core/CMakeLists.txt b/Libs/Scripting/Python/Core/CMakeLists.txt index 381f40b9d4..0b8cb45f14 100644 --- a/Libs/Scripting/Python/Core/CMakeLists.txt +++ b/Libs/Scripting/Python/Core/CMakeLists.txt @@ -36,7 +36,7 @@ configure_file( # Target libraries - See CMake/ctkFunctionGetTargetLibraries.cmake # The following macro will read the target libraries from the file 'target_libraries.cmake' -ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY) +ctkFunctionExtractOptimizedLibrary(Python3_LIBRARIES PYTHON_LIBRARY) ctkFunctionGetTargetLibraries(KIT_target_libraries) ctkMacroBuildLib(