From 5bb745f62ba1aa63e4bbd107b279d96bd06dffda Mon Sep 17 00:00:00 2001 From: Sami Shalayel Date: Fri, 3 Mar 2023 18:01:55 +0100 Subject: [PATCH] _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 Reviewed-by: Ulf Hermann Reviewed-by: Alexandru Croitor Reviewed-by: Fabian Kosmale --- src/corelib/Qt6CoreMacros.cmake | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 91dedbf71f..94e3bd057e 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -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}$<$>:_$>) set(targetincludes "$") set(targetdefines "$") - set(targetincludes "$<$:-I$,\n-I>\n>") - set(targetdefines "$<$:-D$,\n-D>\n>") + set(targetincludes "$<$:-I$>") + set(targetdefines "$<$:-D$>") + string(REPLACE ">" "$" _moc_escaped_parameters "${_moc_parameters}") + string(REPLACE "," "$" _moc_escaped_parameters "${_moc_escaped_parameters}") + + set(concatenated "$<$:${targetincludes};>$<$:${targetdefines};>$<$:${_moc_escaped_parameters};>") + + set(concatenated "$,EXCLUDE,^-[DI]$>") + set(concatenated "$") 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()