ソースを参照

Add support for python wrapping when building against Qt5

This commit allows to successfully build CTK against Qt5 and an install
tree of the latest version of PythonQt generated from the source downloaded
from sourceforge.
Eric Heim 10 年 前
コミット
1b5699d571

+ 4 - 0
CMakeExternals/PythonQt.cmake

@@ -33,6 +33,10 @@ if(NOT DEFINED PYTHONQT_INSTALL_DIR)
 
   # Enable Qt libraries PythonQt wrapping if required
   if (CTK_QT_VERSION VERSION_GREATER "4")
+    message(FATAL_ERROR "To build CTK with Qt >= 5 and wrapping enabled, you "
+                        "are currently required to provide your own PythonQt "
+                        "by re-configuring CTK with option "
+                        "-DPYTHONQT_INSTALL_DIR:PATH=/path/to/PythonQt-30-install")
     list(APPEND ep_PythonQt_args
       -DPythonQt_QT_VERSION:STRING=${CTK_QT_VERSION}
       )

+ 0 - 8
CMakeLists.txt

@@ -494,14 +494,12 @@ ctk_lib_option(DICOM/Widgets
 ctk_lib_option(ImageProcessing/ITK/Core
                "Build the ITK Core library" OFF)
 
-if(CTK_QT_VERSION VERSION_LESS "5")
 ctk_lib_option(Scripting/Python/Core
                "Build the Python Core library" OFF
                CTK_ENABLE_Python_Wrapping)
 
 ctk_lib_option(Scripting/Python/Widgets
                "Build the Python Widgets library" OFF)
-endif()
 
 # VTK libraries have not yet been tested with Qt5
 if(CTK_QT_VERSION VERSION_LESS "5")
@@ -629,11 +627,9 @@ ctk_app_option(ctkDICOMObjectViewer
                "Build the DICOM example application" OFF
                CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
 
-if(CTK_QT_VERSION VERSION_LESS "5")
 ctk_app_option(ctkSimplePythonShell
                "Build the DICOM example application" OFF
                CTK_ENABLE_Python_Wrapping AND CTK_BUILD_EXAMPLES)
-endif()
 
 if(CTK_USE_QTTESTING AND CTK_QT_VERSION VERSION_LESS "5")
   ctk_app_option(ctkQtTesting
@@ -752,10 +748,6 @@ ctk_enable_option(PluginFramework "Enable Plugin Framework" OFF
 ctk_enable_option(Python_Wrapping "Wrap CTK classes using Qt meta-object system into Python language" OFF
                   CTK_LIB_Scripting/Python/Core)
 mark_as_superbuild(CTK_ENABLE_Python_Wrapping)
-if(CTK_QT_VERSION VERSION_GREATER "4" AND CTK_ENABLE_Python_Wrapping)
-  message(WARNING "Disabling CTK_ENABLE_Python_Wrapping because Qt5 support is still missing")
-  set(CTK_ENABLE_Python_Wrapping OFF CACHE BOOL "Wrap CTK classes using Qt meta-object system into Python language" FORCE)
-endif()
 
 # Build examples
 # Create the logical expression containing the minium set of required options

+ 5 - 1
Libs/Scripting/Python/Core/Testing/Cpp/CMakeLists.txt

@@ -13,7 +13,11 @@ set(LIBRARY_NAME ${PROJECT_NAME})
 include_directories(${CMAKE_SOURCE_DIR}/Libs/Testing
                     ${CMAKE_CURRENT_BINARY_DIR})
 
+set(CTK_QT_TEST_LIBRARY )
+
 if (CTK_QT_VERSION VERSION_GREATER "4")
+  find_package(Qt5Test REQUIRED)
+  set(CTK_QT_TEST_LIBRARY Qt5::Test)
   QT5_GENERATE_MOCS(
     ctkAbstractPythonManagerTest.cpp
     )
@@ -24,7 +28,7 @@ else()
 endif()
 
 add_executable(${KIT}CppTests ${Tests})
-target_link_libraries(${KIT}CppTests ${LIBRARY_NAME} ${CTK_BASE_LIBRARIES})
+target_link_libraries(${KIT}CppTests ${LIBRARY_NAME} ${CTK_BASE_LIBRARIES} ${CTK_QT_TEST_LIBRARY})
 
 #
 # Add Tests

+ 6 - 1
Libs/Scripting/Python/Core/ctkAbstractPythonManager.cpp

@@ -28,7 +28,10 @@
 
 // PythonQT includes
 #include <PythonQt.h>
-#include <PythonQt_QtBindings.h>
+
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+  #include <PythonQt_QtBindings.h>
+#endif
 
 // STD includes
 #include <csignal>
@@ -152,7 +155,9 @@ void ctkAbstractPythonManager::initPythonQt(int flags)
   this->connect(PythonQt::self(), SIGNAL(pythonStdErr(QString)),
                 SLOT(printStderr(QString)));
 
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
   PythonQt_init_QtBindings();
+#endif
 
   QStringList initCode;
 

+ 9 - 1
Utilities/CMake/FindPythonQt.cmake

@@ -12,7 +12,15 @@ endif()
 if(NOT EXISTS "${PYTHONQT_INSTALL_DIR}")
   find_path(PYTHONQT_INSTALL_DIR include/PythonQt/PythonQt.h DOC "Directory where PythonQt was installed.")
 endif()
-find_path(PYTHONQT_INCLUDE_DIR PythonQt.h "${PYTHONQT_INSTALL_DIR}/include/PythonQt" DOC "Path to the PythonQt include directory")
+# XXX Since PythonQt 3.0 is not yet cmakeified, depending
+#     on how PythonQt is built, headers will not always be
+#     installed in "include/PythonQt". That is why "src"
+#     is added as an option. See [1] for more details.
+#     [1] https://github.com/commontk/CTK/pull/538#issuecomment-86106367
+find_path(PYTHONQT_INCLUDE_DIR PythonQt.h
+  PATHS "${PYTHONQT_INSTALL_DIR}/include/PythonQt"
+        "${PYTHONQT_INSTALL_DIR}/src"
+  DOC "Path to the PythonQt include directory")
 find_library(PYTHONQT_LIBRARY_RELEASE PythonQt PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "The PythonQt library.")
 find_library(PYTHONQT_LIBRARY_DEBUG NAMES PythonQt${CTK_CMAKE_DEBUG_POSTFIX} PythonQt${CMAKE_DEBUG_POSTFIX} PythonQt PATHS "${PYTHONQT_INSTALL_DIR}/lib" DOC "The PythonQt library.")
 set(PYTHONQT_LIBRARY)