I'm using cmake to compile one of my work projets, here is the deal
- client/ CMakeLists.txt server/ CMakeLists.txt libs/ libstuff/ CMakeLists.txt CMakeLists.txt
So i want to be able to compile each subproject individually, and build both the client and the server from the root folder.
Let's say the client and the server need libstuff.
I tried to use "add_subdirectory" with the path of the lib in both client and server CMakeLists.txt, it works when you compile the server or the client, but if you try to run both from the root directory :
CMake Error at common/libplugin/CMakeLists.txt:33 (ADD_LIBRARY): add_library cannot create target "plugin" because another target with the same name already exists. The existing target is a static library created in source directory "/home/adrien/git/r-type/common/libplugin". See documentation for policy CMP0002 for more details.
So i'm kind of new w/ cmake and i'm not sure what i should do, should i use add_dependencies?
Thanks for your help,
A simple solution is to guard the add_subdirectory
calls in both the client and the server CMake list file with an if
using a TARGET conditional, i.e.:
if (NOT TARGET plugin) add_subdirectory("${CMAKE_SOURCE_DIR}/common/libplugin") endif()
This prevents the libplugin
sub-directory from being added more than once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With