如何列出目标的PRIVATE,PUBLIC和INTERFACE包含目录? [英] How can I list the PRIVATE, PUBLIC and INTERFACE include directories of a target?
问题描述
这个问题:
教我们如何列出CMake目录的包含目录。我们如何为 target 做到这一点,并分隔PUBLIC,PRIVATE和INTERFACE目录?
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?
推荐答案
好吧,相同的getter可以用于目录和目标,只是语法略有不同:
Well, the same getter works for directories and targets, just with slightly different syntax:
get_property(dirs1 TARGET my_target PROPERTY INCLUDE_DIRECTORIES)
现在,这将使我们结合两套包含目录: PUBLIC
和 PRIVATE
,但不是 INTERFACE
。我们还会得到:
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)
现在:
-
PUBLIC
目录是dirs1与dirs2的交集(dirs1∩dirs2)。 -
PRIVATE
目录是dirs1 set-dirs2 (dirs1∖dirs2)。 -
INTERFACE
目录是dirs2 set-减去dirs1(dirs2∖dirs1)。
- 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.
这篇关于如何列出目标的PRIVATE,PUBLIC和INTERFACE包含目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!