From ef3db62459f458948de6db52b20ebb131b2ec17f Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Sun, 8 Sep 2024 16:47:30 +0200 Subject: [PATCH] CMake: Add an install_tools target for static builds We offer a build target called 'host_tools' to build just host tools and their dependencies within a Qt build, but it was not possible to easily install the built tools. Add convenience custom targets called 'install_tools' and 'install_tools_stripped' to install the host tools when building a static Qt build. The convenience targets will be useful for qdoc static builds, to easily be able and install the tools, without having to specify each tool's install target separately. The current approach doesn't work for shared Qt builds because it would necessitate tracking the libraries that the tools depend on, so those are installed as well. So for now, this is limited to static builds only, where there are no shared library dependencies that have to be installed. The implementation passes 'host_tools' as an installation component for qt_internal_add_tool installed targets. The custom target then just calls cmake --install with the component name. Task-number: QTBUG-91243 Task-number: QTBUG-128730 Change-Id: Ic047ec3b8683043f496b4b2c3cf883a3e70440b3 Reviewed-by: Alexey Edelev (cherry picked from commit c64190caa7d515e0efc60a3c435d9d779efd5ac3) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtBuildRepoHelpers.cmake | 18 ++++++++++++++++++ cmake/QtToolHelpers.cmake | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cmake/QtBuildRepoHelpers.cmake b/cmake/QtBuildRepoHelpers.cmake index a93fce7e4be..192dc7662d1 100644 --- a/cmake/QtBuildRepoHelpers.cmake +++ b/cmake/QtBuildRepoHelpers.cmake @@ -308,6 +308,24 @@ macro(qt_build_repo_begin) if(NOT TARGET host_tools) add_custom_target(host_tools) add_custom_target(bootstrap_tools) + + # TODO: Investigate complexity of installing tools for shared builds. + # Currently installing host tools without libraries only really makes sense for static + # builds. Tracking dependencies for shared builds is more involved. + if(NOT BUILD_SHARED_LIBS) + add_custom_target(install_tools + COMMAND ${CMAKE_COMMAND} + --install ${CMAKE_BINARY_DIR} --component host_tools + ) + add_custom_target(install_tools_stripped + COMMAND ${CMAKE_COMMAND} + --install ${CMAKE_BINARY_DIR} --component host_tools --strip + ) + if(NOT QT_INTERNAL_NO_INSTALL_TOOLS_BUILD_DEPS) + add_dependencies(install_tools host_tools) + add_dependencies(install_tools_stripped host_tools) + endif() + endif() endif() # Add benchmark meta target. It's collection of all benchmarks added/registered by diff --git a/cmake/QtToolHelpers.cmake b/cmake/QtToolHelpers.cmake index a974b6784ae..1d0d93a071c 100644 --- a/cmake/QtToolHelpers.cmake +++ b/cmake/QtToolHelpers.cmake @@ -215,7 +215,9 @@ function(qt_internal_add_tool target_name) qt_get_cmake_configurations(cmake_configs) set(install_initial_call_args - EXPORT "${INSTALL_CMAKE_NAMESPACE}${arg_TOOLS_TARGET}ToolsTargets") + EXPORT "${INSTALL_CMAKE_NAMESPACE}${arg_TOOLS_TARGET}ToolsTargets" + COMPONENT host_tools + ) foreach(cmake_config ${cmake_configs}) qt_get_install_target_default_args(