在CMake中,了解如何包含项目的头文件

In CMake how to include header files of the project

本文关键字:项目 文件 何包含 CMake 了解      更新时间:2023-10-16

在C++项目中,我希望将头文件设置为项目源目录的子目录,而不使用UNIX目录快捷方式...。我不知道如何配置cmake来使用它。

我有目录结构:

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

放入root\CMakeList.txt:

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

您可以在子项目中的任何位置使用root_SOURCE_DIR。

欲了解更多信息,请访问http://www.cmake.org/Wiki/CMake_Useful_Variables#Variables_not_listed_here

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