Linking multiple dependent libraries
Hi, I have a framework consisting of several libraries. These libraries are dependent on each other. Under Windows thats no big problem. You have to define dllimport/-export macros and everything works like a charm.
You can compile each lib even without the existance of the other libraries it depends on. But after many days of research I think this is not possible with CMake?
I tried everything. But at the end nothing worked. Either it has thousands of unresolved references to the other libs or it tells me it would not have a rule to build the dependent lib.
So please could you provide an example how to solve such an scenario. E.g. lets assume the following scenario.
Lib: Dependencies:
LibA -
LibB LibA + LibD
LibC LibA + LibB + LibD
LibD LibA + LibB + LibC
For example have a look at my CmakeLists.txt to build "LibB":
# ---- INTERFACE ----
#add_library(LibA INTERFACE)
#set_target_properties(LibA PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${...})
#target_include_directories(LibA INTERFACE ${...})
#add_library(LibD INTERFACE)
#set_target_properties(LibD PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${...})
#target_include_directories(LibD INTERFACE ${...})
# ---- SHARED ----
add_library(LibA SHARED IMPORTED GLOBAL)
set_target_properties(LibA PROPERTIES IMPORTED_LOCATION "...LibA.so")
add_library(LibD SHARED IMPORTED GLOBAL)
set_target_properties(LibD PROPERTIES IMPORTED_LOCATION "...LibD.so")
# ---- BUILD LIB B ----
add_library(objlib OBJECT ${LIBB_SOURCES} ${LIBB_HEADERS})
add_library(LibB SHARED $<TARGET_OBJECTS:objlib>)
target_link_libraries(LibB PRIVATE LibA LibD)
Whether the section INTERFACE nor the section SHARED works. Maybe you could direct me into the right direction what I am doing wrong? Maybe instead of having one CMakeLists.txt for each Lib I should only have one for all? Or maybe CMake can only link to libraries already existing? But that would make it impossible to build/link against libraries with circular dependencies. So is that true. Is CMake broken by design?