# Diamond module dependencies

**URL:** https://discourse.cmake.org/t/diamond-module-dependencies/8727
**Category:** Usage
**Created:** [August 12, 2023, 10:52am UTC](https://discourse.cmake.org/t/diamond-module-dependencies/8727 "2023-08-12T10:52:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AndrzejB](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrzejb/32/815_2.png) [@AndrzejB](https://discourse.cmake.org/u/AndrzejB)
#### Post date: [August 12, 2023, 10:52am UTC](https://discourse.cmake.org/t/diamond-module-dependencies/8727/1 "2023-08-12T10:52:00Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 12, 2023, 8:20pm UTC](https://discourse.cmake.org/t/diamond-module-dependencies/8727/2 "2023-08-12T20:20:45Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [August 12, 2023, 10:32pm UTC](https://discourse.cmake.org/t/diamond-module-dependencies/8727/3 "2023-08-12T22:32:22Z")

</div>

`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](https://cmake.org/cmake/help/latest/module/FetchContent.html) 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.

> [@AndrzejB](#):
>
> I don’t want install them but add as git submodules.

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.
