[PATCH] Build with Qt 4 and 5.
Stephen Kelly
stephen.kelly at kdab.com
Wed Dec 12 11:42:53 EST 2012
---
CMake/ECMQt4To5Porting.cmake | 98 +++++++++++++++++++++++++++
CMake/FindQt5Transitional.cmake | 77 +++++++++++++++++++++
Examples/GUI/Qt/GraphicsView/CMakeLists.txt | 2 +-
GUISupport/Qt/CMakeLists.txt | 3 +-
GUISupport/Qt/Q4VTKWidgetPlugin.cxx | 3 +-
GUISupport/Qt/Q4VTKWidgetPlugin.h | 5 ++
GUISupport/Qt/QVTKWidget.cxx | 2 +-
GUISupport/Qt/QVTKWidget.h | 2 +-
GUISupport/Qt/Testing/Cxx/CMakeLists.txt | 3 +-
GUISupport/QtOpenGL/CMakeLists.txt | 3 +-
GUISupport/QtOpenGL/QVTKGraphicsItem.h | 2 +-
GUISupport/QtSQL/CMakeLists.txt | 3 +-
GUISupport/QtWebkit/CMakeLists.txt | 3 +-
GUISupport/QtWebkit/vtkQtRichTextView.cxx | 2 -
Rendering/Qt/CMakeLists.txt | 3 +-
Views/Qt/CMakeLists.txt | 3 +-
Views/Qt/vtkQtView.cxx | 7 +-
17 files changed, 199 insertions(+), 22 deletions(-)
create mode 100644 CMake/ECMQt4To5Porting.cmake
create mode 100644 CMake/FindQt5Transitional.cmake
diff --git a/CMake/ECMQt4To5Porting.cmake b/CMake/ECMQt4To5Porting.cmake
new file mode 100644
index 0000000..9fc84a6
--- /dev/null
+++ b/CMake/ECMQt4To5Porting.cmake
@@ -0,0 +1,98 @@
+
+set(QT_QTGUI_LIBRARIES
+ ${Qt5Gui_LIBRARIES}
+ ${Qt5Widgets_LIBRARIES}
+ ${Qt5PrintSupport_LIBRARIES}
+ ${Qt5Svg_LIBRARIES}
+)
+
+set(QT_INCLUDES
+ ${Qt5Gui_INCLUDE_DIRS}
+ ${Qt5Widgets_INCLUDE_DIRS}
+ ${Qt5PrintSupport_INCLUDE_DIRS}
+ ${Qt5Svg_INCLUDE_DIRS}
+)
+set(QT_QTGUI_LIBRARY ${QT_QTGUI_LIBRARIES})
+
+set(_qt_modules
+ Core
+ Declarative
+ Widgets
+ Script
+ ScriptTools
+ DBus
+ Network
+ Test
+ Designer
+ Concurrent
+ Xml
+ UiTools
+ Qml
+ Quick1
+ WebKit
+ WebKitWidgets
+ Sql
+ OpenGL
+)
+
+foreach(_module ${_qt_modules})
+ string(TOUPPER ${_module} _module_upper)
+ set(QT_QT${_module_upper}_LIBRARIES ${Qt5${_module}_LIBRARIES})
+ set(QT_QT${_module_upper}_LIBRARY ${QT_QT${_module_upper}_LIBRARIES})
+ list(APPEND QT_INCLUDES ${Qt5${_module}_INCLUDE_DIRS})
+ set(QT_QT${_module_upper}_FOUND ${Qt5${_module}_FOUND})
+endforeach()
+
+list(APPEND QT_QTCORE_LIBRARIES ${Qt5Concurrent_LIBRARIES})
+list(APPEND QT_QTCORE_LIBRARY ${Qt5Concurrent_LIBRARIES})
+
+set(QT_QTDECLARATIVE_LIBRARIES ${Qt5Quick1_LIBRARIES})
+set(QT_QTDECLARATIVE_LIBRARY ${Qt5Quick1_LIBRARIES})
+
+get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake LOCATION)
+get_target_property(QT_RCC_EXECUTABLE Qt5::rcc LOCATION)
+if (TARGET Qt5::uic)
+ get_target_property(QT_UIC_EXECUTABLE Qt5::uic LOCATION)
+endif()
+
+if (TARGET Qt5::qdbuscpp2xml)
+ get_target_property(QT_QDBUSCPP2XML_EXECUTABLE Qt5::qdbuscpp2xml LOCATION)
+endif()
+
+if (TARGET Qt5::qdbusxml2cpp)
+ get_target_property(QT_QDBUSXML2CPP_EXECUTABLE Qt5::qdbusxml2cpp LOCATION)
+endif()
+
+add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
+
+macro(qt4_wrap_ui)
+ qt5_wrap_ui(${ARGN})
+endmacro()
+
+macro(qt4_wrap_cpp)
+ qt5_wrap_cpp(${ARGN})
+endmacro()
+
+macro(qt4_generate_moc)
+ qt5_generate_moc(${ARGN})
+endmacro()
+
+macro(qt4_add_dbus_adaptor)
+ qt5_add_dbus_adaptor(${ARGN})
+endmacro()
+
+macro(qt4_add_dbus_interfaces)
+ qt5_add_dbus_interfaces(${ARGN})
+endmacro()
+
+macro(qt4_add_dbus_interface)
+ qt5_add_dbus_interface(${ARGN})
+endmacro()
+
+macro(qt4_generate_dbus_interface)
+ qt5_generate_dbus_interface(${ARGN})
+endmacro()
+
+macro(qt4_add_resources)
+ qt5_add_resources(${ARGN})
+endmacro()
diff --git a/CMake/FindQt5Transitional.cmake b/CMake/FindQt5Transitional.cmake
new file mode 100644
index 0000000..452c0f7
--- /dev/null
+++ b/CMake/FindQt5Transitional.cmake
@@ -0,0 +1,77 @@
+
+find_package(Qt5Core QUIET)
+
+if (Qt5Core_FOUND)
+ if (NOT Qt5Transitional_FIND_COMPONENTS)
+ foreach(_component
+ Core
+ Gui
+ DBus
+ Designer
+ Declarative
+ Script
+ ScriptTools
+ Network
+ Test
+ Xml
+ Svg
+ Sql
+ Widgets
+ PrintSupport
+ Concurrent
+ UiTools
+ WebKit
+ WebKitWidgets
+ OpenGL
+ )
+ find_package(Qt5${_component})
+ list(APPEND QT_LIBRARIES ${Qt5${_component}_LIBRARIES})
+ endforeach()
+ else()
+ foreach(_component ${Qt5Transitional_FIND_COMPONENTS})
+ find_package(Qt5${_component} REQUIRED)
+ if ("${_component}" STREQUAL "Gui")
+ find_package(Qt5Widgets REQUIRED)
+ find_package(Qt5PrintSupport REQUIRED)
+ find_package(Qt5Svg REQUIRED)
+ list(APPEND QT_LIBRARIES ${Qt5Widgets_LIBRARIES}
+ ${Qt5PrintSupport_LIBRARIES}
+ ${Qt5Svg_LIBRARIES} )
+ endif()
+ if ("${_component}" STREQUAL "Core")
+ find_package(Qt5Concurrent REQUIRED)
+ list(APPEND QT_LIBRARIES ${Qt5Concurrent_LIBRARIES} )
+ endif()
+ if ("${_component}" STREQUAL "WebKit")
+ find_package(Qt5WebKitWidgets REQUIRED)
+ list(APPEND QT_LIBRARIES ${Qt5WebKitWidgets_LIBRARIES} )
+ endif()
+ endforeach()
+ endif()
+
+ set(Qt5Transitional_FOUND TRUE)
+ set(QT5_BUILD TRUE)
+
+ include("${CMAKE_CURRENT_LIST_DIR}/ECMQt4To5Porting.cmake") # TODO: Port away from this.
+ include_directories(${QT_INCLUDES}) # TODO: Port away from this.
+
+ if (Qt5_POSITION_INDEPENDENT_CODE)
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+ endif()
+
+else()
+ foreach(_component ${Qt5Transitional_FIND_COMPONENTS})
+ if("${_component}" STREQUAL "Widgets") # new in Qt5
+ set(_component Gui)
+ elseif("${_component}" STREQUAL "Concurrent") # new in Qt5
+ set(_component Core)
+ endif()
+ list(APPEND _components Qt${_component})
+ endforeach()
+ find_package(Qt4 ${QT_MIN_VERSION} REQUIRED ${_components})
+ include(${QT_USE_FILE})
+
+ if(QT4_FOUND)
+ set(Qt5Transitional_FOUND TRUE)
+ endif()
+endif()
diff --git a/Examples/GUI/Qt/GraphicsView/CMakeLists.txt b/Examples/GUI/Qt/GraphicsView/CMakeLists.txt
index ea466d3..04e978c 100644
--- a/Examples/GUI/Qt/GraphicsView/CMakeLists.txt
+++ b/Examples/GUI/Qt/GraphicsView/CMakeLists.txt
@@ -1,5 +1,5 @@
-find_package(Qt4 REQUIRED)
+find_package(Qt5Transitional REQUIRED)
set(QT_USE_QTOPENGL 1)
set(QT_USE_QTWEBKIT 1)
include(${QT_USE_FILE})
diff --git a/GUISupport/Qt/CMakeLists.txt b/GUISupport/Qt/CMakeLists.txt
index 028d4c6..1a32a10 100644
--- a/GUISupport/Qt/CMakeLists.txt
+++ b/GUISupport/Qt/CMakeLists.txt
@@ -52,9 +52,8 @@ set(QVTKNonMocHeaders
# import Qt4 build settings
set(QT_USE_QTNETWORK 1)
-find_package(Qt4 REQUIRED QUIET)
+find_package(Qt5Transitional REQUIRED QUIET)
mark_as_advanced(QT_QMAKE_EXECUTABLE)
-include(${QT_USE_FILE})
qt4_wrap_cpp(QVTKLibMocSrcs ${QVTKMocHeaders})
diff --git a/GUISupport/Qt/Q4VTKWidgetPlugin.cxx b/GUISupport/Qt/Q4VTKWidgetPlugin.cxx
index 64b68f2..3cd513e 100644
--- a/GUISupport/Qt/Q4VTKWidgetPlugin.cxx
+++ b/GUISupport/Qt/Q4VTKWidgetPlugin.cxx
@@ -144,5 +144,6 @@ QList<QDesignerCustomWidgetInterface*> QVTKPlugin::customWidgets() const
return plugins;
}
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
Q_EXPORT_PLUGIN(QVTKPlugin)
-
+#endif
diff --git a/GUISupport/Qt/Q4VTKWidgetPlugin.h b/GUISupport/Qt/Q4VTKWidgetPlugin.h
index 0aedd9a..09b8d72 100644
--- a/GUISupport/Qt/Q4VTKWidgetPlugin.h
+++ b/GUISupport/Qt/Q4VTKWidgetPlugin.h
@@ -50,11 +50,16 @@ class QVTKWidgetPlugin : public QDesignerCustomWidgetInterface
bool isContainer() const;
};
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#define Q_PLUGIN_METADATA(any)
+#endif
+
// implement designer widget collection interface
class QVTKPlugin : public QObject, public QDesignerCustomWidgetCollectionInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
+ Q_PLUGIN_METADATA(IID "org.vtk.WidgetPlugin")
public:
QVTKPlugin();
~QVTKPlugin();
diff --git a/GUISupport/Qt/QVTKWidget.cxx b/GUISupport/Qt/QVTKWidget.cxx
index 9591717..18c4f4c 100644
--- a/GUISupport/Qt/QVTKWidget.cxx
+++ b/GUISupport/Qt/QVTKWidget.cxx
@@ -398,7 +398,7 @@ bool QVTKWidget::event(QEvent* e)
if(QObject::event(e))
{
- return TRUE;
+ return true;
}
if(e->type() == QEvent::KeyPress)
diff --git a/GUISupport/Qt/QVTKWidget.h b/GUISupport/Qt/QVTKWidget.h
index 2fb7d46..42e06a0 100644
--- a/GUISupport/Qt/QVTKWidget.h
+++ b/GUISupport/Qt/QVTKWidget.h
@@ -38,7 +38,7 @@
#include "vtkGUISupportQtModule.h" // For export macro
#include "QVTKInteractor.h"
-#include <QtGui/QWidget>
+#include <QWidget>
class QVTKInteractorAdapter;
diff --git a/GUISupport/Qt/Testing/Cxx/CMakeLists.txt b/GUISupport/Qt/Testing/Cxx/CMakeLists.txt
index 457cbb2..d1727a9 100644
--- a/GUISupport/Qt/Testing/Cxx/CMakeLists.txt
+++ b/GUISupport/Qt/Testing/Cxx/CMakeLists.txt
@@ -6,8 +6,7 @@ set(MyTests
create_test_sourcelist(Tests ${vtk-module}CxxTests.cxx ${MyTests}
EXTRA_INCLUDE vtkTestDriver.h)
-find_package(Qt4 REQUIRED)
-include(${QT_USE_FILE})
+find_package(Qt5Transitional REQUIRED)
vtk_module_test_executable(${vtk-module}CxxTests ${Tests} QTestApp.cxx)
diff --git a/GUISupport/QtOpenGL/CMakeLists.txt b/GUISupport/QtOpenGL/CMakeLists.txt
index 4a3d8e3..9f018f6 100644
--- a/GUISupport/QtOpenGL/CMakeLists.txt
+++ b/GUISupport/QtOpenGL/CMakeLists.txt
@@ -9,8 +9,7 @@ set(LibSrcs ${QVTKLibSrcs}
# import Qt4 build settings
set(QT_USE_QTOPENGL 1)
-find_package(Qt4 REQUIRED QUIET)
-include(${QT_USE_FILE})
+find_package(Qt5Transitional REQUIRED QUIET)
qt4_wrap_cpp(LibMocSrcs ${MocHeaders})
diff --git a/GUISupport/QtOpenGL/QVTKGraphicsItem.h b/GUISupport/QtOpenGL/QVTKGraphicsItem.h
index dfc5c2e..861acc9 100644
--- a/GUISupport/QtOpenGL/QVTKGraphicsItem.h
+++ b/GUISupport/QtOpenGL/QVTKGraphicsItem.h
@@ -26,7 +26,7 @@
#define QVTKGraphicsItem_hpp
#include "vtkGUISupportQtOpenGLModule.h" // For export macro
-#include <QtGui/QGraphicsWidget>
+#include <QGraphicsWidget>
#include <QtOpenGL/QGLContext>
#include <vtkSmartPointer.h>
#include "QVTKWin32Header.h"
diff --git a/GUISupport/QtSQL/CMakeLists.txt b/GUISupport/QtSQL/CMakeLists.txt
index 5acb86b..11f80d7 100644
--- a/GUISupport/QtSQL/CMakeLists.txt
+++ b/GUISupport/QtSQL/CMakeLists.txt
@@ -9,8 +9,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
# import Qt4 build settings
set(QT_USE_QTSQL 1)
-find_package(Qt4 REQUIRED QUIET)
-include(${QT_USE_FILE})
+find_package(Qt5Transitional REQUIRED QUIET)
set(${vtk-module}_NO_HeaderTest 1)
vtk_module_library(${vtk-module} ${LibSrcs})
diff --git a/GUISupport/QtWebkit/CMakeLists.txt b/GUISupport/QtWebkit/CMakeLists.txt
index 5f9841e..d566a3c 100644
--- a/GUISupport/QtWebkit/CMakeLists.txt
+++ b/GUISupport/QtWebkit/CMakeLists.txt
@@ -1,4 +1,4 @@
-find_package(Qt4 REQUIRED QtCore QtGui QtWebKit QUIET)
+find_package(Qt5Transitional REQUIRED Core Gui WebKit Network QUIET)
# Rich-text view requires Qt >= 4.5.0
# Rich-text depends on Qt Webkit which is not portable on Unix (AIX & HP-UX)
@@ -12,7 +12,6 @@ set(QT_USE_QTWEBKIT 1)
# import Qt4 build settings
set(QT_USE_QTNETWORK 1)
-include(${QT_USE_FILE})
qt4_wrap_cpp(LibMocSrcs ${MocHeaders})
diff --git a/GUISupport/QtWebkit/vtkQtRichTextView.cxx b/GUISupport/QtWebkit/vtkQtRichTextView.cxx
index f117047..0ac1355 100644
--- a/GUISupport/QtWebkit/vtkQtRichTextView.cxx
+++ b/GUISupport/QtWebkit/vtkQtRichTextView.cxx
@@ -51,8 +51,6 @@ PURPOSE. See the above copyright notice for more information.
#include <QWebHistory>
#include <QWebPage>
#include <QWebView>
-#include <QHttpHeader>
-#include <QHttpRequestHeader>
#include <QUrl>
vtkStandardNewMacro(vtkQtRichTextView);
diff --git a/Rendering/Qt/CMakeLists.txt b/Rendering/Qt/CMakeLists.txt
index ddb499e..6b2c909 100644
--- a/Rendering/Qt/CMakeLists.txt
+++ b/Rendering/Qt/CMakeLists.txt
@@ -7,8 +7,7 @@ set(LibSrcs
)
# import Qt4 build settings
-find_package(Qt4 REQUIRED QtCore QtGui QUIET)
-include(${QT_USE_FILE})
+find_package(Qt5Transitional REQUIRED Core Gui QUIET)
vtk_module_library(${vtk-module} ${LibSrcs})
target_link_libraries(${vtk-module} ${QT_LIBRARIES})
diff --git a/Views/Qt/CMakeLists.txt b/Views/Qt/CMakeLists.txt
index efb5588..38e14c3 100644
--- a/Views/Qt/CMakeLists.txt
+++ b/Views/Qt/CMakeLists.txt
@@ -19,8 +19,7 @@ set(MocHeaders
# import Qt4 build settings
set(QT_USE_QTNETWORK 1)
-find_package(Qt4 REQUIRED QUIET)
-include(${QT_USE_FILE})
+find_package(Qt5Transitional REQUIRED QUIET)
qt4_wrap_cpp(LibMocSrcs ${MocHeaders})
diff --git a/Views/Qt/vtkQtView.cxx b/Views/Qt/vtkQtView.cxx
index d9fe0cb..2eeb71d 100644
--- a/Views/Qt/vtkQtView.cxx
+++ b/Views/Qt/vtkQtView.cxx
@@ -16,6 +16,7 @@
#include <QPixmap>
#include "vtkObjectFactory.h"
+#include <QWidget>
//----------------------------------------------------------------------------
vtkQtView::vtkQtView()
@@ -51,5 +52,9 @@ void vtkQtView::ProcessQtEventsNoUserInput()
bool vtkQtView::SaveImage(const char* filename)
{
// This is ok even if this->GetWidget() returns null.
- return QPixmap::grabWidget(this->GetWidget()).save(filename);
+ return QPixmap::grabWidget(this->GetWidget()
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+ , this->GetWidget()->rect()
+#endif
+ ).save(filename);
}
--
1.7.10.4
--nextPart8148542.S6m589kinR--
More information about the CMake
mailing list