0
我正在嘗試使用運行目標生成的文件的內容來定義一些將與另一個目標鏈接的庫。基於執行另一個目標的結果的目標的cmake鏈接庫
這將是這樣的:
add_executable(generator zoot.cpp)
get_property(GEN_LOCATION TARGET generator PROPERTY LOCATION)
add_custom_command(OUTPUT libInfo.txt
COMMAND ${GEN_LOCATION}
DEPENDS someOtherFile.txt)
add_custom_target(lib_info_generator ALL
DEPENDS libInfo.txt someOtherFile.txt)
add_dependencies(lib_info_generator generator)
add_executable(final_target hi.cpp)
file(STRINGS "libInfo.txt" MY_LIB)
if(MY_LIB STREQUAL "lib1")
target_link_libraries(final_target lib1)
else()
target_link_libraries(final_target lib2)
endif()
這不起作用,因爲直到執行目標lib_info_generator libInfo.txt將不存在。
有沒有辦法在CMake中實現這一點?
您可能嘗試爲文件libInfo.txt設置屬性GENERATED,但我認爲這沒有幫助。 – Alexey