On Fri, May 18, 2012 at 1:15 AM, David Doria <daviddo...@gmail.com> wrote: >> Yeah. Well, in that case I'd simply check for the TestB target thats >> defined in TestB/CMakeLists.txt as condition for the top-levels >> add_subdirectory: >> >> if(NOT TARGET TestB) >> add_subdirectory(TestB) >> endif() >> >> That should work. >> >> Andreas > > > Awesome, that seems to do the trick. Thanks! >
Althought this trick works, be aware (assuming you are using Git submodule) that the submodule shared by TestA and TestB (let's call it TestC) may not have the same version. In other word, TestA may refer to TestC version X whereas TestB may refer to TestC version Y which could lead to very wierd and hard to debug errors. For those reasons I try to avoid "diamond" submodules relationship and keep them flat. I don't know an ideal way to handle that problem but what I do is to have: Test with 3 submodules: TestC, TestA and TestB. When compiling TestA alone I use find_package() to search for a binary version of TestC or a config file with target to import. Something like if(NOT TARGET TestC) find_package(TestC REQUIRED) endif() Also I find this approach less cumbersome than updating the TestC submodule in TestA and TestB each time TestC change. Cheers, -Nico -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake