From a907d7df3488764b74afd219e1ddd368062529d6 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 3 May 2019 15:21:30 +0200 Subject: Handle generating find_dependency() calls for nolink targets Previously we just recorded that Gui has to link against Vulkan::Vulkan_nolink, but if an application consumed Gui, it wouldn't find that target. We need to record that if a module links against Vulkan_nolink, and then generate a find_dependency(Vulkan) call in the module config file. We also have to assign the _nolink interface library to an export (the Qt5 one), so that it gets installed as a target. Change-Id: Icbc29ff4161ab18fdd162196ae128e29c1ee8c80 Reviewed-by: Alexandru Croitor --- cmake/QtBuild.cmake | 20 ++++++++++++++++---- cmake/QtPostProcess.cmake | 8 ++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'cmake') diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 1a15c146c7..7c776fcda7 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -193,7 +193,7 @@ macro(assert) endmacro() -function(qt_create_nolink_target target) +function(qt_create_nolink_target target export_target) if(NOT TARGET "${target}") message(FATAL_ERROR "${target} does not exist when trying to build a nolink target.") endif() @@ -205,9 +205,18 @@ function(qt_create_nolink_target target) message(FATAL_ERROR "${target} must not be an object library.") endif() - set(nolink_target "${target}_nolink") + # Strip off the namespace prefix, so from Vulkan::Vulkan to Vulkan, and then append _nolink. + string(REGEX REPLACE "^.*::" "" non_prefixed_target ${target}) + set(nolink_target "${non_prefixed_target}_nolink") + + # Create the nolink interface target, assign the properties from the original target, + # associate the nolink target with the same export which contains + # the target that uses the _nolink target. + # Also create a namespaced alias of the form {$target}::${target}_nolink which is used by + # our modules. if(NOT TARGET "${nolink_target}") - add_library("${nolink_target}" INTERFACE IMPORTED) + add_library("${nolink_target}" INTERFACE) + set(prefixed_nolink_target "${target}_nolink") set_target_properties("${nolink_target}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES $ @@ -219,6 +228,8 @@ function(qt_create_nolink_target target) $ INTERFACE_COMPILE_FEATURES $) + install(TARGETS ${nolink_target} EXPORT ${export_target}) + add_library(${prefixed_nolink_target} ALIAS ${nolink_target}) endif() endfunction() @@ -435,7 +446,8 @@ function(extend_target target) foreach(lib ${arg_PUBLIC_LIBRARIES} ${arg_LIBRARIES}) string(REGEX REPLACE "_nolink$" "" base_lib "${lib}") if(NOT base_lib STREQUAL lib) - qt_create_nolink_target("${base_lib}") + set(export_target "${INSTALL_CMAKE_NAMESPACE}${target}Targets") + qt_create_nolink_target("${base_lib}" ${export_target}) endif() endforeach() diff --git a/cmake/QtPostProcess.cmake b/cmake/QtPostProcess.cmake index 57d194c037..fe6d70985b 100644 --- a/cmake/QtPostProcess.cmake +++ b/cmake/QtPostProcess.cmake @@ -58,6 +58,14 @@ function(qt_internal_create_depends_files) foreach(dep ${${depends_var}}) # Gather third party packages that should be found when using the Qt module. + # Also handle nolink target dependencies. + string(REGEX REPLACE "_nolink$" "" base_dep "${dep}") + if(NOT base_dep STREQUAL dep) + # Resets target name like Vulkan_nolink to Vulkan, because we need to call + # find_package(Vulkan). + set(dep ${base_dep}) + endif() + if(TARGET ${dep}) list(FIND third_party_deps_seen ${dep} dep_seen) -- cgit v1.2.3