【CMake】配置头文件

如果想要在源代码中使用CMakelists.txt中定义的变量就可以使用configure_file命令。

在配置头文件中使用@VAR@的语法引用CMakelists.txt中定义的变量。

示例如下:
TutorialConfig.h.in

// the configured options and settings for Tutorial
#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@

CMakeLists.txt

project(Tutorial VERSION 1.0)
configure_file(TutorialConfig.h.in TutorialConfig.h)
posted @ 2024-06-18 11:18  NotReferenced  阅读(77)  评论(0)    收藏  举报