CMake安装(子目录中的TARGETS) [英] CMake install (TARGETS in subdirectories)

查看:762
本文介绍了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

execAlibB有它们自己的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 ..

如何解决此错误?

推荐答案

根据此错误报告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, running make install (or similar) from a subdirectory will not guarantee that targets from other directories are up-to-date.

这篇关于CMake安装(子目录中的TARGETS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆