Use of include_guard

Is include_guard still expected to only work for include and not add_subdirectory (see https://gitlab.kitware.com/cmake/cmake/-/issues/17895 )?

We have a setup where modules add_subdirectory their direct dependencies, which often means that we get diamond inclusions (A adds B & C which both add D). We were originally protecting against this via if( NOT target ) return() endif(), but include_guard(GLOBAL) appeared to do this without adding extra boilerplate.

Nothing in the include_guard documentation explicitly makes a distinction between inclusion via include vs add_subdirectory.

The explanation already given in the linked issue is pretty clear. Include guards are only for include(). The project must do its own logic to avoid calling add_subdirectory() on the same directory more than once. You can call add_subdirectory() on the same source directory multiple times, but you must specify a different build directory for each call (the second argument to add_subdirectory()). I don’t think this is the situation you’re trying to set up though.

You might want to consider looking into FetchContent which handles the diamond dependency pattern.