【发布时间】:2021-07-17 07:23:23
【问题描述】:
我想使用CMakeList.txt 从命令行更改宏值。我有
#ifndef NUMBER
#define NUMBER 1
#endif
和
#ifndef NAME
#define NAME "MyName" //string format
#endif
我找到了一些链接 -> How to define a C++ preprocessor macro through the command line with CMake?。他们说在 CMake 中添加 add_definitions(-DNUMBER=5) 并且它正在工作我可以使用这种方式更改值。
我想要一些可以使用命令行更改值的方法。喜欢
add_definitions(-DNUMBER=NUMBERX)
从命令行我们提供号码cmake NUMBERX=100. and NAMEX="ALEXA".
或者以其他方式代替add_definitions()。
【问题讨论】:
-
如果您正确拼写 add_definitions,它可能会起作用。定义中没有 a
-
即使你提到的问题也有the answer with option-approach,它允许有条件地设置特定的宏定义,具体取决于命令行参数。 The answer to the duplicate question描述了将命令行值直接用作宏值。