[CMake] De-duplication with generator expressions

Wilke, Jeremiah J jjwilke at sandia.gov
Thu Mar 28 14:13:27 EDT 2019


I am passing several LLVM/Clang passes, which means I need arguments not de-duplicated:


-Xtemplight -profiler -Xtemplight -ignore-system

Otherwise I would get


templight++ -Xtemplight -profiler -ignore-system



which crashes. The SHELL: trick works in some cases. However, I also have scenarios where I need a generator expression so compiler flags only apply to C++ files:


target_compile_options(${target} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:…

The following works:
target_compile_options(${target} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:SHELL:-Xtemplight -profiler -Xtemplight -ignore-system>)

But then splitting around conditionals, the below does not and still does de-dup breaking the build:
if (TEMPLIGHT_IGNORE_SYSTEM)
target_compile_options(${target} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:SHELL:-Xtemplight -ignore-system>)
endif()
target_compile_options(${target} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:SHELL:-Xtemplight -profiler>)

After searching for a bit, it would appear SHELL: can still not be used with generator expressions? Has anyone else encountered this and knows a workaround?  No amount of searching or playing around with quotes got this to work.

-Jeremy






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190328/fb83bc5e/attachment.html>


More information about the CMake mailing list