From 9d30c279e086d1a5ea2454eb1fbed355408d4b12 Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 13 Dec 2015 13:09:25 +0100 Subject: [PATCH] Fixed: Compilation of some tools with Qt 5 in static --HG-- branch : develop --- code/CMakeLists.txt | 174 +++++++++++++++++- .../tools/misc/crash_report/CMakeLists.txt | 14 +- .../tools/misc/crash_report/crash_report.cpp | 13 ++ .../tools/misc/message_box_qt/CMakeLists.txt | 2 - .../tools/misc/words_dic_qt/CMakeLists.txt | 2 - .../client/client_config_qt/CMakeLists.txt | 2 - .../tools/client/client_config_qt/main.cpp | 13 ++ 7 files changed, 202 insertions(+), 18 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index f3325c947..bd1527844 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -68,10 +68,6 @@ IF(WIN32) IF(WITH_MFC) FIND_PACKAGE(MFC QUIET) ENDIF(WITH_MFC) - - IF(NOT DEFINED ENV{QTDIR}) - SET(ENV{QTDIR} "c:/qt/4.6.3") - ENDIF(NOT DEFINED ENV{QTDIR}) ENDIF(WIN32) #----------------------------------------------------------------------------- @@ -144,24 +140,194 @@ IF(WITH_SSE2) ENDIF(WITH_SSE3) ENDIF(WITH_SSE2) +MACRO(ADD_QT_LIBRARY _NAME) + IF(WIN32) + SET(_PREFIX "Qt5") + SET(_EXT "lib") + ELSE() + SET(_PREFIX "libQt5") + SET(_EXT "a") + ENDIF() + SET(_LIB "${QT_LIBRARY_DIR}/${_PREFIX}${_NAME}.${_EXT}") + IF(EXISTS ${_LIB}) + SET(QT_LIBRARIES ${QT_LIBRARIES} optimized ${_LIB}) + ENDIF() + SET(_LIB "${QT_LIBRARY_DIR}/${_PREFIX}${_NAME}d.${_EXT}") + IF(EXISTS ${_LIB}) + SET(QT_LIBRARIES ${QT_LIBRARIES} debug ${_LIB}) + ENDIF() +ENDMACRO() + +MACRO(ADD_QT_PLUGIN _TYPE _NAME) + IF(WIN32) + SET(_PREFIX "") + SET(_EXT "lib") + ELSE() + SET(_PREFIX "lib") + SET(_EXT "a") + ENDIF() + SET(_LIB "${QT_PLUGINS_DIR}/${_TYPE}/${_PREFIX}${_NAME}.${_EXT}") + IF(EXISTS ${_LIB}) + SET(QT_LIBRARIES ${QT_LIBRARIES} optimized ${_LIB}) + ENDIF() + SET(_LIB "${QT_PLUGINS_DIR}/${_TYPE}/${_PREFIX}${_NAME}d.${_EXT}") + IF(EXISTS ${_LIB}) + SET(QT_LIBRARIES ${QT_LIBRARIES} debug ${_LIB}) + ENDIF() +ENDMACRO() + IF(WITH_QT5) CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11 FATAL_ERROR) + SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QTDIR} $ENV{QTDIR}) + FIND_PACKAGE(Qt5Core QUIET) IF(Qt5Core_FOUND) + # Check if we are using Qt static or shared libraries + GET_TARGET_PROPERTY(_FILE Qt5::Core IMPORTED_LOCATION_RELEASE) + + SET(QT_VERSION "${Qt5Core_VERSION_STRING}") + SET(_VERSION "${QT_VERSION}") + + IF(_FILE MATCHES "\\.(lib|a)$") + SET(QT_STATIC ON) + SET(_VERSION "${_VERSION} static version") + ELSE() + SET(QT_STATIC OFF) + SET(_VERSION "${_VERSION} shared version") + ENDIF() + + MESSAGE(STATUS "Found Qt ${_VERSION}") + + # These variables are not defined with Qt5 CMake modules + SET(QT_BINARY_DIR "${_qt5Core_install_prefix}/bin") + SET(QT_LIBRARY_DIR "${_qt5Core_install_prefix}/lib") + SET(QT_PLUGINS_DIR "${_qt5Core_install_prefix}/plugins") + SET(QT_TRANSLATIONS_DIR "${_qt5Core_install_prefix}/translations") + + # Fix wrong include directories with Qt 5 under Mac OS X + INCLUDE_DIRECTORIES("${_qt5Core_install_prefix}/include") + FIND_PACKAGE(Qt5Gui) FIND_PACKAGE(Qt5Widgets) FIND_PACKAGE(Qt5OpenGL) FIND_PACKAGE(Qt5Xml) FIND_PACKAGE(Qt5LinguistTools) FIND_PACKAGE(Qt5Network) + + SET(QT_LIBRARIES Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Network Qt5::OpenGL Qt5::Xml) + + IF(QT_STATIC) + ADD_DEFINITIONS(-DQT_STATICPLUGIN) + + # Core + IF(APPLE) + FIND_LIBRARY(PCRE_LIBRARY pcre16 pcre) + + FIND_LIBRARY(FOUNDATION_FRAMEWORK Foundation) + FIND_LIBRARY(CARBON_FRAMEWORK Carbon) + FIND_LIBRARY(SECURITY_FRAMEWORK Security) + + SET(QT_LIBRARIES ${QT_LIBRARIES} + ${PCRE_LIBRARY} + ${FOUNDATION_FRAMEWORK} + ${CARBON_FRAMEWORK} + ${SECURITY_FRAMEWORK}) + ENDIF() + + # Network + FIND_PACKAGE(OpenSSL REQUIRED) + SET(QT_LIBRARIES ${QT_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES}) + + IF(WIN32) + SET(QT_LIBRARIES ${QT_LIBRARIES} + ${WINSDK_LIBRARY_DIR}/Crypt32.lib + ${WINSDK_LIBRARY_DIR}/WS2_32.Lib) + ENDIF() + + SET(QT_LIBRARIES ${QT_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARY}) + + # Gui + ADD_QT_LIBRARY(PrintSupport) + ADD_QT_LIBRARY(PlatformSupport) + + IF(WIN32) + SET(QT_LIBRARIES ${QT_LIBRARIES} + ${WINSDK_LIBRARY_DIR}/Imm32.lib + ${WINSDK_LIBRARY_DIR}/OpenGL32.lib + ${WINSDK_LIBRARY_DIR}/WinMM.Lib) + ADD_QT_PLUGIN(platforms qwindows) + ELSEIF(APPLE) + # Cups needs .dylib + SET(OLD_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + SET(CMAKE_FIND_LIBRARY_SUFFIXES .dylib) + FIND_LIBRARY(CUPS_LIBRARY cups) + SET(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_CMAKE_FIND_LIBRARY_SUFFIXES}) + + FIND_LIBRARY(IOKIT_FRAMEWORK IOKit) + FIND_LIBRARY(COCOA_FRAMEWORK Cocoa) + FIND_LIBRARY(SYSTEMCONFIGURATION_FRAMEWORK SystemConfiguration) + FIND_LIBRARY(OPENGL_FRAMEWORK NAMES OpenGL) + + SET(QT_LIBRARIES ${QT_LIBRARIES} + ${CUPS_LIBRARY} + ${COCOA_FRAMEWORK} + ${SYSTEMCONFIGURATION_FRAMEWORK} + ${IOKIT_FRAMEWORK} + ${OPENGL_FRAMEWORK}) + + ADD_QT_PLUGIN(printsupport cocoaprintersupport) + ADD_QT_PLUGIN(platforms qcocoa) + ENDIF() + + ADD_QT_PLUGIN(imageformats qgif) + ADD_QT_PLUGIN(imageformats qicns) + ADD_QT_PLUGIN(imageformats qico) + ADD_QT_PLUGIN(imageformats qjpeg) + ADD_QT_PLUGIN(imageformats qmng) + ADD_QT_PLUGIN(imageformats qwebp) + + # harfbuzz is needed since Qt 5.3 + IF(APPLE) + SET(HB_LIB "${QT_LIBRARY_DIR}/libqtharfbuzzng.a") + ELSEIF(WIN32) + SET(HB_LIB "${QT_LIBRARY_DIR}/qtharfbuzzng.lib") + ENDIF() + IF(EXISTS ${HB_LIB}) + SET(QT_LIBRARIES ${QT_LIBRARIES} ${HB_LIB}) + ENDIF() + + # freetype is needed since Qt 5.5 + IF(APPLE) + SET(FREETYPE_LIB "${QT_LIBRARY_DIR}/libqtfreetype.a") + ELSEIF(WIN32) + SET(FREETYPE_LIB "${QT_LIBRARY_DIR}/qtfreetype.lib") + ENDIF() + IF(EXISTS ${FREETYPE_LIB}) + SET(QT_LIBRARIES ${QT_LIBRARIES} ${FREETYPE_LIB}) + ENDIF() + + # pcre is needed since Qt 5.5 + IF(APPLE) + SET(PCRE_LIB "${QT_LIBRARY_DIR}/libqtpcre.a") + ELSEIF(WIN32) + SET(PCRE_LIB "${QT_LIBRARY_DIR}/qtpcre.lib") + ENDIF() + IF(EXISTS ${PCRE_LIB}) + SET(QT_LIBRARIES ${QT_LIBRARIES} ${PCRE_LIB}) + ENDIF() + + ADD_QT_PLUGIN(accessible qtaccessiblewidgets) + ENDIF() ELSE() MESSAGE(WARNING "Unable to find Qt 5") ENDIF() ENDIF() IF(WITH_QT) + SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QTDIR} $ENV{QTDIR}) + # Use Qt 4 FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtXml QtOpenGL REQUIRED) ENDIF(WITH_QT) diff --git a/code/nel/tools/misc/crash_report/CMakeLists.txt b/code/nel/tools/misc/crash_report/CMakeLists.txt index a67b2be5e..d230177f8 100644 --- a/code/nel/tools/misc/crash_report/CMakeLists.txt +++ b/code/nel/tools/misc/crash_report/CMakeLists.txt @@ -11,13 +11,13 @@ SET(CRASHREPORT_UI crash_report_widget.ui ) -SET(QT_USE_QTGUI TRUE) -SET(QT_USE_QTNETWORK TRUE) -SET(QT_USE_QTMAIN TRUE) -SET(QT_USE_QTOPENGL FALSE) -SET(QT_USE_QTXML FALSE) - IF(WITH_QT) + SET(QT_USE_QTGUI TRUE) + SET(QT_USE_QTNETWORK TRUE) + SET(QT_USE_QTMAIN TRUE) + SET(QT_USE_QTOPENGL FALSE) + SET(QT_USE_QTXML FALSE) + INCLUDE_DIRECTORIES(${QT_INCLUDES}) INCLUDE(${QT_USE_FILE}) ADD_DEFINITIONS(${QT_DEFINITIONS}) @@ -29,8 +29,6 @@ IF(WITH_QT) ELSE() QT5_WRAP_CPP(CRASHREPORT_MOC_SRC ${CRASHREPORT_MOC_HDR}) QT5_WRAP_UI(CRASHREPORT_UI_HDR ${CRASHREPORT_UI}) - - SET(QT_LIBRARIES Qt5::Widgets Qt5::Core Qt5::Gui Qt5::Network) ENDIF() SOURCE_GROUP(QtResources FILES ${CRASHREPORT_UI}) diff --git a/code/nel/tools/misc/crash_report/crash_report.cpp b/code/nel/tools/misc/crash_report/crash_report.cpp index c42f1ae6f..72cbc26bf 100644 --- a/code/nel/tools/misc/crash_report/crash_report.cpp +++ b/code/nel/tools/misc/crash_report/crash_report.cpp @@ -76,6 +76,19 @@ public: } }; +#ifdef QT_STATICPLUGIN + +#include + +#ifdef Q_OS_WIN32 + Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) +#endif + +#ifdef Q_OS_MAC + Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) +#endif +#endif + int main( int argc, char **argv ) { #ifndef WIN32 diff --git a/code/nel/tools/misc/message_box_qt/CMakeLists.txt b/code/nel/tools/misc/message_box_qt/CMakeLists.txt index 708e86cf7..be4dd2b63 100644 --- a/code/nel/tools/misc/message_box_qt/CMakeLists.txt +++ b/code/nel/tools/misc/message_box_qt/CMakeLists.txt @@ -1,8 +1,6 @@ IF(WITH_QT) INCLUDE_DIRECTORIES(${QT_INCLUDES}) INCLUDE(${QT_USE_FILE}) -ELSE() - SET(QT_LIBRARIES Qt5::Widgets Qt5::Core Qt5::Gui) ENDIF() INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/code/nel/tools/misc/words_dic_qt/CMakeLists.txt b/code/nel/tools/misc/words_dic_qt/CMakeLists.txt index 55a0a1c66..fc2ced95e 100644 --- a/code/nel/tools/misc/words_dic_qt/CMakeLists.txt +++ b/code/nel/tools/misc/words_dic_qt/CMakeLists.txt @@ -24,8 +24,6 @@ IF(WITH_QT) ADD_DEFINITIONS(${QT_DEFINITIONS}) ELSE() - SET(QT_LIBRARIES Qt5::Widgets Qt5::Core Qt5::Gui) - QT5_ADD_RESOURCES(WORDS_DIC_RC_SRCS ${WORDS_DIC_RCS}) QT5_WRAP_UI(WORDS_DIC_UI_HDRS ${WORDS_DIC_UIS}) QT5_WRAP_CPP(WORDS_DIC_MOC_SRCS ${WORDS_DIC_HDR}) diff --git a/code/ryzom/tools/client/client_config_qt/CMakeLists.txt b/code/ryzom/tools/client/client_config_qt/CMakeLists.txt index 580dc681d..fbc553bda 100644 --- a/code/ryzom/tools/client/client_config_qt/CMakeLists.txt +++ b/code/ryzom/tools/client/client_config_qt/CMakeLists.txt @@ -51,8 +51,6 @@ ELSE() QT5_ADD_RESOURCES(CLIENT_CONFIG_RC_SRCS ${CLIENT_CONFIG_RCS}) QT5_WRAP_CPP(CLIENT_CONFIG_MOC_SRC ${CLIENT_CONFIG_HDR}) QT5_WRAP_UI(CLIENT_CONFIG_UI_HDRS ${CLIENT_CONFIG_UIS}) - - SET(QT_LIBRARIES Qt5::Widgets Qt5::Core Qt5::Gui Qt5::OpenGL) ENDIF() SOURCE_GROUP("Resources" FILES ${CLIENT_CONFIG_RCS}) diff --git a/code/ryzom/tools/client/client_config_qt/main.cpp b/code/ryzom/tools/client/client_config_qt/main.cpp index 2ee5e11bc..33d379068 100644 --- a/code/ryzom/tools/client/client_config_qt/main.cpp +++ b/code/ryzom/tools/client/client_config_qt/main.cpp @@ -21,6 +21,19 @@ #include +#ifdef QT_STATICPLUGIN + +#include + +#ifdef Q_OS_WIN32 + Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) +#endif + +#ifdef Q_OS_MAC + Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) +#endif +#endif + int main( sint32 argc, char **argv ) { QApplication app( argc, argv );