summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2022-09-09 16:28:53 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2022-09-16 13:21:13 +0200
commitaf165e97042d7a8139dbb1a43347ffd765a58a2d (patch)
treec67740ded0c463ce34834178b34dedf54fa22ac4 /cmake
parent3b5ba9e9425f2ce76c5527ccdb5198854c291a6c (diff)
CMake: Rework tool wrapper shell script creation
Instead of creating the tool wrapper shell script only during a Qt build in QtBuild.cmake, ensure it is created any time _qt_internal_wrap_tool_command is called, regardless if we're building Qt or a user project. As a transitional period not to break compatibility, we also need to create the script in QtBuild.cmake, until all usages of QT_TOOL_COMMAND_WRAPPER_PATH are replaced with function calls. Currently such usages are present in qtdeclarative. When considering which bin dirs to add to the script's PATH environment variable assignment, in addition to the build internals relative bin dir, also add QT_BUILD_DIR, QT_ADDITIONAL_PACKAGES_PREFIX_PATH and QT6_INSTALL_PREFIX. QT_BUILD_DIR is important so we always pick up the just-built but not installed libraries in a prefix build when running just-built tools. QT_ADDITIONAL_PACKAGES_PREFIX_PATH is important when building examples as ExternalProjects in prefix builds, to ensure that the not-yet-installed tools and libraries are picked up from the repo build dir, which is passed via QT_ADDITIONAL_PACKAGES_PREFIX_PATH to the external projects. QT6_INSTALL_PREFIX is there in case if the build internals relative dir is located in a different places than the Qt6 package. Task-number: QTBUG-90820 Task-number: QTBUG-96232 Change-Id: I4d76fbbc275ca961379971054f87991adac36539 Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit 74083599f8b175e94789757e478a106ec03750d4)
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtBuild.cmake22
-rw-r--r--cmake/QtPublicToolHelpers.cmake89
2 files changed, 94 insertions, 17 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index bb7049e76a..a097ad60ea 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -268,23 +268,6 @@ function(qt_setup_tool_path_command)
endfunction()
qt_setup_tool_path_command()
-function(qt_internal_generate_tool_command_wrapper)
- get_property(is_called GLOBAL PROPERTY _qt_internal_generate_tool_command_wrapper_called)
- if(NOT CMAKE_HOST_WIN32 OR is_called)
- return()
- endif()
- set(bindir "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${INSTALL_BINDIR}")
- file(TO_NATIVE_PATH "${bindir}" bindir)
- set(tool_command_wrapper_path "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/qt_setup_tool_path.bat")
- file(WRITE "${tool_command_wrapper_path}" "@echo off
-set PATH=${bindir};%PATH%
-%*")
- set(QT_TOOL_COMMAND_WRAPPER_PATH "${tool_command_wrapper_path}"
- CACHE INTERNAL "Path to the wrapper of the tool commands")
- set_property(GLOBAL PROPERTY _qt_internal_generate_tool_command_wrapper_called TRUE)
-endfunction()
-qt_internal_generate_tool_command_wrapper()
-
# Platform define path, etc.
if(WIN32)
set(QT_DEFAULT_PLATFORM_DEFINITIONS WIN32 _ENABLE_EXTENDED_ALIGNED_STORAGE)
@@ -604,6 +587,11 @@ if(COMMAND _qt_internal_get_add_plugin_keywords)
unset(__qt_internal_add_plugin_multi_args)
endif()
+# Create tool script wrapper if necessary.
+# TODO: Remove once all direct usages of QT_TOOL_COMMAND_WRAPPER_PATH are replaced with function
+# calls.
+_qt_internal_generate_tool_command_wrapper()
+
# This sets up the poor man's scope finalizer mechanism.
# For newer CMake versions, we use cmake_language(DEFER CALL) instead.
if(CMAKE_VERSION VERSION_LESS "3.19.0")
diff --git a/cmake/QtPublicToolHelpers.cmake b/cmake/QtPublicToolHelpers.cmake
index cd4b093326..b10e267e0c 100644
--- a/cmake/QtPublicToolHelpers.cmake
+++ b/cmake/QtPublicToolHelpers.cmake
@@ -41,3 +41,92 @@ function(__qt_internal_get_tool_imported_location out_var tool)
set(${out_var} "${${out_var}}" PARENT_SCOPE)
endfunction()
+
+function(_qt_internal_generate_tool_command_wrapper)
+ get_property(is_called GLOBAL PROPERTY _qt_internal_generate_tool_command_wrapper_called)
+ if(NOT CMAKE_HOST_WIN32 OR is_called)
+ return()
+ endif()
+
+ set(prefixes "")
+
+ # In a prefix build, the just-built tools should pick up libraries from the current repo build
+ # dir.
+ if(QT_BUILD_DIR)
+ list(APPEND prefixes "${QT_BUILD_DIR}")
+ endif()
+
+ # Pick up libraries from the main location where Qt was installed during a Qt build.
+ if(QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX)
+ list(APPEND prefixes "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}")
+ endif()
+
+ # Needed for ExternalProjects examples, where the Qt build dir is passed via this variable
+ # to the example project.
+ if(QT_ADDITIONAL_PACKAGES_PREFIX_PATH)
+ __qt_internal_prefix_paths_to_roots(additional_roots
+ "${QT_ADDITIONAL_PACKAGES_PREFIX_PATH}")
+ list(APPEND prefixes ${QT_ADDITIONAL_PACKAGES_PREFIX_PATH})
+ endif()
+
+ # Fallback to wherever Qt6 package is.
+ if(QT6_INSTALL_PREFIX)
+ list(APPEND prefixes "${QT6_INSTALL_PREFIX}")
+ endif()
+
+ # When building qtbase, QT6_INSTALL_BINS is not set yet.
+ if(INSTALL_BINDIR)
+ set(bin_suffix "${INSTALL_BINDIR}")
+ else()
+ set(bin_suffix "${QT6_INSTALL_BINS}")
+ endif()
+
+ set(path_dirs "")
+ foreach(prefix IN LISTS prefixes)
+ set(bin_dir "${prefix}/${bin_suffix}")
+ if(EXISTS "${bin_dir}")
+ file(TO_NATIVE_PATH "${bin_dir}" path_dir)
+ list(APPEND path_dirs "${path_dir}")
+ endif()
+ endforeach()
+
+ set(tool_command_wrapper_dir "${CMAKE_BINARY_DIR}/.qt/bin")
+ file(MAKE_DIRECTORY "${tool_command_wrapper_dir}")
+ set(tool_command_wrapper_path "${tool_command_wrapper_dir}/qt_setup_tool_path.bat")
+
+ file(WRITE "${tool_command_wrapper_path}" "@echo off
+set PATH=${path_dirs};%PATH%
+%*")
+
+ set(QT_TOOL_COMMAND_WRAPPER_PATH "${tool_command_wrapper_path}"
+ CACHE INTERNAL "Path to the wrapper of the tool commands")
+
+ set_property(GLOBAL PROPERTY _qt_internal_generate_tool_command_wrapper_called TRUE)
+endfunction()
+
+# Wraps a tool command with a script that contains the necessary environment for the tool to run
+# correctly.
+# _qt_internal_wrap_tool_command(var <SET|APPEND> <command> [args...])
+# Arguments:
+# APPEND Selects the 'append' mode for the out_variable argument.
+# SET Selects the 'set' mode for the out_variable argument.
+function(_qt_internal_wrap_tool_command out_variable action)
+ set(append FALSE)
+ if(action STREQUAL "APPEND")
+ set(append TRUE)
+ elseif(NOT action STREQUAL "SET")
+ message(FATAL_ERROR "Invalid action specified ${action}. Supported actions: SET, APPEND")
+ endif()
+
+ # Ensure the script wrapper exists.
+ _qt_internal_generate_tool_command_wrapper()
+
+ set(cmd COMMAND ${QT_TOOL_COMMAND_WRAPPER_PATH} ${ARGN})
+
+ if(append)
+ list(APPEND ${out_variable} ${cmd})
+ else()
+ set(${out_variable} ${cmd})
+ endif()
+ set(${out_variable} "${${out_variable}}" PARENT_SCOPE)
+endfunction()