Make module package depend on its own tool package

Also make the tool package depend on all tool packages that correspond
to the qt module dependencies.

So find_package(Qt5Widgets) implicitly calls find_package(Qt5WidgetTools).

And find_package(Qt5WidgetsTools) will call find_package for
Qt5GuiTools, and Qt5CoreTools.

This enhances the user experience, so that in modules like qtsvg, you
don't have to specify both find_package(Qt5Widgets) and
find_package(Qt5WidgetsTools), but only the former.

Or when cross building, you only need to specify Qt5WidgetTools, to get
both Core and Gui tools.

Change-Id: Ib1c5173a5b97584a52e144c22e38e90a712f727a
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Alexandru Croitor 2019-04-29 14:36:25 +02:00
parent 9b0b464e82
commit bcfc3dca5d
4 changed files with 76 additions and 2 deletions

View File

@ -32,3 +32,20 @@ endforeach()
# Restore old module path.
set(CMAKE_MODULE_PATH "${old_CMAKE_MODULE_PATH}")
# Find Qt tool package.
set(_tool_deps "@main_module_tool_deps@")
foreach(_target_dep ${_tool_deps})
list(GET _target_dep 0 pkg)
list(GET _target_dep 1 version)
if (NOT ${pkg}_FOUND)
find_dependency(${pkg} ${version})
endif()
if (NOT ${pkg}_FOUND)
set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND FALSE)
return()
endif()
endforeach()

View File

@ -1,5 +1,12 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
# Find required dependencies, if any.
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Dependencies.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Dependencies.cmake")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake")
@extra_cmake_statements@

View File

@ -0,0 +1,16 @@
# Find "ModuleTools" dependencies, which are other ModuleTools packages.
set(_tool_deps "@tool_deps@")
foreach(_target_dep ${_tool_deps})
list(GET _target_dep 0 pkg)
list(GET _target_dep 1 version)
if (NOT ${pkg}_FOUND)
find_dependency(${pkg} ${version})
endif()
if (NOT ${pkg}_FOUND)
set(@INSTALL_CMAKE_NAMESPACE@@target@Tools_FOUND FALSE)
return()
endif()
endforeach()

View File

@ -20,6 +20,8 @@ function(qt_internal_create_depends_files)
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::(.*)")
@ -32,6 +34,14 @@ function(qt_internal_create_depends_files)
list(FIND QT_KNOWN_MODULES "${dep}" _pos)
if (_pos GREATER -1)
list(APPEND qtdeps "${dep}")
# Make the ModuleTool package depend on dep's ModuleTool package.
list(FIND tool_deps_seen ${dep} dep_seen)
if(dep_seen EQUAL -1 AND ${dep} IN_LIST QT_KNOWN_MODULES_WITH_TOOLS)
list(APPEND tool_deps_seen ${dep})
list(APPEND tool_deps
"${INSTALL_CMAKE_NAMESPACE}${dep}Tools\;${PROJECT_VERSION}")
endif()
endif()
endforeach()
@ -66,6 +76,12 @@ function(qt_internal_create_depends_files)
endif()
endforeach()
# Add dependency to the main ModuleTool package to ModuleDependencies file.
if(${target} IN_LIST QT_KNOWN_MODULES_WITH_TOOLS)
set(main_module_tool_deps
"${INSTALL_CMAKE_NAMESPACE}${target}Tools\;${PROJECT_VERSION}")
endif()
if (DEFINED qtdeps)
list(REMOVE_DUPLICATES qtdeps)
endif()
@ -75,8 +91,9 @@ function(qt_internal_create_depends_files)
qt_internal_write_depends_file("${target}" ${qtdeps})
endif()
if(third_party_deps)
# Configure and install dependencies file.
if(third_party_deps OR main_module_tool_deps)
# Configure and install ModuleDependencies file.
configure_file(
"${QT_CMAKE_DIR}/QtModuleDependencies.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${INSTALL_CMAKE_NAMESPACE}${target}Dependencies.cmake"
@ -91,6 +108,23 @@ function(qt_internal_create_depends_files)
COMPONENT Devel
)
endif()
if(tool_deps)
# Configure and install ModuleToolDependencies file.
configure_file(
"${QT_CMAKE_DIR}/QtModuleToolsDependencies.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${INSTALL_CMAKE_NAMESPACE}${target}ToolsDependencies.cmake"
@ONLY
)
set(config_install_dir
"${INSTALL_LIBDIR}/cmake/${INSTALL_CMAKE_NAMESPACE}${target}Tools")
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${INSTALL_CMAKE_NAMESPACE}${target}ToolsDependencies.cmake"
DESTINATION "${config_install_dir}"
COMPONENT Devel
)
endif()
endforeach()