Compile resource objects of the static library using same options

Introduce the function that appends the specified properties of the
one target to the another. It's possible to copy the standard
property set that affects a compilation only or pass some specific
properties that need to copy. You may also control the visibily of
properties that need to copy by passing the PRIVATE_ONLY or
INTERFACE_ONLY option.

The function is used to compile the resource targets with the same
property set as the main target. Also link the Qt::Platform interface
library to collect platform specific properties.

Pick-to: 6.1
Change-Id: I727fd0a4bc52c4f5128f28ce796d7a5f3005bb30
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2021-04-23 16:23:36 +02:00
parent 8f238788de
commit a239045d59

View File

@ -1329,6 +1329,10 @@ function(__qt_propagate_generated_resource target resource_name generated_source
target_compile_definitions("${resource_target}" PRIVATE
"$<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::Core,INTERFACE_COMPILE_DEFINITIONS>"
)
target_link_libraries(${resource_target} PRIVATE ${QT_CMAKE_EXPORT_NAMESPACE}::Platform)
_qt_internal_copy_dependency_properties(${resource_target} ${target} PRIVATE_ONLY)
# Special handling is required for the Core library resources. The linking of the Core
# library to the resources adds a circular dependency. This leads to the wrong
# objects/library order in the linker command line, since the Core library target is resolved
@ -1715,3 +1719,52 @@ function(_qt_internal_apply_strict_cpp target)
endif()
endif()
endfunction()
# Copies properties of the dependency to the target.
# Arguments:
# PROPERTIES list of properties to copy. If not specified the following properties are copied
# by default: INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES COMPILE_DEFINITIONS
# COMPILE_OPTIONS COMPILE_FEATURES
# PRIVATE_ONLY copy only private properties (without INTERFACE analogues). Optional.
# INTERFACE_ONLY copy only interface properties (without non-prefixed analogues). Optional.
# Note: Not all properties have INTERFACE properties analogues.
# See https://cmake.org/cmake/help/latest/prop_tgt/EXPORT_PROPERTIES.html for details.
#
# PRIVATE_ONLY and INTERFACE_ONLY in the same call are not allowed. Omit these options to copy
# both sets.
function(_qt_internal_copy_dependency_properties target dependency)
cmake_parse_arguments(arg "INTERFACE_ONLY;PRIVATE_ONLY" "" "PROPERTIES" ${ARGN})
if(arg_PRIVATE_ONLY AND arg_INTERFACE_ONLY)
message("Both PRIVATE_ONLY and INTERFACE_ONLY options are set.\
Please use _qt_internal_copy_dependency_properties without these options to copy a set of
properties of both types."
)
endif()
if(arg_PROPERTIES)
set(common_props_to_set ${arg_PROPERTIES})
else()
set(common_props_to_set
INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES
COMPILE_DEFINITIONS COMPILE_OPTIONS
COMPILE_FEATURES
)
endif()
set(props_to_set "")
if(NOT arg_INTERFACE_ONLY)
set(props_to_set ${common_props_to_set})
endif()
if(NOT arg_PRIVATE_ONLY)
list(TRANSFORM common_props_to_set PREPEND INTERFACE_
OUTPUT_VARIABLE interface_properties)
list(APPEND props_to_set ${interface_properties})
endif()
foreach(prop ${props_to_set})
set_property(TARGET
"${target}" APPEND PROPERTY
${prop} "$<TARGET_PROPERTY:${dependency},${prop}>"
)
endforeach()
endfunction()