For a good reason, I am attempting to use add_subdirectory()
on both a fork of a repository and the mainstream repository, and both add_library()
a library with the same name.
I will only privately link these two resulting libraries on 2 different other library targets, that will be dlopen()
ed by the main target, but never linked directly.
What is the best way to do this? Is there anything like namespaces that I could run the add_subdirectory()
calls in to not make the library names collide?
What is the best way to do this?
At the time of this writing? Either patch the target names to prevent name collisions (if you want to continue add_subdirectory
ing them), or drop the add_subdirectory
approach and use ExternalProject to configure, build, and install, and then add the installed targets to your project configuration as imported libraries, which allows you to control the target name.
Is there anything like namespaces that I could run the add_subdirectory() calls in to not make the library names collide?
Not at the time of this writing. See https://gitlab.kitware.com/cmake/cmake/-/issues/22687 and https://gitlab.kitware.com/cmake/cmake/-/issues/16414.
Related: How can I avoid target name collisions when using CMake FetchContent?.