summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2022-12-13 10:30:57 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2022-12-16 18:21:57 +0100
commit8f2d5a56491c55d678415041dc029c4b5b2b8f4b (patch)
tree0ed7cc3d31882caf6505c1bf6c023475aed98168
parentb3750e815f3b8b4dd68b4425014b7b8dfa9b985f (diff)
CMake: Enforce QT_RESOURCE_ALIAS for absolute paths in resources
For Qt resources, enforce QT_RESOURCE_ALIAS for source files that are specified with absolute paths. Users can add generated files to resources, e.g. in qt6_target_qml_sources or qt6_add_qml_module. The file paths of those generated files are typically absolute paths. The function __qt_get_relative_resource_path_for_file is used to construct file paths in the build directory. For the files in question, this function returned an absolute file path. This led to very long subdirectories within the build directory and even invalid paths on Windows. We cannot guess how the user intends to address the file via the resource system and require now that QT_RESOURCE_ALIAS is set on such files. [ChangeLog][CMake] In Qt resources, files that are specified as absolute paths must have the property QT_RESOURCE_ALIAS set. Task-number: QTBUG-108150 Change-Id: Ida092c3d103a243caffc869b4bb887d4b5ce70ab Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--src/corelib/Qt6CoreMacros.cmake7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake
index f5e93d6b14..a3d53e8fc0 100644
--- a/src/corelib/Qt6CoreMacros.cmake
+++ b/src/corelib/Qt6CoreMacros.cmake
@@ -1459,6 +1459,13 @@ function(__qt_get_relative_resource_path_for_file output_alias file)
get_property(alias SOURCE ${file} PROPERTY QT_RESOURCE_ALIAS)
if (NOT alias)
set(alias "${file}")
+ if(IS_ABSOLUTE "${file}")
+ message(FATAL_ERROR
+ "The source file '${file}' was specified with an absolute path and is used in a Qt "
+ "resource. Please set the QT_RESOURCE_ALIAS property on that source file to a "
+ "relative path to make the file properly accessible via the resource system."
+ )
+ endif()
endif()
set(${output_alias} ${alias} PARENT_SCOPE)
endfunction()