[CMake] How to handle a submodule existing twice in a project?

David Doria daviddoria at gmail.com
Thu May 17 17:20:16 EDT 2012


I have a main project (called Test) that has two submodules, TestA and
TestB. TestA also has a submodule, which is exactly the same TestB.

So there is a directory Test/TestB as well as Test/TestA/TestB

In TestA/CMakeLists.txt, I have add_subdirectory(TestB).
In Test/CMakeLists.txt, I have add_subdirectory(TestA) as well
as add_subdirectory(TestB).

CMake complains that it cannot create TestB because another target with the
same name already exists (which it does). What is the right way to handle
this? I always assume that TestB is identical in both places (which might
not be a great assumption...), so I guess I just want, in both places, to
say "include TestB if it already hasn't been included." I tried to do that
by replacing the add_subdirectory(TestB) calls with:

if(NOT TestB_SOURCE_DIR)
 add_subdirectory(TestB)
endif()

but then the linker complains that it can't find TestB.

I have uploaded a demo project here:
http://homepages.rpi.edu/~doriad/Upload/TestCMake2.tar.gz

Thanks!

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120517/833b4f73/attachment.htm>


More information about the CMake mailing list