CMake: Fix creation of versionless targets for tools
We can't use qt_internal_export_modern_cmake_config_targets_file for executables like tools, because it's not possible to use INTERFACE_LINK_LIBRARIES with executables like you can with libraries. We also can't create aliases to non-global imported targets. Instead create new imported executable targets, fish out the imported location, and assign it to the versionless targets. Task-number: QTBUG-74137 Task-number: QTBUG-80477 Task-number: QTBUG-75984 Change-Id: I6a3c9c67ef4699c72a6c9a627c63158dfd6557f8 Reviewed-by: Leander Beernaert <leander.beernaert@qt.io> Reviewed-by: Qt CMake Build Bot Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
05ba991d39
commit
04d895681a
@ -1742,6 +1742,7 @@ function(qt_export_tools module_name)
|
|||||||
# Also assemble a list of tool targets to expose in the config file for informational purposes.
|
# Also assemble a list of tool targets to expose in the config file for informational purposes.
|
||||||
set(extra_cmake_statements "")
|
set(extra_cmake_statements "")
|
||||||
set(tool_targets "")
|
set(tool_targets "")
|
||||||
|
set(tool_targets_non_prefixed "")
|
||||||
|
|
||||||
# List of package dependencies that need be find_package'd when using the Tools package.
|
# List of package dependencies that need be find_package'd when using the Tools package.
|
||||||
set(package_deps "")
|
set(package_deps "")
|
||||||
@ -1763,6 +1764,7 @@ if (NOT QT_NO_CREATE_TARGETS)
|
|||||||
endif()
|
endif()
|
||||||
")
|
")
|
||||||
list(APPEND tool_targets "${QT_CMAKE_EXPORT_NAMESPACE}::${tool_name}")
|
list(APPEND tool_targets "${QT_CMAKE_EXPORT_NAMESPACE}::${tool_name}")
|
||||||
|
list(APPEND tool_targets_non_prefixed "${tool_name}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
string(APPEND extra_cmake_statements
|
string(APPEND extra_cmake_statements
|
||||||
@ -1816,11 +1818,19 @@ endif()
|
|||||||
NAMESPACE "${QT_CMAKE_EXPORT_NAMESPACE}::"
|
NAMESPACE "${QT_CMAKE_EXPORT_NAMESPACE}::"
|
||||||
DESTINATION "${config_install_dir}")
|
DESTINATION "${config_install_dir}")
|
||||||
|
|
||||||
# Temporarily disable creation of versionless targets for tools,
|
|
||||||
# because it breaks qtdeclarative build.
|
# Create versionless targets file.
|
||||||
#qt_internal_export_modern_cmake_config_targets_file(TARGETS ${QT_KNOWN_MODULE_${module_name}_TOOLS}
|
configure_file(
|
||||||
# EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE}${target}
|
"${QT_CMAKE_DIR}/QtModuleToolsVersionlessTargets.cmake.in"
|
||||||
# CONFIG_INSTALL_DIR ${config_install_dir})
|
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}VersionlessTargets.cmake"
|
||||||
|
@ONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
qt_install(FILES
|
||||||
|
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}VersionlessTargets.cmake"
|
||||||
|
DESTINATION "${config_install_dir}"
|
||||||
|
COMPONENT Devel
|
||||||
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
# This function records a dependency between ${target_name} and ${dep_package_name}.
|
# This function records a dependency between ${target_name} and ${dep_package_name}.
|
||||||
|
@ -10,7 +10,9 @@ set(_qt_@PROJECT_VERSION_MAJOR@_config_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")
|
|||||||
|
|
||||||
if (NOT QT_NO_CREATE_TARGETS)
|
if (NOT QT_NO_CREATE_TARGETS)
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Targets.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Targets.cmake")
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@VersionlessTargets.cmake")
|
if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS)
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@VersionlessTargets.cmake")
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
# For examples using `find_package(...)` inside their CMakeLists.txt files:
|
# For examples using `find_package(...)` inside their CMakeLists.txt files:
|
||||||
# Make CMake's AUTOGEN detect this Qt version properly
|
# Make CMake's AUTOGEN detect this Qt version properly
|
||||||
|
@ -21,7 +21,9 @@ endif()
|
|||||||
|
|
||||||
if (NOT QT_NO_CREATE_TARGETS)
|
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@Targets.cmake")
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@VersionlessTargets.cmake")
|
if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS)
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@VersionlessTargets.cmake")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
foreach(extra_cmake_include @extra_cmake_includes@)
|
foreach(extra_cmake_include @extra_cmake_includes@)
|
||||||
|
@ -9,6 +9,9 @@ if (NOT QT_NO_CREATE_TARGETS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake")
|
||||||
|
if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS)
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@VersionlessTargets.cmake")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@extra_cmake_statements@
|
@extra_cmake_statements@
|
||||||
|
23
cmake/QtModuleToolsVersionlessTargets.cmake.in
Normal file
23
cmake/QtModuleToolsVersionlessTargets.cmake.in
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
foreach(__qt_tool @tool_targets_non_prefixed@)
|
||||||
|
if(NOT TARGET Qt::${__qt_tool} AND TARGET Qt6::${__qt_tool})
|
||||||
|
add_executable(Qt::${__qt_tool} IMPORTED)
|
||||||
|
|
||||||
|
# Check all the usual imported location properties to find one that contains a path.
|
||||||
|
foreach(__qt_imported_location_config
|
||||||
|
IMPORTED_LOCATION
|
||||||
|
IMPORTED_LOCATION_RELEASE
|
||||||
|
IMPORTED_LOCATION_RELWITHDEBINFO
|
||||||
|
IMPORTED_LOCATION_MINSIZEREL
|
||||||
|
IMPORTED_LOCATION_DEBUG)
|
||||||
|
|
||||||
|
get_target_property(__qt_imported_location
|
||||||
|
Qt6::${__qt_tool} ${__qt_imported_location_config})
|
||||||
|
if(__qt_imported_location AND EXISTS "${__qt_imported_location}")
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set_target_properties(Qt::${__qt_tool}
|
||||||
|
PROPERTIES IMPORTED_LOCATION "${__qt_imported_location}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
Loading…
x
Reference in New Issue
Block a user