how to handle multiple versions of same library wh

2019-06-22 07:15发布

I have a project that depends on 3 libraries A,B, and C. A and B are git repos which are CMake-based and both depends on C and therefore include it as a submodule (but different versions from different repos). So the structure of my project looks like this:

ext/
    libA/
        libC/  (submodule of libA repo)
        ...
    libB/
        libC/  (submodule of libB repo)
        ...
main.cpp
CMakeLists.txt

CMakeLists.txt looks like this:

add_subdirectory("ext/libA")
add_subdirectory("ext/libB")

add_executable(MyApp main.cpp)
target_include_directories(MyApp ...)
target_link_library(MyApp libA libB libC)

What is the best way to handle this nested common dependency? Ideally I would use a single version of libC for libA, libB and my project, but I don't know a non-intrusive way (i.e. without modifying the cmake files of libA and libB) of doing this.

I really like the combination of submodules and CMake add_subdirectory because it is simple and clean, but nested dependencies are tricky.

0条回答
登录 后发表回答