2022-07-05 11:26:52 +00:00
|
|
|
# Copyright (C) 2022 The Qt Company Ltd.
|
2022-08-19 13:21:34 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
2022-07-05 11:26:52 +00:00
|
|
|
|
2021-04-29 10:47:52 +00:00
|
|
|
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
|
|
|
|
# different directory scope than where the target was created.
|
|
|
|
# Strip it.
|
|
|
|
#
|
|
|
|
# For informational purposes, in CMake 3.18, the target name looks as follows:
|
|
|
|
# ::@(0x5604cb3f6b50);Threads::Threads;::@
|
|
|
|
# This case doesn't have to be stripped (at least for now), because when we iterate over
|
|
|
|
# link libraries, the tokens appear as separate target names.
|
|
|
|
#
|
|
|
|
# Example: Threads::Threads::@<0x5604cb3f6b50>
|
|
|
|
# Output: Threads::Threads
|
|
|
|
string(REGEX REPLACE "::@<.+>$" "" target "${target}")
|
|
|
|
set("${out_var}" "${target}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
2021-05-19 17:46:24 +00:00
|
|
|
|
2021-06-10 17:01:35 +00:00
|
|
|
# Tests if linker could resolve circular dependencies between object files and static libraries.
|
2021-06-16 17:24:59 +00:00
|
|
|
function(__qt_internal_static_link_order_public_test result)
|
2021-06-10 17:01:35 +00:00
|
|
|
# We could trust iOS linker
|
|
|
|
if(IOS)
|
2021-07-08 16:54:53 +00:00
|
|
|
set(QT_HAVE_LINK_ORDER_MATTERS "FALSE" CACHE INTERNAL "Link order matters")
|
2021-06-10 17:01:35 +00:00
|
|
|
endif()
|
|
|
|
|
2021-06-16 17:24:59 +00:00
|
|
|
if(DEFINED QT_HAVE_LINK_ORDER_MATTERS)
|
|
|
|
set(${result} "${QT_HAVE_LINK_ORDER_MATTERS}" PARENT_SCOPE)
|
2021-06-10 17:01:35 +00:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(EXISTS "${QT_CMAKE_DIR}")
|
2021-06-16 17:24:59 +00:00
|
|
|
set(test_source_basedir "${QT_CMAKE_DIR}/..")
|
2021-06-10 17:01:35 +00:00
|
|
|
else()
|
|
|
|
set(test_source_basedir "${_qt_cmake_dir}/${QT_CMAKE_EXPORT_NAMESPACE}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
try_compile(${result}
|
2021-06-16 17:24:59 +00:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/config.tests/static_link_order"
|
2021-06-10 17:01:35 +00:00
|
|
|
"${test_source_basedir}/config.tests/static_link_order"
|
|
|
|
static_link_order_test
|
|
|
|
static_link_order_test
|
|
|
|
)
|
2021-06-16 17:24:59 +00:00
|
|
|
message(STATUS "Check if linker can resolve circular dependencies - ${${result}}")
|
2021-06-10 17:01:35 +00:00
|
|
|
|
|
|
|
# Invert the result
|
|
|
|
if(${result})
|
|
|
|
set(${result} FALSE)
|
|
|
|
else()
|
|
|
|
set(${result} TRUE)
|
|
|
|
endif()
|
|
|
|
|
2021-07-08 16:54:53 +00:00
|
|
|
set(QT_HAVE_LINK_ORDER_MATTERS "${${result}}" CACHE INTERNAL "Link order matters")
|
2021-06-10 17:01:35 +00:00
|
|
|
|
|
|
|
set(${result} "${${result}}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Sets _qt_link_order_matters flag for the target.
|
|
|
|
function(__qt_internal_set_link_order_matters target link_order_matters)
|
|
|
|
if(NOT TARGET ${target})
|
|
|
|
message(FATAL_ERROR "Unable to set _qt_link_order_matters flag. ${target} is not a target.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_target_property(aliased_target ${target} ALIASED_TARGET)
|
|
|
|
if(aliased_target)
|
|
|
|
set(target "${aliased_target}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(link_order_matters)
|
|
|
|
set(link_order_matters TRUE)
|
|
|
|
else()
|
|
|
|
set(link_order_matters FALSE)
|
|
|
|
endif()
|
|
|
|
set_target_properties(${target} PROPERTIES _qt_link_order_matters "${link_order_matters}")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Function combines __qt_internal_static_link_order_public_test and
|
2021-06-16 17:24:59 +00:00
|
|
|
# __qt_internal_set_link_order_matters calls on Qt::Platform target.
|
|
|
|
function(__qt_internal_check_link_order_matters)
|
2021-06-10 17:01:35 +00:00
|
|
|
__qt_internal_static_link_order_public_test(
|
2021-06-16 17:24:59 +00:00
|
|
|
link_order_matters
|
2021-06-10 17:01:35 +00:00
|
|
|
)
|
|
|
|
__qt_internal_set_link_order_matters(
|
2021-06-16 17:24:59 +00:00
|
|
|
${QT_CMAKE_EXPORT_NAMESPACE}::Platform "${link_order_matters}"
|
2021-06-10 17:01:35 +00:00
|
|
|
)
|
2021-06-16 17:24:59 +00:00
|
|
|
|
|
|
|
if("${ARGC}" GREATER "0" AND NOT ARGV0 STREQUAL "")
|
|
|
|
set(${ARGV0} ${link_order_matters} PARENT_SCOPE)
|
|
|
|
endif()
|
2021-06-10 17:01:35 +00:00
|
|
|
endfunction()
|
|
|
|
|
2021-06-29 16:00:39 +00:00
|
|
|
# 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()
|
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
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
|
2021-06-10 17:01:35 +00:00
|
|
|
# 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.
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21)
|
|
|
|
return()
|
|
|
|
endif()
|
2021-06-15 11:09:57 +00:00
|
|
|
get_target_property(processed ${target} _qt_object_libraries_finalizer_processed)
|
2021-05-19 17:46:24 +00:00
|
|
|
if(processed)
|
|
|
|
return()
|
|
|
|
endif()
|
2021-06-15 11:09:57 +00:00
|
|
|
set_target_properties(${target} PROPERTIES _qt_object_libraries_finalizer_processed TRUE)
|
2021-05-19 17:46:24 +00:00
|
|
|
|
2021-06-17 15:55:42 +00:00
|
|
|
get_target_property(qt_link_order_matters
|
|
|
|
${QT_CMAKE_EXPORT_NAMESPACE}::Platform _qt_link_order_matters
|
|
|
|
)
|
2021-06-10 17:01:35 +00:00
|
|
|
__qt_internal_check_finalizer_mode(${target}
|
|
|
|
use_finalizer_mode
|
2021-06-15 11:09:57 +00:00
|
|
|
object_libraries
|
2021-06-17 15:55:42 +00:00
|
|
|
DEFAULT_VALUE "${qt_link_order_matters}"
|
2021-06-10 17:01:35 +00:00
|
|
|
)
|
|
|
|
|
2021-05-19 17:46:24 +00:00
|
|
|
if(NOT use_finalizer_mode)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
__qt_internal_collect_dependency_object_libraries(${target} objects)
|
|
|
|
target_sources(${target} PRIVATE "${objects}")
|
2021-05-19 17:46:24 +00:00
|
|
|
endfunction()
|
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
function(__qt_internal_collect_dependency_object_libraries target out_var)
|
|
|
|
set_property(GLOBAL PROPERTY _qt_processed_object_libraries "")
|
2021-06-02 13:02:03 +00:00
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
__qt_internal_collect_object_libraries_recursively(object_libraries ${target} ${target})
|
2021-06-02 13:02:03 +00:00
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
# Collect object libraries of plugins and plugin dependencies.
|
2021-06-02 13:02:03 +00:00
|
|
|
__qt_internal_collect_plugin_targets_from_dependencies(${target} plugin_targets)
|
2021-06-15 11:09:57 +00:00
|
|
|
__qt_internal_collect_dependency_plugin_object_libraries(${target}
|
2021-06-02 13:02:03 +00:00
|
|
|
"${plugin_targets}"
|
2021-06-15 11:09:57 +00:00
|
|
|
plugin_objects
|
2021-06-02 13:02:03 +00:00
|
|
|
)
|
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
set_property(GLOBAL PROPERTY _qt_processed_object_libraries "")
|
2021-06-29 16:00:39 +00:00
|
|
|
__qt_internal_get_cmp0099_genex_check(cmp0099_check)
|
2021-05-19 17:46:24 +00:00
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
list(REMOVE_DUPLICATES object_libraries)
|
|
|
|
set(objects "")
|
|
|
|
foreach(dep IN LISTS object_libraries)
|
2021-06-29 16:00:39 +00:00
|
|
|
list(PREPEND objects "$<$<NOT:${cmp0099_check}>:$<TARGET_OBJECTS:${dep}>>")
|
2021-05-19 17:46:24 +00:00
|
|
|
endforeach()
|
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
set(${out_var} "${plugin_objects};${objects}" PARENT_SCOPE)
|
2021-06-02 13:02:03 +00:00
|
|
|
endfunction()
|
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
function(__qt_internal_collect_dependency_plugin_object_libraries target plugin_targets out_var)
|
2021-06-29 16:00:39 +00:00
|
|
|
__qt_internal_get_cmp0099_genex_check(cmp0099_check)
|
2021-06-15 11:09:57 +00:00
|
|
|
set(plugin_objects "")
|
2021-06-02 13:02:03 +00:00
|
|
|
foreach(plugin_target IN LISTS plugin_targets)
|
2021-06-15 11:09:57 +00:00
|
|
|
__qt_internal_collect_object_libraries_recursively(plugin_object_libraries
|
2021-06-02 13:02:03 +00:00
|
|
|
"${QT_CMAKE_EXPORT_NAMESPACE}::${plugin_target}"
|
|
|
|
${target}
|
|
|
|
)
|
|
|
|
__qt_internal_get_static_plugin_condition_genex("${plugin_target}" plugin_condition)
|
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
foreach(plugin_object_library IN LISTS plugin_object_libraries)
|
2021-06-29 16:00:39 +00:00
|
|
|
string(JOIN "" plugin_objects_genex
|
|
|
|
"$<"
|
|
|
|
"$<AND:"
|
|
|
|
"$<NOT:${cmp0099_check}>,"
|
|
|
|
"${plugin_condition}"
|
|
|
|
">"
|
|
|
|
":$<TARGET_OBJECTS:${plugin_object_library}>"
|
|
|
|
">"
|
2021-06-02 13:02:03 +00:00
|
|
|
)
|
2021-06-29 16:00:39 +00:00
|
|
|
list(APPEND plugin_objects "${plugin_objects_genex}")
|
2021-06-02 13:02:03 +00:00
|
|
|
endforeach()
|
|
|
|
endforeach()
|
2021-06-15 11:09:57 +00:00
|
|
|
set(${out_var} "${plugin_objects}" PARENT_SCOPE)
|
2021-05-19 17:46:24 +00:00
|
|
|
endfunction()
|
2021-05-28 12:02:29 +00:00
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
function(__qt_internal_collect_object_libraries_recursively out_var target initial_target)
|
|
|
|
get_property(processed_object_libraries GLOBAL PROPERTY _qt_processed_object_libraries)
|
2021-06-01 10:41:55 +00:00
|
|
|
|
|
|
|
set(interface_libs "")
|
|
|
|
set(libs "")
|
2021-05-28 12:02:29 +00:00
|
|
|
if(NOT "${target}" STREQUAL "${initial_target}")
|
|
|
|
get_target_property(interface_libs ${target} INTERFACE_LINK_LIBRARIES)
|
|
|
|
endif()
|
2021-06-01 10:41:55 +00:00
|
|
|
get_target_property(type ${target} TYPE)
|
|
|
|
if(NOT type STREQUAL "INTERFACE_LIBRARY")
|
|
|
|
get_target_property(libs ${target} LINK_LIBRARIES)
|
|
|
|
endif()
|
2021-05-28 12:02:29 +00:00
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
set(object_libraries "")
|
2021-05-28 12:02:29 +00:00
|
|
|
foreach(lib IN LISTS libs interface_libs)
|
2021-06-25 13:16:19 +00:00
|
|
|
# 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()
|
2021-05-28 12:02:29 +00:00
|
|
|
if(TARGET ${lib})
|
|
|
|
get_target_property(aliased_target ${lib} ALIASED_TARGET)
|
|
|
|
if(aliased_target)
|
|
|
|
set(lib ${aliased_target})
|
|
|
|
endif()
|
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
if(${lib} IN_LIST processed_object_libraries)
|
2021-05-28 12:02:29 +00:00
|
|
|
continue()
|
|
|
|
else()
|
2021-06-15 11:09:57 +00:00
|
|
|
list(APPEND processed_object_libraries ${lib})
|
|
|
|
set_property(GLOBAL APPEND PROPERTY _qt_processed_object_libraries ${lib})
|
2021-05-28 12:02:29 +00:00
|
|
|
endif()
|
|
|
|
|
2021-06-15 11:09:57 +00:00
|
|
|
get_target_property(is_qt_propagated_object_library ${lib}
|
|
|
|
_is_qt_propagated_object_library
|
|
|
|
)
|
|
|
|
if(is_qt_propagated_object_library)
|
|
|
|
list(APPEND object_libraries ${lib})
|
2021-05-28 12:02:29 +00:00
|
|
|
else()
|
2021-06-15 11:09:57 +00:00
|
|
|
__qt_internal_collect_object_libraries_recursively(next_level_object_libraries
|
2021-06-02 13:02:03 +00:00
|
|
|
${lib}
|
|
|
|
${initial_target}
|
|
|
|
)
|
2021-06-15 11:09:57 +00:00
|
|
|
list(APPEND object_libraries ${next_level_object_libraries})
|
2021-05-28 12:02:29 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2021-06-15 11:09:57 +00:00
|
|
|
set(${out_var} "${object_libraries}" PARENT_SCOPE)
|
2021-05-28 12:02:29 +00:00
|
|
|
endfunction()
|
2021-05-20 11:38:30 +00:00
|
|
|
|
|
|
|
function(__qt_internal_promote_target_to_global target)
|
|
|
|
get_property(is_global TARGET ${target} PROPERTY IMPORTED_GLOBAL)
|
|
|
|
if(NOT is_global)
|
|
|
|
message(DEBUG "Promoting target to global: '${target}'")
|
|
|
|
set_property(TARGET ${target} PROPERTY IMPORTED_GLOBAL TRUE)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(__qt_internal_promote_target_to_global_checked target)
|
2021-06-11 07:54:47 +00:00
|
|
|
# With CMake version 3.21 we use a different mechanism that allows us to promote all targets
|
|
|
|
# within a scope.
|
|
|
|
if(QT_PROMOTE_TO_GLOBAL_TARGETS AND CMAKE_VERSION VERSION_LESS 3.21)
|
2021-05-20 11:38:30 +00:00
|
|
|
__qt_internal_promote_target_to_global(${target})
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2021-06-11 07:54:47 +00:00
|
|
|
|
|
|
|
function(__qt_internal_promote_targets_in_dir_scope_to_global)
|
|
|
|
# IMPORTED_TARGETS got added in 3.21.
|
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.21)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_directory_property(targets IMPORTED_TARGETS)
|
|
|
|
foreach(target IN LISTS targets)
|
|
|
|
__qt_internal_promote_target_to_global(${target})
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(__qt_internal_promote_targets_in_dir_scope_to_global_checked)
|
|
|
|
if(QT_PROMOTE_TO_GLOBAL_TARGETS)
|
|
|
|
__qt_internal_promote_targets_in_dir_scope_to_global()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# This function ends up being called multiple times as part of a find_package(Qt6Foo) call,
|
|
|
|
# due sub-packages depending on the Qt6 package. Ensure the finalizer is ran only once per
|
|
|
|
# directory scope.
|
|
|
|
function(__qt_internal_defer_promote_targets_in_dir_scope_to_global)
|
|
|
|
get_directory_property(is_deferred _qt_promote_targets_is_deferred)
|
|
|
|
if(NOT is_deferred)
|
|
|
|
set_property(DIRECTORY PROPERTY _qt_promote_targets_is_deferred TRUE)
|
|
|
|
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
|
|
|
|
cmake_language(DEFER CALL __qt_internal_promote_targets_in_dir_scope_to_global_checked)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2021-07-08 12:01:59 +00:00
|
|
|
|
|
|
|
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)
|
2023-08-19 08:27:58 +00:00
|
|
|
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()
|
2021-07-08 12:01:59 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|