diff options
-rw-r--r-- | src/qml/Qt6QmlMacros.cmake | 21 | ||||
-rw-r--r-- | src/qml/doc/src/cmake/qt_target_compile_qml_to_cpp.qdoc | 7 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/CMakeLists.txt | 2 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index 3966946aa3..3ff87ce21a 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -1011,6 +1011,8 @@ function(qt6_target_compile_qml_to_cpp target) endif() get_target_property(target_source_dir ${target} SOURCE_DIR) + get_target_property(target_binary_dir ${target} BINARY_DIR) + set(generated_sources_other_scope) set(compiled_files) # compiled files list to be used to generate MOC C++ @@ -1032,24 +1034,23 @@ function(qt6_target_compile_qml_to_cpp target) # we ensured earlier that prefix always ends with "/" file(TO_CMAKE_PATH "${prefix}${file_resource_path}" file_resource_path) - file(RELATIVE_PATH file_relative ${CMAKE_CURRENT_SOURCE_DIR} ${file_absolute}) - string(REGEX REPLACE "\.qml$" "" compiled_file_base ${file_relative}) - string(REGEX REPLACE "[$#?]+" "_" compiled_file ${compiled_file_base}) + get_filename_component(file_basename ${file_absolute} NAME_WLE) # extension is always .qml + string(REGEX REPLACE "[$#?]+" "_" compiled_file ${file_basename}) string(TOLOWER ${compiled_file} file_name) - # NB: use <path>/<lowercase(file_name)>.<extension> pattern. if + # NB: use <lowercase(file_name)>.<extension> pattern. if # lowercase(file_name) is already taken (e.g. project has main.qml and # main.h/main.cpp), the compilation might fail. in this case, expect # user to specify QT_QMLTC_FILE_BASENAME get_source_file_property(specified_file_name ${qml_file_src} QT_QMLTC_FILE_BASENAME) - if (specified_file_name) # if present, overwrite the default behavior - set(file_name ${specified_file_name}) + if (specified_file_name) + get_filename_component(file_name ${specified_file_name} NAME_WLE) endif() - set(compiled_header - "${CMAKE_CURRENT_BINARY_DIR}/.qmltc/${target}/${file_name}.h") - set(compiled_cpp - "${CMAKE_CURRENT_BINARY_DIR}/.qmltc/${target}/${file_name}.cpp") + # Note: add '${target}' to path to avoid potential conflicts where 2+ + # distinct targets use the same ${target_binary_dir}/.qmltc/ output dir + set(compiled_header "${target_binary_dir}/.qmltc/${target}/${file_name}.h") + set(compiled_cpp "${target_binary_dir}/.qmltc/${target}/${file_name}.cpp") get_filename_component(out_dir ${compiled_header} DIRECTORY) add_custom_command( diff --git a/src/qml/doc/src/cmake/qt_target_compile_qml_to_cpp.qdoc b/src/qml/doc/src/cmake/qt_target_compile_qml_to_cpp.qdoc index 04731a88ee..99c64e74ab 100644 --- a/src/qml/doc/src/cmake/qt_target_compile_qml_to_cpp.qdoc +++ b/src/qml/doc/src/cmake/qt_target_compile_qml_to_cpp.qdoc @@ -73,9 +73,10 @@ While processing FILES, the following source file properties are respected: non-default .h and .cpp file name, which might be useful to e.g. resolve conflicting file names (imagine you have main.qml that is being compiled, but main.h already exists, so #include "main.h" might not do - what you expect it to do). Unlike in the case of default behavior, the - QT_QMLTC_FILE_BASENAME is taken as is, without being lower-cased or - processed by any other means + what you expect it to do). QT_QMLTC_FILE_BASENAME is expected to be a + file name (without extension), so any preceding directory is ignored. + Unlike in the case of default behavior, the QT_QMLTC_FILE_BASENAME is + not lower-cased. \endlist */ diff --git a/tests/auto/qml/qmltc/CMakeLists.txt b/tests/auto/qml/qmltc/CMakeLists.txt index ae83ffc45c..dd601b9fac 100644 --- a/tests/auto/qml/qmltc/CMakeLists.txt +++ b/tests/auto/qml/qmltc/CMakeLists.txt @@ -11,7 +11,7 @@ set(qml_sources ) set_source_files_properties(data/NameConflict.qml PROPERTIES - QT_QMLTC_FILE_BASENAME data/ResolvedNameConflict) + QT_QMLTC_FILE_BASENAME ResolvedNameConflict) qt_internal_add_test(tst_qmltc_diskcache SOURCES |