安装目标依赖项

CMake install target dependencies

本文关键字:依赖 目标 安装      更新时间:2023-10-16

我正在编写一个包含库本身和示例的库,我正在使用CMake:

cmake_minimum_required(VERSION 3.6)
add_executable (example main.cpp)
install(DIRECTORY include DESTINATION include PATTERN ".DS_Store" EXCLUDE)

当我运行cmake --build . --target install -时,它编译example目标并安装include目录

我想排除构建example目标,并且在构建install目标和构建example时仅安装include目录,如果没有任何特殊目标运行:

这里我想要exampleNOT build:cmake --build . --target install

这里我想让example build :cmake --build .

我应该如何改变我的CMakeLists.txt,使其工作,因为我想?

安装时不能排除单个 CMake目标

问题是'install'目标可能只依赖于'all' (default)目标。

虽然你可以删除'install' -> 'all'依赖(通过设置CMAKE_SKIP_INSTALL_ALL_DEPENDENCY变量),但你不能为'install'添加另一个依赖。所以,在安装

之前
cmake --build . --target install

要么执行

cmake --build .

不构建任何(即使是库,你想在任何情况下构建)。