安装(TARGETS ...)和add_subdirectory

发布于 2024-09-15 18:17:53 字数 873 浏览 4 评论 0原文

是否可以将 install(TARGETS ...) 与使用 add_subdirectory 添加的目录中定义的目标一起使用?

我的用例是,我想为 gtest 构建 e.gg rpm。 gtest 项目恰好有一个没有任何安装语句的 CMakeLists.txt。我想构建包而不将这些语句添加到 gtest 的 CMakeLists.txt 中。

我有这样的目录结构:

+ gtest-1.5.0/...
+ CMakeLists.txt 

gtest-1.5.0 的 CMakeLists 定义了这样的库:

cxx_static_library(gtest "${cxx_strict}" src/gtest-all.cc)
cxx_static_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
target_link_libraries(gtest_main gtest)

现在我想将类似的内容添加到我的 CMakeLists.txt 中:

add_subdirectory(gtest-1.5.0)
install(TARGETS gtest gtest_main ARCHIVE DESTINATION lib)

但 cmake 正确地指出:

CMake Error at CMakeLists.txt:10 (install):
  install TARGETS given target "gtest" which does not exist in this
  directory.

有没有办法在不修补 gtest- 的情况下做到这一点1.5.0?

Is it possible to use install(TARGETS ...) with targets that are defined in directories added with add_subdirectory?

My use case is, that I want to build e.gg an rpm for gtest. the gtest project happens to have a CMakeLists.txt without any install statements. I want to build the package without adding those statements to the CMakeLists.txt of gtest.

I have this resulting directory structure:

+ gtest-1.5.0/...
+ CMakeLists.txt 

The CMakeLists of gtest-1.5.0 defines libraries like this:

cxx_static_library(gtest "${cxx_strict}" src/gtest-all.cc)
cxx_static_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
target_link_libraries(gtest_main gtest)

now i want to add something like this to my CMakeLists.txt:

add_subdirectory(gtest-1.5.0)
install(TARGETS gtest gtest_main ARCHIVE DESTINATION lib)

but cmake correctly states:

CMake Error at CMakeLists.txt:10 (install):
  install TARGETS given target "gtest" which does not exist in this
  directory.

Is there a way to do this without patching gtest-1.5.0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呢古 2024-09-22 18:17:53

您可以尝试使用文件安装而不是安装目标。缺点是您必须处理共享和静态构建。

安装(文件 gtest-1.5.0/gtest_main.so 目标库)

You could try using file install rather than install targets. The downside is that you will have to handle shared and static builds.

install(FILES gtest-1.5.0/gtest_main.so DESTINATION lib)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文