I would like to use a cmake option inside a generator expression in order to turn on a certain compile flag. From the documentation it is not clear to me how to achieve this.
I would like to write something like
option(MYOPTION " ... " OFF)
...
add_compile_options($<$<MYOPTION>:-lblas>)
which does not work.
Is there a way to achieve this?
Your example doesn't really specify a use case for this, and I think there are other ways of going about it (as well as -lblas
being a linker flag not a compile option.) Just off of the information you provide, it looks like what you might want is:
option(MYOPTION "My Option" OFF)
...
add_compile_options($<$<BOOL:${MYOPTION}>:-lblas>)
#(or maybe you want?)
target_compile_definitions(YOUR_TARGET PRIVATE $<$<BOOL:${MYOPTION}>:-lblas>)
$<$<BOOL:...>:...>
needs a variable to assist with evaluating (which MYOPTION
fulfills. There are other logical expressions listed in the documentation that you may use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With