summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2022-08-10 17:21:18 +0200
committerAlexey Edelev <alexey.edelev@qt.io>2022-08-19 23:53:11 +0200
commitf3f0d646b90cf31f8ff855c5470b01fd1bea75a0 (patch)
tree063c7acbe4dec4c831f13f10b6b025654b9ad574 /cmake
parenta2809d9ec1c4351bc356e05e8f3c1db0363bef86 (diff)
Add possibility to store source files for interface targets
Add source files to the _qt_internal_target_sources property, when running qt_internal_extend_target on interface libraries instead of ignoring sources for CMake versions that don't support non-interface properties. The property is not full-functional, but still allows to execute internal routines on target sources. Also add qt_internal_get_target_sources_property function that helps to destinguish which property stores target sources. Task-number: QTBUG-103196 Change-Id: I435c558090a24a7988f1a1c49f924dc195e72480 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtTargetHelpers.cmake31
1 files changed, 29 insertions, 2 deletions
diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake
index fefc582f04..1c9e1247b6 100644
--- a/cmake/QtTargetHelpers.cmake
+++ b/cmake/QtTargetHelpers.cmake
@@ -62,14 +62,19 @@ function(qt_internal_extend_target target)
# CMake versions less than 3.19 don't support adding the source files to the PRIVATE scope
# of the INTERFACE libraries. These PRIVATE sources are only needed by IDEs to display
# them in a project tree, so to avoid build issues and appearing the sources in
- # INTERFACE_SOURCES property of INTERFACE_LIBRARY let's simply exclude them for
- # compatibility with CMake versions less than 3.19.
+ # INTERFACE_SOURCES property of INTERFACE_LIBRARY. Collect them inside the
+ # _qt_internal_target_sources property, since they can be useful in the source processing
+ # functions. The property itself is not exported and should only be used in the Qt internal
+ # build tree.
if(NOT is_interface_lib OR CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
target_sources("${target}" PRIVATE ${arg_SOURCES} ${dbus_sources})
if (arg_COMPILE_FLAGS)
set_source_files_properties(${arg_SOURCES} PROPERTIES
COMPILE_FLAGS "${arg_COMPILE_FLAGS}")
endif()
+ else()
+ set_property(TARGET ${target} APPEND PROPERTY
+ _qt_internal_target_sources ${arg_SOURCES} ${dbus_sources})
endif()
set(public_visibility_option "PUBLIC")
@@ -907,3 +912,25 @@ function(qt_internal_add_repo_local_defines target)
target_compile_definitions("${target}" PRIVATE ${QT_EXTRA_INTERNAL_TARGET_DEFINES})
endif()
endfunction()
+
+# The function returns the value of the target's SOURCES property. The function takes into account
+# the limitation of the CMake version less than 3.19, that restricts to add non-interface sources
+# to an interface target.
+# Note: The function works correctly only if qt_internal_extend_target is used when adding source
+# files.
+function(qt_internal_get_target_sources out_var target)
+ qt_internal_get_target_sources_property(sources_property)
+ get_target_property(${out_var} ${target} ${sources_property})
+ set(${out_var} "${${out_var}}" PARENT_SCOPE)
+endfunction()
+
+# The function distinguishes what property supposed to store target sources, based on target TYPE
+# and the CMake version.
+function(qt_internal_get_target_sources_property out_var)
+ set(${out_var} "SOURCES")
+ get_target_property(target_type ${target} TYPE)
+ if(CMAKE_VERSION VERSION_LESS "3.19" AND target_type STREQUAL "INTERFACE_LIBRARY")
+ set(${out_var} "_qt_internal_target_sources")
+ endif()
+ set(${out_var} "${${out_var}}" PARENT_SCOPE)
+endfunction()