8

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.

  • As projects `A` and `B` already use library `C` internally, and you don't want to modify them, you have no other choice than include library `C` for you main project manually, as 3rd copy. – Tsyvarev Mar 28 '16 at 18:33
  • But if the versions of `C` are different it won't work, no? In fact when linking the project, libA and libB will look for symbols of their respective versions of libC which might be different from the 3rd version of libC which I link against.. – Romain Prévost Mar 30 '16 at 08:15
  • Interoperability of different versions of same library depends from the library itself and usage scenario. E.g., most of GUI libraries have different versions not interoperable. From the other side, if the library `C` provides several computational functions, projects `A` and `B` use it *internally*, then there is a high chance that them will work correctly. Again, **it depends**. Just try. – Tsyvarev Mar 30 '16 at 08:47
  • Your libraries are not linking against their version of C in their own CMakeLists.txt files, are they? – ToniBig Apr 04 '16 at 13:04

0 Answers0