INTERFACE_INCLUDE_DIRECTORIES

在 4.4 版被加入.

List of public include directories requirements for a file set.

File sets may populate this property to publish the include directories required to compile the sources for the target. The set_property(FILE_SET) command populates this property.

When target dependencies are specified using target_link_libraries(), CMake will read this property from file sets of all target dependencies to determine the build properties of the consumer. These build properties are only applied to the sources of the file sets. The other sources of the consumer are unaffected.

Contents of INTERFACE_INCLUDE_DIRECTORIES may use "generator expressions" with the syntax $<...>. See the cmake-generator-expressions(7) manual for available expressions. See the cmake-buildsystem(7) -manual for more on defining buildsystem properties.

在构建树和安装树之间,包含目录使用要求通常不同。BUILD_INTERFACEINSTALL_INTERFACE 生成表达式可用于根据使用位置描述分别的使用要求。在 INSTALL_INTERFACE 表达式中允许使用相对路径,并根据安装前缀进行解释。例如:

set_property(FILE_SET myfile_set TARGET mylib PROPERTY INTERFACE_INCLUDE_DIRECTORIES
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/mylib>
  $<INSTALL_INTERFACE:include/mylib>  # <prefix>/include/mylib
)

相關屬性:

建立可重新定位的軟體包

Note that it is not advisable to populate the INSTALL_INTERFACE of the INTERFACE_INCLUDE_DIRECTORIES of a target with absolute paths to the include directories of dependencies. That would hard-code into installed packages the include directory paths for dependencies as found on the machine the package was made on.

The INSTALL_INTERFACE of the INTERFACE_INCLUDE_DIRECTORIES is only suitable for specifying the required include directories for headers provided with the target itself, not those provided by the transitive dependencies listed in its INTERFACE_LINK_LIBRARIES target property. Those dependencies should themselves be targets that specify their own header locations in INTERFACE_INCLUDE_DIRECTORIES.

請參閱 cmake-packages(7) 手冊的 創建可重新定位包 部分,討論在創建可分發包時指定使用要求時必須採取的額外注意事項。