Say I have code that looks like this:
target_compile_options(${PROJECT_NAME}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:...Options...>
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:...Options...>
)
As evident, the second line (which checks if the compiler is GCC, Clang, or AppleClang), is very long in length. In order to shorten this to multiple lines, I tried the following:
target_compile_options(${PROJECT_NAME}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:...Options...>
$<$<OR:$<CXX_COMPILER_ID:GNU>,
$<CXX_COMPILER_ID:Clang>,
$<CXX_COMPILER_ID:AppleClang>>:...Options...>
)
However, upon running CMake, I find that this doesn't work. I get the following error:
CMake Error at CMakeLists.txt:23 (target_compile_options):
Error evaluating generator expression:
$<OR:$<CXX_COMPILER_ID:GNU>,;$<CXX_COMPILER_ID:Clang>,;$<CXX_COMPILER_ID:AppleClang>>
Parameters to $<OR> must resolve to either '0' or '1'.
As evident, CMake doesn't recongize that the next portion of the generator expression is on a consecutive line, not on the same one. Since I want to preserve readability, I do not want to have to resort to the first option. I realize that I can mess around with string(CONCAT ...)
and place the result in a variable, but I want to avoid that, as I only have one target in my whole project, which would make the variable kind of useless.
How do I split such a generator expression into multiple lines in order to preserve readability?