2016-11-08 19:57:57 +01:00
|
|
|
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
|
|
|
|
|
2018-12-05 15:24:04 +01:00
|
|
|
# defines helper to link against Qt dynamically or statically
|
2016-08-29 15:41:11 +02:00
|
|
|
|
2018-12-05 15:24:04 +01:00
|
|
|
# prevent multiple inclusion
|
2019-02-06 17:32:10 +01:00
|
|
|
if (DEFINED QT_LINKAGE_DETERMINED)
|
2018-12-05 15:24:04 +01:00
|
|
|
return()
|
2019-02-06 17:32:10 +01:00
|
|
|
endif ()
|
2018-12-05 15:24:04 +01:00
|
|
|
set(QT_LINKAGE_DETERMINED ON)
|
2016-10-29 00:26:06 +02:00
|
|
|
|
2019-04-22 22:27:00 +02:00
|
|
|
# include validate_visibility from c++utilities' 3rdParty module
|
|
|
|
include(3rdParty)
|
|
|
|
|
2020-11-07 21:37:18 +01:00
|
|
|
# determine the minimum Qt version
|
|
|
|
if (NOT META_QT_VERSION)
|
|
|
|
if (META_QT5_VERSION)
|
|
|
|
# use deprecated META_QT5_VERSION variable (for compatibility)
|
|
|
|
set (META_QT_VERSION "${META_QT5_VERSION}")
|
|
|
|
else ()
|
|
|
|
# require Qt 5.6 or higher by default
|
|
|
|
set(META_QT_VERSION 5.6)
|
|
|
|
endif ()
|
2019-02-06 17:32:10 +01:00
|
|
|
endif ()
|
2016-08-29 15:41:11 +02:00
|
|
|
|
2020-10-10 00:48:06 +02:00
|
|
|
# avoid "add_custom_target cannot create target "apk" because another target…" errors produced by Qt's Android support module
|
|
|
|
# (which can not cope with Qt CMake modules already pulled in by a dependency)
|
2020-10-05 18:37:23 +02:00
|
|
|
if (ANDROID AND NOT ${PROJECT_NAME}-MultiAbiBuild)
|
|
|
|
set(${PROJECT_NAME}-MultiAbiBuild ON)
|
|
|
|
endif ()
|
|
|
|
|
2019-04-04 19:13:30 +02:00
|
|
|
# define function for using Qt and KDE Frameworks modules and static plugins
|
|
|
|
macro (use_qt_module)
|
|
|
|
# parse arguments
|
|
|
|
set(OPTIONAL_ARGS ONLY_PLUGINS)
|
2019-11-30 17:58:56 +01:00
|
|
|
set(ONE_VALUE_ARGS PREFIX MODULE VISIBILITY LIBRARIES_VARIABLE)
|
2019-04-04 19:13:30 +02:00
|
|
|
set(MULTI_VALUE_ARGS TARGETS PLUGINS)
|
2019-11-30 17:58:56 +01:00
|
|
|
cmake_parse_arguments(ARGS "${OPTIONAL_ARGS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN})
|
2016-10-29 00:26:06 +02:00
|
|
|
|
2019-04-04 19:13:30 +02:00
|
|
|
# validate values
|
|
|
|
if (NOT ARGS_PREFIX)
|
|
|
|
message(FATAL_ERROR "use_qt_module called without PREFIX.")
|
2019-05-04 20:59:19 +02:00
|
|
|
endif ()
|
2019-04-04 19:13:30 +02:00
|
|
|
if (NOT ARGS_MODULE)
|
|
|
|
message(FATAL_ERROR "use_qt_module called without MODULE.")
|
2019-05-04 20:59:19 +02:00
|
|
|
endif ()
|
2019-04-04 19:13:30 +02:00
|
|
|
if (ARGS_VISIBILITY)
|
|
|
|
validate_visibility(${ARGS_VISIBILITY})
|
2019-05-04 20:59:19 +02:00
|
|
|
else ()
|
|
|
|
set(ARGS_VISIBILITY PRIVATE)
|
|
|
|
endif ()
|
2019-04-04 19:13:30 +02:00
|
|
|
if (NOT ARGS_LIBRARIES_VARIABLE)
|
2019-05-04 20:59:19 +02:00
|
|
|
set(ARGS_LIBRARIES_VARIABLE "${ARGS_VISIBILITY}_LIBRARIES")
|
|
|
|
endif ()
|
2019-04-04 19:13:30 +02:00
|
|
|
if (NOT ARGS_TARGETS)
|
|
|
|
if (${MODULE}_MODULE_TARGETS)
|
|
|
|
set(ARGS_TARGETS "${${MODULE}_MODULE_TARGETS}")
|
2019-05-04 20:59:19 +02:00
|
|
|
else ()
|
2019-04-04 19:13:30 +02:00
|
|
|
set(ARGS_TARGETS "${ARGS_PREFIX}::${ARGS_MODULE}")
|
2019-05-04 20:59:19 +02:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2019-04-04 19:13:30 +02:00
|
|
|
if (ARGS_ONLY_PLUGINS AND NOT ARGS_PLUGINS)
|
|
|
|
message(FATAL_ERROR "ONLY_PLUGINS specified but no plugins.")
|
2019-05-04 20:59:19 +02:00
|
|
|
endif ()
|
2016-10-29 00:26:06 +02:00
|
|
|
|
2019-04-04 19:13:30 +02:00
|
|
|
# find and use module
|
|
|
|
if (NOT ONLY_PLUGINS)
|
2020-11-07 21:37:18 +01:00
|
|
|
find_package("${ARGS_PREFIX}${ARGS_MODULE}" "${META_QT_VERSION}" REQUIRED)
|
2019-05-04 20:59:19 +02:00
|
|
|
foreach (TARGET ${ARGS_TARGETS})
|
2019-04-04 19:13:30 +02:00
|
|
|
if (NOT TARGET "${TARGET}")
|
|
|
|
message(FATAL_ERROR "The ${ARGS_PREFIX}${ARGS_MODULE} does not provide the target ${TARGET}.")
|
2019-05-04 20:59:19 +02:00
|
|
|
endif ()
|
2019-04-04 19:13:30 +02:00
|
|
|
if ("${TARGET}" IN_LIST "${ARGS_LIBRARIES_VARIABLE}")
|
|
|
|
continue()
|
2019-05-04 20:59:19 +02:00
|
|
|
endif ()
|
2019-04-04 19:13:30 +02:00
|
|
|
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};${TARGET}")
|
|
|
|
set("PKG_CONFIG_${ARGS_PREFIX}_${ARGS_MODULE}" "${ARGS_PREFIX}${ARGS_MODULE}")
|
2020-09-02 19:49:40 +02:00
|
|
|
message(STATUS "Linking ${META_TARGET_NAME} against Qt module ${TARGET}.")
|
2016-08-29 15:41:11 +02:00
|
|
|
|
2019-04-04 19:13:30 +02:00
|
|
|
# hack for "StaticQt5": re-assign INTERFACE_LINK_LIBRARIES_RELEASE to INTERFACE_LINK_LIBRARIES
|
2019-05-04 20:59:19 +02:00
|
|
|
get_target_property("${ARGS_MODULE}_INTERFACE_LINK_LIBRARIES_RELEASE" "${TARGET}"
|
|
|
|
INTERFACE_LINK_LIBRARIES_RELEASE)
|
2019-04-04 19:13:30 +02:00
|
|
|
if ("${ARGS_MODULE}_INTERFACE_LINK_LIBRARIES_RELEASE")
|
2019-11-30 17:58:56 +01:00
|
|
|
set_target_properties("${TARGET}" PROPERTIES INTERFACE_LINK_LIBRARIES
|
|
|
|
"${${ARGS_MODULE}_INTERFACE_LINK_LIBRARIES_RELEASE}")
|
2019-04-04 19:13:30 +02:00
|
|
|
endif ()
|
2019-05-04 20:59:19 +02:00
|
|
|
endforeach ()
|
|
|
|
endif ()
|
2018-12-05 15:24:04 +01:00
|
|
|
|
2019-04-04 19:13:30 +02:00
|
|
|
# find and use plugins
|
|
|
|
foreach (PLUGIN ${ARGS_PLUGINS})
|
2020-11-07 21:26:57 +01:00
|
|
|
set(PLUGIN_TARGET "${ARGS_PREFIX}::Q${PLUGIN}Plugin")
|
|
|
|
if (NOT TARGET "${PLUGIN_TARGET}")
|
2020-11-07 21:37:18 +01:00
|
|
|
find_package("${ARGS_PREFIX}${ARGS_MODULE}" "${META_QT_VERSION}" REQUIRED)
|
2019-05-04 20:59:19 +02:00
|
|
|
endif ()
|
2020-11-07 21:26:57 +01:00
|
|
|
if (NOT TARGET "${PLUGIN_TARGET}" AND PLUGIN MATCHES "Svg.*" AND ARGS_MODULE STREQUAL "Svg")
|
|
|
|
# look for Svg plugins within the Gui module's directory as well
|
2020-11-07 21:37:18 +01:00
|
|
|
find_package("${ARGS_PREFIX}Gui" "${META_QT_VERSION}" REQUIRED)
|
2020-11-07 21:26:57 +01:00
|
|
|
set(PLUGIN_CONFIG "${${ARGS_PREFIX}Gui_DIR}/${ARGS_PREFIX}Q${PLUGIN}PluginConfig.cmake")
|
|
|
|
if (EXISTS "${PLUGIN_CONFIG}")
|
|
|
|
include("${PLUGIN_CONFIG}")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
if (NOT TARGET "${PLUGIN_TARGET}")
|
2020-11-03 18:32:35 +01:00
|
|
|
message(FATAL_ERROR "The ${ARGS_PREFIX}${ARGS_MODULE} package does not provide the target ${ARGS_PREFIX}::Q${PLUGIN}Plugin.")
|
2019-05-04 20:59:19 +02:00
|
|
|
endif ()
|
2020-11-07 21:26:57 +01:00
|
|
|
if ("${PLUGIN_TARGET}" IN_LIST "${ARGS_LIBRARIES_VARIABLE}")
|
2019-04-04 19:13:30 +02:00
|
|
|
continue()
|
2019-05-04 20:59:19 +02:00
|
|
|
endif ()
|
2019-04-04 19:13:30 +02:00
|
|
|
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};${ARGS_PREFIX}::Q${PLUGIN}Plugin")
|
2020-09-02 19:49:40 +02:00
|
|
|
message(STATUS "Linking ${META_TARGET_NAME} against Qt plugin ${ARGS_PREFIX}::Q${PLUGIN}Plugin.")
|
2019-05-04 20:59:19 +02:00
|
|
|
endforeach ()
|
2019-04-04 19:13:30 +02:00
|
|
|
|
|
|
|
# unset variables (can not simply use a function because Qt's variables need to be exported)
|
2019-11-30 17:58:56 +01:00
|
|
|
foreach (ARGUMENT ${OPTIONAL_ARGS} ${ONE_VALUE_ARGS} ${MULTI_VALUE_ARGS})
|
2019-04-04 19:13:30 +02:00
|
|
|
unset(ARGS_${ARGUMENT})
|
2019-05-04 20:59:19 +02:00
|
|
|
endforeach ()
|
|
|
|
endmacro ()
|
2019-04-04 19:13:30 +02:00
|
|
|
|
2020-09-02 19:49:40 +02:00
|
|
|
# define function to make Qt variable available; queries qmake or uses variables provided by Qt 6
|
2019-04-04 19:13:30 +02:00
|
|
|
function (query_qmake_variable QMAKE_VARIABLE)
|
|
|
|
# prevent queries for variables already known
|
|
|
|
if (NOT "${${QMAKE_VARIABLE}}" STREQUAL "")
|
|
|
|
return()
|
2019-05-04 20:59:19 +02:00
|
|
|
endif ()
|
2018-12-02 21:40:53 +01:00
|
|
|
|
2020-09-02 19:49:40 +02:00
|
|
|
# check configuration variables provided by Qt 6
|
|
|
|
if (QMAKE_VARIABLE MATCHES "QT_(.*)")
|
|
|
|
set(VARIABLE_NAME "${CMAKE_MATCH_1}")
|
|
|
|
if (QT6_${VARIABLE_NAME})
|
|
|
|
set(VARIABLE_NAME QT6_${VARIABLE_NAME})
|
|
|
|
endif ()
|
|
|
|
if (NOT "${${VARIABLE_NAME}}" STREQUAL "")
|
2020-10-10 00:48:06 +02:00
|
|
|
set("${QMAKE_VARIABLE}"
|
|
|
|
"${${VARIABLE_NAME}}"
|
|
|
|
PARENT_SCOPE)
|
2020-09-02 19:49:40 +02:00
|
|
|
message(STATUS "Qt variable ${QMAKE_VARIABLE} taken from ${VARIABLE_NAME}: ${${VARIABLE_NAME}}")
|
|
|
|
return()
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
2019-04-04 19:13:30 +02:00
|
|
|
# execute qmake
|
2020-04-27 23:47:08 +02:00
|
|
|
get_target_property(QMAKE_BIN "${QT_QMAKE_TARGET}" IMPORTED_LOCATION)
|
2019-11-30 17:58:56 +01:00
|
|
|
execute_process(
|
|
|
|
COMMAND "${QMAKE_BIN}" -query "${QMAKE_VARIABLE}"
|
|
|
|
RESULT_VARIABLE "${QMAKE_VARIABLE}_RESULT"
|
|
|
|
OUTPUT_VARIABLE "${QMAKE_VARIABLE}")
|
2019-02-06 17:32:10 +01:00
|
|
|
if (NOT "${${QMAKE_VARIABLE}_RESULT}" STREQUAL 0 OR "${${QMAKE_VARIABLE}}" STREQUAL "")
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"Unable to read qmake variable ${QMAKE_VARIABLE} via \"${QMAKE_BIN} -query ${QMAKE_VARIABLE}\"; output was \"${${QMAKE_VARIABLE}}\"."
|
2019-11-30 17:58:56 +01:00
|
|
|
)
|
2019-02-06 17:32:10 +01:00
|
|
|
endif ()
|
2019-04-04 19:13:30 +02:00
|
|
|
|
|
|
|
# remove new-line character at the end
|
2019-11-30 17:58:56 +01:00
|
|
|
string(REGEX REPLACE "\n$" "" "${QMAKE_VARIABLE}" "${${QMAKE_VARIABLE}}")
|
2019-04-04 19:13:30 +02:00
|
|
|
|
|
|
|
# export variable to parent scope
|
2020-10-10 00:48:06 +02:00
|
|
|
set("${QMAKE_VARIABLE}"
|
|
|
|
"${${QMAKE_VARIABLE}}"
|
|
|
|
PARENT_SCOPE)
|
2020-09-02 19:49:40 +02:00
|
|
|
message(STATUS "Qt variable ${QMAKE_VARIABLE} queried from qmake: ${${QMAKE_VARIABLE}}")
|
2019-05-04 20:59:19 +02:00
|
|
|
endfunction ()
|