Skip to content

Commit

Permalink
CMake: Split target finalization code into a separate function
Browse files Browse the repository at this point in the history
It was duplicated across a few public API.
Splitting it will also allow it to be be reused in a future change
in another function.

Also add the ability to use the poor man finalizer approach for
CMake 3.16, but only via an opt-in that will be set by the qt build
process, so that the finalizers can be used for tests in a future
change.

Task-number: QTBUG-93625
Task-number: QTBUG-112212
Change-Id: I097faf5e3db98457acfdfb3ae2011efb6640f35e
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit 2bbc0bd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
  • Loading branch information
alcroito committed Nov 2, 2024
1 parent ef3db62 commit 45c8ab1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
3 changes: 3 additions & 0 deletions cmake/QtScopeFinalizerHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ function(qt_watch_current_list_dir variable access value current_list_file stack
elseif(func STREQUAL "_qt_internal_finalize_sbom")
_qt_internal_finalize_sbom(
${a1} ${a2} ${a3} ${a4} ${a5} ${a6} ${a7} ${a8} ${a9})
elseif(func STREQUAL "qt6_finalize_target")
qt6_finalize_target(
${a1} ${a2} ${a3} ${a4} ${a5} ${a6} ${a7} ${a8} ${a9})
else()
message(FATAL_ERROR "qt_watch_current_list_dir doesn't know about ${func}. Consider adding it.")
endif()
Expand Down
52 changes: 19 additions & 33 deletions src/corelib/Qt6CoreMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -652,17 +652,7 @@ function(qt6_add_executable target)
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_target ${target})")
else()
set_target_properties("${target}" PROPERTIES _qt_is_immediately_finalized TRUE)
qt6_finalize_target("${target}")
endif()
_qt_internal_finalize_target_defer("${target}")
endfunction()

# Just like for qt_add_resources, we should disable zstd compression when cross-compiling to a
Expand Down Expand Up @@ -861,6 +851,22 @@ function(qt6_finalize_target target)
set_target_properties(${target} PROPERTIES _qt_is_finalized TRUE)
endfunction()

function(_qt_internal_finalize_target_defer target)
# 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_target ${target})")
elseif(QT_BUILDING_QT AND QT_INTERNAL_USE_POOR_MANS_SCOPE_FINALIZER)
qt_add_list_file_finalizer(qt6_finalize_target "${target}")
else()
set_target_properties("${target}" PROPERTIES _qt_is_immediately_finalized TRUE)
qt6_finalize_target("${target}")
endif()
endfunction()

function(_qt_internal_finalize_source_groups target)
if(NOT ("${CMAKE_GENERATOR}" STREQUAL "Xcode"
OR "${CMAKE_GENERATOR}" MATCHES "^Visual Studio"))
Expand Down Expand Up @@ -2628,17 +2634,7 @@ function(qt6_add_plugin target)
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_target ${target})")
else()
set_target_properties("${target}" PROPERTIES _qt_is_immediately_finalized TRUE)
qt6_finalize_target("${target}")
endif()
_qt_internal_finalize_target_defer("${target}")
endfunction()

if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
Expand All @@ -2664,17 +2660,7 @@ function(qt6_add_library target)
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_target ${target})")
else()
set_target_properties("${target}" PROPERTIES _qt_is_immediately_finalized TRUE)
qt6_finalize_target("${target}")
endif()
_qt_internal_finalize_target_defer("${target}")
endfunction()

# Creates a library target by forwarding the arguments to add_library.
Expand Down

0 comments on commit 45c8ab1

Please sign in to comment.