cmake目标编译设置中的INTERFACE,PUBLIC,PRIVATE是什么意思? [英] What INTERFACE, PUBLIC, PRIVATE mean in cmake target compilation setting?
问题描述
在CMake中, target_include_directories(), target_compile_definitions()和 target_compile_options()命令指定构建二进制目标的规格和使用要求。
In CMake, the target_include_directories(), target_compile_definitions() and target_compile_options() commands specify the build specifications and the usage requirements of binary targets.
每个命令都有PRIVATE,PUBLIC和INTERFACE模式。但是,我很难理解它们之间的区别。我的理解是上面三个命令用于为特定目标设置编译环境。那么什么使PRIVATE,PUBLIC和INTERFACE模式之间的设置不同呢?
Each of the commands has a PRIVATE, PUBLIC and INTERFACE mode. However, I have a difficult time in understanding the difference between them. My understanding is the above three commands are used to set compiler environment for a particular target. So what makes the setting different between a PRIVATE, PUBLIC and INTERFACE mode?
推荐答案
如果你有一个要重用的目标(通常是库),这些模式是非常有用的。 PRIVATE
定义仅适用于库目标,但不适用于使用此库的其他目标。 INTERFACE
定义仅适用于依赖目标,但不适用于库本身。 PUBLIC
定义适用于库目标以及依赖目标。
These modes are useful if you have a target that is intended to be reused (usually a library). PRIVATE
definitions only apply to the library target, but not to other targets that use this library. INTERFACE
definitions only apply to depending targets, but not to the library itself. PUBLIC
definitions apply both to the library target as wells as the depending targets.
示例:
add_library(test test.cc)
add_executable(main main.cc)
target_compile_features(test PUBLIC cxx_delegating_constructors)
target_link_libraries(main test)
// "target_compile_features(main cxx_delegating_constructors)" is
// implicitly set by CMake
这篇关于cmake目标编译设置中的INTERFACE,PUBLIC,PRIVATE是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!