开发者

install(TARGETS ...) and add_subdirectory

开发者 https://www.devze.com 2023-01-13 04:48 出处:网络
Is it possible to use install(TARGETS ...) with targets that are defined in directories added with add_subdirectory?

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 g开发者_运维百科test. 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?


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号