What is the difference between include_directories and target_include_directories in CMake?(CMake 中的 include_directories 和 target_include_directories 有什么区别?)
问题描述
我的 C++ 代码有一个目录结构,如下所示:
<代码>||->包括|->src
我正在为我的代码编写一个 CMakeLists.txt 文件.我想了解 CMake 中 include_directories 和 target_include_directories 之间的区别.
它们的用法和为了添加我的包含文件路径我应该使用哪一个有什么区别?
include_directories(x/y) 影响目录范围.此 CMakeList 中的所有目标,以及在其调用点之后添加的所有子目录中的目标,都将路径 x/y 添加到它们的包含路径中.
target_include_directories(tx/y) 具有目标范围——它将x/y 添加到目标 t 的包含路径中.
如果您的所有目标都使用相关的包含目录,则您需要前者.如果路径特定于目标,或者您想要更好地控制路径的可见性,则您需要后者.后者来自于 target_include_directories() 支持 PRIVATE、PUBLIC 和 INTERFACE 限定符的事实.>
I have a directory structure for my C++ code which goes like this :
|
|->include
|->src
I am writing a CMakeLists.txt file for my code. I want to understand the difference between include_directories and target_include_directories in CMake.
What is the difference between their usage and in order to add my include file path which one should I be using?
include_directories(x/y) affects directory scope. All targets in this CMakeList, as well as those in all subdirectories added after the point of its call, will have the path x/y added to their include path.
target_include_directories(t x/y) has target scope—it adds x/y to the include path for target t.
You want the former one if all of your targets use the include directories in question. You want the latter one if the path is specific to a target, or if you want finer control of the path's visibility. The latter comes from the fact that target_include_directories() supports the PRIVATE, PUBLIC, and INTERFACE qualifiers.
这篇关于CMake 中的 include_directories 和 target_include_directories 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CMake 中的 include_directories 和 target_include_directories 有什么区别?
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
