cmake没有定义变量
CMake not defining variables
试图在config.h中定义项目版本变量以包含在源文件中时,cmake并未定义它们
cmakelists.txt看起来像
cmake_minimum_required(VERSION 3.0)
project(podder VERSION 1.0 LANGUAGES CXX)
configure_file(config.h.in config.h ESCAPE_QUOTES)
config.h.in
#ifndef HAVE_CONFIG_H
#define HAVE_CONFIG_H
#cmakedefine ${CMAKE_PROJECT_VERSION}
#endif
和生成的config.h看起来像
#ifndef HAVE_CONFIG_H
#define HAVE_CONFIG_H
/* #undef */
#endif
您想要的是
#ifndef HAVE_CONFIG_H
#define HAVE_CONFIG_H
#cmakedefine PROJECT_VERSION ${PROJECT_VERSION}
#endif
语法是 #cmakedefine VAR ...
,其中 VAR
是变量名称(没有 $()
(,并且评估了表达式 ...
,请参见configure_file((。如果未定义变量VAR
或评估为false,则由/* #undef VAR */
替换。
相关文章:
- 用C++中的一个变量定义一个常量
- 变量定义到C++布尔值转换
- 未声明的标识符错误,但变量定义正确 (?)
- C++多线程程序:变量定义为类成员的隔离错误
- 将变量定义为静态时,为什么可以多次定义它
- 初始值设定项列表与构造函数赋值与变量定义
- 如何根据传递给函数的变量定义特征矩阵大小
- C++ 描述如何使用来简化变量定义
- 如何转发声明依赖于变量定义的类,而变体定义又依赖于模板化类?
- 是否修改其声明语句中的变量定义良好
- 使用类的其他成员变量定义类的成员变量数组
- 是否可以通过全局变量定义具有可变参数数的函数中的参数数量
- 元组 std::get() 不适用于变量定义的常量
- 全局使用变量定义和C 声明
- C++变量定义中的易失性类型量词位置
- 将变量定义为数组和正确的语法
- 多个,包括具有变量定义的头文件
- 调用构造函数,并将成员作为参数解析为变量定义
- 逗号分隔变量定义中关系前的序列
- 如何使用命名变量定义常量右值引用参数的默认值