CMake install (TARGETS in subdirectories)(CMake 安装(子目录中的 TARGETS))
问题描述
考虑以下 CMakeLists.txt
文件:
add_subdirectory(execA)
add_subdirectory(libB)
install(TARGETS execA libB
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
我收到以下错误:
install TARGETS given target "execA" which does not exist in this
directory
execA
和 libB
有自己的 CMakeList.txt
文件,也位于 project
目录下作为我运行的构建目录 cmake
(cmake ..
):
execA
and libB
have their own CMakeList.txt
files and are located under project
directory, as well as the build directory I'm running cmake
(cmake ..
):
project
|------ CMakeList.txt (the one with the code)
|----execA
| - .cpp, .hpp and CMakelist.txt
|----libB
| - .cpp, .hpp and CMakelist.txt
|---- lib
|---- bin
---- build (where I´m commanding: $ cmake ..
我该如何解决这个错误?
How do I fix this error?
推荐答案
根据 this bugreport、install(TARGETS)
命令流只接受在同一目录中创建的目标.
According to this bugreport, install(TARGETS)
command flow accepts only targets created within the same directory.
因此您需要将 add_library()
调用移动到顶级目录,或者将 install(TARGETS)
调用拆分为每个目标的调用,然后将每个调用将它们放到相应的子目录中.
So you need either move the add_library()
call into the top-level directory, or split install(TARGETS)
call into per-target ones, and move each of them into the corresponding subdirectory.
自 CMake 3.13 install(TARGETS)
即使使用在其他目录中创建的目标也可以工作.
Since CMake 3.13 install(TARGETS)
can work even with targets created in other directories.
install(TARGETS)
可以安装在其他目录中创建的目标.当使用这样的跨目录安装规则时,从子目录运行 make install
(或类似的)不能保证来自其他目录的目标是最新的.
install(TARGETS)
can install targets that were created in other directories. When using such cross-directory install rules, runningmake install
(or similar) from a subdirectory will not guarantee that targets from other directories are up-to-date.
这篇关于CMake 安装(子目录中的 TARGETS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CMake 安装(子目录中的 TARGETS)
基础教程推荐
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07