How can I list the PRIVATE, PUBLIC and INTERFACE include directories of a target?

梦想的初衷 提交于 2020-01-06 08:05:26

问题


This question:

Listing include_directories in CMake

teaches us how to list include directories for a CMake directory. How do we do that for a target, and separating the PUBLIC, PRIVATE and INTERFACE directories?


回答1:


Well, the same getter works for directories and targets, just with slightly different syntax:

get_property(dirs1 TARGET my_target PROPERTY INCLUDE_DIRECTORIES)

Now, this will get us the union of two sets of include directories: PUBLIC and PRIVATE, but not INTERFACE. We also get:

get_property(dirs2 TARGET my_target PROPERTY INTERFACE_INCLUDE_DIRECTORIES)

Now:

  • The PUBLIC directories are dirs1 intersection-with dirs2 (dirs1 ∩ dirs2).
  • The PRIVATE directories are dirs1 set-minus dirs2 (dirs1 ∖ dirs2).
  • The INTERFACE directories are dirs2 set-minus dirs1 (dirs2 ∖ dirs1).

As described in the question you linked to, once you have your list of directories, you can print it out like so:

foreach(dir ${dirs2})
  message(STATUS "Interface include directory for my_target: ${dir}")
endforeach()

If you need to actually, concretely, generate the three lists - see this question about how to perform union, intersection and difference.



来源:https://stackoverflow.com/questions/59577966/how-can-i-list-the-private-public-and-interface-include-directories-of-a-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!