summaryrefslogtreecommitdiffstats
path: root/src/corelib/Qt6CoreMacros.cmake
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@qt.io>2020-12-08 22:00:22 +1100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-12-10 21:19:01 +0000
commit3c8d95afa56e9787f222086b1918616aeb9d5337 (patch)
tree06b383c7661a55910c09d0602ecc1b9c8c600881 /src/corelib/Qt6CoreMacros.cmake
parentaba6fcbbf64b1bd003b0c47144e2bcce43390f5d (diff)
CMake: Support deferred finalization for qt6_add_executable()
Some parts of qt6_add_executable() need to take into account certain target properties, but the target is created within the function. The caller doesn't get the opportunity to modify those properties before they are used. This change provides a way to defer those property-using steps until either the project explicitly calls a function to finalize the target or the end of the current directory scope is reached. Automatic deferral to end of scope is only supported for CMake 3.19+. With CMake 3.18 or earlier, deferring the finalization step has to be explicitly requested with the new MANUAL_FINALIZATION keyword. The caller is then responsible for also calling qt6_finalize_executable() later. When the keyword is given, automatic finalization is disabled even when using CMake 3.19+. Note that while this could be implemented without CMake 3.19 features, other work relating to qt6_import_qml_plugins() will require it so we may as well use this method now. Fixes: QTBUG-88840 Task-number: QTBUG-86669 Change-Id: Ic3854672ba18cff5af2ffd7f63596aa3ac492f33 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit b94b7687b0635ee74a3ccd83a234ead0600fd47f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib/Qt6CoreMacros.cmake')
-rw-r--r--src/corelib/Qt6CoreMacros.cmake33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake
index 9c381ecb37..626a3ad3f8 100644
--- a/src/corelib/Qt6CoreMacros.cmake
+++ b/src/corelib/Qt6CoreMacros.cmake
@@ -428,7 +428,32 @@ set(_Qt6_COMPONENT_PATH "${CMAKE_CURRENT_LIST_DIR}/..")
# It's signature and behavior might change.
#
# Wrapper function that adds an executable with some Qt specific behavior.
+# Some scenarios require steps to be deferred to the end of the current
+# directory scope so that the caller has an opportunity to modify certain
+# target properties.
function(qt6_add_executable target)
+ cmake_parse_arguments(PARSE_ARGV 1 arg "MANUAL_FINALIZATION" "" "")
+
+ _qt_internal_create_executable("${target}" ${arg_UNPARSED_ARGUMENTS})
+
+ if(arg_MANUAL_FINALIZATION)
+ # Caller says they will call qt6_finalize_executable() themselves later
+ return()
+ endif()
+
+ # Defer the finalization if we can. When the caller's project requires
+ # CMake 3.19 or later, this makes the calls to this function concise while
+ # still allowing target property modification before finalization.
+ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
+ # Need to wrap in an EVAL CODE or else ${target} won't be evaluated
+ # due to special behavior of cmake_language() argument handling
+ cmake_language(EVAL CODE "cmake_language(DEFER CALL qt6_finalize_executable ${target})")
+ else()
+ qt6_finalize_executable("${target}")
+ endif()
+endfunction()
+
+function(_qt_internal_create_executable target)
if(ANDROID)
list(REMOVE_ITEM ARGN "WIN32" "MACOSX_BUNDLE")
add_library("${target}" MODULE ${ARGN})
@@ -444,8 +469,13 @@ function(qt6_add_executable target)
else()
add_executable("${target}" ${ARGN})
endif()
+
target_link_libraries("${target}" PRIVATE Qt::Core)
+endfunction()
+# This function is currently in Technical Preview.
+# It's signature and behavior might change.
+function(qt6_finalize_executable target)
if(ANDROID)
qt_android_generate_deployment_settings("${target}")
qt_android_add_apk_target("${target}")
@@ -456,6 +486,9 @@ if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
function(qt_add_executable)
qt6_add_executable(${ARGV})
endfunction()
+ function(qt_finalize_executable)
+ qt6_finalize_executable(${ARGV})
+ endfunction()
endif()
# Temporarily keep compatibility, until all repositories are migrated.