在生成器表达式中使用cmake选项 [英] Using cmake options in generator expressions
问题描述
我想在生成器表达式中使用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.
我想写类似
option(MYOPTION " ... " OFF)
...
add_compile_options($<$<MYOPTION>:-lblas>)
这不起作用.
有没有办法做到这一点?
Is there a way to achieve this?
推荐答案
您的示例并未真正为此指定用例,而且我认为还有其他解决方法(以及 -lblas
是一个链接器标志,而不是一个编译选项.)仅仅从您提供的信息来看,您可能想要的是:
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:...>:...>
需要一个变量来协助评估( MYOPTION
可以满足.您可能会使用的文档中列出的其他逻辑表达式.
$<$<BOOL:...>:...>
needs a variable to assist with evaluating (which MYOPTION
fulfills. There are other logical expressions listed in the documentation that you may use.
这篇关于在生成器表达式中使用cmake选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!