# What is the preferred method of allowing both bundled and system dependencies on older cmake versions?

**URL:** https://discourse.cmake.org/t/what-is-the-preferred-method-of-allowing-both-bundled-and-system-dependencies-on-older-cmake-versions/7391
**Category:** Usage
**Created:** [February 2, 2023, 7:54pm UTC](https://discourse.cmake.org/t/what-is-the-preferred-method-of-allowing-both-bundled-and-system-dependencies-on-older-cmake-versions/7391 "2023-02-02T19:54:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dundargoc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dundargoc/32/1923_2.png) [@dundargoc](https://discourse.cmake.org/u/dundargoc)
#### Post date: [February 2, 2023, 7:54pm UTC](https://discourse.cmake.org/t/what-is-the-preferred-method-of-allowing-both-bundled-and-system-dependencies-on-older-cmake-versions/7391/1 "2023-02-02T19:54:36Z")

</div>

What is the best/idiomatic way to allow users to either choose to use a dependency they already have, or to let cmake download it themselves? I’m thinking of doing something like the following, where I use externalproject if I want to use the bundled version and find\_package if I want to use the external version:

```cmake
option(USE_BUNDLED_UNIBILIUM "Use the bundled unibilium." ${USE_BUNDLED})

if(USE_BUNDLED_UNIBILIUM)
    ExternalProject_Add(unibilium
      URL ${UNIBILIUM_URL}
      ...
    )
else()
    find_package(unibilium 2.0 REQUIRED)
endif()

```

The idea is then that the `Findunibilium.cmake` finds all necessary libraries and directories and then defines an interface library named `unibilium` with those included. Then the main target can add `unibilium` as a dependency, which can either be from externalproject we built ourselves or from a system package.

This setup is the best I could come up with, but it feels unwieldy. I’m unsure if there’s a more sophisticated way to solve this. Any input is appreciated. My project has version 3.10 as the minimum required version.

---

<div class="post-metadata">

### Author: ![dundargoc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dundargoc/32/1923_2.png) [@dundargoc](https://discourse.cmake.org/u/dundargoc)
#### Post date: [February 3, 2023, 9:44am UTC](https://discourse.cmake.org/t/what-is-the-preferred-method-of-allowing-both-bundled-and-system-dependencies-on-older-cmake-versions/7391/2 "2023-02-03T09:44:06Z")

</div>

[Moved explanation to top post]

---

<div class="post-metadata">

### Author: ![dundargoc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dundargoc/32/1923_2.png) [@dundargoc](https://discourse.cmake.org/u/dundargoc)
#### Post date: [February 4, 2023, 7:38pm UTC](https://discourse.cmake.org/t/what-is-the-preferred-method-of-allowing-both-bundled-and-system-dependencies-on-older-cmake-versions/7391/3 "2023-02-04T19:38:10Z")

</div>

Conclusion: cmake doesn’t seem to have the capabilities to solve this problem other than the above naive solution, which is disappointing as it’s a seemingly basic scenario.
