cmake include_directories分析

自动化编译这几天快把我折磨透了,好烦,但是还要加班来搞,现在静下来慢慢分析:

看官方文档解释:

  • include_directories: 编译时加到包含目录
  •   include_directories([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)
    

    Add the given directories to those the compiler uses to search for include files. These directories are added to the directory property INCLUDE_DIRECTORIES for the current CMakeLists file. They are also added to the target property INCLUDE_DIRECTORIES for each target in the current CMakeLists file. The target property values are the ones used by the generators.

    By default the directories are appended onto the current list of directories. This default behavior can be changed by setting CMAKE_INCLUDE_DIRECTORIES_BEFORE to ON. By using AFTER or BEFORE explicitly, you can select between appending and prepending, independent of the default. If the SYSTEM option is given, the compiler will be told the directories are meant as system include directories on some platforms.

  • 增加指定目录给指定编译器去搜索包含文件。这些目录被当前CMakeLists文件以INCLUDE_DIRECTORIES 来加进文件属性。他们也被


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
target_include_directoriesCMake中的一个命令,用于指定目标的包含目录。它允许你为特定的目标(如可执行文件或库)指定需要包含的头文件目录。通过这个命令,你可以告诉CMake在构建过程中将这些目录添加到编译器的搜索路径中。 命令的语法如下: ``` target_include_directories(target_name [SYSTEM] [BEFORE] <INTERFACE|PUBLIC|PRIVATE> [items1...] [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...]) ``` 参数说明: - target_name:指定目标的名称。 - SYSTEM:可选参数,表示这些目录是系统级别的头文件目录。 - BEFORE:可选参数,表示将这些目录添加到搜索路径的最前面。 - INTERFACE/PUBLIC/PRIVATE:指定目标的属性。INTERFACE表示该目标只会影响链接到它的目标;PUBLIC表示该目标会影响链接到它的目标以及该目标自身;PRIVATE表示该目标只会影响该目标自身。 - items:指定需要包含的头文件目录。 示例用法: ``` target_include_directories(my_target PUBLIC include) target_include_directories(my_target PRIVATE src) target_include_directories(my_target SYSTEM BEFORE third_party) ``` 以上示例中,my_target是一个目标名称,通过target_include_directories命令指定了my_target需要包含的头文件目录。其中,include目录是公共目录,src目录是私有目录,third_party目录是系统级别的头文件目录,并将其添加到搜索路径的最前面。 希望这个解答能够帮到你!如果你还有其他问题,请继续提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值