_qt_internal_create_moc_command: clean up MOC's arguments

MOC was failing to compile due to invalid arguments passed by the CMake
scripts. Notably, because of the "-D" without option that might "eat"
the command behind it.

On Wasm, the empty "-D" argument was eating up the following "-o",
leaving MOC clueless about the "extra" arguments that actually followed
the "-o".

Cleanup the passed arguments in _qt_internal_create_moc_command
to avoid passing -D or -I without macroname or include path.
Also, it seems that -D was passed multiple times: fix the remove
duplicates feature of _qt_internal_create_moc_command to recognize all
duplicates: instead of removing duplicates and then joining the argument
lists together, first join them and then remove the duplicates.

Fixes: QTBUG-111717
Change-Id: Ibf8cd69f162e50afa43bc27e8c242240b92b1a25
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
bb10
Sami Shalayel 2023-03-03 18:01:55 +01:00
parent 4e59a5252c
commit 5bb745f62b
1 changed files with 12 additions and 4 deletions

View File

@ -93,24 +93,32 @@ function(_qt_internal_create_moc_command infile outfile moc_flags moc_options
set(extra_output_files "${outfile}.json")
set(${out_json_file} "${extra_output_files}" PARENT_SCOPE)
endif()
string (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}")
if(moc_target)
set(_moc_parameters_file ${_moc_parameters_file}$<$<BOOL:$<CONFIG>>:_$<CONFIG>>)
set(targetincludes "$<TARGET_PROPERTY:${moc_target},INCLUDE_DIRECTORIES>")
set(targetdefines "$<TARGET_PROPERTY:${moc_target},COMPILE_DEFINITIONS>")
set(targetincludes "$<$<BOOL:${targetincludes}>:-I$<JOIN:$<REMOVE_DUPLICATES:${targetincludes}>,\n-I>\n>")
set(targetdefines "$<$<BOOL:${targetdefines}>:-D$<JOIN:$<REMOVE_DUPLICATES:${targetdefines}>,\n-D>\n>")
set(targetincludes "$<$<BOOL:${targetincludes}>:-I$<JOIN:${targetincludes},;-I>>")
set(targetdefines "$<$<BOOL:${targetdefines}>:-D$<JOIN:${targetdefines},;-D>>")
string(REPLACE ">" "$<ANGLE-R>" _moc_escaped_parameters "${_moc_parameters}")
string(REPLACE "," "$<COMMA>" _moc_escaped_parameters "${_moc_escaped_parameters}")
set(concatenated "$<$<BOOL:${targetincludes}>:${targetincludes};>$<$<BOOL:${targetdefines}>:${targetdefines};>$<$<BOOL:${_moc_escaped_parameters}>:${_moc_escaped_parameters};>")
set(concatenated "$<FILTER:$<REMOVE_DUPLICATES:${concatenated}>,EXCLUDE,^-[DI]$>")
set(concatenated "$<JOIN:${concatenated},\n>")
file (GENERATE
OUTPUT ${_moc_parameters_file}
CONTENT "${targetdefines}${targetincludes}${_moc_parameters}\n"
CONTENT "${concatenated}"
)
set(concatenated)
set(targetincludes)
set(targetdefines)
else()
string (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}")
file(WRITE ${_moc_parameters_file} "${_moc_parameters}\n")
endif()