Halo
发布于 2022-06-16 / 113 阅读 / 0 评论 / 0 点赞

target_include_directories 中使用PRIVATE/INTERFACE/PUBLIC

Therefore, suppose you are creating a library A that uses some Boost headers. You would do:

  • target_include_directories(A PRIVATE ${Boost_INCLUDE_DIRS}) if you only use those Boost headers inside your source files (.cpp) or private header files (.h).
  • target_include_directories(A INTERFACE ${Boost_INCLUDE_DIRS}) if you don’t use those Boost headers inside your source files (therefore, not needing them to compile A). I can’t actually think of a real-world example for this.
  • target_include_directories(A PUBLIC ${Boost_INCLUDE_DIRS}) if you use those Boost headers in your public header files, which are included BOTH in some of A’s source files and might also be included in any other client of your A library.

评论