diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-11-15 16:28:17 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-11-26 10:58:56 +0000 |
commit | 9061f2987213f3b6cc1e6908ba1b0b29daf877f8 (patch) | |
tree | 3ba9caa7267f47d995b22fd573cb1a23209a7d93 | |
parent | 1c655fb0fc08e89ab5efb23889266b710334f1a5 (diff) |
Provide a way to specify extra tool package dependencies
In the qtwayland repo, both WaylandClient and WaylandCompositor
packages need access to the qtwaylandscanner tool. That means
that the add_qt_tool(qtwaylandscanner) can't use the TOOLS_TARGET
argument to associate a dependency with only one of the above
modules.
Instead add_qt_tool now allows specifying a non-existent module
name for the TOOLS_TARGET argument, which can be manually
depended on by other packages.
Actually, you could specify the non-existent module before as
well, but that didn't do everything that had to be done.
This required a bit of refactoring in how the Dependencies file
for Tools packages is created. Now the file is created in
qt_export_tools.
Two new functions were also added to allow recording additional
dependencies between packages.
Also some bug fixes were done to make it all work. Specifically
the _FOUND variable generated in the Dependencies file was incorrect.
Also there are some quotes missing when appending extra package
dependencies via the QT_EXTRA_PACKAGE_DEPENDENCIES property.
Change-Id: I167efec16dff8d036e191df3572ea72764e22bc5
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | cmake/QtBuild.cmake | 68 | ||||
-rw-r--r-- | cmake/QtModuleToolsDependencies.cmake.in | 4 | ||||
-rw-r--r-- | cmake/QtPostProcess.cmake | 25 | ||||
-rw-r--r-- | src/corelib/CMakeLists.txt | 3 |
4 files changed, 77 insertions, 23 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index f4af4a76f6..13e954cd57 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -1715,7 +1715,18 @@ function(qt_export_tools module_name) # Also assemble a list of tool targets to expose in the config file for informational purposes. set(extra_cmake_statements "") set(tool_targets "") + + # List of package dependencies that need be find_package'd when using the Tools package. + set(package_deps "") + foreach(tool_name ${QT_KNOWN_MODULE_${module_name}_TOOLS}) + # Specific tools can have package dependencies. + # e.g. qtwaylandscanner depends on WaylandScanner (non-qt package). + get_target_property(extra_packages "${tool_name}" QT_EXTRA_PACKAGE_DEPENDENCIES) + if(extra_packages) + list(APPEND package_deps "${extra_packages}") + endif() + set(extra_cmake_statements "${extra_cmake_statements} if (NOT QT_NO_CREATE_TARGETS) get_property(is_global TARGET ${INSTALL_CMAKE_NAMESPACE}::${tool_name} PROPERTY IMPORTED_GLOBAL) @@ -1730,6 +1741,31 @@ endif() string(APPEND extra_cmake_statements "set(${QT_CMAKE_EXPORT_NAMESPACE}${module_name}Tools_TARGETS \"${tool_targets}\")") + # Extract package dependencies that were determined in QtPostProcess, but only if ${module_name} + # is an actual target. + # module_name can be a non-existent target, if the tool doesn't have an existing associated + # module, e.g. qtwaylandscanner. + if(TARGET "${module_name}") + get_target_property(module_package_deps "${module_name}" _qt_tools_package_deps) + if(module_package_deps) + list(APPEND package_deps "${module_package_deps}") + endif() + endif() + + # Configure and install dependencies file for the ${module_name}Tools package. + configure_file( + "${QT_CMAKE_DIR}/QtModuleToolsDependencies.cmake.in" + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Dependencies.cmake" + @ONLY + ) + + qt_install(FILES + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Dependencies.cmake" + DESTINATION "${config_install_dir}" + COMPONENT Devel + ) + + # Configure and install the ${module_name}Tools package Config file. configure_package_config_file( "${QT_CMAKE_DIR}/QtModuleToolsConfig.cmake.in" "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Config.cmake" @@ -1760,6 +1796,38 @@ endif() # CONFIG_INSTALL_DIR ${config_install_dir}) endfunction() +# This function records a dependency between ${target_name} and ${dep_package_name}. +# at the CMake package level. +# E.g. The Tools package that provides the qtwaylandscanner target +# needs to call find_package(WaylandScanner) (non-qt-package). +# main_target_name = qtwaylandscanner +# dep_package_name = WaylandScanner +function(qt_record_extra_package_dependency main_target_name dep_package_name dep_package_version) + get_target_property(extra_packages "${main_target_name}" QT_EXTRA_PACKAGE_DEPENDENCIES) + if(NOT extra_packages) + set(extra_packages "") + endif() + + list(APPEND extra_packages "${dep_package_name}\;${dep_package_version}") + set_target_properties("${main_target_name}" PROPERTIES QT_EXTRA_PACKAGE_DEPENDENCIES + "${extra_packages}") +endfunction() + +# This function records a dependency between ${main_target_name} and ${dep_target_name} +# at the CMake package level. +# E.g. Qt6CoreConfig.cmake needs to find_package(Qt6WinMain). +# main_target_name = Core +# dep_target_name = WinMain +# This is just a convenience function that deals with Qt targets and their associated packages +# instead of raw package names. +function(qt_record_extra_qt_package_dependency main_target_name dep_target_name + dep_package_version) + # WinMain -> Qt6WinMain. + qt_internal_module_info(qtfied_target_name "${dep_target_name}") + qt_record_extra_package_dependency("${main_target_name}" "${qtfied_target_name_versioned}" + "${dep_package_version}") +endfunction() + function(qt_internal_check_directory_or_type name dir type default result_var) if ("x${dir}" STREQUAL x) if("x${type}" STREQUAL x) diff --git a/cmake/QtModuleToolsDependencies.cmake.in b/cmake/QtModuleToolsDependencies.cmake.in index bac8bb0e04..46c60b8484 100644 --- a/cmake/QtModuleToolsDependencies.cmake.in +++ b/cmake/QtModuleToolsDependencies.cmake.in @@ -1,5 +1,5 @@ # Find "ModuleTools" dependencies, which are other ModuleTools packages. -set(_tool_deps "@tool_deps@") +set(_tool_deps "@package_deps@") foreach(_target_dep ${_tool_deps}) list(GET _target_dep 0 pkg) list(GET _target_dep 1 version) @@ -9,7 +9,7 @@ foreach(_target_dep ${_tool_deps}) endif() if (NOT ${pkg}_FOUND) - set(@INSTALL_CMAKE_NAMESPACE@@target@Tools_FOUND FALSE) + set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND FALSE) return() endif() endforeach() diff --git a/cmake/QtPostProcess.cmake b/cmake/QtPostProcess.cmake index b063562937..2e0fe602a8 100644 --- a/cmake/QtPostProcess.cmake +++ b/cmake/QtPostProcess.cmake @@ -82,7 +82,7 @@ function(qt_internal_create_module_depends_file target) get_target_property(extra_depends "${target}" QT_EXTRA_PACKAGE_DEPENDENCIES) endif() if(NOT extra_depends STREQUAL "${extra_depends}-NOTFOUND") - list(APPEND target_deps ${extra_depends}) + list(APPEND target_deps "${extra_depends}") endif() # Used for assembling the content of an include/Module/ModuleDepends.h header. @@ -183,23 +183,8 @@ function(qt_internal_create_module_depends_file target) endif() if(tool_deps) - set(path_suffix "${INSTALL_CMAKE_NAMESPACE}${target}Tools") - qt_path_join(config_build_dir ${QT_CONFIG_BUILD_DIR} ${path_suffix}) - qt_path_join(config_install_dir ${QT_CONFIG_INSTALL_DIR} ${path_suffix}) - - # Configure and install ModuleToolDependencies file. - configure_file( - "${QT_CMAKE_DIR}/QtModuleToolsDependencies.cmake.in" - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ToolsDependencies.cmake" - @ONLY - ) - - qt_install(FILES - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ToolsDependencies.cmake" - DESTINATION "${config_install_dir}" - COMPONENT Devel - ) - + # The value of the property will be used by qt_export_tools. + set_property(TARGET "${target}" PROPERTY _qt_tools_package_deps "${tool_deps}") endif() endfunction() @@ -378,12 +363,14 @@ function(qt_internal_create_config_file_for_standalone_tests) ) endfunction() -qt_create_tools_config_files() qt_internal_create_depends_files() qt_generate_build_internals_extra_cmake_code() qt_internal_create_plugins_files() qt_internal_create_config_file_for_standalone_tests() +# Needs to run after qt_internal_create_depends_files. +qt_create_tools_config_files() + if (ANDROID) qt_modules_process_android_dependencies() endif() diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 3c87586e7a..1c3803f7c5 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -1154,8 +1154,7 @@ if(WIN32) set(isPolicyNEW $<TARGET_POLICY:CMP0020>) target_link_libraries(Core INTERFACE $<$<AND:${isExe},${isWin32},${isNotExcluded},${isPolicyNEW}>:Qt::WinMain>) - qt_internal_module_info(win_main_module WinMain) - set_property(TARGET Core APPEND PROPERTY QT_EXTRA_PACKAGE_DEPENDENCIES "${win_main_module_versioned}\\\;${PROJECT_VERSION}") + qt_record_extra_qt_package_dependency(Core WinMain "${PROJECT_VERSION}") endif() # special case end |