问题
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