I am trying to pass "compound" options to the compiler using cmake's add_compile_options
.
That is, options involving two (or more) flags that must be passed in a particular order and where none of the flags can be ommitted even if they have already be passed to the compiler.
An example would be all the llvm options that must be passed through clang to llvm, e.g., -mllvm -ABC -mllvm -XYZ -mllvm ...
.
I would prefer not to use CMake's antipattern set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -ABC")
but use something portable like check_cxx_compiler_flag(flag available)
+ add_compile_option(flag)
.
However, add_compile_options(-mllvm -XYZ -mllvm -ABC)
fails because the -mllvm
option gets cached and is only passed once, such that -mllvm -XYZ -ABC
is passed resulting in an error.
Furthermore, using quotes "" doesn't help since then the quotes are also passed (i.e. they are not stripped), which also results in an error.
What's the idiomatic way of passing these options with CMake?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…