From d3feea63092179734cb9d5e92b4ffecfb411364b Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Sun, 20 Apr 2014 07:57:51 +0200 Subject: [PATCH 2/9] Allow to build with qt5 and qt4 --- CMakeLists.txt | 31 ++++++++- cmake/modules/ECMQt4To5Porting.cmake | 119 +++++++++++++++++++++++++++++++++++ lib/prison/CMakeLists.txt | 2 +- lib/prison/barcodewidget.cpp | 2 + testapp/CMakeLists.txt | 5 +- tools/CMakeLists.txt | 4 +- 6 files changed, 155 insertions(+), 8 deletions(-) create mode 100644 cmake/modules/ECMQt4To5Porting.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 479c563..3c26bb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR) # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") -find_package(Qt4 REQUIRED) find_package(QRencode REQUIRED) find_package(Dmtx REQUIRED) @@ -12,9 +11,39 @@ find_package(Dmtx REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) +option(QT5_BUILD "Build Akonadi using the Qt5 framework" FALSE) + include_directories(${CMAKE_SOURCE_DIR}/lib ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ) +#### Qt 4 and 5 #### +if(QT5_BUILD) + find_package(Qt5Core REQUIRED) + find_package(Qt5Gui REQUIRED) + find_package(Qt5Widgets REQUIRED) + find_package(Qt5Test REQUIRED) + + include("cmake/modules/ECMQt4To5Porting.cmake") + include_directories(${QT_INCLUDES}) # TODO: Port away from this. + + if(CMAKE_VERSION VERSION_LESS 2.8.9) + message(FATAL_ERROR "Akonadi Qt 5 build requires at least CMake version 2.8.9") + endif() + + if (Qt5_POSITION_INDEPENDENT_CODE) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + endif() + + set(QT_QTTEST_LIBRARIES Qt5::Test) +else() + set(QT_USE_IMPORTED_TARGETS TRUE) # Qt 4 only + set(QT_MIN_VERSION 4.8.0) # Qt 4 only + + find_package(Qt4 REQUIRED) + include(${QT_USE_FILE}) +endif() + + add_subdirectory(lib) add_subdirectory(testapp) diff --git a/cmake/modules/ECMQt4To5Porting.cmake b/cmake/modules/ECMQt4To5Porting.cmake new file mode 100644 index 0000000..7d6458a --- /dev/null +++ b/cmake/modules/ECMQt4To5Porting.cmake @@ -0,0 +1,119 @@ +#============================================================================= +# Copyright 2005-2011 Kitware, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of Kitware, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +# Portability helpers. + +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_modules + Core + Declarative + Widgets + Script + ScriptTools + DBus + Network + Test + Designer + Concurrent + Xml + UiTools + WebKit + 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() + +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() + +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/lib/prison/CMakeLists.txt b/lib/prison/CMakeLists.txt index 04d9a89..6916329 100644 --- a/lib/prison/CMakeLists.txt +++ b/lib/prison/CMakeLists.txt @@ -12,7 +12,7 @@ SET( prison_SRC add_library(prison SHARED ${prison_SRC}) target_link_libraries(prison ${DMTX_LIBRARIES} ${QRENCODE_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) -set_target_properties(prison PROPERTIES VERSION "0.1.0" SOVERSION "0" LINK_INTERFACE_LIBRARIES "" DEFINE_SYMBOL BUILDING_PRISON) +set_target_properties(prison PROPERTIES VERSION "0.2.0" SOVERSION "0" LINK_INTERFACE_LIBRARIES "" DEFINE_SYMBOL BUILDING_PRISON) set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" ) diff --git a/lib/prison/barcodewidget.cpp b/lib/prison/barcodewidget.cpp index fc673c6..54edf13 100644 --- a/lib/prison/barcodewidget.cpp +++ b/lib/prison/barcodewidget.cpp @@ -28,6 +28,8 @@ #include "abstractbarcode.h" #include #include +#include +#include using namespace prison; diff --git a/testapp/CMakeLists.txt b/testapp/CMakeLists.txt index c76f7ab..95d3403 100644 --- a/testapp/CMakeLists.txt +++ b/testapp/CMakeLists.txt @@ -1,7 +1,4 @@ -include_directories(${CMAKE_SOURCE_DIR}/lib ${CMAKE_CURRENT_BINARY_DIR}) - set(prison_SRCS prison.cpp main.cpp) -qt4_automoc(${prison_SRCS}) add_executable(test-prison ${prison_SRCS}) -target_link_libraries(test-prison ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} prison) +target_link_libraries(test-prison ${QT_QTGUI_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} prison) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index c2ad7c3..ea5132e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,5 +1,5 @@ -find_package(Qt4 COMPONENTS QtGui QtCore REQUIRED) +#find_package(Qt4 COMPONENTS QtGui QtCore REQUIRED) add_executable(prison-datamatrix prison-datamatrix.cpp) -target_link_libraries(prison-datamatrix prison ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}) +target_link_libraries(prison-datamatrix prison ${QT_QTGUI_LIBRARIES} ${QT_QTCORE_LIBRARY}) -- 2.5.0