There is no explicit way to find out if (sub) project is already included.
There is no explicit way to find out if (sub)project is included.
What is expected?
In some situations there is need to know if some (sub)project is already "included" (i.e. add_subdirectory to such project has been called).
It would be nice something like "<MySubProject>_PRESENT" set to be TRUE when such project gets activated by calling the "PROJECT" command. Of course this variable must not be cached.
Half working workaround?
Although one can test some project specific variables (e.g. <MySubProject>_SOURCE_DIR), this does work only when cmake is called for the first time.
However it does NOT work, when cmake is invoked on existing cmake build tree, due to the project specific variables caching (i.e. variable "<MySubProject>_SOURCE_DIR" is present and filled with previous path even the project may not be included in current cmake run.).