cmake: move dependencies accumulation in QtPostProcess.cmake

This is needed because dependencies added after add_qt_module with extend_target
are currently not taken into account.

Task-number: QTBUG-75538
Change-Id: I2c72207fb88b2480e41a2c8550978fb194275617
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Jean-Michaël Celerier 2019-05-03 11:38:41 +02:00 committed by Jean-Michaël Celerier
parent 914b367c7f
commit 753d35cd56
4 changed files with 71 additions and 29 deletions

View File

@ -422,6 +422,22 @@ function(extend_target target)
endif()
endforeach()
# Find dependencies to internal libraries
get_target_property(target_deps "${target}" _qt_target_deps)
if(NOT target_deps)
set(target_deps "")
endif()
foreach(lib ${arg_LIBRARIES})
if (TARGET "${lib}")
get_target_property(_is_exported "${lib}" INTERFACE_QT_EXPORTED_LIBRARY)
if("${_is_exported}")
list(APPEND target_deps "${lib}\;${PROJECT_VERSION}")
endif()
endif()
endforeach()
# Set-up the target
target_sources("${target}" PRIVATE ${arg_SOURCES} ${dbus_sources})
if (arg_COMPILE_FLAGS)
set_source_files_properties(${arg_SOURCES} PROPERTIES COMPILE_FLAGS "${arg_COMPILE_FLAGS}")
@ -431,7 +447,11 @@ function(extend_target target)
target_link_libraries("${target}" PUBLIC ${arg_PUBLIC_LIBRARIES} PRIVATE ${arg_LIBRARIES})
target_compile_options("${target}" PUBLIC ${arg_PUBLIC_COMPILE_OPTIONS} PRIVATE ${arg_COMPILE_OPTIONS})
target_link_options("${target}" PUBLIC ${arg_PUBLIC_LINK_OPTIONS} PRIVATE ${arg_LINK_OPTIONS})
set_target_properties("${target}" PROPERTIES AUTOMOC_MOC_OPTIONS "${arg_MOC_OPTIONS}")
set_target_properties("${target}" PROPERTIES
AUTOMOC_MOC_OPTIONS "${arg_MOC_OPTIONS}"
_qt_target_deps "${target_deps}"
)
else()
if(QT_CMAKE_DEBUG_EXTEND_TARGET)
message("extend_target(${target} CONDITION ${arg_CONDITION} ...): Skipped")
@ -698,7 +718,13 @@ function(add_qt_module target)
$<INSTALL_INTERFACE:include/${module}/${PROJECT_VERSION}/${module}>
)
set(target_deps)
get_target_property(target_deps "${target}" _qt_target_deps)
if(NOT target_deps)
set(target_deps "")
endif()
# TODO: should this also be in extend_target ? From the looks of it I would say that
# it is not necessary but I'm not sure
foreach(lib IN LISTS arg_PUBLIC_LIBRARIES qt_libs_private)
if ("${lib}" MATCHES "^Qt::(.*)")
set(lib "${CMAKE_MATCH_1}")
@ -712,14 +738,7 @@ function(add_qt_module target)
endif()
endforeach()
foreach(lib ${arg_LIBRARIES})
if (TARGET "${lib}")
get_target_property(_is_exported "${lib}" INTERFACE_QT_EXPORTED_LIBRARY)
if("${_is_exported}")
list(APPEND target_deps "${lib}\;${PROJECT_VERSION}")
endif()
endif()
endforeach()
set_target_properties("${target}" PROPERTIES _qt_target_deps "${target_deps}")
configure_package_config_file(
"${QT_CMAKE_DIR}/QtModuleConfig.cmake.in"

View File

@ -10,24 +10,6 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Dependenci
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Dependencies.cmake")
endif()
# note: target_deps example: "Qt5Core\;5.12.0;Qt5Gui\;5.12.0"
set(_target_deps "@target_deps@")
foreach(_target_dep ${_target_deps})
list(GET _target_dep 0 pkg)
list(GET _target_dep 1 version)
if (NOT ${pkg}_FOUND)
find_dependency(${pkg} ${version}
PATHS "${CMAKE_CURRENT_LIST_DIR}/.." NO_DEFAULT_PATH
)
endif()
if (NOT ${pkg}_FOUND)
set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND FALSE)
return()
endif()
endforeach()
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake")
foreach(extra_cmake_include @extra_cmake_includes@)

View File

@ -49,3 +49,22 @@ foreach(_target_dep ${_tool_deps})
endif()
endforeach()
# note: target_deps example: "Qt5Core\;5.12.0;Qt5Gui\;5.12.0"
set(_target_deps "@target_deps@")
foreach(_target_dep ${_target_deps})
list(GET _target_dep 0 pkg)
list(GET _target_dep 1 version)
if (NOT ${pkg}_FOUND)
find_dependency(${pkg} ${version}
PATHS "${CMAKE_CURRENT_LIST_DIR}/.." NO_DEFAULT_PATH
)
endif()
if (NOT ${pkg}_FOUND)
set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND FALSE)
return()
endif()
endforeach()

View File

@ -17,11 +17,15 @@ function(qt_internal_create_depends_files)
foreach (target ${QT_KNOWN_MODULES})
get_target_property(depends "${target}" LINK_LIBRARIES)
get_target_property(public_depends "${target}" INTERFACE_LINK_LIBRARIES)
get_target_property(target_deps "${target}" _qt_target_deps)
set(target_deps_seen "")
set(qtdeps "")
set(third_party_deps "")
set(third_party_deps_seen "")
set(tool_deps "")
set(tool_deps_seen "")
foreach (dep ${depends})
# Normalize module by stripping leading "Qt::" and trailing "Private"
if (dep MATCHES "Qt::(.*)")
@ -82,6 +86,24 @@ function(qt_internal_create_depends_files)
"${INSTALL_CMAKE_NAMESPACE}${target}Tools\;${PROJECT_VERSION}")
endif()
# Dirty hack because https://gitlab.kitware.com/cmake/cmake/issues/19200
foreach(dep ${target_deps})
if(dep)
list(FIND target_deps_seen "${dep}" dep_seen)
if(dep_seen EQUAL -1)
list(LENGTH dep len)
if(NOT (len EQUAL 2))
message(FATAL_ERROR "List '${dep}' should look like QtFoo;version")
endif()
list(GET dep 0 dep_name)
list(GET dep 1 dep_ver)
list(APPEND target_deps_seen "${dep_name}\;${dep_ver}")
endif()
endif()
endforeach()
set(target_deps "${target_deps_seen}")
if (DEFINED qtdeps)
list(REMOVE_DUPLICATES qtdeps)
endif()
@ -92,7 +114,7 @@ function(qt_internal_create_depends_files)
endif()
if(third_party_deps OR main_module_tool_deps)
if(third_party_deps OR main_module_tool_deps OR target_deps)
# Configure and install ModuleDependencies file.
configure_file(
"${QT_CMAKE_DIR}/QtModuleDependencies.cmake.in"