From aef11e420db95a5dd42faa314f9afe69e890ee8d Mon Sep 17 00:00:00 2001 From: Kevin Funk Date: Fri, 3 May 2019 12:30:09 +0200 Subject: [PATCH] cmake: Generate config files with Qt:: prefix Generate CMake config files which export Qt targets with a Qt:: prefix (i.e. without a major version suffix in the namespace) Change-Id: Ia07f98be6d0e24c196e3880b7469f1f0c6232c06 Reviewed-by: Alexandru Croitor --- cmake/QtBaseGlobalTargets.cmake | 4 ++++ cmake/QtBuild.cmake | 26 +++++++++++++++++++++++++- cmake/QtConfig.cmake.in | 2 ++ cmake/QtModuleConfig.cmake.in | 2 ++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index b4c4bd0298..af320a05b3 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -80,6 +80,10 @@ install(TARGETS Platform GlobalConfig GlobalConfigPrivate EXPORT "${INSTALL_CMAK install(EXPORT "${INSTALL_CMAKE_NAMESPACE}Targets" NAMESPACE ${QT_CMAKE_EXPORT_NAMESPACE}:: DESTINATION "${config_install_dir}") export(EXPORT "${INSTALL_CMAKE_NAMESPACE}Targets") +qt_internal_export_modern_cmake_config_targets_file(TARGETS Platform GlobalConfig GlobalConfigPrivate + EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE} + CONFIG_INSTALL_DIR ${config_install_dir}) + ## Install some QtBase specific CMake files: install(FILES cmake/QtBuild.cmake diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 059b0c82fc..1a15c146c7 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -130,6 +130,23 @@ endif() # Functions and macros: +function(qt_internal_export_modern_cmake_config_targets_file) + cmake_parse_arguments(__arg "" "EXPORT_NAME_PREFIX;CONFIG_INSTALL_DIR" "TARGETS" ${ARGN}) + + foreach(target ${__arg_TARGETS}) + if (TARGET "${target}Versionless") + continue() + endif() + + add_library("${target}Versionless" INTERFACE) + target_link_libraries("${target}Versionless" INTERFACE "${target}") + set_target_properties("${target}Versionless" PROPERTIES EXPORT_NAME "${target}") + install(TARGETS "${target}Versionless" EXPORT "${__arg_EXPORT_NAME_PREFIX}VersionlessTargets") + endforeach() + + install(EXPORT "${__arg_EXPORT_NAME_PREFIX}VersionlessTargets" NAMESPACE Qt:: DESTINATION "${__arg_CONFIG_INSTALL_DIR}") +endfunction() + # Print all variables defined in the current scope. macro(qt_debug_print_variables) cmake_parse_arguments(__arg "DEDUP" "" "MATCH;IGNORE" ${ARGN}) @@ -678,10 +695,13 @@ function(add_qt_module target) PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR}/${module} PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR}/${module}/${PROJECT_VERSION}/${module}/private ) - set(config_install_dir "${INSTALL_LIBDIR}/cmake/${INSTALL_CMAKE_NAMESPACE}${target}") install(EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets" NAMESPACE ${QT_CMAKE_EXPORT_NAMESPACE}:: DESTINATION ${config_install_dir}) + qt_internal_export_modern_cmake_config_targets_file(TARGETS "${target}" "${target_private}" + EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE}${target} + CONFIG_INSTALL_DIR "${config_install_dir}") + set(extra_cmake_files) set(extra_cmake_includes) if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}${target}Macros.cmake") @@ -816,6 +836,10 @@ endif() install(EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets" NAMESPACE "${QT_CMAKE_EXPORT_NAMESPACE}::" DESTINATION "${INSTALL_LIBDIR}/cmake/${INSTALL_CMAKE_NAMESPACE}${target}") + + qt_internal_export_modern_cmake_config_targets_file(TARGETS ${QT_KNOWN_MODULE_${module_name}_TOOLS} + EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE}${target} + CONFIG_INSTALL_DIR ${config_install_dir}) endfunction() function(qt_internal_check_directory_or_type name dir type default result_var) diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index f30cd82cf1..73871747e0 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -9,6 +9,8 @@ get_filename_component(_qt_cmake_dir "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@VersionlessTargets.cmake") + # if (NOT @INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS) # set(@INSTALL_CMAKE_NAMESPACE@_NOT_FOUND_MESSAGE "The Qt package requires at least one component") # set(@INSTALL_CMAKE_NAMESPACE@_FOUND False) diff --git a/cmake/QtModuleConfig.cmake.in b/cmake/QtModuleConfig.cmake.in index 9d2135d842..7baea8cf9c 100644 --- a/cmake/QtModuleConfig.cmake.in +++ b/cmake/QtModuleConfig.cmake.in @@ -12,6 +12,8 @@ endif() include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@VersionlessTargets.cmake") + foreach(extra_cmake_include @extra_cmake_includes@) include("${CMAKE_CURRENT_LIST_DIR}/${extra_cmake_include}") endforeach()