I've got 2 adjacent repositories containing projectA and projectB
projectA uses cmake to construct 3 libraries, if I build it by itself, I get 3 outputs in the build folder, 1 library for each library sub-project. so after running cmake I'll have something like this:
build/
lib1/*.a
lib2/*.a
lib3/*.a
projectB uses cmake to construct 1 executable. It uses 2 of the libraries from projectA to do that. Instead of linking against the already built library files, I'm obtaining those libraries with add_subdirectory(${CMAKE_SOURCE_DIR}/../projectA projectA)
and then calling target_link_libraries(${PROJECT_NAME} lib1 lib3)
with their names. This allows me to make them as a sort of dependency for projectB so that they will be built first if they are not already and yields something like this:
build/
projectA/
lib1/*.a
lib2/*.a
lib3/*.a
projectB
however it also means that if I now wanted to make another adjacent repository with executable, projectC, that wants to use those libraries, it would end up duplicating the build. It also means if I run make all in projectB (or C), the libraries I'm not using in that particular executable gets built anyways since the entirety of projectA is now considered part of them.
So, my question is: How can I add the libraries from projectA to projectB where they will only get built inside of projectA, but projectB (or C) determines what gets built and when (only the one nedeed, only if not yet built, if src changed)?