Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using cmake options in generator expressions

Tags:

cmake

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?

like image 615
Wentzell Avatar asked Oct 17 '17 15:10

Wentzell


1 Answers

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.

like image 172
Cinder Biscuits Avatar answered Nov 11 '22 11:11

Cinder Biscuits