diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-11-01 14:23:17 +0100 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2021-11-09 15:14:27 +0100 |
commit | d4a28c6adc57f3e6f774f3ff338589591ff6fae4 (patch) | |
tree | 2737ed5bb930d67d695a499603879b8b7ceb5b90 /src/qml/Qt6QmlMacros.cmake | |
parent | 7f018794beebf360bf375e065d2547c71150fdf6 (diff) |
qt6_target_compile_qml_to_cpp: improve QT_QMLTC_FILE_BASENAME handling
Let's simplify the whole output path logic for .cpp and .h:
- there's really little use in relative prefixes (e.g. we don't need
data/ in data/HelloWorld.qml to operate)
- similarly, let's ignore/discourage the use of such prefixes in
QT_QMLTC_FILE_BASENAME. I envision poor output dir structure otherwise
(not that anyone will notice it anyway)
As a drive by, also replace CMAKE_CURRENT_*_DIR with target_*_dir as we
should really use target's dir structure, not the (potentially wrong)
current dir structure
Task-number: QTBUG-96040
Change-Id: Ib9a108941e5179809855d28003ec157a07163c0e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/Qt6QmlMacros.cmake')
-rw-r--r-- | src/qml/Qt6QmlMacros.cmake | 21 |
1 files changed, 11 insertions, 10 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( |