21
是否有可能使用install(TARGETS ...)與在add_subdirectory中添加的目錄中定義的目標一起使用?install(TARGETS ...)和add_subdirectory
我使用的情況是,我想建立e.gg爲GTEST一個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?
確定..這可能是工作,但我不明白,爲什麼我可以使用target_link_libraries定義的名稱,而不是在安裝命令! – Gizmomogwai 2010-08-24 07:24:06
安裝命令僅在查找目標是否存在時纔會查看當前目錄,而不像掃描所有目標的target_link_libraries。 – RobertJMaynard 2010-08-24 13:22:48
好的...謝謝你的解釋,我想過這樣的事情,但我不確定(你可以編輯你的安裝(FILES命令,因爲安裝(FILES不接受ARCHIVE參數)。 – Gizmomogwai 2010-08-25 07:24:43