summaryrefslogtreecommitdiffstats
path: root/cmake/QtPublicTargetHelpers.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/QtPublicTargetHelpers.cmake')
-rw-r--r--cmake/QtPublicTargetHelpers.cmake95
1 files changed, 88 insertions, 7 deletions
diff --git a/cmake/QtPublicTargetHelpers.cmake b/cmake/QtPublicTargetHelpers.cmake
index 5f09e97e0f..02d5546560 100644
--- a/cmake/QtPublicTargetHelpers.cmake
+++ b/cmake/QtPublicTargetHelpers.cmake
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
function(__qt_internal_strip_target_directory_scope_token target out_var)
# In CMake versions earlier than CMake 3.18, a subdirectory scope id is appended to the
# target name if the target is referenced in a target_link_libraries command from a
@@ -19,7 +22,7 @@ endfunction()
function(__qt_internal_static_link_order_public_test result)
# We could trust iOS linker
if(IOS)
- set(QT_HAVE_LINK_ORDER_MATTERS "FALSE" CACHE BOOL "Link order matters")
+ set(QT_HAVE_LINK_ORDER_MATTERS "FALSE" CACHE INTERNAL "Link order matters")
endif()
if(DEFINED QT_HAVE_LINK_ORDER_MATTERS)
@@ -48,7 +51,7 @@ function(__qt_internal_static_link_order_public_test result)
set(${result} TRUE)
endif()
- set(QT_HAVE_LINK_ORDER_MATTERS "${${result}}" CACHE BOOL "Link order matters")
+ set(QT_HAVE_LINK_ORDER_MATTERS "${${result}}" CACHE INTERNAL "Link order matters")
set(${result} "${${result}}" PARENT_SCOPE)
endfunction()
@@ -87,14 +90,43 @@ function(__qt_internal_check_link_order_matters)
endif()
endfunction()
+# Constructs a TARGET_POLICY genex expression if the policy is available.
+function(__qt_internal_get_cmp0099_genex_check result)
+ if(POLICY CMP0099)
+ set(${result} "$<BOOL:$<TARGET_POLICY:CMP0099>>" PARENT_SCOPE)
+ else()
+ set(${result} "$<BOOL:FALSE>" PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(__qt_internal_check_cmp0099_available)
+ set(platform_target ${QT_CMAKE_EXPORT_NAMESPACE}::Platform)
+ get_target_property(aliased_target ${platform_target} ALIASED_TARGET)
+ if(aliased_target)
+ set(platform_target "${aliased_target}")
+ endif()
+
+ __qt_internal_get_cmp0099_genex_check(cmp0099_check)
+ set_target_properties(${platform_target} PROPERTIES
+ _qt_cmp0099_policy_check "${cmp0099_check}"
+ )
+
+ set(result TRUE)
+ if(NOT POLICY CMP0099)
+ set(result FALSE)
+ endif()
+
+ if("${ARGC}" GREATER "0" AND NOT ARGV0 STREQUAL "")
+ set(${ARGV0} ${result} PARENT_SCOPE)
+ endif()
+endfunction()
+
function(__qt_internal_process_dependency_object_libraries target)
# The CMake versions greater than 3.21 take care about the order of object files in a
# linker line, it's expected that all object files are located at the beginning of the linker
# line.
# So circular dependencies between static libraries and object files are resolved and no need
# to call the finalizer code.
- # TODO: This check is added before the actual release of CMake 3.21. So need to confirm that the
- # target version meets the expectations.
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21)
return()
endif()
@@ -134,17 +166,19 @@ function(__qt_internal_collect_dependency_object_libraries target out_var)
)
set_property(GLOBAL PROPERTY _qt_processed_object_libraries "")
+ __qt_internal_get_cmp0099_genex_check(cmp0099_check)
list(REMOVE_DUPLICATES object_libraries)
set(objects "")
foreach(dep IN LISTS object_libraries)
- list(PREPEND objects "$<TARGET_OBJECTS:${dep}>")
+ list(PREPEND objects "$<$<NOT:${cmp0099_check}>:$<TARGET_OBJECTS:${dep}>>")
endforeach()
set(${out_var} "${plugin_objects};${objects}" PARENT_SCOPE)
endfunction()
function(__qt_internal_collect_dependency_plugin_object_libraries target plugin_targets out_var)
+ __qt_internal_get_cmp0099_genex_check(cmp0099_check)
set(plugin_objects "")
foreach(plugin_target IN LISTS plugin_targets)
__qt_internal_collect_object_libraries_recursively(plugin_object_libraries
@@ -154,9 +188,16 @@ function(__qt_internal_collect_dependency_plugin_object_libraries target plugin_
__qt_internal_get_static_plugin_condition_genex("${plugin_target}" plugin_condition)
foreach(plugin_object_library IN LISTS plugin_object_libraries)
- list(APPEND plugin_objects
- "$<${plugin_condition}:$<TARGET_OBJECTS:${plugin_object_library}>>"
+ string(JOIN "" plugin_objects_genex
+ "$<"
+ "$<AND:"
+ "$<NOT:${cmp0099_check}>,"
+ "${plugin_condition}"
+ ">"
+ ":$<TARGET_OBJECTS:${plugin_object_library}>"
+ ">"
)
+ list(APPEND plugin_objects "${plugin_objects_genex}")
endforeach()
endforeach()
set(${out_var} "${plugin_objects}" PARENT_SCOPE)
@@ -177,6 +218,11 @@ function(__qt_internal_collect_object_libraries_recursively out_var target initi
set(object_libraries "")
foreach(lib IN LISTS libs interface_libs)
+ # Extract possible target from exported LINK_ONLY dependencies.
+ # This is super important for traversing backing library dependencies of qml plugins.
+ if(lib MATCHES "^\\$<LINK_ONLY:(.*)>$")
+ set(lib "${CMAKE_MATCH_1}")
+ endif()
if(TARGET ${lib})
get_target_property(aliased_target ${lib} ALIASED_TARGET)
if(aliased_target)
@@ -254,3 +300,38 @@ function(__qt_internal_defer_promote_targets_in_dir_scope_to_global)
endif()
endif()
endfunction()
+
+function(_qt_internal_set_up_static_runtime_library target)
+ if(QT_FEATURE_static_runtime)
+ if(MSVC)
+ set_property(TARGET ${target} PROPERTY
+ MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+ elseif(MINGW)
+ get_target_property(target_type ${target} TYPE)
+ if(target_type STREQUAL "EXECUTABLE")
+ set(link_option PRIVATE)
+ else()
+ set(link_option INTERFACE)
+ endif()
+ if(CLANG)
+ target_link_options(${target} ${link_option} "LINKER:-Bstatic")
+ else()
+ target_link_options(${target} ${link_option} "-static")
+ endif()
+ endif()
+ endif()
+endfunction()
+
+function(_qt_internal_warn_about_example_add_subdirectory)
+ # This is set by qt_build_repo_impl_examples() in QtBuildRepoHelpers.cmake, only for developer
+ # builds, to catch examples that are added via add_subdirectory instead of via
+ # qt_internal_add_example.
+ if(QT_WARN_ABOUT_EXAMPLE_ADD_SUBDIRECTORY)
+ get_filename_component(dir_name "${PROJECT_SOURCE_DIR}" NAME)
+ message(AUTHOR_WARNING
+ "It looks like this example project was added via add_subdirectory instead of via "
+ "qt_internal_add_example. This causes issues in certain build configurations. Please "
+ "change the code to use\n qt_internal_add_example(${dir_name})\ninstead."
+ )
+ endif()
+endfunction()