我有以下简单的 CMake 代码:
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!
,但事实并非如此。我反而得到 $<$<OR:0,0,1>:YAY!>
作为输出。如何在配置期间打印计算的生成器表达式的结果?
最佳答案
How do I print the result of the evaluated generator expression during configuration?
你不能。生成器表达式适用于在配置阶段并不完全了解的事物:它们取决于构建类型,在多重配置的情况下generators仅在构建阶段才知道。
但是,您可以将生成器表达式的值保存到文件中,但该文件只会在配置阶段结束时写入:
file(GENERATE OUTPUT <filename> CONTENT <string-with-generator-expression>)
更详细的说明
file(GENERATOR)
见documentation .
关于cmake - 如何在 CMake 中输出生成器表达式的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51353110/