安装(TARGETS ...)和add_subdirectory
是否可以将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用文件安装而不是安装目标。缺点是您必须处理共享和静态构建。
安装(文件 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)