Apply cmake-format

This commit is contained in:
Martchus 2019-02-06 17:32:10 +01:00
parent 72d642c892
commit 190e58fe67
7 changed files with 652 additions and 631 deletions

View File

@ -6,7 +6,8 @@ set(META_PROJECT_VARNAME QT_UTILITIES)
set(META_APP_NAME "Qt Utilities") set(META_APP_NAME "Qt Utilities")
set(META_APP_AUTHOR "Martchus") set(META_APP_AUTHOR "Martchus")
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models") set(META_APP_DESCRIPTION
"Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models")
set(META_VERSION_MAJOR 5) set(META_VERSION_MAJOR 5)
set(META_VERSION_MINOR 12) set(META_VERSION_MINOR 12)
set(META_VERSION_PATCH 1) set(META_VERSION_PATCH 1)
@ -24,18 +25,14 @@ set(HEADER_FILES
models/checklistmodel.h models/checklistmodel.h
resources/qtconfigarguments.h resources/qtconfigarguments.h
resources/resources.h resources/resources.h
resources/importplugin.h resources/importplugin.h)
)
set(SRC_FILES set(SRC_FILES
misc/dialogutils.cpp misc/dialogutils.cpp
misc/desktoputils.cpp misc/desktoputils.cpp
models/checklistmodel.cpp models/checklistmodel.cpp
resources/qtconfigarguments.cpp resources/qtconfigarguments.cpp
resources/resources.cpp resources/resources.cpp)
) set(RES_FILES resources/qtutilsicons.qrc)
set(RES_FILES
resources/qtutilsicons.qrc
)
set(WIDGETS_HEADER_FILES set(WIDGETS_HEADER_FILES
aboutdialog/aboutdialog.h aboutdialog/aboutdialog.h
@ -55,8 +52,7 @@ set(WIDGETS_HEADER_FILES
widgets/pathselection.h widgets/pathselection.h
paletteeditor/paletteeditor.h paletteeditor/paletteeditor.h
paletteeditor/colorbutton.h paletteeditor/colorbutton.h
misc/recentmenumanager.h misc/recentmenumanager.h)
)
set(WIDGETS_SRC_FILES set(WIDGETS_SRC_FILES
aboutdialog/aboutdialog.cpp aboutdialog/aboutdialog.cpp
enterpassworddialog/enterpassworddialog.cpp enterpassworddialog/enterpassworddialog.cpp
@ -75,8 +71,7 @@ set(WIDGETS_SRC_FILES
widgets/pathselection.cpp widgets/pathselection.cpp
paletteeditor/paletteeditor.cpp paletteeditor/paletteeditor.cpp
paletteeditor/colorbutton.cpp paletteeditor/colorbutton.cpp
misc/recentmenumanager.cpp misc/recentmenumanager.cpp)
)
set(WIDGETS_UI_FILES set(WIDGETS_UI_FILES
aboutdialog/aboutdialog.ui aboutdialog/aboutdialog.ui
enterpassworddialog/enterpassworddialog.ui enterpassworddialog/enterpassworddialog.ui
@ -84,8 +79,7 @@ set(WIDGETS_UI_FILES
settingsdialog/qtappearanceoptionpage.ui settingsdialog/qtappearanceoptionpage.ui
settingsdialog/qtlanguageoptionpage.ui settingsdialog/qtlanguageoptionpage.ui
settingsdialog/qtenvoptionpage.ui settingsdialog/qtenvoptionpage.ui
paletteeditor/paletteeditor.ui paletteeditor/paletteeditor.ui)
)
set(CMAKE_MODULE_FILES set(CMAKE_MODULE_FILES
cmake/modules/AndroidApk.cmake cmake/modules/AndroidApk.cmake
@ -93,31 +87,21 @@ set(CMAKE_MODULE_FILES
cmake/modules/QtGuiConfig.cmake cmake/modules/QtGuiConfig.cmake
cmake/modules/QtLinkage.cmake cmake/modules/QtLinkage.cmake
cmake/modules/JsProviderConfig.cmake cmake/modules/JsProviderConfig.cmake
cmake/modules/WebViewProviderConfig.cmake cmake/modules/WebViewProviderConfig.cmake)
)
set(CMAKE_TEMPLATE_FILES set(CMAKE_TEMPLATE_FILES
cmake/templates/qtconfig.h.in cmake/templates/qtconfig.h.in
cmake/templates/webviewdefs.h.in cmake/templates/webviewdefs.h.in
cmake/templates/webviewincludes.h.in cmake/templates/webviewincludes.h.in
cmake/templates/jsdefs.h.in cmake/templates/jsdefs.h.in
cmake/templates/jsincludes.h.in cmake/templates/jsincludes.h.in)
) if (ANDROID)
if(ANDROID) list(APPEND CMAKE_MODULE_FILES)
list(APPEND CMAKE_MODULE_FILES list(APPEND CMAKE_TEMPLATE_FILES cmake/templates/android-deployment.json.in)
) endif ()
list(APPEND CMAKE_TEMPLATE_FILES
cmake/templates/android-deployment.json.in
)
endif()
set(TS_FILES set(TS_FILES translations/${META_PROJECT_NAME}_de_DE.ts translations/${META_PROJECT_NAME}_en_US.ts)
translations/${META_PROJECT_NAME}_de_DE.ts
translations/${META_PROJECT_NAME}_en_US.ts
)
set(DOC_FILES set(DOC_FILES README.md)
README.md
)
set(REQUIRED_ICONS set(REQUIRED_ICONS
dialog-cancel dialog-cancel
@ -133,71 +117,58 @@ set(REQUIRED_ICONS
system-file-manager system-file-manager
system-run system-run
system-search system-search
window-close window-close)
)
set(SCRIPT_FILES set(SCRIPT_FILES scripts/required_icons.sh)
scripts/required_icons.sh
)
# required to include CMake modules from own project directory # required to include CMake modules from own project directory
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" "${CMAKE_MODULE_PATH}") set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" "${CMAKE_MODULE_PATH}")
# configure platform specific capslock detection for enterpassworddialog.cpp # configure platform specific capslock detection for enterpassworddialog.cpp
if(WIN32 OR (UNIX AND NOT APPLE AND NOT ANDROID)) if (WIN32 OR (UNIX AND NOT APPLE AND NOT ANDROID))
set(ENABLE_CAPSLOCK_DETECTION_BY_DEFAULT ON) set(ENABLE_CAPSLOCK_DETECTION_BY_DEFAULT ON)
else() else ()
set(ENABLE_CAPSLOCK_DETECTION_BY_DEFAULT OFF) set(ENABLE_CAPSLOCK_DETECTION_BY_DEFAULT OFF)
endif() endif ()
option(CAPSLOCK_DETECTION "enables capslock detection" ${ENABLE_CAPSLOCK_DETECTION_BY_DEFAULT}) option(CAPSLOCK_DETECTION "enables capslock detection" ${ENABLE_CAPSLOCK_DETECTION_BY_DEFAULT})
if(CAPSLOCK_DETECTION) if (CAPSLOCK_DETECTION)
if(WIN32) if (WIN32)
# WinAPI provides functions to provide capslock detection # WinAPI provides functions to provide capslock detection
set(HAVE_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION ON) set(HAVE_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION ON)
else() else ()
# X11 can provide functions for capslock detection under non-Windows environments # X11 can provide functions for capslock detection under non-Windows environments
find_package(X11) find_package(X11)
if(X11_FOUND) if (X11_FOUND)
list(APPEND LIBRARIES ${X11_LIBRARIES}) list(APPEND LIBRARIES ${X11_LIBRARIES})
set(HAVE_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION ON) set(HAVE_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION ON)
endif() endif ()
endif() endif ()
if(NOT HAVE_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION) if (NOT HAVE_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION)
message(FATAL_ERROR "No backend for capslock detection found (WinAPI or X11 must be provided)") message(FATAL_ERROR "No backend for capslock detection found (WinAPI or X11 must be provided)")
endif() endif ()
set_property( set_property(SOURCE enterpassworddialog/enterpassworddialog.cpp
SOURCE enterpassworddialog/enterpassworddialog.cpp APPEND
APPEND PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_PLATFORM_SPECIFIC_CAPSLOCK_DETECTION)
) endif ()
endif()
# configure support for D-Bus notifications # configure support for D-Bus notifications
if(UNIX AND NOT APPLE AND NOT ANDROID) if (UNIX AND NOT APPLE AND NOT ANDROID)
set(ENABLE_DBUS_NOTIFICATIONS_BY_DEFAULT ON) set(ENABLE_DBUS_NOTIFICATIONS_BY_DEFAULT ON)
else() else ()
set(ENABLE_DBUS_NOTIFICATIONS_BY_DEFAULT OFF) set(ENABLE_DBUS_NOTIFICATIONS_BY_DEFAULT OFF)
endif() endif ()
option(DBUS_NOTIFICATIONS "enables support for D-Bus notifications" ${ENABLE_DBUS_NOTIFICATIONS_BY_DEFAULT}) option(DBUS_NOTIFICATIONS "enables support for D-Bus notifications" ${ENABLE_DBUS_NOTIFICATIONS_BY_DEFAULT})
set(DBUS_NOTIFICATIONS_FILE_NAME misc/dbusnotification) set(DBUS_NOTIFICATIONS_FILE_NAME misc/dbusnotification)
if(DBUS_NOTIFICATIONS) if (DBUS_NOTIFICATIONS)
list(APPEND HEADER_FILES list(APPEND HEADER_FILES ${DBUS_NOTIFICATIONS_FILE_NAME}.h)
${DBUS_NOTIFICATIONS_FILE_NAME}.h list(APPEND SRC_FILES ${DBUS_NOTIFICATIONS_FILE_NAME}.cpp)
) list(APPEND DBUS_FILES dbus/org.freedesktop.Notifications.xml)
list(APPEND SRC_FILES
${DBUS_NOTIFICATIONS_FILE_NAME}.cpp
)
list(APPEND DBUS_FILES
dbus/org.freedesktop.Notifications.xml
)
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_SUPPORT_DBUS_NOTIFICATIONS) list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_SUPPORT_DBUS_NOTIFICATIONS)
message(STATUS "D-Bus notifications enabled") message(STATUS "D-Bus notifications enabled")
else() else ()
list(APPEND DOC_ONLY_FILES list(APPEND DOC_ONLY_FILES ${DBUS_NOTIFICATIONS_FILE_NAME}.h ${DBUS_NOTIFICATIONS_FILE_NAME}.cpp)
${DBUS_NOTIFICATIONS_FILE_NAME}.h
${DBUS_NOTIFICATIONS_FILE_NAME}.cpp
)
message(STATUS "D-Bus notifications disabled") message(STATUS "D-Bus notifications disabled")
endif() endif ()
# find c++utilities # find c++utilities
find_package(c++utilities 4.13.0 REQUIRED) find_package(c++utilities 4.13.0 REQUIRED)

View File

@ -2,37 +2,39 @@ cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
# add a target to create an Android API with the help of androiddeployqt if target platform is Android # add a target to create an Android API with the help of androiddeployqt if target platform is Android
if(NOT ANDROID) if (NOT ANDROID)
return() return()
endif() endif ()
if(NOT BASIC_PROJECT_CONFIG_DONE OR NOT QT_CONFIGURED) if (NOT BASIC_PROJECT_CONFIG_DONE OR NOT QT_CONFIGURED)
message(FATAL_ERROR "Before including the ApkConfig module, the AppTarget module and QtConfig module must be included.") message(FATAL_ERROR "Before including the ApkConfig module, the AppTarget module and QtConfig module must be included.")
endif() endif ()
if(ANDROID_APK_CONFIGURED) if (ANDROID_APK_CONFIGURED)
message(FATAL_ERROR "The AndroidApk module mustn't be included twice.") message(FATAL_ERROR "The AndroidApk module mustn't be included twice.")
endif() endif ()
if(NOT EXISTS "${CMAKE_ANDROID_SDK}") if (NOT EXISTS "${CMAKE_ANDROID_SDK}")
message(FATAL_ERROR "CMAKE_ANDROID_SDK must contain the path of the Android SDK.") message(FATAL_ERROR "CMAKE_ANDROID_SDK must contain the path of the Android SDK.")
endif() endif ()
if(NOT EXISTS "${CMAKE_ANDROID_NDK}") if (NOT EXISTS "${CMAKE_ANDROID_NDK}")
message(FATAL_ERROR "CMAKE_ANDROID_NDK must contain the path of the Android NDK.") message(FATAL_ERROR "CMAKE_ANDROID_NDK must contain the path of the Android NDK.")
endif() endif ()
# find "android" subdirectory in the source directory and check for AndroidManifest.xml # find "android" subdirectory in the source directory and check for AndroidManifest.xml
set(ANDROID_APK_SUBDIR "${CMAKE_CURRENT_SOURCE_DIR}/android") set(ANDROID_APK_SUBDIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
if(NOT IS_DIRECTORY "${ANDROID_APK_SUBDIR}") if (NOT IS_DIRECTORY "${ANDROID_APK_SUBDIR}")
message(FATAL_ERROR "The directory containing Android-specific files is expected to be \"${ANDROID_APK_SUBDIR}\" but doesn't exist.") message(
endif() FATAL_ERROR
"The directory containing Android-specific files is expected to be \"${ANDROID_APK_SUBDIR}\" but doesn't exist.")
endif ()
set(ANDROID_APK_MANIFEST_PATH "${ANDROID_APK_SUBDIR}/AndroidManifest.xml") set(ANDROID_APK_MANIFEST_PATH "${ANDROID_APK_SUBDIR}/AndroidManifest.xml")
if(NOT EXISTS "${ANDROID_APK_MANIFEST_PATH}") if (NOT EXISTS "${ANDROID_APK_MANIFEST_PATH}")
message(FATAL_ERROR "The Android manifest doesn't exist at \"${ANDROID_APK_SUBDIR}/AndroidManifest.xml\".") message(FATAL_ERROR "The Android manifest doesn't exist at \"${ANDROID_APK_SUBDIR}/AndroidManifest.xml\".")
endif() endif ()
# caveat: adding new files or removing files requires to re-run CMake manually # caveat: adding new files or removing files requires to re-run CMake manually
file(GLOB_RECURSE ANDROID_APK_FILES file(GLOB_RECURSE ANDROID_APK_FILES
LIST_DIRECTORIES false LIST_DIRECTORIES
"${ANDROID_APK_SUBDIR}/*" false
) "${ANDROID_APK_SUBDIR}/*")
# make subdirectory to store build artefacts for APK # make subdirectory to store build artefacts for APK
set(ANDROID_APK_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/apk") set(ANDROID_APK_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/apk")
@ -45,105 +47,101 @@ get_filename_component(ANDROID_APK_QT_INSTALL_PREFIX "${ANDROID_APK_QT_LIBRARY_D
# deduce Android toolchain prefix and version from "CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX" # deduce Android toolchain prefix and version from "CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX"
message(STATUS "Android toolchain prefix: ${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}") message(STATUS "Android toolchain prefix: ${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}")
if(CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX MATCHES ".*/(.+)-") if (CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX MATCHES ".*/(.+)-")
set(ANDROID_APK_TOOL_PREFIX "${CMAKE_MATCH_1}") set(ANDROID_APK_TOOL_PREFIX "${CMAKE_MATCH_1}")
else() else ()
set(ANDROID_APK_TOOL_PREFIX "${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}") set(ANDROID_APK_TOOL_PREFIX "${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}")
endif() endif ()
set(ANDROID_APK_TOOLCHAIN_VERSION "" CACHE STRING "toolchain version for making APK file") set(ANDROID_APK_TOOLCHAIN_VERSION "" CACHE STRING "toolchain version for making APK file")
if(NOT ANDROID_APK_TOOLCHAIN_VERSION) if (NOT ANDROID_APK_TOOLCHAIN_VERSION)
if(CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX MATCHES ".*/.+-linux-android-([^/]+)/.*") if (CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX MATCHES ".*/.+-linux-android-([^/]+)/.*")
set(ANDROID_APK_TOOLCHAIN_VERSION "${CMAKE_MATCH_1}") set(ANDROID_APK_TOOLCHAIN_VERSION "${CMAKE_MATCH_1}")
elseif(NOT CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION MATCHES "clang.*") elseif (NOT CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION MATCHES "clang.*")
set(ANDROID_APK_TOOLCHAIN_VERSION "${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}") set(ANDROID_APK_TOOLCHAIN_VERSION "${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}")
else() else ()
message(FATAL_ERROR "Unable to detect the toolchain version for making the APK.") message(FATAL_ERROR "Unable to detect the toolchain version for making the APK.")
endif() endif ()
endif() endif ()
# determine Android build tools version # determine Android build tools version note: Assuming the build tools are installed under "${CMAKE_ANDROID_SDK}/build-tools"
# note: Assuming the build tools are installed under "${CMAKE_ANDROID_SDK}/build-tools" file(GLOB ANDROID_APK_BUILD_TOOLS_VERSIONS LIST_DIRECTORIES TRUE
file(GLOB ANDROID_APK_BUILD_TOOLS_VERSIONS RELATIVE "${CMAKE_ANDROID_SDK}/build-tools" "${CMAKE_ANDROID_SDK}/build-tools/*")
LIST_DIRECTORIES TRUE if (NOT ANDROID_APK_BUILD_TOOLS_VERSIONS)
RELATIVE "${CMAKE_ANDROID_SDK}/build-tools"
"${CMAKE_ANDROID_SDK}/build-tools/*"
)
if(NOT ANDROID_APK_BUILD_TOOLS_VERSIONS)
message(FATAL_ERROR "No build-tools present under \"${CMAKE_ANDROID_SDK}/build-tools\".") message(FATAL_ERROR "No build-tools present under \"${CMAKE_ANDROID_SDK}/build-tools\".")
endif() endif ()
list(GET ANDROID_APK_BUILD_TOOLS_VERSIONS 0 ANDROID_APK_BUILD_TOOLS_VERSION) list(GET ANDROID_APK_BUILD_TOOLS_VERSIONS 0 ANDROID_APK_BUILD_TOOLS_VERSION)
# deduce path of C++ standard library from "CMAKE_CXX_STANDARD_LIBRARIES" # deduce path of C++ standard library from "CMAKE_CXX_STANDARD_LIBRARIES" note: Assuming CMAKE_CXX_STANDARD_LIBRARIES
# note: Assuming CMAKE_CXX_STANDARD_LIBRARIES contains a paths or quotes paths with flags appended. # contains a paths or quotes paths with flags appended.
set(ANDROID_APK_CXX_STANDARD_LIBRARY "" CACHE STRING "path to standard library for making APK file") set(ANDROID_APK_CXX_STANDARD_LIBRARY "" CACHE STRING "path to standard library for making APK file")
if(NOT ANDROID_APK_CXX_STANDARD_LIBRARY) if (NOT ANDROID_APK_CXX_STANDARD_LIBRARY)
foreach(CMAKE_CXX_STANDARD_LIBRARY ${CMAKE_CXX_STANDARD_LIBRARIES}) foreach (CMAKE_CXX_STANDARD_LIBRARY ${CMAKE_CXX_STANDARD_LIBRARIES})
if(EXISTS "${CMAKE_CXX_STANDARD_LIBRARY}") if (EXISTS "${CMAKE_CXX_STANDARD_LIBRARY}")
set(ANDROID_APK_CXX_STANDARD_LIBRARY "${CMAKE_CXX_STANDARD_LIBRARY}") set(ANDROID_APK_CXX_STANDARD_LIBRARY "${CMAKE_CXX_STANDARD_LIBRARY}")
break() break()
elseif(CMAKE_CXX_STANDARD_LIBRARY MATCHES "\"(.*)\".*") elseif (CMAKE_CXX_STANDARD_LIBRARY MATCHES "\"(.*)\".*")
if(EXISTS "${CMAKE_MATCH_1}") if (EXISTS "${CMAKE_MATCH_1}")
set(ANDROID_APK_CXX_STANDARD_LIBRARY "${CMAKE_MATCH_1}") set(ANDROID_APK_CXX_STANDARD_LIBRARY "${CMAKE_MATCH_1}")
break() break()
endif() endif ()
endif() endif ()
message(WARNING "${CMAKE_CXX_STANDARD_LIBRARY} from CMAKE_CXX_STANDARD_LIBRARIES does not exist.") message(WARNING "${CMAKE_CXX_STANDARD_LIBRARY} from CMAKE_CXX_STANDARD_LIBRARIES does not exist.")
endforeach() endforeach ()
endif() endif ()
if(NOT ANDROID_APK_CXX_STANDARD_LIBRARY) if (NOT ANDROID_APK_CXX_STANDARD_LIBRARY)
message(FATAL_ERROR "CMAKE_CXX_STANDARD_LIBRARIES does not contain path to standard library.") message(FATAL_ERROR "CMAKE_CXX_STANDARD_LIBRARIES does not contain path to standard library.")
endif() endif ()
# determine extra prefix dirs # determine extra prefix dirs
set(ANDROID_APK_BINARY_DIRS "${RUNTIME_LIBRARY_PATH}") set(ANDROID_APK_BINARY_DIRS "${RUNTIME_LIBRARY_PATH}")
if(NOT CMAKE_CURRENT_BINARY_DIR IN_LIST ANDROID_APK_BINARY_DIRS) if (NOT CMAKE_CURRENT_BINARY_DIR IN_LIST ANDROID_APK_BINARY_DIRS)
list(APPEND ANDROID_APK_BINARY_DIRS "${CMAKE_CURRENT_BINARY_DIR}") list(APPEND ANDROID_APK_BINARY_DIRS "${CMAKE_CURRENT_BINARY_DIR}")
endif() endif ()
set(ANDROID_APK_BINARY_DIRS_DEPENDS "") set(ANDROID_APK_BINARY_DIRS_DEPENDS "")
foreach(PATH ${ANDROID_APK_BINARY_DIRS}) foreach (PATH ${ANDROID_APK_BINARY_DIRS})
# symlink "lib" subdirectory so androiddeployqt finds the library in the runtime path # symlink "lib" subdirectory so androiddeployqt finds the library in the runtime path when specified via
# when specified via "extraPrefixDirs" # "extraPrefixDirs"
list(APPEND ANDROID_APK_BINARY_DIRS_DEPENDS "${PATH}/lib") list(APPEND ANDROID_APK_BINARY_DIRS_DEPENDS "${PATH}/lib")
add_custom_command( add_custom_command(OUTPUT "${PATH}/lib"
OUTPUT "${PATH}/lib" COMMAND "${CMAKE_COMMAND}" -E create_symlink "${PATH}" "${PATH}/lib")
COMMAND "${CMAKE_COMMAND}" -E create_symlink "${PATH}" "${PATH}/lib" endforeach ()
)
endforeach()
include(ListToString) include(ListToString)
list_to_string("" "\n \"" "\"," "${ANDROID_APK_BINARY_DIRS}" ANDROID_APK_BINARY_DIRS) list_to_string("" "\n \"" "\"," "${ANDROID_APK_BINARY_DIRS}" ANDROID_APK_BINARY_DIRS)
# find dependencies # find dependencies note: androiddeployqt seems to find only Qt libraries and plugins but misses other target_link_libraries
# note: androiddeployqt seems to find only Qt libraries and plugins but misses other target_link_libraries
set(ANDROID_APK_ADDITIONAL_LIBS "" CACHE STRING "additional libraries to be bundled into the Android APK") set(ANDROID_APK_ADDITIONAL_LIBS "" CACHE STRING "additional libraries to be bundled into the Android APK")
set(ANDROID_APK_EXTRA_LIBS "${ANDROID_APK_ADDITIONAL_LIBS}") set(ANDROID_APK_EXTRA_LIBS "${ANDROID_APK_ADDITIONAL_LIBS}")
function(add_android_apk_extra_libs TARGET_NAME) function (add_android_apk_extra_libs TARGET_NAME)
get_target_property(ANDROID_APK_EXTRA_LIBS_FOR_TARGET ${TARGET_NAME} LINK_LIBRARIES) get_target_property(ANDROID_APK_EXTRA_LIBS_FOR_TARGET ${TARGET_NAME} LINK_LIBRARIES)
if(NOT ANDROID_APK_EXTRA_LIBS_FOR_TARGET) if (NOT ANDROID_APK_EXTRA_LIBS_FOR_TARGET)
return() return()
endif() endif ()
foreach(LIBRARY ${ANDROID_APK_EXTRA_LIBS_FOR_TARGET}) foreach (LIBRARY ${ANDROID_APK_EXTRA_LIBS_FOR_TARGET})
if(TARGET "${LIBRARY}") if (TARGET "${LIBRARY}")
list(APPEND ANDROID_APK_EXTRA_LIBS "\$<TARGET_FILE:${LIBRARY}>") list(APPEND ANDROID_APK_EXTRA_LIBS "\$<TARGET_FILE:${LIBRARY}>")
add_android_apk_extra_libs(${LIBRARY}) add_android_apk_extra_libs(${LIBRARY})
elseif(EXISTS "${LIBRARY}") elseif (EXISTS "${LIBRARY}")
list(APPEND ANDROID_APK_EXTRA_LIBS "${LIBRARY}") list(APPEND ANDROID_APK_EXTRA_LIBS "${LIBRARY}")
else() else ()
message(WARNING "Unable to find library \"${LIBRARY}\" required by target \"${TARGET_NAME}\". It won't be added to the APK.") message(
endif() WARNING
endforeach() "Unable to find library \"${LIBRARY}\" required by target \"${TARGET_NAME}\". It won't be added to the APK."
)
endif ()
endforeach ()
set(ANDROID_APK_EXTRA_LIBS "${ANDROID_APK_EXTRA_LIBS}" PARENT_SCOPE) set(ANDROID_APK_EXTRA_LIBS "${ANDROID_APK_EXTRA_LIBS}" PARENT_SCOPE)
endfunction() endfunction ()
add_android_apk_extra_libs("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}") add_android_apk_extra_libs("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}")
list_to_string("," "" "" "${ANDROID_APK_EXTRA_LIBS}" ANDROID_APK_EXTRA_LIBS) list_to_string("," "" "" "${ANDROID_APK_EXTRA_LIBS}" ANDROID_APK_EXTRA_LIBS)
# query certain qmake variables # query certain qmake variables
foreach(QMAKE_VARIABLE QT_INSTALL_QML QT_INSTALL_PLUGINS QT_INSTALL_IMPORTS) foreach (QMAKE_VARIABLE QT_INSTALL_QML QT_INSTALL_PLUGINS QT_INSTALL_IMPORTS)
query_qmake_variable(${QMAKE_VARIABLE}) query_qmake_variable(${QMAKE_VARIABLE})
endforeach() endforeach ()
# define function to get a list of (existing) paths # define function to get a list of (existing) paths
function(compose_dirs_for_android_apk) function (compose_dirs_for_android_apk)
# parse arguments # parse arguments
set(OPTIONAL_ARGS) set(OPTIONAL_ARGS)
set(ONE_VALUE_ARGS OUTPUT_VARIABLE) set(ONE_VALUE_ARGS OUTPUT_VARIABLE)
@ -152,161 +150,148 @@ function(compose_dirs_for_android_apk)
list(REMOVE_DUPLICATES ARGS_POSSIBLE_DIRS) list(REMOVE_DUPLICATES ARGS_POSSIBLE_DIRS)
unset(DIRS) unset(DIRS)
foreach(POSSIBLE_DIR ${ARGS_POSSIBLE_DIRS}) foreach (POSSIBLE_DIR ${ARGS_POSSIBLE_DIRS})
if(IS_DIRECTORY "${POSSIBLE_DIR}") if (IS_DIRECTORY "${POSSIBLE_DIR}")
list(APPEND DIRS "${POSSIBLE_DIR}") list(APPEND DIRS "${POSSIBLE_DIR}")
endif() endif ()
endforeach() endforeach ()
list_to_string("," "" "" "${DIRS}" DIRS) list_to_string("," "" "" "${DIRS}" DIRS)
set("${ARGS_OUTPUT_VARIABLE}" "${DIRS}" PARENT_SCOPE) set("${ARGS_OUTPUT_VARIABLE}" "${DIRS}" PARENT_SCOPE)
endfunction() endfunction ()
# pick QML import paths from install prefix # pick QML import paths from install prefix
compose_dirs_for_android_apk( compose_dirs_for_android_apk(OUTPUT_VARIABLE
OUTPUT_VARIABLE ANDROID_APK_QML_IMPORT_DIRS ANDROID_APK_QML_IMPORT_DIRS
POSSIBLE_DIRS POSSIBLE_DIRS
"${QT_INSTALL_IMPORTS}" "${QT_INSTALL_IMPORTS}"
"${QT_INSTALL_QML}" "${QT_INSTALL_QML}"
"${CMAKE_INSTALL_PREFIX}/lib/qt/imports" "${CMAKE_INSTALL_PREFIX}/lib/qt/imports"
"${CMAKE_INSTALL_PREFIX}/lib/imports" "${CMAKE_INSTALL_PREFIX}/lib/imports"
"${CMAKE_INSTALL_PREFIX}/lib/qt/qml" "${CMAKE_INSTALL_PREFIX}/lib/qt/qml"
"${CMAKE_INSTALL_PREFIX}/lib/qml" "${CMAKE_INSTALL_PREFIX}/lib/qml")
) if (NOT ANDROID_APK_QML_IMPORT_DIRS)
if(NOT ANDROID_APK_QML_IMPORT_DIRS)
message(WARNING "Unable to find QML import directories for making the APK.") message(WARNING "Unable to find QML import directories for making the APK.")
endif() endif ()
# pick extra plugins from install prefix # pick extra plugins from install prefix
compose_dirs_for_android_apk( compose_dirs_for_android_apk(OUTPUT_VARIABLE
OUTPUT_VARIABLE ANDROID_APK_EXTRA_PLUGIN_DIRS ANDROID_APK_EXTRA_PLUGIN_DIRS
POSSIBLE_DIRS POSSIBLE_DIRS
"${QT_INSTALL_PLUGINS}" "${QT_INSTALL_PLUGINS}"
"${QT_INSTALL_QML}" "${QT_INSTALL_QML}"
"${CMAKE_INSTALL_PREFIX}/lib/qt/plugins" "${CMAKE_INSTALL_PREFIX}/lib/qt/plugins"
"${CMAKE_INSTALL_PREFIX}/lib/plugins" "${CMAKE_INSTALL_PREFIX}/lib/plugins"
"${CMAKE_INSTALL_PREFIX}/lib/qt/qml" "${CMAKE_INSTALL_PREFIX}/lib/qt/qml"
"${CMAKE_INSTALL_PREFIX}/lib/qml" "${CMAKE_INSTALL_PREFIX}/lib/qml"
"${CMAKE_INSTALL_PREFIX}/share" "${CMAKE_INSTALL_PREFIX}/share")
) if (NOT ANDROID_APK_EXTRA_PLUGIN_DIRS)
if(NOT ANDROID_APK_EXTRA_PLUGIN_DIRS)
message(WARNING "Unable to find extra plugin directories for making the APK.") message(WARNING "Unable to find extra plugin directories for making the APK.")
endif() endif ()
# find template for deployment JSON # find template for deployment JSON
find_template_file("android-deployment.json" QT_UTILITIES ANDROID_DEPLOYMENT_JSON_TEMPLATE_FILE) find_template_file("android-deployment.json" QT_UTILITIES ANDROID_DEPLOYMENT_JSON_TEMPLATE_FILE)
set(ANDROID_DEPLOYMENT_JSON_FILE "${CMAKE_CURRENT_BINARY_DIR}/android-deployment.json") set(ANDROID_DEPLOYMENT_JSON_FILE "${CMAKE_CURRENT_BINARY_DIR}/android-deployment.json")
configure_file( configure_file("${ANDROID_DEPLOYMENT_JSON_TEMPLATE_FILE}" "${ANDROID_DEPLOYMENT_JSON_FILE}.configured")
"${ANDROID_DEPLOYMENT_JSON_TEMPLATE_FILE}" file(GENERATE OUTPUT "${ANDROID_DEPLOYMENT_JSON_FILE}" INPUT "${ANDROID_DEPLOYMENT_JSON_FILE}.configured")
"${ANDROID_DEPLOYMENT_JSON_FILE}.configured"
)
file(GENERATE
OUTPUT "${ANDROID_DEPLOYMENT_JSON_FILE}"
INPUT "${ANDROID_DEPLOYMENT_JSON_FILE}.configured"
)
# pass make arguments # pass make arguments
if (CMAKE_GENERATOR STREQUAL "Unix Makefiles") if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(MAKE_ARGUMENTS "\\$(ARGS)") set(MAKE_ARGUMENTS "\\$(ARGS)")
endif() endif ()
# add rules to make APK # add rules to make APK
option(ANDROID_APK_FORCE_DEBUG "specifies whether a debug APK should be created even when building in release mode" OFF) option(ANDROID_APK_FORCE_DEBUG "specifies whether a debug APK should be created even when building in release mode" OFF)
if (Qt5Core_VERSION VERSION_LESS 5.12.0) if (Qt5Core_VERSION VERSION_LESS 5.12.0)
set(ANDROID_APK_FILE_DIRECTORY "") set(ANDROID_APK_FILE_DIRECTORY "")
else() else ()
if(ANDROID_APK_FORCE_DEBUG OR CMAKE_BUILD_TYPE STREQUAL "Debug") if (ANDROID_APK_FORCE_DEBUG OR CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ANDROID_APK_FILE_DIRECTORY "debug/") set(ANDROID_APK_FILE_DIRECTORY "debug/")
else() else ()
set(ANDROID_APK_FILE_DIRECTORY "release/") set(ANDROID_APK_FILE_DIRECTORY "release/")
endif() endif ()
endif() endif ()
if(ANDROID_APK_FORCE_DEBUG OR CMAKE_BUILD_TYPE STREQUAL "Debug") if (ANDROID_APK_FORCE_DEBUG OR CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ANDROID_APK_FILE_PATH "${ANDROID_APK_BUILD_DIR}/build/outputs/apk/${ANDROID_APK_FILE_DIRECTORY}apk-debug.apk") set(ANDROID_APK_FILE_PATH "${ANDROID_APK_BUILD_DIR}/build/outputs/apk/${ANDROID_APK_FILE_DIRECTORY}apk-debug.apk")
set(ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS) set(ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS)
else() else ()
set(ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS --release) set(ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS --release)
set(ANDROID_APK_KEYSTORE_URL "" CACHE STRING "keystore URL for signing the Android APK") set(ANDROID_APK_KEYSTORE_URL "" CACHE STRING "keystore URL for signing the Android APK")
set(ANDROID_APK_KEYSTORE_ALIAS "" CACHE STRING "keystore alias for signing the Android APK") set(ANDROID_APK_KEYSTORE_ALIAS "" CACHE STRING "keystore alias for signing the Android APK")
set(ANDROID_APK_KEYSTORE_PASSWORD "" CACHE STRING "keystore password for signing the Android APK") set(ANDROID_APK_KEYSTORE_PASSWORD "" CACHE STRING "keystore password for signing the Android APK")
set(ANDROID_APK_KEYSTORE_KEY_PASSWORD "" CACHE STRING "keystore key password for signing the Android APK") set(ANDROID_APK_KEYSTORE_KEY_PASSWORD "" CACHE STRING "keystore key password for signing the Android APK")
if(ANDROID_APK_KEYSTORE_URL AND ANDROID_APK_KEYSTORE_ALIAS) if (ANDROID_APK_KEYSTORE_URL AND ANDROID_APK_KEYSTORE_ALIAS)
set(ANDROID_APK_FILE_PATH "${ANDROID_APK_BUILD_DIR}/build/outputs/apk/${ANDROID_APK_FILE_DIRECTORY}apk-release-signed.apk") set(ANDROID_APK_FILE_PATH
"${ANDROID_APK_BUILD_DIR}/build/outputs/apk/${ANDROID_APK_FILE_DIRECTORY}apk-release-signed.apk")
list(APPEND ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS list(APPEND ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS
--sign "${ANDROID_APK_KEYSTORE_URL}" "${ANDROID_APK_KEYSTORE_ALIAS}") --sign
if(ANDROID_APK_KEYSTORE_PASSWORD) "${ANDROID_APK_KEYSTORE_URL}"
list(APPEND ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS "${ANDROID_APK_KEYSTORE_ALIAS}")
--storepass "${ANDROID_APK_KEYSTORE_PASSWORD}") if (ANDROID_APK_KEYSTORE_PASSWORD)
endif() list(APPEND ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS --storepass "${ANDROID_APK_KEYSTORE_PASSWORD}")
if(ANDROID_APK_KEYSTORE_KEY_PASSWORD) endif ()
list(APPEND ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS if (ANDROID_APK_KEYSTORE_KEY_PASSWORD)
--keypass "${ANDROID_APK_KEYSTORE_KEY_PASSWORD}") list(APPEND ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS --keypass "${ANDROID_APK_KEYSTORE_KEY_PASSWORD}")
endif() endif ()
else() else ()
set(ANDROID_APK_FILE_PATH "${ANDROID_APK_BUILD_DIR}/build/outputs/apk/${ANDROID_APK_FILE_DIRECTORY}apk-release-unsigned.apk") set(ANDROID_APK_FILE_PATH
"${ANDROID_APK_BUILD_DIR}/build/outputs/apk/${ANDROID_APK_FILE_DIRECTORY}apk-release-unsigned.apk")
message(WARNING "Set ANDROID_APK_KEYSTORE_URL/ANDROID_APK_KEYSTORE_ALIAS to sign Android APK release.") message(WARNING "Set ANDROID_APK_KEYSTORE_URL/ANDROID_APK_KEYSTORE_ALIAS to sign Android APK release.")
endif() endif ()
endif() endif ()
set(ANDROID_APK_BINARY_PATH "${ANDROID_APK_BUILD_DIR}/libs/${CMAKE_ANDROID_ARCH_ABI}/lib${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}.so") set(ANDROID_APK_BINARY_PATH
"${ANDROID_APK_BUILD_DIR}/libs/${CMAKE_ANDROID_ARCH_ABI}/lib${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}.so")
add_custom_command(OUTPUT "${ANDROID_APK_BINARY_PATH}" add_custom_command(OUTPUT "${ANDROID_APK_BINARY_PATH}"
COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_FILE:${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}>" "${ANDROID_APK_BINARY_PATH}" COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_FILE:${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}>"
COMMENT "Preparing build dir for Android APK" "${ANDROID_APK_BINARY_PATH}"
DEPENDS "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}" COMMENT "Preparing build dir for Android APK"
COMMAND_EXPAND_LISTS DEPENDS "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}" COMMAND_EXPAND_LISTS
VERBATIM VERBATIM)
) add_custom_command(
add_custom_command(OUTPUT "${ANDROID_APK_FILE_PATH}" OUTPUT "${ANDROID_APK_FILE_PATH}"
COMMAND $<TARGET_FILE_DIR:Qt5::qmake>/androiddeployqt COMMAND $<TARGET_FILE_DIR:Qt5::qmake>/androiddeployqt
--gradle --gradle
--input "${ANDROID_DEPLOYMENT_JSON_FILE}" --input "${ANDROID_DEPLOYMENT_JSON_FILE}"
--output "${ANDROID_APK_BUILD_DIR}" --output "${ANDROID_APK_BUILD_DIR}"
--deployment bundled ${MAKE_ARGUMENTS} --deployment bundled ${MAKE_ARGUMENTS}
--verbose --verbose ${ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS}
${ANDROID_APK_ADDITIONAL_ANDROIDDEPOYQT_OPTIONS}
WORKING_DIRECTORY "${ANDROID_APK_BUILD_DIR}" WORKING_DIRECTORY "${ANDROID_APK_BUILD_DIR}"
COMMENT "Creating Android APK ${ANDROID_APK_FILE_PATH} using androiddeployqt" COMMENT "Creating Android APK ${ANDROID_APK_FILE_PATH} using androiddeployqt"
DEPENDS "${ANDROID_DEPLOYMENT_JSON_FILE};${ANDROID_APK_BINARY_PATH};${ANDROID_APK_FILES};${ANDROID_APK_BINARY_DIRS_DEPENDS}" DEPENDS
COMMAND_EXPAND_LISTS "${ANDROID_DEPLOYMENT_JSON_FILE};${ANDROID_APK_BINARY_PATH};${ANDROID_APK_FILES};${ANDROID_APK_BINARY_DIRS_DEPENDS}"
VERBATIM COMMAND_EXPAND_LISTS
) VERBATIM)
add_custom_target("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_apk" add_custom_target("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_apk"
COMMENT "Android APK" COMMENT "Android APK"
DEPENDS "${ANDROID_APK_FILE_PATH}" DEPENDS "${ANDROID_APK_FILE_PATH}")
) if (NOT TARGET apk)
if(NOT TARGET apk)
add_custom_target(apk) add_custom_target(apk)
endif() endif ()
add_dependencies(apk "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_apk") add_dependencies(apk "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_apk")
# add install target for APK # add install target for APK
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ANDROID_APK_FINAL_NAME "${META_ID}-debug-${META_APP_VERSION}.apk") set(ANDROID_APK_FINAL_NAME "${META_ID}-debug-${META_APP_VERSION}.apk")
else() else ()
set(ANDROID_APK_FINAL_NAME "${META_ID}-${META_APP_VERSION}.apk") set(ANDROID_APK_FINAL_NAME "${META_ID}-${META_APP_VERSION}.apk")
endif() endif ()
install( install(FILES "${ANDROID_APK_FILE_PATH}" DESTINATION "share/apk" RENAME "${ANDROID_APK_FINAL_NAME}" COMPONENT apk)
FILES "${ANDROID_APK_FILE_PATH}"
DESTINATION "share/apk"
RENAME "${ANDROID_APK_FINAL_NAME}"
COMPONENT apk
)
add_custom_target("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_install_apk" add_custom_target("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_install_apk"
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=apk -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=apk -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
) add_dependencies("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_install_apk"
add_dependencies("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_install_apk" "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_apk") "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_apk")
if(NOT TARGET install-apk) if (NOT TARGET install-apk)
add_custom_target(install-apk) add_custom_target(install-apk)
endif() endif ()
add_dependencies(install-apk "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_install_apk") add_dependencies(install-apk "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_install_apk")
# add deploy target for APK # add deploy target for APK
find_program(ADB_BIN adb) find_program(ADB_BIN adb)
add_custom_target("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_deploy_apk" add_custom_target("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_deploy_apk"
COMMAND "${ADB_BIN}" install -r "${ANDROID_APK_FILE_PATH}" COMMAND "${ADB_BIN}" install -r "${ANDROID_APK_FILE_PATH}"
COMMENT "Deploying Android APK" COMMENT "Deploying Android APK"
DEPENDS "${ANDROID_APK_FILE_PATH}" DEPENDS "${ANDROID_APK_FILE_PATH}")
)
set(ANDROID_APK_CONFIGURED YES) set(ANDROID_APK_CONFIGURED YES)

View File

@ -1,80 +1,75 @@
# determines the JavaScript provider (either Qt Script or Qt Declarative) # determines the JavaScript provider (either Qt Script or Qt Declarative)
if(TARGET_CONFIG_DONE) if (TARGET_CONFIG_DONE)
message(FATAL_ERROR "Can not include JsProviderConfig module when targets are already configured.") message(FATAL_ERROR "Can not include JsProviderConfig module when targets are already configured.")
endif() endif ()
include(QtLinkage) include(QtLinkage)
set(JS_PROVIDER "auto" CACHE STRING "specifies the JavaScript provider: auto (default), qml, script or none") set(JS_PROVIDER "auto" CACHE STRING "specifies the JavaScript provider: auto (default), qml, script or none")
if(NOT JS_PROVIDER OR "${JS_PROVIDER}" STREQUAL "auto") if (NOT JS_PROVIDER OR "${JS_PROVIDER}" STREQUAL "auto")
find_qt5_module(Script OPTIONAL) find_qt5_module(Script OPTIONAL)
if(QT5_Script_FOUND) if (QT5_Script_FOUND)
set(JS_PROVIDER Script) set(JS_PROVIDER Script)
set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_SCRIPT") set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_SCRIPT")
list(APPEND ADDITIONAL_QT_REPOS "script") list(APPEND ADDITIONAL_QT_REPOS "script")
message(STATUS "No JavaScript provider explicitly specified, defaulting to Qt Script.") message(STATUS "No JavaScript provider explicitly specified, defaulting to Qt Script.")
else() else ()
find_qt5_module(Qml OPTIONAL) find_qt5_module(Qml OPTIONAL)
if(QT5_Qml_FOUND) if (QT5_Qml_FOUND)
set(JS_PROVIDER Qml) set(JS_PROVIDER Qml)
set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_JSENGINE") set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_JSENGINE")
list(APPEND ADDITIONAL_QT_REPOS "declarative") list(APPEND ADDITIONAL_QT_REPOS "declarative")
message(STATUS "No JavaScript provider explicitly specified, defaulting to Qt QML.") message(STATUS "No JavaScript provider explicitly specified, defaulting to Qt QML.")
else() else ()
set(JS_PROVIDER "") set(JS_PROVIDER "")
set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_NO_JSENGINE") set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_NO_JSENGINE")
message(STATUS "No JavaScript provider available, features requiring JavaScript have been disabled.") message(STATUS "No JavaScript provider available, features requiring JavaScript have been disabled.")
endif() endif ()
endif() endif ()
else() else ()
if(${JS_PROVIDER} STREQUAL "script") if (${JS_PROVIDER} STREQUAL "script")
find_qt5_module(Script REQUIRED) find_qt5_module(Script REQUIRED)
set(JS_PROVIDER Script) set(JS_PROVIDER Script)
set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_SCRIPT") set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_SCRIPT")
list(APPEND ADDITIONAL_QT_REPOS "script") list(APPEND ADDITIONAL_QT_REPOS "script")
message(STATUS "Using Qt Script as JavaScript provider.") message(STATUS "Using Qt Script as JavaScript provider.")
elseif(${JS_PROVIDER} STREQUAL "qml") elseif (${JS_PROVIDER} STREQUAL "qml")
find_qt5_module(Qml REQUIRED) find_qt5_module(Qml REQUIRED)
set(JS_PROVIDER Qml) set(JS_PROVIDER Qml)
set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_JSENGINE") set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_JSENGINE")
list(APPEND ADDITIONAL_QT_REPOS "declarative") list(APPEND ADDITIONAL_QT_REPOS "declarative")
message(STATUS "Using Qt QML as JavaScript provider.") message(STATUS "Using Qt QML as JavaScript provider.")
elseif(${JS_PROVIDER} STREQUAL "none") elseif (${JS_PROVIDER} STREQUAL "none")
set(JS_PROVIDER "") set(JS_PROVIDER "")
set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_NO_JSENGINE") set(JS_DEFINITION "${META_PROJECT_VARNAME_UPPER}_NO_JSENGINE")
message(STATUS "JavaScript provider has been disabled.") message(STATUS "JavaScript provider has been disabled.")
else() else ()
message(FATAL_ERROR "The specified JavaScript provider '${JS_PROVIDER}' is unknown.") message(FATAL_ERROR "The specified JavaScript provider '${JS_PROVIDER}' is unknown.")
endif() endif ()
endif() endif ()
if(JS_PROVIDER) if (JS_PROVIDER)
use_qt5_module(${JS_PROVIDER} REQUIRED) use_qt5_module(${JS_PROVIDER} REQUIRED)
# add header files with some defines/includes to conveniently use the selected provider # add header files with some defines/includes to conveniently use the selected provider
if(META_JS_SRC_DIR) if (META_JS_SRC_DIR)
set(JS_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${META_JS_SRC_DIR}") set(JS_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${META_JS_SRC_DIR}")
else() else ()
set(JS_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gui") set(JS_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gui")
endif() endif ()
include(TemplateFinder) include(TemplateFinder)
find_template_file("jsdefs.h" QT_UTILITIES JS_DEFS_H_TEMPLATE_FILE) find_template_file("jsdefs.h" QT_UTILITIES JS_DEFS_H_TEMPLATE_FILE)
configure_file( configure_file("${JS_DEFS_H_TEMPLATE_FILE}"
"${JS_DEFS_H_TEMPLATE_FILE}" "${JS_HEADER_DIR}/jsdefs.h" # simply add this to source to ease inclusion
"${JS_HEADER_DIR}/jsdefs.h" # simply add this to source to ease inclusion NEWLINE_STYLE UNIX # since this goes to sources ensure consistency
NEWLINE_STYLE UNIX # since this goes to sources ensure consistency )
)
find_template_file("jsincludes.h" QT_UTILITIES JS_INCLUDES_H_TEMPLATE_FILE) find_template_file("jsincludes.h" QT_UTILITIES JS_INCLUDES_H_TEMPLATE_FILE)
configure_file( configure_file("${JS_INCLUDES_H_TEMPLATE_FILE}"
"${JS_INCLUDES_H_TEMPLATE_FILE}" "${JS_HEADER_DIR}/jsincludes.h" # simply add this to source to ease inclusion
"${JS_HEADER_DIR}/jsincludes.h" # simply add this to source to ease inclusion NEWLINE_STYLE UNIX # since this goes to sources ensure consistency
NEWLINE_STYLE UNIX # since this goes to sources ensure consistency )
) list(APPEND WIDGETS_FILES "${JS_HEADER_DIR}/jsdefs.h" "${JS_HEADER_DIR}/jsincludes.h")
list(APPEND WIDGETS_FILES endif ()
"${JS_HEADER_DIR}/jsdefs.h"
"${JS_HEADER_DIR}/jsincludes.h"
)
endif()
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${JS_DEFINITION}) list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${JS_DEFINITION})

View File

@ -1,27 +1,25 @@
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR) cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
# applies Qt specific configuration # applies Qt specific configuration for GUI applications, QtGuiAppConfig must be included before this module must always be
# for GUI applications, QtGuiAppConfig must be included before # included before AppTarget/LibraryTarget
# this module must always be included before AppTarget/LibraryTarget
# ensure generated sources are processed by AUTOMOC and AUTOUIC # ensure generated sources are processed by AUTOMOC and AUTOUIC
if(POLICY CMP0071) if (POLICY CMP0071)
cmake_policy(SET CMP0071 NEW) cmake_policy(SET CMP0071 NEW)
endif() endif ()
if(NOT BASIC_PROJECT_CONFIG_DONE) if (NOT BASIC_PROJECT_CONFIG_DONE)
message(FATAL_ERROR "Before including the QtConfig module, the BasicConfig module must be included.") message(FATAL_ERROR "Before including the QtConfig module, the BasicConfig module must be included.")
endif() endif ()
if(QT_CONFIGURED) if (QT_CONFIGURED)
message(FATAL_ERROR "The QtConfig module can not be included when Qt usage has already been configured.") message(FATAL_ERROR "The QtConfig module can not be included when Qt usage has already been configured.")
endif() endif ()
if(TARGET_CONFIG_DONE) if (TARGET_CONFIG_DONE)
message(FATAL_ERROR "Can not include QtConfig module when targets are already configured.") message(FATAL_ERROR "Can not include QtConfig module when targets are already configured.")
endif() endif ()
# add the Core module as it is always required # add the Core module as it is always required also add additional Qt/KF modules which must have been specified before if
# also add additional Qt/KF modules which must have been specified before if required # required the Gui/Widgets/Quick modules should be added by including QtGuiAppConfig
# the Gui/Widgets/Quick modules should be added by including QtGuiAppConfig
set(QT_REPOS base ${ADDITIONAL_QT_REPOS}) set(QT_REPOS base ${ADDITIONAL_QT_REPOS})
set(QT_MODULES ${ADDITIONAL_QT_MODULES} Core) set(QT_MODULES ${ADDITIONAL_QT_MODULES} Core)
set(KF_MODULES ${ADDITIONAL_KF_MODULES}) set(KF_MODULES ${ADDITIONAL_KF_MODULES})
@ -32,122 +30,122 @@ set(QT_PLUGIN_DIR "" CACHE STRING "specifies the directory to install Qt plugins
include(QtLinkage) include(QtLinkage)
# check whether D-Bus interfaces need to be processed # check whether D-Bus interfaces need to be processed
if(DBUS_FILES) if (DBUS_FILES)
message(STATUS "Project has D-Bus interface declarations which will be processed.") message(STATUS "Project has D-Bus interface declarations which will be processed.")
# the D-Bus Qt module is required # the D-Bus Qt module is required
list(APPEND QT_MODULES DBus) list(APPEND QT_MODULES DBus)
endif() endif ()
# remove duplicates # remove duplicates
list(REMOVE_DUPLICATES QT_REPOS) list(REMOVE_DUPLICATES QT_REPOS)
list(REMOVE_DUPLICATES QT_MODULES) list(REMOVE_DUPLICATES QT_MODULES)
if(IMPORTED_QT_MODULES) if (IMPORTED_QT_MODULES)
list(REMOVE_DUPLICATES IMPORTED_QT_MODULES) list(REMOVE_DUPLICATES IMPORTED_QT_MODULES)
endif() endif ()
if(KF_MODULES) if (KF_MODULES)
list(REMOVE_DUPLICATES KF_MODULES) list(REMOVE_DUPLICATES KF_MODULES)
endif() endif ()
if(IMPORTED_KF_MODULES) if (IMPORTED_KF_MODULES)
list(REMOVE_DUPLICATES IMPORTED_KF_MODULES) list(REMOVE_DUPLICATES IMPORTED_KF_MODULES)
endif() endif ()
# actually find the required Qt/KF modules # actually find the required Qt/KF modules
foreach(QT_MODULE ${QT_MODULES}) foreach (QT_MODULE ${QT_MODULES})
# using those helpers allows using static Qt 5 build # using those helpers allows using static Qt 5 build
find_qt5_module(${QT_MODULE} REQUIRED) find_qt5_module(${QT_MODULE} REQUIRED)
use_qt5_module(${QT_MODULE} REQUIRED) use_qt5_module(${QT_MODULE} REQUIRED)
endforeach() endforeach ()
foreach(QT_MODULE ${IMPORTED_QT_MODULES}) foreach (QT_MODULE ${IMPORTED_QT_MODULES})
if(NOT "${QT_MODULE}" IN_LIST QT_MODULES) if (NOT "${QT_MODULE}" IN_LIST QT_MODULES)
find_qt5_module(${QT_MODULE} REQUIRED) find_qt5_module(${QT_MODULE} REQUIRED)
endif() endif ()
endforeach() endforeach ()
foreach(KF_MODULE ${KF_MODULES}) foreach (KF_MODULE ${KF_MODULES})
# only shared KF5 modules supported # only shared KF5 modules supported
find_package(KF5${KF_MODULE} REQUIRED) find_package(KF5${KF_MODULE} REQUIRED)
set(KF5_${KF_MODULE}_DYNAMIC_LIB KF5::${KF_MODULE}) set(KF5_${KF_MODULE}_DYNAMIC_LIB KF5::${KF_MODULE})
link_against_library(KF5_${KF_MODULE} "AUTO_LINKAGE" REQUIRED) link_against_library(KF5_${KF_MODULE} "AUTO_LINKAGE" REQUIRED)
endforeach() endforeach ()
foreach(KF_MODULE ${IMPORTED_KF_MODULES}) foreach (KF_MODULE ${IMPORTED_KF_MODULES})
if(NOT "${KF_MODULE}" IN_LIST KF_MODULES) if (NOT "${KF_MODULE}" IN_LIST KF_MODULES)
find_package(KF5${KF_MODULE} REQUIRED) find_package(KF5${KF_MODULE} REQUIRED)
endif() endif ()
endforeach() endforeach ()
# built-in platform, imageformat and iconengine plugins when linking statically against Qt Gui # built-in platform, imageformat and iconengine plugins when linking statically against Qt Gui -> determine whether
# -> determine whether application target links statically against Qt Gui # application target links statically against Qt Gui
if(META_PROJECT_TYPE STREQUAL "application") if (META_PROJECT_TYPE STREQUAL "application")
set(USING_STATIC_QT_GUI_FOR_APPLICATION NO) set(USING_STATIC_QT_GUI_FOR_APPLICATION NO)
foreach(MODULE Gui Widgets Quick) foreach (MODULE Gui Widgets Quick)
if(QT5_${MODULE}_STATIC_LIB IN_LIST LIBRARIES OR QT5_${MODULE}_STATIC_LIB IN_LIST PRIVATE_LIBRARIES) if (QT5_${MODULE}_STATIC_LIB IN_LIST LIBRARIES OR QT5_${MODULE}_STATIC_LIB IN_LIST PRIVATE_LIBRARIES)
set(USING_STATIC_QT_GUI_FOR_APPLICATION YES) set(USING_STATIC_QT_GUI_FOR_APPLICATION YES)
message(STATUS "Linking application ${META_PROJECT_NAME} against static Qt 5 plugins.") message(STATUS "Linking application ${META_PROJECT_NAME} against static Qt 5 plugins.")
break() break()
endif() endif ()
endforeach() endforeach ()
endif() endif ()
# -> link against plugins according to platform and configuration # -> link against plugins according to platform and configuration
if(USING_STATIC_QT_GUI_FOR_APPLICATION) if (USING_STATIC_QT_GUI_FOR_APPLICATION)
if(NOT USE_STATIC_QT5_Gui) if (NOT USE_STATIC_QT5_Gui)
find_qt5_module(Gui REQUIRED) find_qt5_module(Gui REQUIRED)
endif() endif ()
# ensure platform integration plugins for corresponding platforms are built-in when creating a GUI application # ensure platform integration plugins for corresponding platforms are built-in when creating a GUI application
if(WIN32) if (WIN32)
use_static_qt5_plugin(Gui WindowsIntegration ON OFF) use_static_qt5_plugin(Gui WindowsIntegration ON OFF)
elseif(APPLE) elseif (APPLE)
use_static_qt5_plugin(Gui CocoaIntegration ON OFF) use_static_qt5_plugin(Gui CocoaIntegration ON OFF)
elseif(TARGET ${QT5_Gui_STATIC_PREFIX}QXcbIntegrationPlugin) elseif (TARGET ${QT5_Gui_STATIC_PREFIX}QXcbIntegrationPlugin)
use_static_qt5_plugin(Gui XcbIntegration ON OFF) use_static_qt5_plugin(Gui XcbIntegration ON OFF)
else() else ()
message(WARNING "The required platform plugin for your platform is unknown an can not be linked in statically.") message(WARNING "The required platform plugin for your platform is unknown an can not be linked in statically.")
endif() endif ()
# ensure all available widget style plugins are built-in when creating a Qt Widgets application # ensure all available widget style plugins are built-in when creating a Qt Widgets application note: required since Qt
# note: required since Qt 5.10 because the styles have been "pluginized" (see commit 4f3249f) # 5.10 because the styles have been "pluginized" (see commit 4f3249f)
set(KNOWN_WIDGET_STYLE_PLUGINS WindowsVistaStyle MacStyle AndroidStyle) set(KNOWN_WIDGET_STYLE_PLUGINS WindowsVistaStyle MacStyle AndroidStyle)
set(USED_WIDGET_STYLE_PLUGINS) set(USED_WIDGET_STYLE_PLUGINS)
if(QT5_Widgets_STATIC_LIB IN_LIST LIBRARIES OR QT5_Widgets_STATIC_LIB IN_LIST PRIVATE_LIBRARIES) if (QT5_Widgets_STATIC_LIB IN_LIST LIBRARIES OR QT5_Widgets_STATIC_LIB IN_LIST PRIVATE_LIBRARIES)
foreach(WIDGET_STYLE_PLUGIN ${KNOWN_WIDGET_STYLE_PLUGINS}) foreach (WIDGET_STYLE_PLUGIN ${KNOWN_WIDGET_STYLE_PLUGINS})
if(TARGET "${QT5_Widgets_STATIC_PREFIX}Q${WIDGET_STYLE_PLUGIN}Plugin") if (TARGET "${QT5_Widgets_STATIC_PREFIX}Q${WIDGET_STYLE_PLUGIN}Plugin")
use_static_qt5_plugin(Widgets "${WIDGET_STYLE_PLUGIN}" ON OFF) use_static_qt5_plugin(Widgets "${WIDGET_STYLE_PLUGIN}" ON OFF)
list(APPEND USED_WIDGET_STYLE_PLUGINS "${WIDGET_STYLE_PLUGIN}") list(APPEND USED_WIDGET_STYLE_PLUGINS "${WIDGET_STYLE_PLUGIN}")
endif() endif ()
endforeach() endforeach ()
# allow importing image format plugins via config.h # allow importing image format plugins via config.h
include(ListToString) include(ListToString)
list_to_string(" " "\\\n Q_IMPORT_PLUGIN(Q" "Plugin)" "${USED_WIDGET_STYLE_PLUGINS}" WIDGET_STYLE_PLUGINS_ARRAY) list_to_string(" " "\\\n Q_IMPORT_PLUGIN(Q" "Plugin)" "${USED_WIDGET_STYLE_PLUGINS}" WIDGET_STYLE_PLUGINS_ARRAY)
endif() endif ()
# ensure image format plugins (beside SVG) are built-in if configured # ensure image format plugins (beside SVG) are built-in if configured
if(IMAGE_FORMAT_SUPPORT) if (IMAGE_FORMAT_SUPPORT)
foreach(IMAGE_FORMAT ${IMAGE_FORMAT_SUPPORT}) foreach (IMAGE_FORMAT ${IMAGE_FORMAT_SUPPORT})
if(IMAGE_FORMAT EQUAL "Svg") if (IMAGE_FORMAT EQUAL "Svg")
# the image format plugin of the Qt Svg module is handled separately # the image format plugin of the Qt Svg module is handled separately
set(SVG_SUPPORT ON) set(SVG_SUPPORT ON)
list(REMOVE_ITEM IMAGE_FORMAT_SUPPORT Svg) list(REMOVE_ITEM IMAGE_FORMAT_SUPPORT Svg)
else() else ()
use_static_qt5_plugin(Gui "${IMAGE_FORMAT}" ON OFF) use_static_qt5_plugin(Gui "${IMAGE_FORMAT}" ON OFF)
endif() endif ()
endforeach() endforeach ()
# allow importing image format plugins via config.h # allow importing image format plugins via config.h
include(ListToString) include(ListToString)
list_to_string(" " "\\\n Q_IMPORT_PLUGIN(Q" "Plugin)" "${IMAGE_FORMAT_SUPPORT}" IMAGE_FORMAT_SUPPORT_ARRAY) list_to_string(" " "\\\n Q_IMPORT_PLUGIN(Q" "Plugin)" "${IMAGE_FORMAT_SUPPORT}" IMAGE_FORMAT_SUPPORT_ARRAY)
endif() endif ()
# ensure SVG plugins are built-in if configured # ensure SVG plugins are built-in if configured
if((SVG_SUPPORT OR SVG_ICON_SUPPORT) AND NOT USE_STATIC_QT5_Svg) if ((SVG_SUPPORT OR SVG_ICON_SUPPORT) AND NOT USE_STATIC_QT5_Svg)
find_qt5_module(Svg REQUIRED) find_qt5_module(Svg REQUIRED)
endif() endif ()
if(SVG_SUPPORT) if (SVG_SUPPORT)
use_static_qt5_plugin(Svg Svg ON OFF) use_static_qt5_plugin(Svg Svg ON OFF)
endif() endif ()
if(SVG_ICON_SUPPORT) if (SVG_ICON_SUPPORT)
use_static_qt5_plugin(Svg SvgIcon ON OFF) use_static_qt5_plugin(Svg SvgIcon ON OFF)
endif() endif ()
endif() endif ()
# option for built-in translations # option for built-in translations
option(BUILTIN_TRANSLATIONS "enables/disables built-in translations when building applications and libraries" OFF) option(BUILTIN_TRANSLATIONS "enables/disables built-in translations when building applications and libraries" OFF)
@ -155,35 +153,32 @@ option(BUILTIN_TRANSLATIONS "enables/disables built-in translations when buildin
# determine relevant Qt translation files # determine relevant Qt translation files
set(QT_TRANSLATION_FILES) set(QT_TRANSLATION_FILES)
set(QT_TRANSLATION_SEARCH_PATHS) set(QT_TRANSLATION_SEARCH_PATHS)
if(CMAKE_FIND_ROOT_PATH) if (CMAKE_FIND_ROOT_PATH)
list(APPEND QT_TRANSLATION_SEARCH_PATHS list(APPEND QT_TRANSLATION_SEARCH_PATHS "${CMAKE_FIND_ROOT_PATH}/share/qt/translations"
"${CMAKE_FIND_ROOT_PATH}/share/qt/translations" "${CMAKE_FIND_ROOT_PATH}/share/qt5/translations")
"${CMAKE_FIND_ROOT_PATH}/share/qt5/translations" endif ()
)
endif()
list(APPEND QT_TRANSLATION_SEARCH_PATHS list(APPEND QT_TRANSLATION_SEARCH_PATHS
"${CMAKE_INSTALL_PREFIX}/share/qt/translations" "${CMAKE_INSTALL_PREFIX}/share/qt/translations"
"${CMAKE_INSTALL_PREFIX}/share/qt5/translations" "${CMAKE_INSTALL_PREFIX}/share/qt5/translations"
"/usr/share/qt/translations" "/usr/share/qt/translations"
"/usr/share/qt5/translations" "/usr/share/qt5/translations")
) foreach (QT_TRANSLATION_PATH ${QT_TRANSLATION_SEARCH_PATHS})
foreach(QT_TRANSLATION_PATH ${QT_TRANSLATION_SEARCH_PATHS}) if (IS_DIRECTORY "${QT_TRANSLATION_PATH}")
if(IS_DIRECTORY "${QT_TRANSLATION_PATH}") foreach (QT_REPO ${QT_REPOS})
foreach(QT_REPO ${QT_REPOS})
file(GLOB QT_QM_FILES "${QT_TRANSLATION_PATH}/qt${QT_REPO}_*.qm") file(GLOB QT_QM_FILES "${QT_TRANSLATION_PATH}/qt${QT_REPO}_*.qm")
if(QT_QM_FILES) if (QT_QM_FILES)
# add files to list of built-in translations # add files to list of built-in translations but only if that configuration is enabled and if we're building
# but only if that configuration is enabled and if we're building the final application # the final application
if(BUILTIN_TRANSLATIONS AND "${META_PROJECT_TYPE}" STREQUAL "application") if (BUILTIN_TRANSLATIONS AND "${META_PROJECT_TYPE}" STREQUAL "application")
file(COPY ${QT_QM_FILES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") file(COPY ${QT_QM_FILES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
list(APPEND EXTERNAL_QM_FILES ${QT_QM_FILES}) list(APPEND EXTERNAL_QM_FILES ${QT_QM_FILES})
endif() endif ()
list(APPEND QT_TRANSLATION_FILES "qt${QT_REPO}") list(APPEND QT_TRANSLATION_FILES "qt${QT_REPO}")
endif() endif ()
endforeach() endforeach ()
break() break()
endif() endif ()
endforeach() endforeach ()
# make relevant Qt translations available as array via config.h # make relevant Qt translations available as array via config.h
include(ListToString) include(ListToString)
@ -191,231 +186,275 @@ list_to_string("," " \\\n QStringLiteral(\"" "\")" "${QT_TRANSLATION_FILES}"
# enable lrelease and add install target for localization # enable lrelease and add install target for localization
option(ENABLE_QT_TRANSLATIONS "specifies whether Qt translations should be updated/released" ON) option(ENABLE_QT_TRANSLATIONS "specifies whether Qt translations should be updated/released" ON)
if(ENABLE_QT_TRANSLATIONS AND TS_FILES) if (ENABLE_QT_TRANSLATIONS AND TS_FILES)
message(STATUS "Project has translations which will be released.") message(STATUS "Project has translations which will be released.")
set(APP_SPECIFIC_QT_TRANSLATIONS_AVAILABLE YES) set(APP_SPECIFIC_QT_TRANSLATIONS_AVAILABLE YES)
# the LinguistTools module is required # the LinguistTools module is required (but not add it to QT_MODULES because we don't link against it)
# (but not add it to QT_MODULES because we don't link against it)
find_package(Qt5LinguistTools REQUIRED) find_package(Qt5LinguistTools REQUIRED)
set(LUPDATE_OPTIONS "" CACHE STRING "specifies options passed to lupdate") set(LUPDATE_OPTIONS "" CACHE STRING "specifies options passed to lupdate")
# adds the translations and a target for it # adds the translations and a target for it
qt5_create_translation(QM_FILES qt5_create_translation(QM_FILES
${HEADER_FILES} ${SRC_FILES} ${HEADER_FILES}
${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES} ${WIDGETS_UI_FILES} ${SRC_FILES}
${QML_HEADER_FILES} ${QML_SRC_FILES} ${QML_RES_FILES} ${WIDGETS_HEADER_FILES}
${TS_FILES} ${WIDGETS_SRC_FILES}
OPTIONS ${LUPDATE_OPTIONS} ${WIDGETS_UI_FILES}
) ${QML_HEADER_FILES}
${QML_SRC_FILES}
${QML_RES_FILES}
${TS_FILES}
OPTIONS
${LUPDATE_OPTIONS})
add_custom_target(${META_PROJECT_NAME}_translations DEPENDS ${QM_FILES}) add_custom_target(${META_PROJECT_NAME}_translations DEPENDS ${QM_FILES})
if(NOT TARGET translations) if (NOT TARGET translations)
add_custom_target(translations DEPENDS ${META_PROJECT_NAME}_translations) add_custom_target(translations DEPENDS ${META_PROJECT_NAME}_translations)
else() else ()
add_dependencies(translations ${META_PROJECT_NAME}_translations) add_dependencies(translations ${META_PROJECT_NAME}_translations)
endif() endif ()
# add install target for translations # add install target for translations
if(NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS) if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
install(FILES ${QM_FILES} install(FILES ${QM_FILES} DESTINATION share/${META_PROJECT_NAME}/translations COMPONENT localization)
DESTINATION share/${META_PROJECT_NAME}/translations if (NOT TARGET install-localization)
COMPONENT localization
)
if(NOT TARGET install-localization)
set(LOCALIZATION_TARGET "install-localization") set(LOCALIZATION_TARGET "install-localization")
add_custom_target(${LOCALIZATION_TARGET} add_custom_target(${LOCALIZATION_TARGET}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=localization -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=localization -P
) "${CMAKE_BINARY_DIR}/cmake_install.cmake")
add_dependencies(${LOCALIZATION_TARGET} ${META_PROJECT_NAME}_translations) add_dependencies(${LOCALIZATION_TARGET} ${META_PROJECT_NAME}_translations)
endif() endif ()
endif() endif ()
list(APPEND APP_SPECIFIC_QT_TRANSLATION_FILES "${META_PROJECT_NAME}") list(APPEND APP_SPECIFIC_QT_TRANSLATION_FILES "${META_PROJECT_NAME}")
endif() endif ()
# make application specific translation available as array via config.h # make application specific translation available as array via config.h (even if this project has no translations, there
# (even if this project has no translations, there might be some from dependencies) # might be some from dependencies)
if(APP_SPECIFIC_QT_TRANSLATION_FILES) if (APP_SPECIFIC_QT_TRANSLATION_FILES)
list_to_string("," " \\\n QStringLiteral(\"" "\")" "${APP_SPECIFIC_QT_TRANSLATION_FILES}" APP_SPECIFIC_QT_TRANSLATION_FILES_ARRAY) list_to_string(","
else() " \\\n QStringLiteral(\""
"\")"
"${APP_SPECIFIC_QT_TRANSLATION_FILES}"
APP_SPECIFIC_QT_TRANSLATION_FILES_ARRAY)
else ()
set(APP_SPECIFIC_QT_TRANSLATIONS_AVAILABLE NO) set(APP_SPECIFIC_QT_TRANSLATIONS_AVAILABLE NO)
endif() endif ()
# built-in translations # built-in translations
if(BUILTIN_TRANSLATIONS AND (QM_FILES OR EXTERNAL_QM_FILES)) if (BUILTIN_TRANSLATIONS AND (QM_FILES OR EXTERNAL_QM_FILES))
# write a qrc file for the qm files and add it to the resource files # write a qrc file for the qm files and add it to the resource files
set(TRANSLATIONS_QRC_FILE_NAME "${META_PROJECT_VARNAME_LOWER}_translations.qrc") set(TRANSLATIONS_QRC_FILE_NAME "${META_PROJECT_VARNAME_LOWER}_translations.qrc")
set(TRANSLATIONS_QRC_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TRANSLATIONS_QRC_FILE_NAME}") set(TRANSLATIONS_QRC_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TRANSLATIONS_QRC_FILE_NAME}")
file(WRITE "${TRANSLATIONS_QRC_FILE}" "<RCC><qresource prefix=\"/translations\">") file(WRITE "${TRANSLATIONS_QRC_FILE}" "<RCC><qresource prefix=\"/translations\">")
foreach(QM_FILE ${QM_FILES} ${EXTERNAL_QM_FILES}) foreach (QM_FILE ${QM_FILES} ${EXTERNAL_QM_FILES})
get_filename_component(QM_FILE_NAME "${QM_FILE}" NAME) get_filename_component(QM_FILE_NAME "${QM_FILE}" NAME)
file(APPEND "${TRANSLATIONS_QRC_FILE}" "<file>${QM_FILE_NAME}</file>") file(APPEND "${TRANSLATIONS_QRC_FILE}" "<file>${QM_FILE_NAME}</file>")
endforeach() endforeach ()
file(APPEND "${TRANSLATIONS_QRC_FILE}" "</qresource></RCC>") file(APPEND "${TRANSLATIONS_QRC_FILE}" "</qresource></RCC>")
list(APPEND RES_FILES "${TRANSLATIONS_QRC_FILE}") list(APPEND RES_FILES "${TRANSLATIONS_QRC_FILE}")
list(APPEND AUTOGEN_DEPS ${QM_FILES} ${EXTERNAL_QM_FILES}) list(APPEND AUTOGEN_DEPS ${QM_FILES} ${EXTERNAL_QM_FILES})
list(APPEND BUILTIN_TRANSLATION_FILES "${TRANSLATIONS_QRC_FILE_NAME}") list(APPEND BUILTIN_TRANSLATION_FILES "${TRANSLATIONS_QRC_FILE_NAME}")
endif() endif ()
# generate DBus interfaces # generate DBus interfaces
if(DBUS_FILES) if (DBUS_FILES)
qt5_add_dbus_interfaces(GENERATED_DBUS_FILES ${DBUS_FILES}) qt5_add_dbus_interfaces(GENERATED_DBUS_FILES ${DBUS_FILES})
endif() endif ()
# add icons to be built-in # add icons to be built-in
if(REQUIRED_ICONS) if (REQUIRED_ICONS)
set(BUILTIN_ICON_THEMES "" CACHE STRING "specifies icon themes to be built-in") set(BUILTIN_ICON_THEMES "" CACHE STRING "specifies icon themes to be built-in")
option(BUILTIN_ICON_THEMES_IN_LIBRARIES "specifies whether icon themes should also be built-in when building libraries" OFF) option(BUILTIN_ICON_THEMES_IN_LIBRARIES "specifies whether icon themes should also be built-in when building libraries"
if(BUILTIN_ICON_THEMES AND (BUILTIN_ICON_THEMES_IN_LIBRARIES OR (NOT "${META_PROJECT_TYPE}" STREQUAL "library"))) OFF)
if (BUILTIN_ICON_THEMES AND (BUILTIN_ICON_THEMES_IN_LIBRARIES OR (NOT "${META_PROJECT_TYPE}" STREQUAL "library")))
set(ICON_THEME_FILES) set(ICON_THEME_FILES)
set(ICON_SEARCH_PATHS) set(ICON_SEARCH_PATHS)
if(CMAKE_FIND_ROOT_PATH) if (CMAKE_FIND_ROOT_PATH)
# find icons from the regular prefix when cross-compiling # find icons from the regular prefix when cross-compiling
list(APPEND ICON_SEARCH_PATHS "${CMAKE_FIND_ROOT_PATH}/share/icons") list(APPEND ICON_SEARCH_PATHS "${CMAKE_FIND_ROOT_PATH}/share/icons")
endif() endif ()
list(APPEND ICON_SEARCH_PATHS "${CMAKE_INSTALL_PREFIX}/share/icons") list(APPEND ICON_SEARCH_PATHS "${CMAKE_INSTALL_PREFIX}/share/icons")
list(APPEND ICON_SEARCH_PATHS "/usr/share/icons") list(APPEND ICON_SEARCH_PATHS "/usr/share/icons")
set(BUILTIN_ICONS_DIR "${CMAKE_CURRENT_BINARY_DIR}/icons") set(BUILTIN_ICONS_DIR "${CMAKE_CURRENT_BINARY_DIR}/icons")
set(DEFAULT_THEME_INDEX_FILE "${BUILTIN_ICONS_DIR}/default/index.theme") set(DEFAULT_THEME_INDEX_FILE "${BUILTIN_ICONS_DIR}/default/index.theme")
file(REMOVE_RECURSE "${BUILTIN_ICONS_DIR}") file(REMOVE_RECURSE "${BUILTIN_ICONS_DIR}")
file(MAKE_DIRECTORY "${BUILTIN_ICONS_DIR}") file(MAKE_DIRECTORY "${BUILTIN_ICONS_DIR}")
foreach(ICON_THEME ${BUILTIN_ICON_THEMES}) foreach (ICON_THEME ${BUILTIN_ICON_THEMES})
string(REGEX MATCHALL "([^:]+|[^:]+$)" ICON_THEME_PARTS "${ICON_THEME}") string(REGEX MATCHALL
"([^:]+|[^:]+$)"
ICON_THEME_PARTS
"${ICON_THEME}")
list(LENGTH ICON_THEME_PARTS ICON_THEME_PARTS_LENGTH) list(LENGTH ICON_THEME_PARTS ICON_THEME_PARTS_LENGTH)
if("${ICON_THEME_PARTS_LENGTH}" STREQUAL 2) if ("${ICON_THEME_PARTS_LENGTH}" STREQUAL 2)
list(GET ICON_THEME_PARTS 0 ICON_THEME) list(GET ICON_THEME_PARTS 0 ICON_THEME)
list(GET ICON_THEME_PARTS 1 NEW_ICON_THEME_NAME) list(GET ICON_THEME_PARTS 1 NEW_ICON_THEME_NAME)
else() else ()
set(NEW_ICON_THEME_NAME "${ICON_THEME}") set(NEW_ICON_THEME_NAME "${ICON_THEME}")
endif() endif ()
foreach(ICON_SEARCH_PATH ${ICON_SEARCH_PATHS}) foreach (ICON_SEARCH_PATH ${ICON_SEARCH_PATHS})
set(ICON_THEME_PATH "${ICON_SEARCH_PATH}/${ICON_THEME}") set(ICON_THEME_PATH "${ICON_SEARCH_PATH}/${ICON_THEME}")
set(NEW_ICON_THEME_PATH "${ICON_SEARCH_PATH}/${ICON_THEME}") set(NEW_ICON_THEME_PATH "${ICON_SEARCH_PATH}/${ICON_THEME}")
if(IS_DIRECTORY "${ICON_THEME_PATH}") if (IS_DIRECTORY "${ICON_THEME_PATH}")
message(STATUS "The specified icon theme \"${ICON_THEME}\" has been located under \"${ICON_THEME_PATH}\" and will be built-in.") message(
STATUS
"The specified icon theme \"${ICON_THEME}\" has been located under \"${ICON_THEME_PATH}\" and will be built-in."
)
# find index files # find index files
if(NOT ICON_THEME STREQUAL FALLBACK_ICON_THEME) if (NOT ICON_THEME STREQUAL FALLBACK_ICON_THEME)
file(GLOB GLOBBED_ICON_THEME_INDEX_FILES LIST_DIRECTORIES false "${ICON_THEME_PATH}/index.theme" "${ICON_THEME_PATH}/icon-theme.cache") file(GLOB GLOBBED_ICON_THEME_INDEX_FILES
else() LIST_DIRECTORIES
false
"${ICON_THEME_PATH}/index.theme"
"${ICON_THEME_PATH}/icon-theme.cache")
else ()
# only index.theme required when icons are provided as fallback anyways # only index.theme required when icons are provided as fallback anyways
file(GLOB GLOBBED_ICON_THEME_INDEX_FILES LIST_DIRECTORIES false "${ICON_THEME_PATH}/index.theme") file(GLOB GLOBBED_ICON_THEME_INDEX_FILES
endif() LIST_DIRECTORIES
false
"${ICON_THEME_PATH}/index.theme")
endif ()
# make the first specified built-in the default theme # make the first specified built-in the default theme
if(NOT EXISTS "${DEFAULT_THEME_INDEX_FILE}") if (NOT EXISTS "${DEFAULT_THEME_INDEX_FILE}")
file(MAKE_DIRECTORY "${BUILTIN_ICONS_DIR}/default") file(MAKE_DIRECTORY "${BUILTIN_ICONS_DIR}/default")
file(WRITE "${DEFAULT_THEME_INDEX_FILE}" "[Icon Theme]\nInherits=${NEW_ICON_THEME_NAME}") file(WRITE "${DEFAULT_THEME_INDEX_FILE}" "[Icon Theme]\nInherits=${NEW_ICON_THEME_NAME}")
list(APPEND ICON_THEME_FILES "<file>default/index.theme</file>") list(APPEND ICON_THEME_FILES "<file>default/index.theme</file>")
endif() endif ()
# find required icons, except the icon theme is provided as fallback anyways # find required icons, except the icon theme is provided as fallback anyways
if(NOT ICON_THEME STREQUAL FALLBACK_ICON_THEME) if (NOT ICON_THEME STREQUAL FALLBACK_ICON_THEME)
set(GLOB_PATTERNS) set(GLOB_PATTERNS)
foreach(REQUIRED_ICON ${REQUIRED_ICONS}) foreach (REQUIRED_ICON ${REQUIRED_ICONS})
list(APPEND GLOB_PATTERNS list(APPEND GLOB_PATTERNS
"${ICON_THEME_PATH}/${REQUIRED_ICON}" "${ICON_THEME_PATH}/${REQUIRED_ICON}"
"${ICON_THEME_PATH}/${REQUIRED_ICON}.*" "${ICON_THEME_PATH}/${REQUIRED_ICON}.*"
"${ICON_THEME_PATH}/*/${REQUIRED_ICON}" "${ICON_THEME_PATH}/*/${REQUIRED_ICON}"
"${ICON_THEME_PATH}/*/${REQUIRED_ICON}.*" "${ICON_THEME_PATH}/*/${REQUIRED_ICON}.*")
endforeach ()
file(GLOB_RECURSE GLOBBED_ICON_THEME_FILES
LIST_DIRECTORIES
false
${GLOB_PATTERNS})
else ()
message(
STATUS
"Icon files for specified theme \"${ICON_THEME}\" are skipped because these are provided as fallback anyways."
) )
endforeach()
file(GLOB_RECURSE GLOBBED_ICON_THEME_FILES LIST_DIRECTORIES false ${GLOB_PATTERNS})
else()
message(STATUS "Icon files for specified theme \"${ICON_THEME}\" are skipped because these are provided as fallback anyways.")
set(GLOBBED_ICON_THEME_FILES) set(GLOBBED_ICON_THEME_FILES)
endif() endif ()
# make temporary copy of required icons and create resource list for Qt # make temporary copy of required icons and create resource list for Qt
foreach(ICON_THEME_FILE ${GLOBBED_ICON_THEME_INDEX_FILES} ${GLOBBED_ICON_THEME_FILES}) foreach (ICON_THEME_FILE ${GLOBBED_ICON_THEME_INDEX_FILES} ${GLOBBED_ICON_THEME_FILES})
# resolve symlinks # resolve symlinks
if(IS_SYMLINK "${ICON_THEME_FILE}") if (IS_SYMLINK "${ICON_THEME_FILE}")
string(REGEX REPLACE "^${ICON_SEARCH_PATH}/" "" ICON_THEME_FILE_RELATIVE_PATH "${ICON_THEME_FILE}") string(REGEX
string(REGEX REPLACE "(^[^/\\]+)" "${NEW_ICON_THEME_NAME}" NEW_ICON_THEME_FILE_RELATIVE_PATH "${ICON_THEME_FILE_RELATIVE_PATH}") REPLACE "^${ICON_SEARCH_PATH}/"
""
ICON_THEME_FILE_RELATIVE_PATH
"${ICON_THEME_FILE}")
string(REGEX
REPLACE "(^[^/\\]+)"
"${NEW_ICON_THEME_NAME}"
NEW_ICON_THEME_FILE_RELATIVE_PATH
"${ICON_THEME_FILE_RELATIVE_PATH}")
set(ICON_THEME_FILE_ALIAS " alias=\"${NEW_ICON_THEME_FILE_RELATIVE_PATH}\"") set(ICON_THEME_FILE_ALIAS " alias=\"${NEW_ICON_THEME_FILE_RELATIVE_PATH}\"")
get_filename_component(ICON_THEME_FILE "${ICON_THEME_FILE}" REALPATH) get_filename_component(ICON_THEME_FILE "${ICON_THEME_FILE}" REALPATH)
else() else ()
unset(ICON_THEME_FILE_ALIAS) unset(ICON_THEME_FILE_ALIAS)
endif() endif ()
string(REGEX REPLACE "^${ICON_SEARCH_PATH}/" "" ICON_THEME_FILE_RELATIVE_PATH "${ICON_THEME_FILE}") string(REGEX
string(REGEX REPLACE "(^[^/\\]+)" "${NEW_ICON_THEME_NAME}" NEW_ICON_THEME_FILE_RELATIVE_PATH "${ICON_THEME_FILE_RELATIVE_PATH}") REPLACE "^${ICON_SEARCH_PATH}/"
""
ICON_THEME_FILE_RELATIVE_PATH
"${ICON_THEME_FILE}")
string(REGEX
REPLACE "(^[^/\\]+)"
"${NEW_ICON_THEME_NAME}"
NEW_ICON_THEME_FILE_RELATIVE_PATH
"${ICON_THEME_FILE_RELATIVE_PATH}")
get_filename_component(ICON_THEME_FILE_DIR "${ICON_THEME_FILE_RELATIVE_PATH}" DIRECTORY) get_filename_component(ICON_THEME_FILE_DIR "${ICON_THEME_FILE_RELATIVE_PATH}" DIRECTORY)
string(REGEX REPLACE "(^[^/\\]+)" "${NEW_ICON_THEME_NAME}" NEW_ICON_THEME_FILE_DIR "${ICON_THEME_FILE_DIR}") string(REGEX
REPLACE "(^[^/\\]+)"
"${NEW_ICON_THEME_NAME}"
NEW_ICON_THEME_FILE_DIR
"${ICON_THEME_FILE_DIR}")
file(MAKE_DIRECTORY "${BUILTIN_ICONS_DIR}/${NEW_ICON_THEME_FILE_DIR}") file(MAKE_DIRECTORY "${BUILTIN_ICONS_DIR}/${NEW_ICON_THEME_FILE_DIR}")
file(COPY "${ICON_THEME_FILE}" DESTINATION "${BUILTIN_ICONS_DIR}/${NEW_ICON_THEME_FILE_DIR}") file(COPY "${ICON_THEME_FILE}" DESTINATION "${BUILTIN_ICONS_DIR}/${NEW_ICON_THEME_FILE_DIR}")
list(APPEND ICON_THEME_FILES "<file${ICON_THEME_FILE_ALIAS}>${NEW_ICON_THEME_FILE_RELATIVE_PATH}</file>") list(APPEND ICON_THEME_FILES
endforeach() "<file${ICON_THEME_FILE_ALIAS}>${NEW_ICON_THEME_FILE_RELATIVE_PATH}</file>")
endforeach ()
break() break()
endif() endif ()
unset(ICON_THEME_PATH) unset(ICON_THEME_PATH)
endforeach() endforeach ()
if(NOT ICON_THEME_PATH) if (NOT ICON_THEME_PATH)
message(FATAL_ERROR "The specified icon theme \"${ICON_THEME}\" coud not be found.") message(FATAL_ERROR "The specified icon theme \"${ICON_THEME}\" coud not be found.")
endif() endif ()
endforeach() endforeach ()
set(BUILTIN_ICON_THEMES_QRC_FILE "${CMAKE_CURRENT_BINARY_DIR}/icons/${META_PROJECT_NAME}_builtinicons.qrc") set(BUILTIN_ICON_THEMES_QRC_FILE "${CMAKE_CURRENT_BINARY_DIR}/icons/${META_PROJECT_NAME}_builtinicons.qrc")
list(REMOVE_DUPLICATES ICON_THEME_FILES) list(REMOVE_DUPLICATES ICON_THEME_FILES)
string(CONCAT BUILTIN_ICON_THEMES_QRC_FILE_CONTENT "<RCC><qresource prefix=\"/icons\">" ${ICON_THEME_FILES} "</qresource></RCC>") string(CONCAT BUILTIN_ICON_THEMES_QRC_FILE_CONTENT
"<RCC><qresource prefix=\"/icons\">"
${ICON_THEME_FILES}
"</qresource></RCC>")
file(WRITE "${BUILTIN_ICON_THEMES_QRC_FILE}" "${BUILTIN_ICON_THEMES_QRC_FILE_CONTENT}") file(WRITE "${BUILTIN_ICON_THEMES_QRC_FILE}" "${BUILTIN_ICON_THEMES_QRC_FILE_CONTENT}")
list(APPEND RES_FILES "${BUILTIN_ICON_THEMES_QRC_FILE}") list(APPEND RES_FILES "${BUILTIN_ICON_THEMES_QRC_FILE}")
endif() endif ()
endif() endif ()
# export Qt resources from specified RES_FILES # export Qt resources from specified RES_FILES
foreach(RES_FILE ${RES_FILES}) foreach (RES_FILE ${RES_FILES})
get_filename_component(RES_EXT ${RES_FILE} EXT) get_filename_component(RES_EXT ${RES_FILE} EXT)
if(RES_EXT STREQUAL ".qrc") if (RES_EXT STREQUAL ".qrc")
get_filename_component(RES_NAME ${RES_FILE} NAME_WE) get_filename_component(RES_NAME ${RES_FILE} NAME_WE)
list(APPEND QT_RESOURCES "${RES_NAME}") list(APPEND QT_RESOURCES "${RES_NAME}")
endif() endif ()
endforeach() endforeach ()
# export Qt resources required by static libraries the static library depends on # export Qt resources required by static libraries the static library depends on
if(STATIC_LIBRARIES_QT_RESOURCES) if (STATIC_LIBRARIES_QT_RESOURCES)
list(REMOVE_DUPLICATES STATIC_LIBRARIES_QT_RESOURCES) list(REMOVE_DUPLICATES STATIC_LIBRARIES_QT_RESOURCES)
list(APPEND QT_RESOURCES ${STATIC_LIBRARIES_QT_RESOURCES}) list(APPEND QT_RESOURCES ${STATIC_LIBRARIES_QT_RESOURCES})
endif() endif ()
# enable Qt resources required by static libraries the shared library or application depends on # enable Qt resources required by static libraries the shared library or application depends on
if(LIBRARIES_QT_RESOURCES) if (LIBRARIES_QT_RESOURCES)
list(REMOVE_DUPLICATES LIBRARIES_QT_RESOURCES) list(REMOVE_DUPLICATES LIBRARIES_QT_RESOURCES)
# make enabling resources of static dependencies available via config.h # make enabling resources of static dependencies available via config.h
unset(ENABLE_QT_RESOURCES_OF_STATIC_DEPENDENCIES) unset(ENABLE_QT_RESOURCES_OF_STATIC_DEPENDENCIES)
foreach(QT_RESOURCE ${LIBRARIES_QT_RESOURCES}) foreach (QT_RESOURCE ${LIBRARIES_QT_RESOURCES})
set(ENABLE_QT_RESOURCES_OF_STATIC_DEPENDENCIES set(
ENABLE_QT_RESOURCES_OF_STATIC_DEPENDENCIES
"${ENABLE_QT_RESOURCES_OF_STATIC_DEPENDENCIES} \\\n struct initializer_${QT_RESOURCE} { \\\n initializer_${QT_RESOURCE}() { Q_INIT_RESOURCE(${QT_RESOURCE}); } \\\n ~initializer_${QT_RESOURCE}() { Q_CLEANUP_RESOURCE(${QT_RESOURCE}); } \\\n } dummy_${QT_RESOURCE};" "${ENABLE_QT_RESOURCES_OF_STATIC_DEPENDENCIES} \\\n struct initializer_${QT_RESOURCE} { \\\n initializer_${QT_RESOURCE}() { Q_INIT_RESOURCE(${QT_RESOURCE}); } \\\n ~initializer_${QT_RESOURCE}() { Q_CLEANUP_RESOURCE(${QT_RESOURCE}); } \\\n } dummy_${QT_RESOURCE};"
) )
endforeach() endforeach ()
endif() endif ()
# prevent duplicated resources # prevent duplicated resources
if(QT_RESOURCES) if (QT_RESOURCES)
list(REMOVE_DUPLICATES QT_RESOURCES) list(REMOVE_DUPLICATES QT_RESOURCES)
endif() endif ()
# enable moc, uic and rcc by default for all targets # enable moc, uic and rcc by default for all targets
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(WIDGETS_UI_FILES AND WIDGETS_GUI) if (WIDGETS_UI_FILES AND WIDGETS_GUI)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
if(INSTALL_UI_HEADER) if (INSTALL_UI_HEADER)
# also add install for header files generated by uic # also add install for header files generated by uic
foreach(UI_FILE WIDGETS_UI_FILES) foreach (UI_FILE WIDGETS_UI_FILES)
get_filename_component(UI_NAME "${UI_FILE}" NAME_WE) get_filename_component(UI_NAME "${UI_FILE}" NAME_WE)
install( install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ui_${UI_NAME}.h"
FILES "${CMAKE_CURRENT_BINARY_DIR}/ui_${UI_NAME}.h" DESTINATION "include/${META_PROJECT_NAME}/ui"
DESTINATION "include/${META_PROJECT_NAME}/ui" COMPONENT ui-header)
COMPONENT ui-header endforeach ()
) endif ()
endforeach() endif ()
endif()
endif()
# add configuration header for Qt-specific configuration # add configuration header for Qt-specific configuration
include(TemplateFinder) include(TemplateFinder)
find_template_file("qtconfig.h" QT_UTILITIES QT_CONFIG_H_TEMPLATE_FILE) find_template_file("qtconfig.h" QT_UTILITIES QT_CONFIG_H_TEMPLATE_FILE)
configure_file( configure_file("${QT_CONFIG_H_TEMPLATE_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/resources/qtconfig.h")
"${QT_CONFIG_H_TEMPLATE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/resources/qtconfig.h"
)
set(QT_CONFIGURED YES) set(QT_CONFIGURED YES)

View File

@ -1,68 +1,75 @@
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR) cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
if(NOT BASIC_PROJECT_CONFIG_DONE) if (NOT BASIC_PROJECT_CONFIG_DONE)
message(FATAL_ERROR "Before including the QtGuiConfig module, the BasicConfig module must be included.") message(FATAL_ERROR "Before including the QtGuiConfig module, the BasicConfig module must be included.")
endif() endif ()
if(QT_CONFIGURED) if (QT_CONFIGURED)
message(FATAL_ERROR "The QtGuiConfig module can not be included when Qt usage has already been configured.") message(FATAL_ERROR "The QtGuiConfig module can not be included when Qt usage has already been configured.")
endif() endif ()
if(TARGET_CONFIG_DONE) if (TARGET_CONFIG_DONE)
message(FATAL_ERROR "Can not include QtGuiConfig module when targets are already configured.") message(FATAL_ERROR "Can not include QtGuiConfig module when targets are already configured.")
endif() endif ()
# enable Qt Widgets GUI # enable Qt Widgets GUI
if(WIDGETS_GUI) if (WIDGETS_GUI)
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS GUI_QTWIDGETS) list(APPEND META_PRIVATE_COMPILE_DEFINITIONS GUI_QTWIDGETS)
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_GUI_QTWIDGETS) list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_GUI_QTWIDGETS)
list(APPEND WIDGETS_FILES ${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES} ${WIDGETS_RES_FILES} ${WIDGETS_UI_FILES}) list(APPEND WIDGETS_FILES
${WIDGETS_HEADER_FILES}
${WIDGETS_SRC_FILES}
${WIDGETS_RES_FILES}
${WIDGETS_UI_FILES})
list(APPEND ADDITIONAL_HEADER_FILES ${WIDGETS_HEADER_FILES}) list(APPEND ADDITIONAL_HEADER_FILES ${WIDGETS_HEADER_FILES})
if(WIDGETS_FILES) if (WIDGETS_FILES)
list(APPEND ADDITIONAL_QT_MODULES Widgets) list(APPEND ADDITIONAL_QT_MODULES Widgets)
message(STATUS "Building with Qt Widgets GUI.") message(STATUS "Building with Qt Widgets GUI.")
else() else ()
message(STATUS "Qt Widgets GUI is not available.") message(STATUS "Qt Widgets GUI is not available.")
endif() endif ()
else() else ()
message(STATUS "Building WITHOUT Qt Widgets GUI.") message(STATUS "Building WITHOUT Qt Widgets GUI.")
endif() endif ()
# enable Qt Quick GUI # enable Qt Quick GUI
if(QUICK_GUI) if (QUICK_GUI)
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS GUI_QTQUICK) list(APPEND META_PRIVATE_COMPILE_DEFINITIONS GUI_QTQUICK)
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_GUI_QTQUICK) list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_GUI_QTQUICK)
list(APPEND QML_FILES ${QML_HEADER_FILES} ${QML_SRC_FILES} ${QML_RES_FILES}) list(APPEND QML_FILES
${QML_HEADER_FILES}
${QML_SRC_FILES}
${QML_RES_FILES})
list(APPEND ADDITIONAL_HEADER_FILES ${QML_HEADER_FILES}) list(APPEND ADDITIONAL_HEADER_FILES ${QML_HEADER_FILES})
if(QML_FILES) if (QML_FILES)
list(APPEND ADDITIONAL_QT_MODULES Qml Quick) list(APPEND ADDITIONAL_QT_MODULES Qml Quick)
list(APPEND ADDITIONAL_QT_REPOS "declarative") list(APPEND ADDITIONAL_QT_REPOS "declarative")
message(STATUS "Building with Qt Quick GUI.") message(STATUS "Building with Qt Quick GUI.")
# enable QML debugging # enable QML debugging
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if (CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS QT_QML_DEBUG) list(APPEND META_PRIVATE_COMPILE_DEFINITIONS QT_QML_DEBUG)
endif() endif ()
# enable Qt Quick Controls 2 # enable Qt Quick Controls 2
if(META_USE_QQC2) if (META_USE_QQC2)
list(APPEND ADDITIONAL_QT_MODULES QuickControls2) list(APPEND ADDITIONAL_QT_MODULES QuickControls2)
endif() endif ()
else() else ()
message(STATUS "Qt Quick GUI is not available.") message(STATUS "Qt Quick GUI is not available.")
endif() endif ()
else() else ()
message(STATUS "Building WITHOUT Qt Quick GUI.") message(STATUS "Building WITHOUT Qt Quick GUI.")
endif() endif ()
# do further GUI-related configuration only if at least one kind of GUI is enabled (tageditor allows building without GUI # do further GUI-related configuration only if at least one kind of GUI is enabled (tageditor allows building without GUI so
# so this is a valid configuration) # this is a valid configuration)
if(WIDGETS_GUI OR QUICK_GUI) if (WIDGETS_GUI OR QUICK_GUI)
if(WIN32) if (WIN32)
# set "GUI-type" to WIN32 to hide console under Windows # set "GUI-type" to WIN32 to hide console under Windows
set(GUI_TYPE WIN32) set(GUI_TYPE WIN32)
elseif(APPLE) elseif (APPLE)
# make the GUI application a "bundle" under MacOSX # make the GUI application a "bundle" under MacOSX
set(GUI_TYPE MACOSX_BUNDLE) set(GUI_TYPE MACOSX_BUNDLE)
endif() endif ()
# add source files requried by both GUI variants # add source files requried by both GUI variants
list(APPEND SRC_FILES ${GUI_SRC_FILES}) list(APPEND SRC_FILES ${GUI_SRC_FILES})
@ -71,9 +78,10 @@ if(WIDGETS_GUI OR QUICK_GUI)
# add option for enabling/disabling static Qt plugins # add option for enabling/disabling static Qt plugins
option(SVG_SUPPORT "whether to link against the SVG image format plugin (only relevant when using static Qt)" ON) option(SVG_SUPPORT "whether to link against the SVG image format plugin (only relevant when using static Qt)" ON)
option(SVG_ICON_SUPPORT "whether to link against the SVG icon engine (only relevant when using static Qt)" ON) option(SVG_ICON_SUPPORT "whether to link against the SVG icon engine (only relevant when using static Qt)" ON)
set(IMAGE_FORMAT_SUPPORT "Gif;ICO;Jpeg" CACHE STRING "specifies the image format plugins to link against (only relevant when using static Qt)") set(IMAGE_FORMAT_SUPPORT "Gif;ICO;Jpeg"
CACHE STRING "specifies the image format plugins to link against (only relevant when using static Qt)")
if (ANDROID) if (ANDROID)
list(APPEND ADDITIONAL_QT_MODULES Svg) list(APPEND ADDITIONAL_QT_MODULES Svg)
endif() endif ()
endif() endif ()

View File

@ -3,52 +3,63 @@ cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
# defines helper to link against Qt dynamically or statically # defines helper to link against Qt dynamically or statically
# prevent multiple inclusion # prevent multiple inclusion
if(DEFINED QT_LINKAGE_DETERMINED) if (DEFINED QT_LINKAGE_DETERMINED)
return() return()
endif() endif ()
set(QT_LINKAGE_DETERMINED ON) set(QT_LINKAGE_DETERMINED ON)
include(3rdParty) include(3rdParty)
# by default, require Qt 5.6 or higher # by default, require Qt 5.6 or higher
if(NOT META_QT5_VERSION) if (NOT META_QT5_VERSION)
set(META_QT5_VERSION 5.6) set(META_QT5_VERSION 5.6)
endif() endif ()
# determine whether to use dynamic or shared version of Qt (or both) # determine whether to use dynamic or shared version of Qt (or both)
set(QT_LINKAGE "AUTO_LINKAGE" CACHE STRING "specifies whether to link statically or dynamically against Qt 5") set(QT_LINKAGE "AUTO_LINKAGE" CACHE STRING "specifies whether to link statically or dynamically against Qt 5")
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")) 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) set(USE_STATIC_QT_BUILD ON)
message(STATUS "Checking for static Qt 5 libraries to use in project ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}") message(
endif() STATUS "Checking for static Qt 5 libraries to use in project ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}")
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")) 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) 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}") message(
endif() 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) macro (find_qt5_module MODULE REQUIRED)
# determine whether the library is required or optional # determine whether the library is required or optional FIXME: improve passing required argument
# FIXME: improve passing required argument if ("${REQUIRED}" STREQUAL "OPTIONAL")
if("${REQUIRED}" STREQUAL "OPTIONAL")
unset(QT_5_${MODULE}_REQUIRED) unset(QT_5_${MODULE}_REQUIRED)
elseif("${REQUIRED}" STREQUAL "REQUIRED") elseif ("${REQUIRED}" STREQUAL "REQUIRED")
set(QT_5_${MODULE}_REQUIRED "REQUIRED") set(QT_5_${MODULE}_REQUIRED "REQUIRED")
else() else ()
message(FATAL_ERROR "Invalid use of link_against_library; must specify either REQUIRED or OPTIONAL.") message(FATAL_ERROR "Invalid use of link_against_library; must specify either REQUIRED or OPTIONAL.")
endif() endif ()
# find static version # find static version
if(USE_STATIC_QT_BUILD) if (USE_STATIC_QT_BUILD)
# check for 'Static'-prefixed CMake module first # check for 'Static'-prefixed CMake module first - patched mingw-w64-qt5 packages providing those files are available
# - patched mingw-w64-qt5 packages providing those files are available in my PKGBUILDs repository # in my PKGBUILDs repository - has the advantage that usage of dynamic and static Qt during the same build is
# - has the advantage that usage of dynamic and static Qt during the same build is possible # possible
find_package(StaticQt5${MODULE} ${META_QT5_VERSION}) find_package(StaticQt5${MODULE} ${META_QT5_VERSION})
if(StaticQt5${MODULE}_FOUND) if (StaticQt5${MODULE}_FOUND)
if(TARGET StaticQt5::${MODULE}) if (TARGET StaticQt5::${MODULE})
set(QT5_${MODULE}_STATIC_PREFIX "StaticQt5::") set(QT5_${MODULE}_STATIC_PREFIX "StaticQt5::")
else() else ()
set(QT5_${MODULE}_STATIC_PREFIX "Qt5::static::") set(QT5_${MODULE}_STATIC_PREFIX "Qt5::static::")
endif() endif ()
set(QT5_${MODULE}_STATIC_LIB "${QT5_${MODULE}_STATIC_PREFIX}${MODULE}") set(QT5_${MODULE}_STATIC_LIB "${QT5_${MODULE}_STATIC_PREFIX}${MODULE}")
set(QT5_${MODULE}_ASSUME_STATIC OFF) set(QT5_${MODULE}_ASSUME_STATIC OFF)
set(QT5_${MODULE}_FOUND ON) set(QT5_${MODULE}_FOUND ON)
@ -56,74 +67,91 @@ macro(find_qt5_module MODULE REQUIRED)
set(PC_PKG_STATIC_Qt5_${MODULE} "StaticQt5${MODULE}") set(PC_PKG_STATIC_Qt5_${MODULE} "StaticQt5${MODULE}")
set(PC_PKG_STATIC_StaticQt5_${MODULE} "StaticQt5${MODULE}") set(PC_PKG_STATIC_StaticQt5_${MODULE} "StaticQt5${MODULE}")
set(PC_PKG_STATIC_Qt5_static_${MODULE} "StaticQt5${MODULE}") set(PC_PKG_STATIC_Qt5_static_${MODULE} "StaticQt5${MODULE}")
else() else ()
# consider the regular Qt package (without "Static" prefix) the static version if # consider the regular Qt package (without "Static" prefix) the static version if static Qt is required and Qt
# static Qt is required and Qt package with "Static" prefix doesn't exist # package with "Static" prefix doesn't exist (fallback if not using patched version of Qt mentioned above)
# (fallback if not using patched version of Qt mentioned above)
find_package(Qt5${MODULE} ${META_QT5_VERSION} ${QT_5_${MODULE}_REQUIRED}) find_package(Qt5${MODULE} ${META_QT5_VERSION} ${QT_5_${MODULE}_REQUIRED})
if(Qt5${MODULE}_FOUND) if (Qt5${MODULE}_FOUND)
set(QT5_${MODULE}_STATIC_PREFIX "Qt5::") set(QT5_${MODULE}_STATIC_PREFIX "Qt5::")
set(QT5_${MODULE}_STATIC_LIB "${QT5_${MODULE}_STATIC_PREFIX}${MODULE}") set(QT5_${MODULE}_STATIC_LIB "${QT5_${MODULE}_STATIC_PREFIX}${MODULE}")
set(QT5_${MODULE}_ASSUME_STATIC ON) set(QT5_${MODULE}_ASSUME_STATIC ON)
set(QT5_${MODULE}_FOUND ON) set(QT5_${MODULE}_FOUND ON)
# reverse lookup for pkg-config # reverse lookup for pkg-config
set(PC_PKG_STATIC_Qt5_${MODULE} "Qt5${MODULE}") set(PC_PKG_STATIC_Qt5_${MODULE} "Qt5${MODULE}")
message(WARNING "Building static libs and/or static Qt linkage has been enabled. Hence assuming provided Qt 5 module ${MODULE} is static.") message(
endif() WARNING
endif() "Building static libs and/or static Qt linkage has been enabled. Hence assuming provided Qt 5 module ${MODULE} is static."
)
endif ()
endif ()
# use INTERFACE_LINK_LIBRARIES_RELEASE of the imported target as general INTERFACE_LINK_LIBRARIES to get correct transitive dependencies # use INTERFACE_LINK_LIBRARIES_RELEASE of the imported target as general INTERFACE_LINK_LIBRARIES to get correct
# under any configuration # transitive dependencies under any configuration
if(StaticQt5${MODULE}_FOUND OR Qt5${MODULE}_FOUND) if (StaticQt5${MODULE}_FOUND OR Qt5${MODULE}_FOUND)
get_target_property(QT5_${MODULE}_STATIC_LIB_DEPS "${QT5_${MODULE}_STATIC_LIB}" INTERFACE_LINK_LIBRARIES_RELEASE) get_target_property(QT5_${MODULE}_STATIC_LIB_DEPS "${QT5_${MODULE}_STATIC_LIB}" INTERFACE_LINK_LIBRARIES_RELEASE)
set_target_properties("${QT5_${MODULE}_STATIC_LIB}" PROPERTIES INTERFACE_LINK_LIBRARIES "${QT5_${MODULE}_STATIC_LIB_DEPS}") set_target_properties("${QT5_${MODULE}_STATIC_LIB}"
endif() PROPERTIES INTERFACE_LINK_LIBRARIES "${QT5_${MODULE}_STATIC_LIB_DEPS}")
endif() endif ()
endif ()
# find dynamic version # find dynamic version
if(USE_SHARED_QT_BUILD) if (USE_SHARED_QT_BUILD)
if(QT5_${MODULE}_ASSUME_STATIC) if (QT5_${MODULE}_ASSUME_STATIC)
message(FATAL_ERROR "The provided Qt 5 module ${MODULE} is assumed to be static. However, a shared version is required for building dynamic libs and/or dynamic Qt linkage.") message(
endif() FATAL_ERROR
"The provided Qt 5 module ${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} ${META_QT5_VERSION} ${QT_5_${MODULE}_REQUIRED}) find_package(Qt5${MODULE} ${META_QT5_VERSION} ${QT_5_${MODULE}_REQUIRED})
if(Qt5${MODULE}_FOUND) if (Qt5${MODULE}_FOUND)
set(QT5_${MODULE}_DYNAMIC_LIB Qt5::${MODULE}) set(QT5_${MODULE}_DYNAMIC_LIB Qt5::${MODULE})
set(QT5_${MODULE}_FOUND ON) set(QT5_${MODULE}_FOUND ON)
# reverse lookup for pkg-config # reverse lookup for pkg-config
set(PC_PKG_SHARED_Qt5_${MODULE} "Qt5${MODULE}") set(PC_PKG_SHARED_Qt5_${MODULE} "Qt5${MODULE}")
endif() endif ()
endif() endif ()
endmacro() endmacro ()
macro(use_qt5_module MODULE REQUIRED) macro (use_qt5_module MODULE REQUIRED)
if(${MODULE} IN_LIST META_PUBLIC_QT_MODULES) if (${MODULE} IN_LIST META_PUBLIC_QT_MODULES)
list(APPEND META_PUBLIC_SHARED_LIB_DEPENDS "${QT5_${MODULE}_DYNAMIC_LIB}") list(APPEND META_PUBLIC_SHARED_LIB_DEPENDS "${QT5_${MODULE}_DYNAMIC_LIB}")
list(APPEND META_PUBLIC_STATIC_LIB_DEPENDS "${QT5_${MODULE}_STATIC_LIB}") list(APPEND META_PUBLIC_STATIC_LIB_DEPENDS "${QT5_${MODULE}_STATIC_LIB}")
endif() endif ()
link_against_library("QT5_${MODULE}" "${QT_LINKAGE}" "${REQUIRED}") link_against_library("QT5_${MODULE}" "${QT_LINKAGE}" "${REQUIRED}")
endmacro() endmacro ()
macro(use_static_qt5_plugin MODULE PLUGIN FOR_SHARED_TARGET FOR_STATIC_TARGET) macro (use_static_qt5_plugin MODULE PLUGIN FOR_SHARED_TARGET FOR_STATIC_TARGET)
if("${FOR_SHARED_TARGET}") if ("${FOR_SHARED_TARGET}")
list(APPEND PRIVATE_LIBRARIES "${QT5_${MODULE}_STATIC_PREFIX}Q${PLUGIN}Plugin") list(APPEND PRIVATE_LIBRARIES "${QT5_${MODULE}_STATIC_PREFIX}Q${PLUGIN}Plugin")
message(STATUS "Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} against static Qt 5 plugin ${QT5_${MODULE}_STATIC_PREFIX}Q${PLUGIN}Plugin") message(
endif() STATUS
if("${FOR_STATIC_TARGET}") "Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} against static Qt 5 plugin ${QT5_${MODULE}_STATIC_PREFIX}Q${PLUGIN}Plugin"
)
endif ()
if ("${FOR_STATIC_TARGET}")
list(APPEND PRIVATE_STATIC_LIBRARIES "${QT5_${MODULE}_STATIC_PREFIX}Q${PLUGIN}Plugin") list(APPEND PRIVATE_STATIC_LIBRARIES "${QT5_${MODULE}_STATIC_PREFIX}Q${PLUGIN}Plugin")
message(STATUS "Adding static Qt 5 plugin ${QT5_${MODULE}_STATIC_PREFIX}Q${PLUGIN}Plugin to dependencies of static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}") message(
endif() STATUS
endmacro() "Adding static Qt 5 plugin ${QT5_${MODULE}_STATIC_PREFIX}Q${PLUGIN}Plugin to dependencies of static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}"
)
endif ()
endmacro ()
macro(query_qmake_variable QMAKE_VARIABLE) macro (query_qmake_variable QMAKE_VARIABLE)
get_target_property(QMAKE_BIN Qt5::qmake IMPORTED_LOCATION) get_target_property(QMAKE_BIN Qt5::qmake IMPORTED_LOCATION)
execute_process( execute_process(COMMAND "${QMAKE_BIN}" -query "${QMAKE_VARIABLE}"
COMMAND "${QMAKE_BIN}" -query "${QMAKE_VARIABLE}" RESULT_VARIABLE "${QMAKE_VARIABLE}_RESULT"
RESULT_VARIABLE "${QMAKE_VARIABLE}_RESULT" OUTPUT_VARIABLE "${QMAKE_VARIABLE}")
OUTPUT_VARIABLE "${QMAKE_VARIABLE}" if (NOT "${${QMAKE_VARIABLE}_RESULT}" STREQUAL 0 OR "${${QMAKE_VARIABLE}}" STREQUAL "")
) message(
if(NOT "${${QMAKE_VARIABLE}_RESULT}" STREQUAL 0 OR "${${QMAKE_VARIABLE}}" STREQUAL "") FATAL_ERROR
message(FATAL_ERROR "Unable to read qmake variable ${QMAKE_VARIABLE} via \"${QMAKE_BIN} -query ${QMAKE_VARIABLE}\"; output was \"${${QMAKE_VARIABLE}}\".") "Unable to read qmake variable ${QMAKE_VARIABLE} via \"${QMAKE_BIN} -query ${QMAKE_VARIABLE}\"; output was \"${${QMAKE_VARIABLE}}\"."
endif() )
string(REGEX REPLACE "\n$" "" "${QMAKE_VARIABLE}" "${${QMAKE_VARIABLE}}") endif ()
string(REGEX
REPLACE "\n$"
""
"${QMAKE_VARIABLE}"
"${${QMAKE_VARIABLE}}")
message(STATUS "qmake variable ${QMAKE_VARIABLE} is ${${QMAKE_VARIABLE}}") message(STATUS "qmake variable ${QMAKE_VARIABLE} is ${${QMAKE_VARIABLE}}")
endmacro() endmacro ()

View File

@ -1,79 +1,74 @@
# determines the web view provider (either Qt WebKit or Qt WebEngine) # determines the web view provider (either Qt WebKit or Qt WebEngine)
if(TARGET_CONFIG_DONE) if (TARGET_CONFIG_DONE)
message(FATAL_ERROR "Can not include WebViewProviderConfig module when targets are already configured.") message(FATAL_ERROR "Can not include WebViewProviderConfig module when targets are already configured.")
endif() endif ()
include(QtLinkage) include(QtLinkage)
set(WEBVIEW_PROVIDER "auto" CACHE STRING "specifies the web view provider: auto (default), webkit, webengine or none") set(WEBVIEW_PROVIDER "auto" CACHE STRING "specifies the web view provider: auto (default), webkit, webengine or none")
if(NOT WEBVIEW_PROVIDER OR "${WEBVIEW_PROVIDER}" STREQUAL "auto") if (NOT WEBVIEW_PROVIDER OR "${WEBVIEW_PROVIDER}" STREQUAL "auto")
find_qt5_module(WebKitWidgets OPTIONAL) find_qt5_module(WebKitWidgets OPTIONAL)
if(QT5_WebKitWidgets_FOUND) if (QT5_WebKitWidgets_FOUND)
set(WEBVIEW_PROVIDER WebKitWidgets) set(WEBVIEW_PROVIDER WebKitWidgets)
set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_WEBKIT") set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_WEBKIT")
message(STATUS "No web view provider explicitly specified, defaulting to Qt WebKit.") message(STATUS "No web view provider explicitly specified, defaulting to Qt WebKit.")
else() else ()
find_qt5_module(WebEngineWidgets OPTIONAL) find_qt5_module(WebEngineWidgets OPTIONAL)
if(QT5_WebEngineWidgets_FOUND) if (QT5_WebEngineWidgets_FOUND)
set(WEBVIEW_PROVIDER WebEngineWidgets) set(WEBVIEW_PROVIDER WebEngineWidgets)
set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_WEBENGINE") set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_WEBENGINE")
list(APPEND ADDITIONAL_QT_REPOS "webengine") list(APPEND ADDITIONAL_QT_REPOS "webengine")
message(STATUS "No web view provider explicitly specified, defaulting to Qt WebEngine.") message(STATUS "No web view provider explicitly specified, defaulting to Qt WebEngine.")
else() else ()
set(WEBVIEW_PROVIDER "") set(WEBVIEW_PROVIDER "")
set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_NO_WEBVIEW") set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_NO_WEBVIEW")
message(STATUS "No web view provider available, web view has been disabled.") message(STATUS "No web view provider available, web view has been disabled.")
endif() endif ()
endif() endif ()
else() else ()
if(${WEBVIEW_PROVIDER} STREQUAL "webkit") if (${WEBVIEW_PROVIDER} STREQUAL "webkit")
find_qt5_module(WebKitWidgets REQUIRED) find_qt5_module(WebKitWidgets REQUIRED)
set(WEBVIEW_PROVIDER WebKitWidgets) set(WEBVIEW_PROVIDER WebKitWidgets)
set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_WEBKIT") set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_WEBKIT")
message(STATUS "Using Qt WebKit as web view provider.") message(STATUS "Using Qt WebKit as web view provider.")
elseif(${WEBVIEW_PROVIDER} STREQUAL "webengine") elseif (${WEBVIEW_PROVIDER} STREQUAL "webengine")
find_qt5_module(WebEngineWidgets REQUIRED) find_qt5_module(WebEngineWidgets REQUIRED)
set(WEBVIEW_PROVIDER WebEngineWidgets) set(WEBVIEW_PROVIDER WebEngineWidgets)
set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_WEBENGINE") set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_USE_WEBENGINE")
list(APPEND ADDITIONAL_QT_REPOS "webengine") list(APPEND ADDITIONAL_QT_REPOS "webengine")
message(STATUS "Using Qt WebEngine as web view provider.") message(STATUS "Using Qt WebEngine as web view provider.")
elseif(${WEBVIEW_PROVIDER} STREQUAL "none") elseif (${WEBVIEW_PROVIDER} STREQUAL "none")
set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_NO_WEBVIEW") set(WEBVIEW_DEFINITION "${META_PROJECT_VARNAME_UPPER}_NO_WEBVIEW")
set(WEBVIEW_PROVIDER "") set(WEBVIEW_PROVIDER "")
message(STATUS "Web view has been disabled.") message(STATUS "Web view has been disabled.")
else() else ()
message(FATAL_ERROR "The specified web view provider '${WEBVIEW_PROVIDER}' is unknown.") message(FATAL_ERROR "The specified web view provider '${WEBVIEW_PROVIDER}' is unknown.")
endif() endif ()
endif() endif ()
if(WEBVIEW_PROVIDER) if (WEBVIEW_PROVIDER)
# require the selected Qt module # require the selected Qt module
use_qt5_module(${WEBVIEW_PROVIDER} REQUIRED) use_qt5_module(${WEBVIEW_PROVIDER} REQUIRED)
# add header files with some defines/includes to conveniently use the selected provider # add header files with some defines/includes to conveniently use the selected provider
if(META_WEBVIEW_SRC_DIR) if (META_WEBVIEW_SRC_DIR)
set(WEBVIEW_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${META_WEBVIEW_SRC_DIR}") set(WEBVIEW_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${META_WEBVIEW_SRC_DIR}")
else() else ()
set(WEBVIEW_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gui") set(WEBVIEW_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gui")
endif() endif ()
include(TemplateFinder) include(TemplateFinder)
find_template_file("webviewdefs.h" QT_UTILITIES WEBVIEWDEFS_H_TEMPLATE_FILE) find_template_file("webviewdefs.h" QT_UTILITIES WEBVIEWDEFS_H_TEMPLATE_FILE)
configure_file( configure_file("${WEBVIEWDEFS_H_TEMPLATE_FILE}"
"${WEBVIEWDEFS_H_TEMPLATE_FILE}" "${WEBVIEW_HEADER_DIR}/webviewdefs.h" # simply add this to source to ease inclusion
"${WEBVIEW_HEADER_DIR}/webviewdefs.h" # simply add this to source to ease inclusion NEWLINE_STYLE UNIX # since this goes to sources ensure consistency
NEWLINE_STYLE UNIX # since this goes to sources ensure consistency )
)
find_template_file("webviewincludes.h" QT_UTILITIES WEBVIEWINCLUDES_H_TEMPLATE_FILE) find_template_file("webviewincludes.h" QT_UTILITIES WEBVIEWINCLUDES_H_TEMPLATE_FILE)
configure_file( configure_file("${WEBVIEWINCLUDES_H_TEMPLATE_FILE}"
"${WEBVIEWINCLUDES_H_TEMPLATE_FILE}" "${WEBVIEW_HEADER_DIR}/webviewincludes.h" # simply add this to source to ease inclusion
"${WEBVIEW_HEADER_DIR}/webviewincludes.h" # simply add this to source to ease inclusion NEWLINE_STYLE UNIX # since this goes to sources ensure consistency
NEWLINE_STYLE UNIX # since this goes to sources ensure consistency )
) list(APPEND WIDGETS_FILES "${WEBVIEW_HEADER_DIR}/webviewdefs.h" "${WEBVIEW_HEADER_DIR}/webviewincludes.h")
list(APPEND WIDGETS_FILES endif ()
"${WEBVIEW_HEADER_DIR}/webviewdefs.h"
"${WEBVIEW_HEADER_DIR}/webviewincludes.h"
)
endif()
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${WEBVIEW_DEFINITION}) list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${WEBVIEW_DEFINITION})