Diamond module dependencies

I have application which uses two modules : editor and viewer, I don’t want install them but add as git submodules. Both of them uses syntax highlighting module.
Application can simply uses it as three static libraries, but I want also test standalone editor and viewer with its testing programs. Can I write CMakeLists.txt for editor which search syntax module not from project sub-directory but assume that is is neighbor/sibling?

I think @craig.scott can help guide with FetchContent (which I believe has a pattern for this problem), but I prefer the strategy of always using find_package for dependencies myself unless there’s a strong need to vendor them (e.g., easier development for Windows and macOS developers).

find_package() would be ok if you had pre-built packages installed somewhere for your dependencies (editor, viewer and syntax highlighter). Normally that would be the recommended way of bringing in dependencies, if available. If you don’t have pre-built packages and need to build them from source, then FetchContent would be the tool I’d reach for in this case. It handles diamond dependencies, like the syntax viewer in your scenario. Rather than repeat all the details here, I’ll direct you to the FetchContent module documentation for how to use it.

With CMake 3.24 or later, your projects can use find_package() calls, but you can still use FetchContent to intercept those calls and have your dependencies built from source. This is probably not relevant to you right now, but may become relevant in the future if you might eventually want to start using binary packages instead of building from source. The main reason I’m mentioning this now is to highlight that if you choose FetchContent now, you still have a supported path for migrating to find_package() calls later.

Most times where I see CMake projects being added as git submodules, I find FetchContent is a more flexible way to achieve a similar result.