C++ CMake 包含路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15392561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:20:39  来源:igfitidea点击:

CMake include path

c++cmake

提问by user1377000

In a C++ project, I would to include the header files as as descendants of the project's source directory without use of UNIX directory shortcuts . or .. . Im not sure how to configure cmake to work with that.

在 C++ 项目中,我会将头文件作为项目源目录的后代包含在内,而不使用 UNIX 目录快捷方式。或者 .. 。我不确定如何配置 cmake 来处理它。

I have the directory structure:

我有目录结构:

Root
|-include
| |- foo.h
|-src
| | foo.cpp

回答by AnatolyS

put into root\CMakeList.txt:

放入 root\CMakeList.txt:

project(root)
include_directories(${root_SOURCE_DIR}/include)
...

you can use root_SOURCE_DIR everywhere in sub projects.

您可以在子项目中随处使用 root_SOURCE_DIR。

for more information consider to visit http://www.cmake.org/Wiki/CMake_Useful_Variables#Variables_not_listed_here

有关更多信息,请考虑访问http://www.cmake.org/Wiki/CMake_Useful_Variables#Variables_not_listed_here

回答by yattering

Use include_directories( include )for CMakeLists.txt in Root folder. Or include_directories( ${CMAKE_SOURCE_DIR}/include )from any subfolder.

使用include_directories( include )在根文件夹中的CMakeLists.txt。或include_directories( ${CMAKE_SOURCE_DIR}/include )来自任何子文件夹。