Consider the following three projects.
ProjectA does not have any dependencies and its CMakeLists.txt at top level is like the following,
ProjectA
CMakeLists.txt
You can check whether the target a already exists before calling add_subdirectory:
a
add_subdirectory
if (NOT TARGET a) add_subdirectory(ProjectA) endif ()
so that it only adds the subdirectory once for your whole CMake project.