Backstory. 1) Starting with Qt 6.8, the prebuilt Qt for iOS SDK is built as static framework bundles instead of static libraries. That is done so that we can embed a privacy manifest into each framework bundle. 2) Up until CMake 3.28, CMake would not attempt to de-duplicate static libraries (or frameworks) on the command line. Starting with CMake 3.29, the CMP0156 policy was introduced to allow such de-duplication. 3) Since a while ago, Qt had its own policy handling for CMP0156, which it force sets to OLD, to disable any de-duplication. That was done to avoid possible regressions on platforms where link order matters. 4) A developer might add the -ObjC linker flag to a project, to ensure the linker retains all Objective-C categories it encounters in all the static libraries that were provided on the link line. Retaining in this case means that the /whole/ object file of a static library will be linked to the final executable. 5) The Apple ld linker (both the legacy and the new ld_prime one) can't cope with duplicate static frameworks on the link line when the -ObjC flag is used. It ends up throwing duplicate symbol errors, from trying to link the same object file from the same static framework more than once. The linker works just fine if the link line contains duplicate static libraries, rather than static frameworks. 6) When a project links against Qt6::Gui and Qt6::Core, the link line will contain Qt6::Core twice. This gets even more involved, when linking plugins, which cause static framework cycles, and thus a framework might appear multiple times. Thus, we have the situation that Qt forces the CMP0156 policy to OLD, Qt6::Core appears multiple times on the link line, no de-duplication is performed, the project adds the -ObjC flag, and the linker throws duplicate symbol errors. We can fix this by force setting the CMP0156 policy to NEW when targeting Apple platforms and using CMake 3.29+. A potential workaround for a project developer is to set the policy to NEW manually in their project. Unfortunately that doesn't work for older Qt versions. That's because CMake applies the policy value when add_executable is called, and the policy value in qt_add_executable is the one that is recorded when the function is defined. And the recorded policy is always OLD, because Qt6Config.cmake calls cmake_minimum_required with VERSION up to 3.21, which resets the policy value to OLD. So we have to force set the policy in qt_add_executable / qt_add_library via the existing __qt_internal_set_cmp0156 function. The __qt_internal_set_cmp0156 had some diagnostics to show a warning when the user modifies the policy themselves, but this never worked because of reason stated above: the policy value was always overridden in Qt6Config.cmake. To actually make the diagnostic work, there is now new code to save the policy value in the current directory scope, before Qt resets it. This only works if a project uses the find_package(Qt6 COMPONENTS Foo) signature. It won't work with a find_package(Qt6Core)-like signature. The policy value is not modified for platforms other than Apple ones for now. Amends 9702c3c78b2c16db6a9d0515d7d7698d9b064cd8 Pick-to: 6.5 6.8 6.9 Fixes: QTBUG-135978 Change-Id: I4d6e6c2a01e7092b417fc669d2aea40cf2dca578 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
264 lines
12 KiB
CMake
264 lines
12 KiB
CMake
# Copyright (C) 2024 The Qt Company Ltd.
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
@PACKAGE_INIT@
|
|
|
|
# This is included before the cmake_minimum_required on purpose.
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicCMakeEarlyPolicyHelpers.cmake")
|
|
__qt_internal_save_directory_scope_policy_cmp0156()
|
|
|
|
cmake_minimum_required(VERSION @min_new_policy_version@...@max_new_policy_version@)
|
|
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@ConfigExtras.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicCMakeVersionHelpers.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicCMakeHelpers.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtInstallPaths.cmake")
|
|
|
|
__qt_internal_require_suitable_cmake_version_for_using_qt()
|
|
|
|
get_filename_component(_qt_cmake_dir "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
|
|
set(_qt_@PROJECT_VERSION_MAJOR@_config_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")
|
|
|
|
if (NOT QT_NO_CREATE_TARGETS)
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Targets.cmake")
|
|
if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS)
|
|
if(CMAKE_VERSION VERSION_LESS 3.18 OR QT_USE_OLD_VERSION_LESS_TARGETS)
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@VersionlessTargets.cmake")
|
|
else()
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@VersionlessAliasTargets.cmake")
|
|
endif()
|
|
endif()
|
|
else()
|
|
# For examples using `find_package(...)` inside their CMakeLists.txt files:
|
|
# Make CMake's AUTOGEN detect this Qt version properly
|
|
set_directory_properties(PROPERTIES
|
|
QT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
|
QT_VERSION_MINOR @PROJECT_VERSION_MINOR@
|
|
QT_VERSION_PATCH @PROJECT_VERSION_PATCH@)
|
|
endif()
|
|
|
|
if(TARGET @INSTALL_CMAKE_NAMESPACE@::PlatformCommonInternal)
|
|
get_target_property(_qt_platform_internal_common_target
|
|
@INSTALL_CMAKE_NAMESPACE@::PlatformCommonInternal ALIASED_TARGET)
|
|
if(NOT _qt_platform_internal_common_target)
|
|
set(_qt_platform_internal_common_target @INSTALL_CMAKE_NAMESPACE@::PlatformCommonInternal)
|
|
endif()
|
|
set(_qt_internal_clang_msvc_frontend FALSE)
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
|
|
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
|
|
set(_qt_internal_clang_msvc_frontend TRUE)
|
|
endif()
|
|
set_target_properties(${_qt_platform_internal_common_target}
|
|
PROPERTIES
|
|
_qt_internal_cmake_generator "${CMAKE_GENERATOR}"
|
|
_qt_internal_clang_msvc_frontend "${_qt_internal_clang_msvc_frontend}"
|
|
)
|
|
unset(_qt_platform_internal_common_target)
|
|
endif()
|
|
|
|
get_filename_component(_qt_import_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
|
get_filename_component(_qt_import_prefix "${_qt_import_prefix}" REALPATH)
|
|
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}")
|
|
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/3rdparty/extra-cmake-modules/find-modules")
|
|
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/3rdparty/kwin")
|
|
|
|
if(APPLE)
|
|
if(NOT CMAKE_SYSTEM_NAME OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
|
set(__qt_internal_cmake_apple_support_files_path "${_qt_import_prefix}/macos")
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
|
set(__qt_internal_cmake_apple_support_files_path "${_qt_import_prefix}/ios")
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "visionOS")
|
|
set(__qt_internal_cmake_apple_support_files_path "${_qt_import_prefix}/visionos")
|
|
endif()
|
|
endif()
|
|
|
|
# Public helpers available to all Qt packages.
|
|
set(__qt_public_files_to_include
|
|
@QT_PUBLIC_FILES_TO_INCLUDE@
|
|
)
|
|
foreach(__qt_public_file_to_include IN LISTS __qt_public_files_to_include)
|
|
include("${__qt_public_file_to_include}")
|
|
endforeach()
|
|
|
|
if(NOT DEFINED QT_CMAKE_EXPORT_NAMESPACE)
|
|
set(QT_CMAKE_EXPORT_NAMESPACE @QT_CMAKE_EXPORT_NAMESPACE@)
|
|
endif()
|
|
|
|
set(QT_ADDITIONAL_PACKAGES_PREFIX_PATH "" CACHE STRING
|
|
"Additional directories where find(Qt6 ...) components are searched")
|
|
set(QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH "" CACHE STRING
|
|
"Additional directories where find(Qt6 ...) host Qt components are searched")
|
|
|
|
__qt_internal_collect_additional_prefix_paths(_qt_additional_packages_prefix_paths
|
|
QT_ADDITIONAL_PACKAGES_PREFIX_PATH)
|
|
__qt_internal_collect_additional_prefix_paths(_qt_additional_host_packages_prefix_paths
|
|
QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH)
|
|
|
|
__qt_internal_prefix_paths_to_roots(_qt_additional_host_packages_root_paths
|
|
"${_qt_additional_host_packages_prefix_paths}")
|
|
|
|
__qt_internal_collect_additional_module_paths()
|
|
|
|
# Propagate sanitizer flags to both internal Qt builds and user projects.
|
|
# Allow opt-out in case if downstream projects handle it in a different way.
|
|
set(QT_CONFIGURED_SANITIZER_OPTIONS "@ECM_ENABLE_SANITIZERS@")
|
|
|
|
if(QT_CONFIGURED_SANITIZER_OPTIONS
|
|
AND NOT __qt_sanitizer_options_set
|
|
AND NOT QT_NO_ADD_SANITIZER_OPTIONS)
|
|
set(ECM_ENABLE_SANITIZERS "${QT_CONFIGURED_SANITIZER_OPTIONS}")
|
|
include(
|
|
"${CMAKE_CURRENT_LIST_DIR}/3rdparty/extra-cmake-modules/modules/ECMEnableSanitizers.cmake")
|
|
endif()
|
|
# Mark that the current directory scope has its sanitizer flags set.
|
|
set(__qt_sanitizer_options_set TRUE)
|
|
|
|
# Find required dependencies, if any.
|
|
include(CMakeFindDependencyMacro)
|
|
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Dependencies.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Dependencies.cmake")
|
|
|
|
_qt_internal_suggest_dependency_debugging(@INSTALL_CMAKE_NAMESPACE@
|
|
__qt_@INSTALL_CMAKE_NAMESPACE@_pkg ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE)
|
|
|
|
if(NOT @INSTALL_CMAKE_NAMESPACE@_FOUND)
|
|
# Clear the components, no need to look for them if dependencies were not found, otherwise
|
|
# you get a wall of recursive error messages.
|
|
set(@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS "")
|
|
endif()
|
|
endif()
|
|
|
|
set(_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_QUIET)
|
|
if(@INSTALL_CMAKE_NAMESPACE@_FIND_QUIETLY)
|
|
set(_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_QUIET QUIET)
|
|
endif()
|
|
|
|
set(__qt_use_no_default_path_for_qt_packages "NO_DEFAULT_PATH")
|
|
if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES)
|
|
set(__qt_use_no_default_path_for_qt_packages "")
|
|
endif()
|
|
|
|
set(__qt_umbrella_find_components ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS})
|
|
__qt_internal_handle_find_all_qt_module_packages(__qt_umbrella_find_components
|
|
COMPONENTS ${__qt_umbrella_find_components}
|
|
)
|
|
|
|
foreach(module ${__qt_umbrella_find_components})
|
|
if(NOT "${QT_HOST_PATH}" STREQUAL ""
|
|
AND "${module}" MATCHES "Tools$"
|
|
AND NOT "${module}" MATCHES "UiTools$"
|
|
AND NOT "${module}" MATCHES "ShaderTools$"
|
|
AND NOT "${module}" MATCHES "^Tools$"
|
|
AND NOT QT_NO_FIND_HOST_TOOLS_PATH_MANIPULATION)
|
|
# Make sure that a Qt*Tools package is also looked up in QT_HOST_PATH.
|
|
# But don't match QtShaderTools and QtTools which are cross-compiled target package names.
|
|
# Allow opt out just in case.
|
|
get_filename_component(__qt_find_package_host_qt_path
|
|
"${@INSTALL_CMAKE_NAMESPACE@HostInfo_DIR}/.." ABSOLUTE)
|
|
set(__qt_backup_cmake_prefix_path "${CMAKE_PREFIX_PATH}")
|
|
set(__qt_backup_cmake_find_root_path "${CMAKE_FIND_ROOT_PATH}")
|
|
list(PREPEND CMAKE_PREFIX_PATH "${__qt_find_package_host_qt_path}"
|
|
${_qt_additional_host_packages_prefix_paths})
|
|
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}"
|
|
${_qt_additional_host_packages_root_paths})
|
|
endif()
|
|
|
|
_qt_internal_save_find_package_context_for_debugging(@INSTALL_CMAKE_NAMESPACE@${module})
|
|
|
|
if(@INSTALL_CMAKE_NAMESPACE@${module}_FOUND)
|
|
# Tools packages don't usually provide a qt module, so there's no target.
|
|
if(TARGET @INSTALL_CMAKE_NAMESPACE@::${module})
|
|
get_target_property(__qt_${module}_is_private @INSTALL_CMAKE_NAMESPACE@::${module}
|
|
_qt_is_private_module
|
|
)
|
|
if(__qt_${module}_is_private)
|
|
_qt_internal_show_private_module_warning(${module})
|
|
endif()
|
|
unset(__qt_${module}_is_private)
|
|
endif()
|
|
else()
|
|
find_package(@INSTALL_CMAKE_NAMESPACE@${module}
|
|
${@INSTALL_CMAKE_NAMESPACE@_FIND_VERSION}
|
|
${_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_QUIET}
|
|
PATHS
|
|
${QT_BUILD_CMAKE_PREFIX_PATH}
|
|
${_qt_cmake_dir}
|
|
${_qt_additional_packages_prefix_paths}
|
|
${__qt_find_package_host_qt_path}
|
|
${_qt_additional_host_packages_prefix_paths}
|
|
${__qt_use_no_default_path_for_qt_packages}
|
|
)
|
|
endif()
|
|
|
|
if(NOT "${__qt_find_package_host_qt_path}" STREQUAL "")
|
|
set(CMAKE_PREFIX_PATH "${__qt_backup_cmake_prefix_path}")
|
|
set(CMAKE_FIND_ROOT_PATH "${__qt_backup_cmake_find_root_path}")
|
|
unset(__qt_backup_cmake_prefix_path)
|
|
unset(__qt_backup_cmake_find_root_path)
|
|
unset(__qt_find_package_host_qt_path)
|
|
endif()
|
|
|
|
if (NOT @INSTALL_CMAKE_NAMESPACE@${module}_FOUND)
|
|
set(_qt_expected_component_config_path
|
|
"${_qt_cmake_dir}/@INSTALL_CMAKE_NAMESPACE@${module}/@INSTALL_CMAKE_NAMESPACE@${module}Config.cmake")
|
|
get_filename_component(
|
|
_qt_expected_component_dir_path "${_qt_expected_component_config_path}" DIRECTORY)
|
|
|
|
set(_qt_component_not_found_msg
|
|
"\nExpected Config file at \"${_qt_expected_component_config_path}\"")
|
|
|
|
if(EXISTS "${_qt_expected_component_config_path}")
|
|
string(APPEND _qt_component_not_found_msg " exists \n")
|
|
else()
|
|
string(APPEND _qt_component_not_found_msg " does NOT exist\n")
|
|
endif()
|
|
|
|
set(_qt_candidate_component_dir_path "${@INSTALL_CMAKE_NAMESPACE@${module}_DIR}")
|
|
|
|
if(_qt_candidate_component_dir_path AND
|
|
NOT _qt_expected_component_dir_path STREQUAL _qt_candidate_component_dir_path)
|
|
string(APPEND _qt_component_not_found_msg
|
|
"\n@INSTALL_CMAKE_NAMESPACE@${module}_DIR was computed by CMake or specified on the "
|
|
"command line by the user: \"${_qt_candidate_component_dir_path}\" "
|
|
"\nThe expected and computed paths are different, which might be the reason for "
|
|
"the package not to be found.")
|
|
endif()
|
|
|
|
if(@INSTALL_CMAKE_NAMESPACE@_FIND_REQUIRED_${module})
|
|
set(@INSTALL_CMAKE_NAMESPACE@_FOUND False)
|
|
set(_Qt_NOTFOUND_MESSAGE
|
|
"${_Qt_NOTFOUND_MESSAGE}Failed to find required Qt component \"${module}\". ${_qt_component_not_found_msg}")
|
|
set(_qt_full_component_name "@INSTALL_CMAKE_NAMESPACE@${module}")
|
|
_qt_internal_suggest_dependency_debugging(${_qt_full_component_name}
|
|
_qt_full_component_name _Qt_NOTFOUND_MESSAGE)
|
|
unset(_qt_full_component_name)
|
|
break()
|
|
elseif(NOT @INSTALL_CMAKE_NAMESPACE@_FIND_QUIETLY)
|
|
message(WARNING
|
|
"Failed to find optional Qt component \"${module}\". ${_qt_component_not_found_msg}")
|
|
endif()
|
|
|
|
unset(_qt_expected_component_config_path)
|
|
unset(_qt_expected_component_dir_path)
|
|
unset(_qt_candidate_component_dir_path)
|
|
unset(_qt_component_not_found_msg)
|
|
endif()
|
|
endforeach()
|
|
|
|
if(@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS AND _Qt_NOTFOUND_MESSAGE)
|
|
set(@INSTALL_CMAKE_NAMESPACE@_NOT_FOUND_MESSAGE "${_Qt_NOTFOUND_MESSAGE}")
|
|
unset(_Qt_NOTFOUND_MESSAGE)
|
|
endif()
|
|
|
|
if(@INSTALL_CMAKE_NAMESPACE@_FOUND
|
|
AND COMMAND _qt_internal_override_example_install_dir_to_dot
|
|
AND NOT _qt_internal_example_dir_set_to_dot)
|
|
_qt_internal_override_example_install_dir_to_dot()
|
|
endif()
|
|
|
|
__qt_internal_defer_promote_targets_in_dir_scope_to_global()
|
|
if(CMAKE_VERSION VERSION_LESS 3.21)
|
|
__qt_internal_check_link_order_matters()
|
|
__qt_internal_check_cmp0099_available()
|
|
endif()
|