【发布时间】:2020-08-17 12:20:14
【问题描述】:
鉴于这样的项目结构:
project/
src/
CMakeLists.txt
foo.h
main.cpp
util/
CMakeLists.txt
bar.h
bar.h 内部是否可以有一个包含语句为 #include "foo.h" ?我已经通过 Visual Studio 中的“预编译头”配置看到了一些可能的方法,但不直接使用 CMake。
【问题讨论】:
-
假设您在 include 目录中有
project/src目录,那么#include "foo.h"将起作用。在 CMake 中包含目录是使用 include_directories 命令指定的。 -
这与预编译的头文件无关。
-
#include "../foo.h"有什么问题?为什么util会触及其父级?听起来设计很糟糕。 -
@WilliamBright 关键是,为源代码树中的每个目录都有一个 CMakeLists.txt 不是正确的方法。