Skip to content

Commit

Permalink
CMake: Replace qt_finalize_executable with qt_finalize_target
Browse files Browse the repository at this point in the history
It's very likely that we'll have to run certain finalizer code for
targets other than executables.

Rename qt_finalize_executable to _qt_internal_finalize_executable so
it's internal.

Introduce a new function qt_finalize_target which will call the above
internal one when the target is an executable.

This should future proof the API so we have a hook to call code for
any user CMake project that intends to use Qt CMake API.

Change-Id: I03f6f4dcba22461351c247a20241ca7de1a59c1d
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Joerg Bornemann <[email protected]>
  • Loading branch information
alcroito committed May 20, 2021
1 parent 560d839 commit c4df673
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
35 changes: 22 additions & 13 deletions src/corelib/Qt6CoreMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ function(qt6_add_executable target)
_qt_internal_create_executable("${target}" ${arg_UNPARSED_ARGUMENTS})

if(arg_MANUAL_FINALIZATION)
# Caller says they will call qt6_finalize_executable() themselves later
# Caller says they will call qt6_finalize_target() themselves later
return()
endif()

Expand All @@ -485,10 +485,10 @@ function(qt6_add_executable target)
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})")
cmake_language(EVAL CODE "cmake_language(DEFER CALL qt6_finalize_target ${target})")
else()
set_target_properties("${target}" PROPERTIES _qt_is_immediately_finalized TRUE)
qt6_finalize_executable("${target}")
qt6_finalize_target("${target}")
endif()
endfunction()

Expand All @@ -512,13 +512,11 @@ function(_qt_internal_create_executable target)
target_link_libraries("${target}" PRIVATE Qt6::Core)
endfunction()

# This function is currently in Technical Preview.
# It's signature and behavior might change.
function(qt6_finalize_executable target)
function(_qt_internal_finalize_executable target)
get_target_property(is_finalized "${target}" _qt_executable_is_finalized)
if(is_finalized)
message(AUTHOR_WARNING
"Tried to call qt6_finalize_executable twice on executable: '${target}'. \
"Tried to call qt6_finalize_target twice on executable: '${target}'. \
Did you forget to specify MANUAL_FINALIZATION to qt6_add_executable?")
return()
endif()
Expand Down Expand Up @@ -589,6 +587,17 @@ function(qt6_finalize_executable target)
set_target_properties(${target} PROPERTIES _qt_executable_is_finalized TRUE)
endfunction()

function(qt6_finalize_target target)
if(NOT TARGET "${target}")
message(FATAL_ERROR "No target '${target}' found in current scope.")
endif()

get_target_property(target_type ${target} TYPE)
if(target_type STREQUAL "EXECUTABLE")
_qt_internal_finalize_executable(${ARGV})
endif()
endfunction()

function(_qt_internal_find_ios_development_team_id out_var)
get_property(team_id GLOBAL PROPERTY _qt_internal_ios_development_team_id)
get_property(team_id_computed GLOBAL PROPERTY _qt_internal_ios_development_team_id_computed)
Expand Down Expand Up @@ -728,8 +737,8 @@ if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
function(qt_add_executable)
qt6_add_executable(${ARGV})
endfunction()
function(qt_finalize_executable)
qt6_finalize_executable(${ARGV})
function(qt_finalize_target)
qt6_finalize_target(${ARGV})
endfunction()
endif()

Expand Down Expand Up @@ -847,10 +856,10 @@ function(qt6_import_plugins target)
# If the project called qt_import_plugins, use this as an event to enable finalizer mode for
# plugin importing.
#
# This is done in addition to the code in qt_finalize_executable, to ensure pre-existing
# This is done in addition to the code in qt_finalize_target, to ensure pre-existing
# projects that use qt_import_plugins activate finalizer mode even with an older CMake version
# that doesn't support deferred calls (and projects that don't explicitly call
# qt_finalize_executable).
# qt_finalize_target).
__qt_internal_apply_plugin_imports_finalizer_mode(${target})
endfunction()

Expand All @@ -877,9 +886,9 @@ endif()
#
# Finalizer mode is enabled by default if:
# - the project calls qt_import_plugins explicitly or
# - the project calls qt_finalize_executable explicitly or
# - the project calls qt_finalize_target explicitly or
# - the project uses qt_add_executable and a CMake version greater than or equal to 3.19
# (which will DEFER CALL qt_finalize_executable)
# (which will DEFER CALL qt_finalize_target)
function(qt6_enable_import_plugins_finalizer_mode target enabled)
if(enabled)
set(enabled "TRUE")
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/doc/snippets/cmake-macros/examples.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ qt_add_executable(simpleapp main.cpp)
#! [qt_add_executable_deferred]
qt_add_executable(complexapp MANUAL_FINALIZATION complex.cpp)
set_target_properties(complexapp PROPERTIES OUTPUT_NAME Complexify)
qt_finalize_executable(complexapp)
qt_finalize_target(complexapp)
#! [qt_add_executable_deferred]

#! [qt_android_deploy_basic]
Expand Down
22 changes: 11 additions & 11 deletions src/corelib/doc/src/cmake-macros.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ for you as a convenience.
After a target is created, further processing or \e{finalization} steps are
commonly needed. The steps to perform depend on the platform and on various
properties of the target. The finalization processing is implemented by the
\l{qt6_finalize_executable}{qt_finalize_executable()} command.
\l{qt6_finalize_target}{qt_finalize_target()} command.

Finalization can occur either as part of this call or be deferred to sometime
after this command returns (but it should still be in the same directory scope).
Expand All @@ -432,11 +432,11 @@ CMake versions earlier than 3.19, automatic deferral isn't supported. In that
case, finalization is performed immediately before this command returns.

Regardless of the CMake version, the \c{MANUAL_FINALIZATION} keyword can be given to
indicate that you will explicitly call \l{qt6_finalize_executable}{qt_finalize_executable()}
indicate that you will explicitly call \l{qt6_finalize_target}{qt_finalize_target()}
yourself instead at some later time. In general, \c MANUAL_FINALIZATION should
not be needed unless the project has to support CMake 3.18 or earlier.

\sa {qt6_finalize_executable}{qt_finalize_executable()}
\sa {qt6_finalize_target}{qt_finalize_target()}

\section1 Examples

Expand All @@ -457,11 +457,11 @@ for finalizing the target by adding the \c{MANUAL_FINALIZATION} keyword.
*/

/*!
\page qt_finalize_executable.html
\page qt_finalize_target.html
\ingroup cmake-macros-qtcore

\title qt_finalize_executable
\target qt6_finalize_executable
\title qt_finalize_target
\target qt6_finalize_target

\brief Handles various common platform-specific tasks associated with Qt targets.

Expand All @@ -470,9 +470,9 @@ for finalizing the target by adding the \c{MANUAL_FINALIZATION} keyword.
\section1 Synopsis

\badcode
qt_finalize_executable(target)
qt_finalize_target(target)

qt6_finalize_executable(target)
qt6_finalize_target(target)
\endcode

\section1 Description
Expand Down Expand Up @@ -573,7 +573,7 @@ Some are provided by Qt, others by CMake or the Android NDK.

The properties below will be read from the specified \c{target}. Note that this
command is called as part of target finalization (see
\l{qt6_finalize_executable}{qt_finalize_executable()}). If you are using
\l{qt6_finalize_target}{qt_finalize_target()}). If you are using
\l{qt6_add_executable}{qt_add_executable()} to create the target and you need to
modify some of these target properties, you need to ensure that target
finalization is deferred. See \l{qt6_add_executable}{qt_add_executable()} for
Expand All @@ -597,7 +597,7 @@ Upon return, the \c{QT_ANDROID_DEPLOYMENT_SETTINGS_FILE} target property will
contain the location of the generated deployment settings file.

\sa {qt6_android_add_apk_target}{qt_android_add_apk_target()},
{qt6_finalize_executable}{qt_finalize_executable()}
{qt6_finalize_target}{qt_finalize_target()}

\section1 Example

Expand Down Expand Up @@ -639,7 +639,7 @@ the \c{apk} build target, which will be created if it doesn't already exist.
This can be disabled by setting the \c{QT_NO_GLOBAL_APK_TARGET} variable to true.

\sa {qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()},
{qt6_finalize_executable}{qt_finalize_executable()}
{qt6_finalize_target}{qt_finalize_target()}

\section1 Example

Expand Down
2 changes: 1 addition & 1 deletion tests/auto/cmake/test_import_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ create_test_executable(default_qt_add_executable_manually_finalized
FINALIZER_MODE QT_WRAPPER
ADD_EXECUTABLE_ARGS MANUAL_FINALIZATION)

qt_finalize_executable(${target})
qt_finalize_target(${target})

# Check that plugin importing with automatic finalization works when the CMake version is high
# enough.
Expand Down

0 comments on commit c4df673

Please sign in to comment.