我想向目标添加依赖项。此依赖项是预编译的lib。我希望能够通过在add_dep(libName)
中指定CMakeLists.txt
这样的名称来获得外部依赖关系。 add_dep
函数应该可以重用于不同的库。
我无法找到任何方法,only for libs which are compiled during build
how would I pass the target name in a generic form here?
would be fine, but the "consumer" shouldn't have to add inc/lib dirs etc
答案 0 :(得分:1)
在外部库CMakeList.txt
的目录中:
find_library(lib libName dir/to)
add_library(libName SHARED IMPORTED GLOBAL) # GLOBAL -> if outside src tree
set_property(TARGET libName PROPERTY IMPORTED_LOCATION ${lib})
set_property(TARGET libName APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include)
在" root" CMakeList.txt
:
add_subdirectory("$ENV{COMMON_ROOT}/libs/libName" "$ENV{COMMON_ROOT}/libs/libName") # usage for out of src ref
将target_link_libraries(target libName)
添加到需要它的CMakeLists.txt
。