aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Shalayel <[email protected]>2025-03-03 14:28:12 +0100
committerSami Shalayel <[email protected]>2025-04-17 08:51:47 +0200
commit538cd9d8ce5539d0b95d8e33cdd705a4cb388d53 (patch)
tree61baa4badcf2c1294619a5e56b5eacace40c83ac
parente812d93162024288095c106fe7a4cbf54959fd6f (diff)
cmake: recreate .qmlls.ini on build folder change
Change the way that qmlls.ini files are generated in the source folder, such that they can be automatically recreated on build folder change, for example when using a source folder with multiple different build folders. Introduce new files in the build folder: .qmlls.ini.build contains the content of the .qmlls.ini, .qmlls.ini.timestamp is empty and is a marker to indicate to CMake whether the .qmlls.ini.build content should be written to the source folder .qmlls.ini. When there is a timestamp in the build folder, then we know that the .qmlls.ini file in the source folder is up-to-date and nothing needs to be done. If there is no timestamp (the project was not build before, or the timestamp was deleted), use newly-added Qt6UpdateQmllsIni.cmake to find the build folder used by the source-folder .qmlls.ini and to invalidate (delete) all timestamp files it can find there, to signal the previous build folder that its .qmlls.ini is out-dated. Then, write the .qmlls.ini content to the source folder and create a timestamp file in the current build folder. If the previous build folder is built again, it will see the missing timestamp files and will re-write the .qmlls.ini files in the source folder. Add a test in a separate commit because RunCMakeTest does not seem to work yet. Pick-to: 6.8 6.9 Task-number: QTBUG-133793 Change-Id: I66aa259e56d795860bb346d53d9841714048e478 Reviewed-by: Fabian Kosmale <[email protected]>
-rw-r--r--src/qml/CMakeLists.txt1
-rw-r--r--src/qml/Qt6QmlMacros.cmake44
-rw-r--r--src/qml/Qt6UpdateQmllsIni.cmake22
3 files changed, 58 insertions, 9 deletions
diff --git a/src/qml/CMakeLists.txt b/src/qml/CMakeLists.txt
index 5eb4cd0e39..970103e527 100644
--- a/src/qml/CMakeLists.txt
+++ b/src/qml/CMakeLists.txt
@@ -437,6 +437,7 @@ qt_internal_add_qml_module(Qml
"${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}QmlModuleDirMappingTemplate.qrc.in"
"${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}QmltcFileMappingTemplate.qrc.in"
"${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}QmlPublicCMakeHelpers.cmake"
+ "${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}UpdateQmllsIni.cmake"
${extra_cmake_files}
EXTRA_CMAKE_INCLUDES
"${INSTALL_CMAKE_NAMESPACE}QmlFindQmlscInternal.cmake"
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake
index 0c70efd711..6122394e09 100644
--- a/src/qml/Qt6QmlMacros.cmake
+++ b/src/qml/Qt6QmlMacros.cmake
@@ -1272,23 +1272,49 @@ function(_populate_qmlls_ini_file target qmlls_ini_file concatenated_build_dirs
set(no_cmake_calls "false")
endif()
+ set(qmlls_ini_build_file "${CMAKE_CURRENT_BINARY_DIR}/.qt/qmlls.ini.build")
+
+ #note: delete this file to mark .qmlls.ini as outdated
+ set(qmlls_ini_timestamp_file
+ "${CMAKE_CURRENT_BINARY_DIR}/.qt/qmlls.ini.timestamp")
+
+ # generate the .qmlls.ini file content in the build folder
add_custom_command(
OUTPUT
- ${qmlls_ini_file}
- COMMAND ${CMAKE_COMMAND} -E echo "[General]" > ${qmlls_ini_file}
- COMMAND ${CMAKE_COMMAND} -E echo "buildDir=\"${concatenated_build_dirs}\"" >> ${qmlls_ini_file}
- COMMAND ${CMAKE_COMMAND} -E echo "no-cmake-calls=${no_cmake_calls}" >> ${qmlls_ini_file}
- COMMAND ${CMAKE_COMMAND} -E echo_append "docDir=" >> ${qmlls_ini_file}
+ ${qmlls_ini_build_file}
+ COMMAND ${CMAKE_COMMAND} -E echo "[General]" > ${qmlls_ini_build_file}
+ COMMAND ${CMAKE_COMMAND} -E echo "buildDir=\"${concatenated_build_dirs}\""
+ >> ${qmlls_ini_build_file}
+ COMMAND ${CMAKE_COMMAND} -E echo "no-cmake-calls=${no_cmake_calls}"
+ >> ${qmlls_ini_build_file}
+ COMMAND ${CMAKE_COMMAND} -E echo_append "docDir=" >> ${qmlls_ini_build_file}
COMMAND
${tool_wrapper}
${qtpaths}
- --query QT_INSTALL_DOCS >> ${qmlls_ini_file}
- COMMAND ${CMAKE_COMMAND} -E echo "importPaths=\"${import_paths}\"" >> ${qmlls_ini_file}
- COMMENT "Populating .qmlls.ini file"
+ --query QT_INSTALL_DOCS >> ${qmlls_ini_build_file}
+ COMMAND ${CMAKE_COMMAND} -E echo "importPaths=\"${import_paths}\""
+ >> ${qmlls_ini_build_file}
+ COMMENT "Populating .qmlls.ini file at ${qmlls_ini_build_file}"
+ VERBATIM
+ )
+ # delete timestamps from previous configuration, if available, then copy qmlls to source folder and create timestamp
+ add_custom_command(
+ OUTPUT
+ ${qmlls_ini_timestamp_file}
+ BYPRODUCTS
+ ${qmlls_ini_file}
+ DEPENDS
+ ${qmlls_ini_build_file}
+ COMMAND ${CMAKE_COMMAND}
+ -DqmllsIniPath=${qmlls_ini_file}
+ -P "${__qt_qml_macros_module_base_dir}/Qt6UpdateQmllsIni.cmake"
+ COMMAND ${CMAKE_COMMAND} -E copy ${qmlls_ini_build_file} ${qmlls_ini_file}
+ COMMAND ${CMAKE_COMMAND} -E touch ${qmlls_ini_timestamp_file}
+ COMMENT "Copying .qmlls.ini file at ${qmlls_ini_build_file} to ${qmlls_ini_file}"
VERBATIM
)
add_custom_target(${target}_generate_qmlls_ini_file
- DEPENDS ${qmlls_ini_file}
+ DEPENDS ${qmlls_ini_timestamp_file}
VERBATIM
)
add_dependencies(${target} ${target}_generate_qmlls_ini_file)
diff --git a/src/qml/Qt6UpdateQmllsIni.cmake b/src/qml/Qt6UpdateQmllsIni.cmake
new file mode 100644
index 0000000000..ecadf89253
--- /dev/null
+++ b/src/qml/Qt6UpdateQmllsIni.cmake
@@ -0,0 +1,22 @@
+# Copyright (C) 2025 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+if(NOT EXISTS "${qmllsIniPath}")
+ return()
+endif()
+
+file(READ "${qmllsIniPath}" qmllsIniContent)
+string(REGEX REPLACE ".*buildDir=\"([^\"]*)\".*" "\\1" buildPaths "${qmllsIniContent}")
+
+# replace unix path separator with CMake list separator
+# note that the windows path separator is the CMake list separator already
+if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
+ string(REPLACE ":" ";" buildPaths "${buildPaths}")
+endif()
+
+foreach(path "${buildPaths}")
+ file(GLOB_RECURSE qmllsIniFiles "${path}/*qmlls.ini.timestamp")
+ file(REMOVE "${qmllsIniFiles}")
+endforeach()