summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2024-01-24 16:12:19 +0100
committerAlexey Edelev <alexey.edelev@qt.io>2024-03-12 20:27:42 +0100
commit173164cd477211e574c0d04abef51aa0f4c3f78d (patch)
treef6ed45b761b5a133ba1ff409aeb99ea076ad304e
parenta1d18276a84f0f72af48c3b899c80d4b9407ef4b (diff)
"Simplify" versionless targets
Versionless targets in Qt6 are interface libraries that link the versioned libraries using the INTERFACE link type. This makes the linking chain more complicated than it can be. Also we miss some significant interface properties in the versionless targets comparing to the versioned targets. The new approach manually generates the versionless targets, instead of using CMake exports. For CMake versions < 3.18 we now create a copy of the versioned targets. The copy includes all the relevant INTERFACE properties from the versioned targets and imported locations for all configs. For CMake versions >= 3.18 we now create the versionless target ALIASes which should behave give the transparent access to the versioned targets. Using the QT_USE_OLD_VERSION_LESS_TARGETS flag you may force the behavor of the CMake versions <= 3.18 The change is partial workaround for QTBUG-86533. Task-number: QTBUG-114706 Change-Id: Iafadf6154eb4912df0697648c031fcc1cbde04e0 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--cmake/Qt3rdPartyLibraryConfig.cmake.in6
-rw-r--r--cmake/Qt3rdPartyLibraryHelpers.cmake1
-rw-r--r--cmake/QtBaseGlobalTargets.cmake7
-rw-r--r--cmake/QtBuildHelpers.cmake2
-rw-r--r--cmake/QtConfig.cmake.in7
-rw-r--r--cmake/QtModuleConfig.cmake.in11
-rw-r--r--cmake/QtModuleHelpers.cmake4
-rw-r--r--cmake/QtPriHelpers.cmake6
-rw-r--r--cmake/QtPublicCMakeHelpers.cmake149
-rw-r--r--cmake/QtTargetHelpers.cmake58
-rw-r--r--cmake/QtVersionlessAliasTargets.cmake.in7
-rw-r--r--cmake/QtVersionlessTargets.cmake.in7
-rw-r--r--tests/auto/cmake/test_versionless_targets/CMakeLists.txt103
-rw-r--r--tests/auto/cmake/test_versionless_targets/default/CMakeLists.txt17
-rw-r--r--tests/auto/cmake/test_versionless_targets/force_off/CMakeLists.txt18
-rw-r--r--tests/auto/cmake/test_versionless_targets/force_old/CMakeLists.txt21
-rw-r--r--tests/auto/cmake/test_versionless_targets/force_on/CMakeLists.txt20
17 files changed, 406 insertions, 38 deletions
diff --git a/cmake/Qt3rdPartyLibraryConfig.cmake.in b/cmake/Qt3rdPartyLibraryConfig.cmake.in
index 6a5c652f53..869c67443f 100644
--- a/cmake/Qt3rdPartyLibraryConfig.cmake.in
+++ b/cmake/Qt3rdPartyLibraryConfig.cmake.in
@@ -23,7 +23,11 @@ if (NOT QT_NO_CREATE_TARGETS)
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@AdditionalTargetInfo.cmake")
if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS)
- include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@VersionlessTargets.cmake")
+ if(CMAKE_VERSION VERSION_LESS 3.18 OR QT_USE_OLD_VERSION_LESS_TARGETS)
+ include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@VersionlessTargets.cmake")
+ else()
+ include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@VersionlessAliasTargets.cmake")
+ endif()
endif()
endif()
diff --git a/cmake/Qt3rdPartyLibraryHelpers.cmake b/cmake/Qt3rdPartyLibraryHelpers.cmake
index dca360d074..924db182be 100644
--- a/cmake/Qt3rdPartyLibraryHelpers.cmake
+++ b/cmake/Qt3rdPartyLibraryHelpers.cmake
@@ -310,6 +310,7 @@ function(qt_internal_add_3rdparty_library target)
qt_internal_export_modern_cmake_config_targets_file(
TARGETS ${target}
EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE}${target}
+ CONFIG_BUILD_DIR "${config_build_dir}"
CONFIG_INSTALL_DIR "${config_install_dir}"
)
diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake
index 3535f41a3b..5bb4714cb0 100644
--- a/cmake/QtBaseGlobalTargets.cmake
+++ b/cmake/QtBaseGlobalTargets.cmake
@@ -159,9 +159,10 @@ qt_install(EXPORT ${__export_name}
DESTINATION "${__GlobalConfig_install_dir}")
qt_internal_export_modern_cmake_config_targets_file(TARGETS ${__export_targets}
- EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE}
- CONFIG_INSTALL_DIR
- ${__GlobalConfig_install_dir})
+ EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE}
+ CONFIG_BUILD_DIR "${__GlobalConfig_build_dir}"
+ CONFIG_INSTALL_DIR "${__GlobalConfig_install_dir}"
+)
# Save minimum required CMake version to use Qt.
qt_internal_get_supported_min_cmake_version_for_using_qt(supported_min_version_for_using_qt)
diff --git a/cmake/QtBuildHelpers.cmake b/cmake/QtBuildHelpers.cmake
index 9b17dba7ac..cce57cd5f6 100644
--- a/cmake/QtBuildHelpers.cmake
+++ b/cmake/QtBuildHelpers.cmake
@@ -253,6 +253,8 @@ function(qt_internal_get_qt_build_private_files_to_install out_var)
QtSeparateDebugInfo.Info.plist.in
QtSetup.cmake
QtStandaloneTestsConfig.cmake.in
+ QtVersionlessAliasTargets.cmake.in
+ QtVersionlessTargets.cmake.in
QtWriteArgsFile.cmake
modulecppexports.h.in
qbatchedtestrunner.in.cpp
diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in
index fb0e823eaa..fee5682d28 100644
--- a/cmake/QtConfig.cmake.in
+++ b/cmake/QtConfig.cmake.in
@@ -7,6 +7,7 @@ cmake_minimum_required(VERSION @min_new_policy_version@...@max_new_policy_versio
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@ConfigExtras.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicCMakeVersionHelpers.cmake")
+include("${CMAKE_CURRENT_LIST_DIR}/QtPublicCMakeHelpers.cmake")
__qt_internal_require_suitable_cmake_version_for_using_qt()
get_filename_component(_qt_cmake_dir "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
@@ -15,7 +16,11 @@ 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)
- include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@VersionlessTargets.cmake")
+ 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:
diff --git a/cmake/QtModuleConfig.cmake.in b/cmake/QtModuleConfig.cmake.in
index 23d3ff366d..06a7daad71 100644
--- a/cmake/QtModuleConfig.cmake.in
+++ b/cmake/QtModuleConfig.cmake.in
@@ -32,9 +32,6 @@ if (NOT QT_NO_CREATE_TARGETS AND @INSTALL_CMAKE_NAMESPACE@@target@_FOUND)
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@AdditionalTargetInfo.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@ExtraProperties.cmake"
OPTIONAL)
- if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS)
- include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@VersionlessTargets.cmake")
- endif()
# DEPRECATED
# Provide old style variables for includes, compile definitions, etc.
@@ -131,6 +128,14 @@ if (TARGET @QT_CMAKE_EXPORT_NAMESPACE@::@target@)
EXISTS "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@BuildInternals.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@BuildInternals.cmake")
endif()
+
+ 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@@target@VersionlessTargets.cmake")
+ else()
+ include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@VersionlessAliasTargets.cmake")
+ endif()
+ endif()
else()
set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND FALSE)
diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake
index a4fa66c037..6c768c6456 100644
--- a/cmake/QtModuleHelpers.cmake
+++ b/cmake/QtModuleHelpers.cmake
@@ -834,7 +834,9 @@ set(QT_ALLOW_MISSING_TOOLS_PACKAGES TRUE)")
qt_internal_export_modern_cmake_config_targets_file(
TARGETS ${exported_targets}
EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE}${target}
- CONFIG_INSTALL_DIR "${config_install_dir}")
+ CONFIG_BUILD_DIR "${config_build_dir}"
+ CONFIG_INSTALL_DIR "${config_install_dir}"
+ )
qt_internal_export_genex_properties(TARGETS ${target}
EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE}${target}
diff --git a/cmake/QtPriHelpers.cmake b/cmake/QtPriHelpers.cmake
index f1d45cdcf6..e0590791b3 100644
--- a/cmake/QtPriHelpers.cmake
+++ b/cmake/QtPriHelpers.cmake
@@ -153,6 +153,12 @@ function(qt_get_direct_module_dependencies target out_var)
list(PREPEND libs ${ifacelibs})
continue()
endif()
+ get_target_property(aliased_target ${lib} ALIASED_TARGET)
+ if(TARGET "${aliased_target}")
+ # If versionless target is alias, use what the alias points to.
+ list(PREPEND libs "${aliased_target}")
+ continue()
+ endif()
if(lib_type STREQUAL "OBJECT_LIBRARY")
# Skip object libraries, because they're already part of ${target}.
continue()
diff --git a/cmake/QtPublicCMakeHelpers.cmake b/cmake/QtPublicCMakeHelpers.cmake
index e8372a64ca..2bfefae7e9 100644
--- a/cmake/QtPublicCMakeHelpers.cmake
+++ b/cmake/QtPublicCMakeHelpers.cmake
@@ -266,3 +266,152 @@ function(_qt_internal_add_phony_target_deferred target)
cmake_language(CALL ${creation_hook} ${target})
endif()
endfunction()
+
+# The helper function that checks if module was included multiple times, and has the inconsistent
+# set of targets that belong to the module. It's expected that either all 'targets' or none of them
+# will be written to the 'targets_not_defined' variable, if the module was not or was
+# searched before accordingly.
+function(_qt_internal_check_multiple_inclusion targets_not_defined targets)
+ set(targets_defined "")
+ set(${targets_not_defined} "")
+ set(expected_targets "")
+ foreach(expected_target ${targets})
+ list(APPEND expected_targets ${expected_target})
+ if(NOT TARGET Qt::${expected_target})
+ list(APPEND ${targets_not_defined} ${expected_target})
+ endif()
+ if(TARGET Qt::${expected_target})
+ list(APPEND targets_defined ${expected_target})
+ endif()
+ endforeach()
+ if("${targets_defined}" STREQUAL "${expected_targets}")
+ set(${targets_not_defined} "" PARENT_SCOPE)
+ return()
+ endif()
+ if(NOT "${targets_defined}" STREQUAL "")
+ message(FATAL_ERROR "Some (but not all) targets in this export set were already defined."
+ "\nTargets Defined: ${targets_defined}\nTargets not yet defined: "
+ "${${targets_not_defined}}\n"
+ )
+ endif()
+ set(${targets_not_defined} "${${targets_not_defined}}" PARENT_SCOPE)
+endfunction()
+
+# The function is used when creating version less targets using ALIASes.
+function(_qt_internal_create_versionless_alias_targets targets install_namespace)
+ foreach(target IN LISTS targets)
+ add_library(Qt::${target} ALIAS ${install_namespace}::${target})
+ endforeach()
+endfunction()
+
+# The function is used when creating version less targets from scratch but not using ALIASes.
+# It assigns the known properties from the versioned targets to the versionless created in this
+# function. This allows versionless targets mimic the versioned.
+function(_qt_internal_create_versionless_targets targets install_namespace)
+ set(known_interface_properties
+ QT_MAJOR_VERSION
+ AUTOMOC_MACRO_NAMES
+ AUTOUIC_OPTIONS
+ COMPILE_DEFINITIONS
+ COMPILE_FEATURES
+ COMPILE_OPTIONS
+ CXX_MODULE_SETS
+ HEADER_SETS
+ HEADER_SETS_TO_VERIFY
+ INCLUDE_DIRECTORIES
+ LINK_DEPENDS
+ LINK_DIRECTORIES
+ LINK_LIBRARIES
+ LINK_LIBRARIES_DIRECT
+ LINK_LIBRARIES_DIRECT_EXCLUDE
+ LINK_OPTIONS
+ POSITION_INDEPENDENT_CODE
+ PRECOMPILE_HEADERS
+ SOURCES
+ SYSTEM_INCLUDE_DIRECTORIES
+ )
+
+ set(known_qt_exported_properties
+ MODULE_PLUGIN_TYPES
+ QT_DISABLED_PRIVATE_FEATURES
+ QT_DISABLED_PUBLIC_FEATURES
+ QT_ENABLED_PRIVATE_FEATURES
+ QT_ENABLED_PUBLIC_FEATURES
+ QT_QMAKE_PRIVATE_CONFIG
+ QT_QMAKE_PUBLIC_CONFIG
+ QT_QMAKE_PUBLIC_QT_CONFIG
+ _qt_config_module_name
+ _qt_is_public_module
+ _qt_module_has_headers
+ _qt_module_has_private_headers
+ _qt_module_has_public_headers
+ _qt_module_has_qpa_headers
+ _qt_module_has_rhi_headers
+ _qt_module_include_name
+ _qt_module_interface_name
+ _qt_package_name
+ _qt_package_version
+ _qt_private_module_target_name
+ )
+
+ set(supported_target_types STATIC_LIBRARY MODULE_LIBRARY SHARED_LIBRARY OBJECT_LIBRARY
+ INTERFACE_LIBRARY)
+
+ foreach(target IN LISTS targets)
+ if(NOT TARGET ${install_namespace}::${target})
+ message(FATAL_ERROR "${install_namespace}::${target} is not a target, can not extend"
+ " an alias target")
+ endif()
+
+ get_target_property(type ${install_namespace}::${target} TYPE)
+ if(NOT type)
+ message(FATAL_ERROR "Cannot get the ${install_namespace}::${target} target type.")
+ endif()
+
+ if(NOT "${type}" IN_LIST supported_target_types)
+ message(AUTHOR_WARNING "${install_namespace}::${target} requires the versionless"
+ " target creation, but it has incompatible type ${type}.")
+ continue()
+ endif()
+
+ string(REPLACE "_LIBRARY" "" creation_type "${type}")
+ add_library(Qt::${target} ${creation_type} IMPORTED)
+
+ if(NOT "${type}" STREQUAL "INTERFACE_LIBRARY")
+ foreach(config "" _RELEASE _DEBUG _RELWITHDEBINFO _MINSIZEREL)
+ get_target_property(target_imported_location
+ ${install_namespace}::${target} IMPORTED_LOCATION${config})
+ if(NOT target_imported_location)
+ if("${config}" STREQUAL "")
+ message(FATAL_ERROR "Cannot create versionless target for"
+ " ${install_namespace}::${target}. IMPORTED_LOCATION property is "
+ "missing."
+ )
+ else()
+ continue()
+ endif()
+ endif()
+ set_property(TARGET Qt::${target} PROPERTY
+ IMPORTED_LOCATION${config} "${target_imported_location}")
+ endforeach()
+
+ foreach(property IN LISTS known_qt_exported_properties)
+ get_target_property(exported_property_value
+ ${install_namespace}::${target} ${property})
+ if(exported_property_value)
+ set_property(TARGET Qt::${target} APPEND PROPERTY
+ ${property} "${exported_property_value}")
+ endif()
+ endforeach()
+ endif()
+
+ foreach(property IN LISTS known_interface_properties)
+ get_target_property(interface_property_value
+ ${install_namespace}::${target} INTERFACE_${property})
+ if(interface_property_value)
+ set_property(TARGET Qt::${target} APPEND PROPERTY
+ INTERFACE_${property} "${interface_property_value}")
+ endif()
+ endforeach()
+ endforeach()
+endfunction()
diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake
index d1bbc15665..8cc09fe83d 100644
--- a/cmake/QtTargetHelpers.cmake
+++ b/cmake/QtTargetHelpers.cmake
@@ -1004,25 +1004,51 @@ unset(_qt_imported_configs)")
endfunction()
function(qt_internal_export_modern_cmake_config_targets_file)
- cmake_parse_arguments(__arg "" "EXPORT_NAME_PREFIX;CONFIG_INSTALL_DIR" "TARGETS" ${ARGN})
+ cmake_parse_arguments(arg
+ ""
+ "EXPORT_NAME_PREFIX;CONFIG_BUILD_DIR;CONFIG_INSTALL_DIR"
+ "TARGETS"
+ ${ARGN}
+ )
- set(export_name "${__arg_EXPORT_NAME_PREFIX}VersionlessTargets")
- foreach(target ${__arg_TARGETS})
- if (TARGET "${target}Versionless")
- continue()
- endif()
+ if("${arg_TARGETS}" STREQUAL "")
+ message(FATAL_ERROR "Target list is empty")
+ endif()
- add_library("${target}Versionless" INTERFACE)
- target_link_libraries("${target}Versionless" INTERFACE "${target}")
- set_target_properties("${target}Versionless" PROPERTIES
- EXPORT_NAME "${target}"
- _qt_is_versionless_target "TRUE")
- set_property(TARGET "${target}Versionless"
- APPEND PROPERTY EXPORT_PROPERTIES _qt_is_versionless_target)
+ if("${arg_CONFIG_BUILD_DIR}" STREQUAL "")
+ message(FATAL_ERROR "CONFIG_BUILD_DIR is not specified")
+ endif()
- qt_install(TARGETS "${target}Versionless" EXPORT ${export_name})
- endforeach()
- qt_install(EXPORT ${export_name} NAMESPACE Qt:: DESTINATION "${__arg_CONFIG_INSTALL_DIR}")
+ if("${arg_CONFIG_INSTALL_DIR}" STREQUAL "")
+ message(FATAL_ERROR "CONFIG_INSTALL_DIR is not specified")
+ endif()
+
+ if("${arg_EXPORT_NAME_PREFIX}" STREQUAL "")
+ message(FATAL_ERROR "EXPORT_NAME_PREFIX is not specified")
+ endif()
+
+ set(versionless_targets ${arg_TARGETS})
+
+ # CMake versions < 3.18 compatibility code. Creates the mimics of the versioned libraries.
+ set(versionless_targets_export "${arg_CONFIG_BUILD_DIR}/${arg_EXPORT_NAME_PREFIX}VersionlessTargets.cmake")
+ configure_file("${QT_CMAKE_DIR}/QtVersionlessTargets.cmake.in"
+ "${versionless_targets_export}"
+ @ONLY
+ )
+
+ # CMake versions >= 3.18 code. Create the versionless ALIAS targets.
+ set(alias_export "${arg_CONFIG_BUILD_DIR}/${arg_EXPORT_NAME_PREFIX}VersionlessAliasTargets.cmake")
+ configure_file("${QT_CMAKE_DIR}/QtVersionlessAliasTargets.cmake.in"
+ "${alias_export}"
+ @ONLY
+ )
+
+ qt_install(FILES
+ "${alias_export}"
+ "${versionless_targets_export}"
+ DESTINATION "${arg_CONFIG_INSTALL_DIR}"
+ COMPONENT Devel
+ )
endfunction()
function(qt_internal_create_tracepoints name tracepoints_file)
diff --git a/cmake/QtVersionlessAliasTargets.cmake.in b/cmake/QtVersionlessAliasTargets.cmake.in
new file mode 100644
index 0000000000..fcf182941c
--- /dev/null
+++ b/cmake/QtVersionlessAliasTargets.cmake.in
@@ -0,0 +1,7 @@
+# Protect against multiple inclusion, which would fail when already imported targets are
+# added once more.
+_qt_internal_check_multiple_inclusion(_targets_not_defined "@versionless_targets@")
+
+_qt_internal_create_versionless_alias_targets("${_targets_not_defined}" @INSTALL_CMAKE_NAMESPACE@)
+
+unset(_targets_not_defined)
diff --git a/cmake/QtVersionlessTargets.cmake.in b/cmake/QtVersionlessTargets.cmake.in
new file mode 100644
index 0000000000..c809915e65
--- /dev/null
+++ b/cmake/QtVersionlessTargets.cmake.in
@@ -0,0 +1,7 @@
+# Protect against multiple inclusion, which would fail when already imported targets are
+# added once more.
+_qt_internal_check_multiple_inclusion(_targets_not_defined "@versionless_targets@")
+
+_qt_internal_create_versionless_targets("${_targets_not_defined}" @INSTALL_CMAKE_NAMESPACE@)
+
+unset(_targets_not_defined)
diff --git a/tests/auto/cmake/test_versionless_targets/CMakeLists.txt b/tests/auto/cmake/test_versionless_targets/CMakeLists.txt
index 3514f4e0f9..1afcaa6a93 100644
--- a/tests/auto/cmake/test_versionless_targets/CMakeLists.txt
+++ b/tests/auto/cmake/test_versionless_targets/CMakeLists.txt
@@ -5,22 +5,99 @@ cmake_minimum_required(VERSION 3.16)
project(versionless_targets)
-set(QT_NO_CREATE_VERSIONLESS_TARGETS ON)
+function(check_versionless_targets)
+ set(known_interface_properties
+ QT_MAJOR_VERSION
+ AUTOMOC_MACRO_NAMES
+ AUTOUIC_OPTIONS
+ COMPILE_DEFINITIONS
+ COMPILE_FEATURES
+ COMPILE_OPTIONS
+ CXX_MODULE_SETS
+ HEADER_SETS
+ HEADER_SETS_TO_VERIFY
+ INCLUDE_DIRECTORIES
+ LINK_DEPENDS
+ LINK_DIRECTORIES
+ LINK_LIBRARIES
+ LINK_LIBRARIES_DIRECT
+ LINK_LIBRARIES_DIRECT_EXCLUDE
+ LINK_OPTIONS
+ POSITION_INDEPENDENT_CODE
+ PRECOMPILE_HEADERS
+ SOURCES
+ SYSTEM_INCLUDE_DIRECTORIES
+ )
-find_package(Qt6Core REQUIRED)
+ set(known_qt_exported_properties
+ MODULE_PLUGIN_TYPES
+ QT_DISABLED_PRIVATE_FEATURES
+ QT_DISABLED_PUBLIC_FEATURES
+ QT_ENABLED_PRIVATE_FEATURES
+ QT_ENABLED_PUBLIC_FEATURES
+ QT_QMAKE_PRIVATE_CONFIG
+ QT_QMAKE_PUBLIC_CONFIG
+ QT_QMAKE_PUBLIC_QT_CONFIG
+ _qt_config_module_name
+ _qt_is_public_module
+ _qt_module_has_headers
+ _qt_module_has_private_headers
+ _qt_module_has_public_headers
+ _qt_module_has_qpa_headers
+ _qt_module_has_rhi_headers
+ _qt_module_include_name
+ _qt_module_interface_name
+ _qt_package_name
+ _qt_package_version
+ _qt_private_module_target_name
+ )
-if (NOT TARGET Qt6::Core)
- message(SEND_ERROR "Qt6::Core target not defined!")
-endif()
+ foreach(prop ${known_interface_properties})
+ set(versionless_prop "")
+ set(versioned_prop "")
+ get_target_property(versionless_prop Qt::Core INTERFACE_${prop})
+ get_target_property(versioned_prop Qt6::Core INTERFACE_${prop})
+ if(NOT versionless_prop AND NOT versioned_prop)
+ continue()
+ endif()
-if (TARGET Qt::Core)
- message(SEND_ERROR "Qt::Core target defined despite QT_NO_CREATE_VERSIONLESS_TARGETS!")
-endif()
+ if(NOT "${versionless_prop}" STREQUAL "${versioned_prop}")
+ message(SEND_ERROR "INTERFACE_${prop} doesn't match versionless ${versionless_prop}"
+ " versioned ${versioned_prop}")
+ endif()
+ endforeach()
-set(QT_NO_CREATE_VERSIONLESS_TARGETS OFF)
+ foreach(prop ${known_qt_exported_properties})
+ set(versionless_prop "")
+ set(versioned_prop "")
+ get_target_property(versionless_prop Qt::Core ${prop})
+ get_target_property(versioned_prop Qt6::Core ${prop})
+ if(NOT versionless_prop AND NOT versioned_prop)
+ continue()
+ endif()
-find_package(Qt6Core REQUIRED)
+ if(NOT "${versionless_prop}" STREQUAL "${versioned_prop}")
+ message(SEND_ERROR "${prop} doesn't match versionless ${versionless_prop}"
+ " versioned ${versioned_prop}")
+ endif()
+ endforeach()
-if (NOT TARGET Qt::Core)
- message(SEND_ERROR "Qt::Core target not defined!")
-endif()
+ foreach(conf "" _RELEASE _DEBUG _RELWITHDEBINFO _MINSIZEREL)
+ set(versionless_prop "")
+ set(versioned_prop "")
+ get_target_property(versionless_prop Qt::Core IMPORTED_LOCATION${conf})
+ get_target_property(versioned_prop Qt6::Core IMPORTED_LOCATION${conf})
+ if(NOT versionless_prop AND NOT versioned_prop)
+ continue()
+ endif()
+ if(NOT "${versionless_prop}" STREQUAL "${versioned_prop}")
+ message(SEND_ERROR "IMPORTED_LOCATION${conf} doesn't match versionless ${versionless_prop}"
+ " versioned ${versioned_prop}")
+ endif()
+ endforeach()
+endfunction()
+
+add_subdirectory(default)
+add_subdirectory(force_off)
+add_subdirectory(force_on)
+add_subdirectory(force_old)
diff --git a/tests/auto/cmake/test_versionless_targets/default/CMakeLists.txt b/tests/auto/cmake/test_versionless_targets/default/CMakeLists.txt
new file mode 100644
index 0000000000..a8757607cf
--- /dev/null
+++ b/tests/auto/cmake/test_versionless_targets/default/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+message("Test default creating of versionless targets")
+find_package(Qt6Core REQUIRED)
+
+if(NOT TARGET Qt6::Core)
+ message(SEND_ERROR "Qt6::Core target not defined!")
+endif()
+
+if(NOT TARGET Qt::Core)
+ message(SEND_ERROR "Qt::Core target not defined!")
+endif()
+
+check_versionless_targets()
diff --git a/tests/auto/cmake/test_versionless_targets/force_off/CMakeLists.txt b/tests/auto/cmake/test_versionless_targets/force_off/CMakeLists.txt
new file mode 100644
index 0000000000..247b1b8c27
--- /dev/null
+++ b/tests/auto/cmake/test_versionless_targets/force_off/CMakeLists.txt
@@ -0,0 +1,18 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+message("Test disabled versionless targets")
+
+set(QT_NO_CREATE_VERSIONLESS_TARGETS ON)
+
+find_package(Qt6Core REQUIRED)
+
+if(NOT TARGET Qt6::Core)
+ message(SEND_ERROR "Qt6::Core target not defined!")
+endif()
+
+if(TARGET Qt::Core)
+ message(SEND_ERROR "Qt::Core target defined despite QT_NO_CREATE_VERSIONLESS_TARGETS!")
+endif()
diff --git a/tests/auto/cmake/test_versionless_targets/force_old/CMakeLists.txt b/tests/auto/cmake/test_versionless_targets/force_old/CMakeLists.txt
new file mode 100644
index 0000000000..9e83fec7b3
--- /dev/null
+++ b/tests/auto/cmake/test_versionless_targets/force_old/CMakeLists.txt
@@ -0,0 +1,21 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+message("Test force old versionless targets")
+
+set(QT_USE_OLD_VERSION_LESS_TARGETS ON)
+
+find_package(Qt6Core REQUIRED)
+
+if(NOT TARGET Qt6::Core)
+ message(SEND_ERROR "Qt6::Core target not defined!")
+endif()
+
+if(NOT TARGET Qt::Core)
+ message(SEND_ERROR "Qt::Core target not defined!")
+endif()
+
+check_versionless_targets()
+
diff --git a/tests/auto/cmake/test_versionless_targets/force_on/CMakeLists.txt b/tests/auto/cmake/test_versionless_targets/force_on/CMakeLists.txt
new file mode 100644
index 0000000000..b3d7596143
--- /dev/null
+++ b/tests/auto/cmake/test_versionless_targets/force_on/CMakeLists.txt
@@ -0,0 +1,20 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+message("Test enabled versionless targets")
+
+set(QT_NO_CREATE_VERSIONLESS_TARGETS OFF)
+
+find_package(Qt6Core REQUIRED)
+
+if(NOT TARGET Qt6::Core)
+ message(SEND_ERROR "Qt6::Core target not defined!")
+endif()
+
+if(NOT TARGET Qt::Core)
+ message(SEND_ERROR "Qt::Core target not defined!")
+endif()
+
+check_versionless_targets()