Allow building shared and static libs at the same time
Use 'Static'-prefixed CMake modules provided by patched mingw-w64-qt5 packages
This commit is contained in:
parent
b35e5311a9
commit
d9380d024e
|
@ -4,16 +4,16 @@ include(QtLinkage)
|
|||
|
||||
set(JS_PROVIDER "auto" CACHE STRING "specifies the JavaScript provider: auto (default), qml, script or none")
|
||||
if(${JS_PROVIDER} STREQUAL "auto")
|
||||
find_package(Qt5Script)
|
||||
if(Qt5Script_FOUND)
|
||||
set(JS_PROVIDER Qt5::Script)
|
||||
find_qt5_module(Script OPTIONAL)
|
||||
if(QT5_Script_FOUND)
|
||||
set(JS_PROVIDER Script)
|
||||
set(JS_DEFINITION "-D${META_PROJECT_VARNAME_UPPER}_USE_SCRIPT")
|
||||
list(APPEND ADDITIONAL_QT_REPOS "script")
|
||||
message(STATUS "No JavaScript provider explicitly specified, defaulting to Qt Script.")
|
||||
else()
|
||||
find_package(Qt5Qml)
|
||||
if(Qt5Qml_FOUND)
|
||||
set(JS_PROVIDER Qt5::Qml)
|
||||
find_qt5_module(Qml OPTIONAL)
|
||||
if(QT5_Qml_FOUND)
|
||||
set(JS_PROVIDER Qml)
|
||||
set(JS_DEFINITION "-D${META_PROJECT_VARNAME_UPPER}_USE_JSENGINE")
|
||||
list(APPEND ADDITIONAL_QT_REPOS "declarative")
|
||||
message(STATUS "No JavaScript provider explicitly specified, defaulting to Qt QML.")
|
||||
|
@ -25,14 +25,13 @@ if(${JS_PROVIDER} STREQUAL "auto")
|
|||
endif()
|
||||
else()
|
||||
if(${JS_PROVIDER} STREQUAL "script")
|
||||
find_package(Qt5Script REQUIRED)
|
||||
set(JS_PROVIDER Qt5::Script)
|
||||
find_qt5_module(Script REQUIRED)
|
||||
set(JS_DEFINITION "-D${META_PROJECT_VARNAME_UPPER}_USE_SCRIPT")
|
||||
list(APPEND ADDITIONAL_QT_REPOS "script")
|
||||
message(STATUS "Using Qt Script as JavaScript provider.")
|
||||
elseif(${JS_PROVIDER} STREQUAL "qml")
|
||||
find_package(Qt5Qml REQUIRED)
|
||||
set(JS_PROVIDER Qt5::Qml)
|
||||
find_qt5_module(Qml REQUIRED)
|
||||
set(JS_PROVIDER Qml)
|
||||
set(JS_DEFINITION "-D${META_PROJECT_VARNAME_UPPER}_USE_JSENGINE")
|
||||
list(APPEND ADDITIONAL_QT_REPOS "declarative")
|
||||
message(STATUS "Using Qt QML as JavaScript provider.")
|
||||
|
@ -45,5 +44,7 @@ else()
|
|||
endif()
|
||||
endif()
|
||||
|
||||
list(APPEND LIBRARIES ${JS_PROVIDER})
|
||||
if(JS_PROVIDER)
|
||||
use_qt5_module(${JS_PROVIDER} OPTIONAL)
|
||||
endif()
|
||||
add_definitions(${JS_DEFINITION})
|
||||
|
|
|
@ -29,31 +29,34 @@ if(KF_MODULES)
|
|||
list(REMOVE_DUPLICATES KF_MODULES)
|
||||
endif()
|
||||
|
||||
message(STATUS "Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} against the following Qt 5 modules: ${QT_MODULES}")
|
||||
message(STATUS "Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} against the following KDE 5 modules: ${KF_MODULES}")
|
||||
|
||||
# actually find the required Qt/KF modules
|
||||
foreach(QT_MODULE ${QT_MODULES})
|
||||
find_package(Qt5${QT_MODULE} REQUIRED)
|
||||
list(APPEND LIBRARIES Qt5::${QT_MODULE})
|
||||
list(APPEND STATIC_LIBRARIES Qt5::${QT_MODULE})
|
||||
# using those helpers allows using static Qt 5 build
|
||||
find_qt5_module(${QT_MODULE} REQUIRED)
|
||||
use_qt5_module(${QT_MODULE} REQUIRED)
|
||||
endforeach()
|
||||
foreach(KF_MODULE ${KF_MODULES})
|
||||
# only shared KF5 modules supported
|
||||
find_package(KF5${KF_MODULE} REQUIRED)
|
||||
list(APPEND LIBRARIES KF5::${KF_MODULE})
|
||||
list(APPEND STATIC_LIBRARIES KF5::${KF_MODULE})
|
||||
set(KF5_${KF_MODULE}_DYNAMIC_LIB KF5::${KF_MODULE})
|
||||
link_against_library(KF5_${KF_MODULE} "AUTO_LINKAGE" REQUIRED)
|
||||
endforeach()
|
||||
|
||||
# include plugins statically
|
||||
if(USE_STATIC_QT_BUILD AND (WIDGETS_GUI OR QUICK_GUI))
|
||||
# tune for static build
|
||||
if(USE_STATIC_QT5_CORE AND (WIDGETS_GUI OR QUICK_GUI))
|
||||
# include plugins statically
|
||||
if(WIN32)
|
||||
list(APPEND LIBRARIES Qt5::QWindowsIntegrationPlugin)
|
||||
list(APPEND STATIC_LIBRARIES Qt5::QWindowsIntegrationPlugin)
|
||||
list(APPEND LIBRARIES Qt5::static::QWindowsIntegrationPlugin)
|
||||
list(APPEND STATIC_LIBRARIES Qt5::static::QWindowsIntegrationPlugin)
|
||||
endif()
|
||||
if(SVG_ICON_SUPPORT)
|
||||
list(APPEND LIBRARIES Qt5::QSvgPlugin)
|
||||
list(APPEND STATIC_LIBRARIES Qt5::QSvgPlugin)
|
||||
endif()
|
||||
|
||||
# workaround for missing compile definition GRAPHITE2_STATIC
|
||||
#set_property(TARGET Qt5::Gui APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS GRAPHITE2_STATIC)
|
||||
|
||||
endif()
|
||||
|
||||
# option for built-in translations
|
||||
|
|
|
@ -40,14 +40,13 @@ endif()
|
|||
|
||||
if(WIDGETS_GUI OR QUICK_GUI)
|
||||
list(APPEND QT_MODULES Gui)
|
||||
|
||||
# set "GUI-type" to WIN32 to hide console under windows
|
||||
if(WIN32)
|
||||
set(GUI_TYPE WIN32)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# add source files requried by both GUI variants
|
||||
if(WIDGETS_GUI OR QUICK_GUI)
|
||||
# add source files requried by both GUI variants
|
||||
list(APPEND SRC_FILES ${GUI_SRC_FILES})
|
||||
list(APPEND ADDITIONAL_HEADER_FILES ${GUI_HEADER_FILES})
|
||||
endif()
|
||||
|
|
|
@ -2,20 +2,81 @@
|
|||
|
||||
if(NOT DEFINED QT_LINKAGE_DETERMINED)
|
||||
set(QT_LINKAGE_DETERMINED true)
|
||||
include(3rdParty)
|
||||
|
||||
set(QT_LINKAGE "AUTO_LINKAGE" CACHE STRING "specifies whether to link statically or dynamically against Qt 5")
|
||||
|
||||
set(QT_LINKAGE "AUTO_LINKAGE")
|
||||
if(BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "When using Qt/KDE modules it is not possible to build shared and static libraries at the same time.")
|
||||
endif()
|
||||
# set USE_STATIC_QT_BUILD variable to ON to use static Qt
|
||||
# this only works with patched mingw-w64-qt5-* packages found in my PKGBUILDs repository
|
||||
# in any other environment you must ensure that the available Qt version is in accordance with the specified STATIC_LINKAGE/STATIC_LIBRARY_LINKAGE options
|
||||
if(BUILD_STATIC_LIBS OR ("${QT_LINKAGE}" STREQUAL "AUTO_LINKAGE" AND ((STATIC_LINKAGE AND "${META_PROJECT_TYPE}" STREQUAL "application") OR (STATIC_LIBRARY_LINKAGE AND ("${META_PROJECT_TYPE}" STREQUAL "" OR "${META_PROJECT_TYPE}" STREQUAL "library")))) OR ("${QT_LINKAGE}" STREQUAL "STATIC"))
|
||||
set(USE_STATIC_QT_BUILD ON)
|
||||
message(STATUS "Linking ${META_PROJECT_NAME} statically against Qt 5.")
|
||||
elseif(("${QT_LINKAGE}" STREQUAL "AUTO_LINKAGE") OR ("${QT_LINKAGE}" STREQUAL "SHARED"))
|
||||
set(USE_STATIC_QT_BUILD OFF)
|
||||
message(STATUS "Linking ${META_PROJECT_NAME} dynamically against Qt 5.")
|
||||
message(STATUS "Checking for static Qt 5 libraries to use in project ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}")
|
||||
endif()
|
||||
if(("${QT_LINKAGE}" STREQUAL "AUTO_LINKAGE" AND (NOT (STATIC_LINKAGE AND "${META_PROJECT_TYPE}" STREQUAL "application") OR NOT (STATIC_LIBRARY_LINKAGE AND ("${META_PROJECT_TYPE}" STREQUAL "" OR "${META_PROJECT_TYPE}" STREQUAL "library")))) OR ("${QT_LINKAGE}" STREQUAL "SHARED"))
|
||||
set(USE_SHARED_QT_BUILD ON)
|
||||
message(STATUS "Checking for dynamic Qt 5 libraries to use in project ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}")
|
||||
endif()
|
||||
|
||||
macro(find_qt5_module MODULE REQUIRED)
|
||||
# determine whether the library is required or optional
|
||||
# FIXME: improve passing required argument
|
||||
if("${REQUIRED}" STREQUAL "OPTIONAL")
|
||||
set(${MODULE}_REQUIRED "")
|
||||
elseif("${REQUIRED}" STREQUAL "REQUIRED")
|
||||
set(QT_5_${MODULE}_REQUIRED "REQUIRED")
|
||||
else()
|
||||
message(FATAL_ERROR "Invalid use of link_against_library; must specify either REQUIRED or OPTIONAL.")
|
||||
endif()
|
||||
|
||||
# find static version
|
||||
if(USE_STATIC_QT_BUILD)
|
||||
# check for 'Static'-prefixed CMake module first
|
||||
# - patched mingw-w64-qt5 packages providing those files are available in my PKGBUILDs repository
|
||||
# - has the advantage that usage of dynamic and static Qt during the same build is possible
|
||||
find_package(StaticQt5${MODULE})
|
||||
if(StaticQt5${MODULE}_FOUND)
|
||||
set(QT5_${MODULE}_STATIC_LIB Qt5::static::${MODULE})
|
||||
set(QT5_${MODULE}_ASSUME_STATIC OFF)
|
||||
set(QT5_${MODULE}_FOUND ON)
|
||||
else()
|
||||
# consider the regular Qt package (without "Static" prefix) the static version if
|
||||
# static Qt is required and Qt package with "Static" prefix doesn't exist
|
||||
# (fallback if not using patched version of Qt mentioned above)
|
||||
if(USE_STATIC_QT_BUILD AND NOT StaticQt5${MODULE}_FOUND AND Qt5${MODULE}_FOUND)
|
||||
find_package(Qt5${MODULE} ${QT_5_${MODULE}_REQUIRED})
|
||||
if(Qt5${MODULE}_FOUND)
|
||||
set(QT5_${MODULE}_STATIC_LIB Qt5::${MODULE})
|
||||
set(QT5_${MODULE}_ASSUME_STATIC ON)
|
||||
set(QT5_${MODULE}_FOUND ON)
|
||||
message(WARNING "Building static libs and/or static Qt linkage has been enabled. Hence assuming provided Qt 5 ${MODULE} library is static.")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# find dynamic version
|
||||
if(USE_SHARED_QT_BUILD)
|
||||
if(QT5_${MODULE}_ASSUME_STATIC)
|
||||
message(FATAL_ERROR "The provided Qt 5 ${MODULE} is assumed to be static. However, a shared version is required for building dynamic libs and/or dynamic Qt linkage.")
|
||||
endif()
|
||||
find_package(Qt5${MODULE} ${QT_5_${MODULE}_REQUIRED})
|
||||
if(Qt5${MODULE}_FOUND)
|
||||
set(QT5_${MODULE}_DYNAMIC_LIB Qt5::${MODULE})
|
||||
set(QT5_${MODULE}_FOUND ON)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(use_qt5_module MODULE REQUIRED)
|
||||
link_against_library("QT5_${MODULE}" "${QT_LINKAGE}" "${REQUIRED}")
|
||||
endmacro()
|
||||
|
||||
macro(use_static_qt5_plugin PLUGIN)
|
||||
if(TARGET "Qt5::static::Q${PLUGIN}Plugin")
|
||||
list(APPEND LIBRARIES "Qt5::static::Q${PLUGIN}Plugin")
|
||||
list(APPEND STATIC_LIBRARIES "Qt5::static::Q${PLUGIN}Plugin")
|
||||
else()
|
||||
list(APPEND LIBRARIES "Qt5::Q${PLUGIN}Plugin")
|
||||
list(APPEND STATIC_LIBRARIES "Qt5::Q${PLUGIN}Plugin")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
endif(NOT DEFINED QT_LINKAGE_DETERMINED)
|
||||
|
|
|
@ -4,15 +4,15 @@ include(QtLinkage)
|
|||
|
||||
set(WEBVIEW_PROVIDER "auto" CACHE STRING "specifies the web view provider: auto (default), webkit, webengine or none")
|
||||
if(${WEBVIEW_PROVIDER} STREQUAL "auto")
|
||||
find_package(Qt5WebKitWidgets)
|
||||
if(Qt5WebKitWidgets_FOUND)
|
||||
set(WEBVIEW_PROVIDER Qt5::WebKitWidgets)
|
||||
find_qt5_module(WebKitWidgets OPTIONAL)
|
||||
if(QT5_WebKitWidgets_FOUND)
|
||||
set(WEBVIEW_PROVIDER WebKitWidgets)
|
||||
set(WEBVIEW_DEFINITION "-D${META_PROJECT_VARNAME_UPPER}_USE_WEBKIT")
|
||||
message(STATUS "No web view provider explicitly specified, defaulting to Qt WebKit.")
|
||||
else()
|
||||
find_package(Qt5WebEngineWidgets)
|
||||
if(Qt5WebEngineWidgets_FOUND)
|
||||
set(WEBVIEW_PROVIDER Qt5::WebEngineWidgets)
|
||||
find_qt5_module(WebEngineWidgets OPTIONAL)
|
||||
if(QT5_WebEngineWidgets_FOUND)
|
||||
set(WEBVIEW_PROVIDER WebEngineWidgets)
|
||||
set(WEBVIEW_DEFINITION "-D${META_PROJECT_VARNAME_UPPER}_USE_WEBENGINE")
|
||||
list(APPEND ADDITIONAL_QT_REPOS "webengine")
|
||||
message(STATUS "No web view provider explicitly specified, defaulting to Qt WebEngine.")
|
||||
|
@ -24,13 +24,13 @@ if(${WEBVIEW_PROVIDER} STREQUAL "auto")
|
|||
endif()
|
||||
else()
|
||||
if(${WEBVIEW_PROVIDER} STREQUAL "webkit")
|
||||
find_package(Qt5WebKitWidgets REQUIRED)
|
||||
set(WEBVIEW_PROVIDER Qt5::WebKitWidgets)
|
||||
find_qt5_module(WebKitWidgets REQUIRED)
|
||||
set(WEBVIEW_PROVIDER WebKitWidgets)
|
||||
set(WEBVIEW_DEFINITION "-D${META_PROJECT_VARNAME_UPPER}_USE_WEBKIT")
|
||||
message(STATUS "Using Qt WebKit as web view provider.")
|
||||
elseif(${WEBVIEW_PROVIDER} STREQUAL "webengine")
|
||||
find_package(Qt5WebEngineWidgets REQUIRED)
|
||||
set(WEBVIEW_PROVIDER Qt5::WebEngineWidgets)
|
||||
find_qt5_module(WebEngineWidgets REQUIRED)
|
||||
set(WEBVIEW_PROVIDER WebEngineWidgets)
|
||||
set(WEBVIEW_DEFINITION "-D${META_PROJECT_VARNAME_UPPER}_USE_WEBENGINE")
|
||||
list(APPEND ADDITIONAL_QT_REPOS "webengine")
|
||||
message(STATUS "Using Qt WebEngine as web view provider.")
|
||||
|
@ -43,5 +43,7 @@ else()
|
|||
endif()
|
||||
endif()
|
||||
|
||||
list(APPEND LIBRARIES ${WEBVIEW_PROVIDER})
|
||||
if(WEBVIEW_PROVIDER)
|
||||
use_qt5_module(${WEBVIEW_PROVIDER} OPTIONAL)
|
||||
endif()
|
||||
add_definitions(${WEBVIEW_DEFINITION})
|
||||
|
|
Loading…
Reference in New Issue