diff options
author | Alexey Edelev <alexey.edelev@qt.io> | 2021-04-06 18:57:11 +0200 |
---|---|---|
committer | Alexey Edelev <alexey.edelev@qt.io> | 2021-05-20 19:40:45 +0200 |
commit | 425ff34aa10a02524f2d52f544dc00b539ef9a26 (patch) | |
tree | 9cc29e0bfb507c60ff0b7cc8209704e5bab04720 /cmake/QtPostProcessHelpers.cmake | |
parent | 640eb55c130c6c2c982dc212a8a5bd2b8fb7a225 (diff) |
Merge main and private targets of the internal modules
In cmake, targets are used as an entity for modules. This causes a
number of problems when we want to manipulate a module as a separate
entity with properties associated with it.
The _qt_internal_module_interface_name target property is introduced to
represent the module entity. All modules write a name to this property,
which will subsequently expand into the module name matched with
the module name in qmake.
The 'qt_internal_module_info' function is responsible for providing the
correct values for the module properties used when working with a module
target.
Unlike qmake, for internal modules in cmake it is expected that the
Private suffix will be specified explicitly. In case the user wants to
have a different module name, an additional argument
MODULE_INTERFACE_NAME of the qt_internal_add_module function is
introduced.
This also changes the way how target dependencies are collected and
resolved. Since the 'Private' suffix no longer means an unique
identifier of the module 'Private' part, we look for the both Private
and non-Private package names when resolving dependencies.
TODO: This change doesn't affect the existing internal modules, so to
keep compatibility with the existing code the existing internal modules
create 'Private' aliases. The code that provides backward compatibility
must be removed once all internal modules will get the proper names.
Taks-number: QTBUG-87775
Change-Id: Ib4f28341506fb2e73eee960a709e24c42bbcd5ec
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake/QtPostProcessHelpers.cmake')
-rw-r--r-- | cmake/QtPostProcessHelpers.cmake | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/cmake/QtPostProcessHelpers.cmake b/cmake/QtPostProcessHelpers.cmake index c8d310d93d..9307ea8a20 100644 --- a/cmake/QtPostProcessHelpers.cmake +++ b/cmake/QtPostProcessHelpers.cmake @@ -3,7 +3,7 @@ function(qt_internal_write_depends_file module) set(contents "/* This file was generated by cmake with the info from ${module} target. */\n") string(APPEND contents "#ifdef __cplusplus /* create empty PCH in C mode */\n") foreach (m ${ARGN}) - string(APPEND contents "# include <Qt${m}/Qt${m}>\n") + string(APPEND contents "# include <${m}/${m}>\n") endforeach() string(APPEND contents "#endif\n") @@ -64,6 +64,41 @@ macro(qt_collect_third_party_deps target) endforeach() endmacro() +# Filter the dependency targets to collect unique set of the dependencies. +# non-Private and Private targets are treated as the single object in this context +# since they are defined by the same CMake package. For internal modules +# the CMake package will be always Private. +function(qt_internal_remove_qt_dependency_duplicates out_deps deps) + set(${out_deps} "") + foreach(dep ${deps}) + if(dep) + list(FIND ${out_deps} "${dep}" dep_seen) + + # If the library depends on the Private and non-Private targets, + # we only need to 'find_dependency' for one of them. + if(dep_seen EQUAL -1 AND "${dep}" MATCHES "(.+)Private\;(.+)") + list(FIND ${out_deps} "${CMAKE_MATCH_1};${CMAKE_MATCH_2}" dep_seen) + endif() + 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) + + # Skip over Qt6 dependency, because we will manually handle it in the Dependencies + # file before everything else, to ensure that find_package(Qt6Core)-style works. + if(dep_name STREQUAL "${INSTALL_CMAKE_NAMESPACE}") + continue() + endif() + list(APPEND ${out_deps} "${dep_name}\;${dep_ver}") + endif() + endif() + endforeach() + set(${out_deps} "${${out_deps}}" PARENT_SCOPE) +endfunction() + function(qt_internal_create_module_depends_file target) get_target_property(target_type "${target}" TYPE) if(target_type STREQUAL "INTERFACE_LIBRARY") @@ -93,7 +128,7 @@ function(qt_internal_create_module_depends_file target) if(NOT arg_HEADER_MODULE) get_target_property(extra_depends "${target}" QT_EXTRA_PACKAGE_DEPENDENCIES) endif() - if(NOT extra_depends STREQUAL "${extra_depends}-NOTFOUND") + if(NOT extra_depends MATCHES "-NOTFOUND$") list(APPEND target_deps "${extra_depends}") endif() @@ -152,13 +187,11 @@ function(qt_internal_create_module_depends_file target) endif() endif() endif() - if (dep MATCHES "(.*)Private") - set(dep "${CMAKE_MATCH_1}") - endif() list(FIND known_modules "${dep}" _pos) if (_pos GREATER -1) - list(APPEND qtdeps "${dep}") + qt_internal_module_info(module ${QT_CMAKE_EXPORT_NAMESPACE}::${dep}) + list(APPEND qtdeps ${module}) # Make the ModuleTool package depend on dep's ModuleTool package. list(FIND tool_deps_seen ${dep} dep_seen) @@ -178,33 +211,16 @@ function(qt_internal_create_module_depends_file target) "${INSTALL_CMAKE_NAMESPACE}${target}Tools\;${PROJECT_VERSION}") endif() - # Dirty deduplication hack because of 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) - - # Skip over Qt6 dependency, because we will manually handle it in the Dependencies - # file before everything else, to ensure that find_package(Qt6Core)-style works. - if(dep_name STREQUAL INSTALL_CMAKE_NAMESPACE) - continue() - endif() - - list(APPEND target_deps_seen "${dep_name}\;${dep_ver}") - - if (dep_name MATCHES "${INSTALL_CMAKE_NAMESPACE}(.*)") - list(APPEND qt_module_dependencies "${CMAKE_MATCH_1}") - endif() - endif() + if(NOT dep MATCHES ".+Private$" AND + dep MATCHES "${INSTALL_CMAKE_NAMESPACE}(.+)") + list(APPEND qt_module_dependencies "${CMAKE_MATCH_1}") endif() endforeach() - set(target_deps "${target_deps_seen}") + list(REMOVE_DUPLICATES qt_module_dependencies) + + qt_internal_remove_qt_dependency_duplicates(target_deps "${target_deps}") + if (DEFINED qtdeps) list(REMOVE_DUPLICATES qtdeps) @@ -251,23 +267,7 @@ function(qt_internal_create_plugin_depends_file target) qt_collect_third_party_deps(${target}) - # 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}") + qt_internal_remove_qt_dependency_duplicates(target_deps "${target_deps}") if(third_party_deps OR target_deps) # Setup build and install paths |