PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> ) In this example, target_include_directories adds two include directories to the build of the MyLibrary target: The include directory is added as a PUBLIC include directo...
CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE变量可以用来控制是否将目录加入INTERFACE_INCLUDE_DIRECTORIES目标属性中。这使得通过target_link_libraries()指令可以方便地使用多个不同目录下的目标。 构建需求传递 目标的构建需求可以通过依赖传递。target_link_libraries()指令可以通过PRIVATE,INTERFACE和PUBLIC关键字来控制传递。
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> ) BUILD_INTERFACE 表达式包装的构建需求只被在同一个构建系统下,或者使用 export() 指令导出的目标上使用。INSTALL_INTERFACE 表达式包装的构建需求只被用在使用 install(EXPORT) 指令安装和导出的目标上: 3.9 函数和宏 函数...
"$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>>" "$<${msvc_cxx}:$<BUILD_INTERFACE:-W3>>" ) 我们可以看到警告标志封装在BUILD_INTERFACE条件内。这样做是为了让已安装项目的使用者不会继承我们的警告标志。 修改MathFunctions/CMakeLists.txt文件,使所有的目标都增...
COMPATIBLE_INTERFACE_STRING LIB_VERSION )add_library(lib1Version3 SHARED lib1_v3.cpp)set_property(TARGETlib1Version3 PROPERTY INTERFACE_LIB_VERSION3)add_executable(exe1 exe1.cpp)target_link_libraries(exe1 lib1Version2)# LIB_VERSION will be "2"add_executable(exe2 exe2.cpp)target_link_libraries...
COMPATIBLE_INTERFACE_STRING LIB_VERSION )add_library(lib1Version3 SHARED lib1_v3.cpp)set_property(TARGETlib1Version3 PROPERTY INTERFACE_LIB_VERSION3)add_executable(exe1 exe1.cpp)target_link_libraries(exe1 lib1Version2)# LIB_VERSION will be "2"add_executable(exe2 exe2.cpp)target_link_libraries...
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>) set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/output") set(INSTALL_DIR "${OUTPUT_DIR}/my_library") set(INSTALL_LIB_DIR "${INSTALL_DIR}/lib") set(INSTALL_INC_DIR "${INSTALL_DIR}/include") ...
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${INSTALL_INCLUDEDIR}> ) 链接库和目标属性与前一个食谱相比未更改: 代码语言:javascript 复制 target_link_libraries(message-static PUBLIC $<$<BOOL:${UUID_FOUND}>:PkgConfig::UUID> ...
target_include_directories(MathFunctions INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include> ) 更新后,我们可以重新运行CMake并确认它不再发出警告。 至此,我们已经正确地打包了CMake所需的目标信息,但仍然需要生成MathFunctionsConfig.cmake,以便CMake find_package命令可以找到...
cmake -DCMAKE_BUILD_TYPE=Debug 1. CMAKE_BUILD_TYPE是cmake中的一个内置变量,用于指定构建类型。 5、流程控制 (1)if set(ARCH "x86") if(ARCH MATCHES "x86") message("ARCH is x86") else() message("ARCH is arm") endif() 1.