Hi all,
I am working on a project making excessive use of run-time library loading, i.e. dlopen()/LoadLibrary().
This means that if target B uses library A, it needs:
- at compile time: the include directories of A
- at link time: nothing
- at load time: nothing
- at run time: the shared library A to be present
Currently I do the following:
add_library(A.SharedLib SHARED …)
add_library(A INTERFACE)
target_include_directories(A INTERFACE path/to/A/includes)
add_dependencies(A A.SharedLib) # make sure that if a target depending on A is built, then A.SharedLib is also built so that it is available at run time
target_link_libraries(B PRIVATE A)
This works, but it has the drawback of non-optimal parallelization: A and B could be built in parallel, but thanks to add_dependencies(), A must be completely built and linked before B starts to build.
So: is there a way to tell CMake that target B needs target A only at runtime, or in other words:
- if B is built, A must be brought up to date as well
- but B does not need A at compile or link time
We use Visual Studio, Makefile and Ninja as generators. So adding another “dummy” target that depends on both B and A is probably out because developers would still build and run the executable target A from their VS environment and not the dummy target.