ldionne wrote:

This is really tricky, however I believe the current behavior is correct (and 
in fact it's the only correct way of handling this). The 
`{LIBCXX,LIBCXXABI,LIBUNWIND}_ADDITIONAL_COMPILE_FLAGS` options expect to be 
passed something that is already formatted as a CMake list with `;` to delimit 
separate arguments. This is necessary to prevent CMake from incorrectly 
deduplicating some flags.

For example, after your patch, passing 
`-DLIBCXX_ADDITIONAL_COMPILE_FLAGS="-Xclang -pedantic -Xclang 
-disable-llvm-passes"` when configuring with CMake would fail, because that 
would be split into the list `-Xclang;-pedantic;-Xclang;-disable-llvm-passes`, 
which CMake will deduplicate to `-Xclang;-pedantic;-disable-llvm-passes` and 
pass to the compiler as `-Xclang -pedantic -disable-llvm-passes`, which is 
invalid. Getting this right is very tricky. CMake option-deduplication is 
documented 
[here](https://cmake.org/cmake/help/v3.30/command/add_compile_options.html#option-de-duplication).

The right way to pass such arguments is to use `SHELL:` to tell Clang that it 
should group arguments and then separate them before passing them to the 
compiler. So you end up passing 
`-DLIBCXX_ADDITIONAL_COMPILE_FLAGS="-v;-O3;SHELL:-Xclang -pedantic;-Xclang 
-disable-llvm-passes"` to CMake, which will then pass `-v -O3 -Xclang -pedantic 
-Xclang -disable-llvm-passes` to the compiler. Alternatively, I think you can 
also just pass a single `SHELL` argument like 
`-DLIBCXX_ADDITIONAL_COMPILE_FLAGS="SHELL:-v -O3 -Xclang -pedantic -Xclang 
-disable-llvm-passes"` -- in that case you'd be passing a 1-element list of 
compile flags, which is comprised of the `-v -O3 -Xclang -pedantic -Xclang 
-disable-llvm-passes` "option-group".

https://github.com/llvm/llvm-project/pull/112703
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to