根据配置有条件地在cmake中设置变量
Conditionally set a variable in cmake based on configuration
是否可以根据配置在cmake中有条件地设置一个变量?例如,我正在尝试这样的事情:
set(VAR
$<$<CONFIG:Debug>:definition_for_debug>
$<$<CONFIG:RelWithDebInfo>:definition_for_rel_with_debug>
$<$<CONFIG:Release>:definition_for_release>
$<$<CONFIG:MinSizeRel>:definition_for_tight_release>
)
但是,当我这样做时,cmake returns 使用变量的地方出错。我在这里做错了什么?还有其他方法吗?
想通了。不同的生成器表达式之间不应有空格:
set(VAR $<$<CONFIG:Debug>:definition_for_debug>$<$<CONFIG:RelWithDebInfo>:definition_for_rel_with_debug>$<$<CONFIG:Release>:definition_for_release> $<$<CONFIG:MinSizeRel>:definition_for_tight_release>
)
是否可以根据配置在cmake中有条件地设置一个变量?例如,我正在尝试这样的事情:
set(VAR
$<$<CONFIG:Debug>:definition_for_debug>
$<$<CONFIG:RelWithDebInfo>:definition_for_rel_with_debug>
$<$<CONFIG:Release>:definition_for_release>
$<$<CONFIG:MinSizeRel>:definition_for_tight_release>
)
但是,当我这样做时,cmake returns 使用变量的地方出错。我在这里做错了什么?还有其他方法吗?
想通了。不同的生成器表达式之间不应有空格:
set(VAR $<$<CONFIG:Debug>:definition_for_debug>$<$<CONFIG:RelWithDebInfo>:definition_for_rel_with_debug>$<$<CONFIG:Release>:definition_for_release> $<$<CONFIG:MinSizeRel>:definition_for_tight_release>
)