如何在 CMake 中输出生成器表达式的结果? [英] How do I output the result of a generator expression in CMake?
问题描述
我有以下简单的 CMake 代码:
I have the following simple CMake code:
cmake_minimum_required(VERSION 3.1)
project(PrintGenerators)
set(TEST_OR_GENERATOR "$<$<OR:0,0,1>:YAY!>")
message(STATUS ${TEST_OR_GENERATOR}) # Print out the result of the build
我希望这段代码能打印出YAY!
,但它没有.我取而代之的是 $<$
作为输出.如何在配置期间打印计算的生成器表达式的结果?
I expect this code to print out YAY!
, but it does not. I instead get $<$<OR:0,0,1>:YAY!>
as the output. How do I print the result of the evaluated generator expression during configuration?
推荐答案
如何在配置过程中打印生成器表达式的计算结果?
How do I print the result of the evaluated generator expression during configuration?
你不能.生成器表达式适用于在配置阶段并不完全知道的事物:它们取决于构建类型,在多配置的情况下 generators 仅在构建阶段才被知晓.
You cannot. Generator expressions are intended for things, which are not exactly known at configuration stage: they depends on build type, which, in case of multiconfiguration generators becomes known only at the build stage.
然而,您可以将生成器表达式的值保存到文件中,但文件只会在配置阶段结束时写入:
You may, however, save a value of the generator expression into the file, but the file will be written only at the end of the configuration stage:
file(GENERATE OUTPUT <filename> CONTENT <string-with-generator-expression>)
file(GENERATOR)
的更详细描述见 文档.
这篇关于如何在 CMake 中输出生成器表达式的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!