Skip to content

Cannot add a list of flags with `add_compile_options` using generator expressions

I am having a problem with setting multiple compilation flags in my root CMake file. I am trying to set a list of flags for all projects/targets in a directory using add_compile_options like so:

add_compile_options($<$<CXX_COMPILER_ID:GNU>:-pedantic;-Wall;-Wextra>)

however this results in a compilation error. The ninja files looks like this:

FLAGS = -g   "\$$<1:-Wall" "-Wextra>"

I tried using different separators (spaces, commas, quotes) but none of them seem to be working. If I set one single compile flag everything works perfectly fine, meaning I face this issue when I am setting a list of flags.

The most interesting thing is that when I use the target_compile_options to set the same flags in each individual subproject everything works perfectly fine. Below works perfectly fine:

target_compile_options(myTarget PRIVATE
   $<$<CXX_COMPILER_ID:GNU>:-pedantic;-Wall;-Wextra>)

So, I don't understand what I am missing here? Why can't I set multiple flags in a single add_compile_options call?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information