我真的需要指定 install-interface includes dependencies 吗?
Do I really need to specify install-interface includes dependencies?
在我的包裹中,我目前有:
include(GNUInstallDirs)
target_include_directories(
mylib
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> # ***
)
还有:
install(
TARGETS mylib
EXPORT mylib
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
EXPORT mylib
FILE "mylib-config.cmake"
NAMESPACE mylib::
DESTINATION "lib/cmake/mylib" )
我注意到在安装的 config.cmake
文件中,我看到包含目录 两次:
set_target_properties(mylib::mylib PROPERTIES
# etc. etc.
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include"
)
因此,作为实验,我删除了上面标记为 ***
的行 - 配置文件现在只有 once.
包含目录
那么,这样做安全吗?也就是说,如果我使用 INCLUDES 参数安装目标,我真的不需要指定 install-interface 包含目录吗?或者 - 我错过了什么吗?
文档明确指出 both target_include_directories
命令带有非 PRIVATE 关键字和 INCLUDES DESTINATION install
命令的子句填充 INTERFACE_INCLUDE_DIRECTORIES 属性.
使用哪种方法由您决定。
请注意,同一个目标可以安装多次。 target_include_directories
影响 所有 安装,但 INCLUDES DESTINATION 仅影响 特定 安装。
Documentation 用于 INCLUDES DESTINATION 子句:
This option specifies a list of directories which will be added to the INTERFACE_INCLUDE_DIRECTORIES
target property of the <targets>
when exported by the install(EXPORT)
command. If a relative path is specified, it is treated as relative to the $<INSTALL_PREFIX>
.
Documentation 对于 target_include_directories
:
PUBLIC
and INTERFACE
items will populate the INTERFACE_INCLUDE_DIRECTORIES
property of <target>
.
在我的包裹中,我目前有:
include(GNUInstallDirs)
target_include_directories(
mylib
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> # ***
)
还有:
install(
TARGETS mylib
EXPORT mylib
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
EXPORT mylib
FILE "mylib-config.cmake"
NAMESPACE mylib::
DESTINATION "lib/cmake/mylib" )
我注意到在安装的 config.cmake
文件中,我看到包含目录 两次:
set_target_properties(mylib::mylib PROPERTIES
# etc. etc.
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include"
)
因此,作为实验,我删除了上面标记为 ***
的行 - 配置文件现在只有 once.
那么,这样做安全吗?也就是说,如果我使用 INCLUDES 参数安装目标,我真的不需要指定 install-interface 包含目录吗?或者 - 我错过了什么吗?
文档明确指出 both target_include_directories
命令带有非 PRIVATE 关键字和 INCLUDES DESTINATION install
命令的子句填充 INTERFACE_INCLUDE_DIRECTORIES 属性.
使用哪种方法由您决定。
请注意,同一个目标可以安装多次。 target_include_directories
影响 所有 安装,但 INCLUDES DESTINATION 仅影响 特定 安装。
Documentation 用于 INCLUDES DESTINATION 子句:
This option specifies a list of directories which will be added to the
INTERFACE_INCLUDE_DIRECTORIES
target property of the<targets>
when exported by theinstall(EXPORT)
command. If a relative path is specified, it is treated as relative to the$<INSTALL_PREFIX>
.
Documentation 对于 target_include_directories
:
PUBLIC
andINTERFACE
items will populate theINTERFACE_INCLUDE_DIRECTORIES
property of<target>
.