# How let cmake know that dependencies must firstly be from a certain location

**URL:** https://discourse.cmake.org/t/how-let-cmake-know-that-dependencies-must-firstly-be-from-a-certain-location/2875
**Category:** Usage
**Created:** [March 3, 2021, 12:59am UTC](https://discourse.cmake.org/t/how-let-cmake-know-that-dependencies-must-firstly-be-from-a-certain-location/2875 "2021-03-03T00:59:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![abd](https://discourse.cmake.org/user_avatar/discourse.cmake.org/abd/32/1256_2.png) [@abd](https://discourse.cmake.org/u/abd)
#### Post date: [March 3, 2021, 12:59am UTC](https://discourse.cmake.org/t/how-let-cmake-know-that-dependencies-must-firstly-be-from-a-certain-location/2875/1 "2021-03-03T00:59:07Z")

</div>

How can we force cmake to check that dependencies must firstly be looked up in a certain directory instead of default /usr/bin/, /usr/lib/, etc Linux dirs., then that default, in that order

> **[olive-editor/olive](https://github.com/olive-editor/olive)**
>
> Free open-source non-linear video editor. Contribute to olive-editor/olive development by creating an account on GitHub.

> <https://github.com/olive-editor/olive/blob/master/CMakeLists.txt>

as its cmake firstly check the Linux default shared lib.:

```auto
Could NOT find OpenImageIO: Found unsuitable version "2.0.5", but required
  is at least "2.1.12"

```

but those required libs. and their deps have been being prepared and gathered in one certain directory only, how to to do such that it will build olive smoothly

I’m a newbie on Cmake, could know few commands now, so would one point out the gist of the key commands along with their brief yet very clear explanations that’d give to the solution?  
also what’s the difference of CMakeLists.txt and .cmake files  
Please help out

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [March 3, 2021, 3:17am UTC](https://discourse.cmake.org/t/how-let-cmake-know-that-dependencies-must-firstly-be-from-a-certain-location/2875/2 "2021-03-03T03:17:47Z")

</div>

“How can we force cmake to check that dependencies must firstly be looked up in a certain directory instead of default /usr/bin/, /usr/lib/, etc Linux dirs., then that default, in that order”

find\_package has documentation on the [search procedure](https://cmake.org/cmake/help/latest/command/find_package.html?highlight=find_package#search-procedure)

"The default search order is designed to be most-specific to least-specific for common use cases. "

Let’s look at the first thing find\_package uses to search:

From the cmake docs:

1. New in version 3.12: Search paths specified in the [`<PackageName>_ROOT`](https://cmake.org/cmake/help/latest/variable/PackageName_ROOT.html#variable:%3CPackageName%3E_ROOT) CMake variable and the [`<PackageName>_ROOT`](https://cmake.org/cmake/help/latest/envvar/PackageName_ROOT.html#envvar:%3CPackageName%3E_ROOT) environment variable, where `<PackageName>` is the package to be found. The package root variables are maintained as a stack so if called from within a find module, root paths from the parent’s find module will also be searched after paths for the current package. This can be skipped if `NO_PACKAGE_ROOT_PATH` is passed or by setting the [`CMAKE_FIND_USE_PACKAGE_ROOT_PATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_USE_PACKAGE_ROOT_PATH.html#variable:CMAKE_FIND_USE_PACKAGE_ROOT_PATH) to `FALSE`. See policy [`CMP0074`](https://cmake.org/cmake/help/latest/policy/CMP0074.html#policy:CMP0074).

Basically can either do a more global approach or a more narrow approach

- Global: You can set [CMAKE\_FIND\_ROOT\_PATH](https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_ROOT_PATH.html#variable:CMAKE_FIND_ROOT_PATH) so that all find\_\* calls looks there first.
- Or set the root path for each individual package: [PackageName\_ROOT](https://cmake.org/cmake/help/latest/variable/PackageName_ROOT.html#variable:%3CPackageName%3E_ROOT)

```auto
# So basically I think you want the more global approach
# “How can we force cmake to check that dependencies must firstly be looked up in a certain directory instead of default /usr/bin/, /usr/lib/, etc Linux dirs., then that default, in that order”
# Let's say 'certain directory' is called foobar
set(foobar "C:/foobar")
list(APPEND CMAKE_FIND_ROOT_PATH "${foobar}")

# Now it will look at "C:/foobar" first.
find_package(OpenImageIO 2.1.12 REQUIRED)

```

I think that answers your primary question.

> [@abd](#):
>
> I’m a newbie on Cmake … also what’s the difference of CMakeLists.txt and .cmake files

You are overloading your question. So I’ll just suggest you checkout this book.

> **[Professional CMake: A Practical Guide](https://crascit.com/professional-cmake/)**
>
> The handbook for every CMake user, providing structured learning, the latest best practices, and real-world advice from a CMake co-maintainer.

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [March 3, 2021, 3:38am UTC](https://discourse.cmake.org/t/how-let-cmake-know-that-dependencies-must-firstly-be-from-a-certain-location/2875/3 "2021-03-03T03:38:16Z")

</div>

Also it’s more helpful to users in the future that you just paste the code that is causing you problems instead of linking to the GitHub.

Something like this would suffice:

```auto
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)

project(olive-editor VERSION 0.2.0 LANGUAGES CXX)

...

find_package(OpenGL REQUIRED)

find_package(OpenColorIO 2.0.0 REQUIRED)

find_package(OpenImageIO 2.1.12 REQUIRED)

find_package(OpenEXR REQUIRED)

find_package(Qt5 5.6 REQUIRED
  COMPONENTS
  Core
  Gui
  Widgets
  Multimedia
  OpenGL
  Svg
  LinguistTools
  Concurrent
)

find_package(FFMPEG 3.0 REQUIRED
  COMPONENTS
  avutil
  avcodec
  avformat
  avfilter
  swscale
  swresample
)

find_package(OpenTimelineIO)

```

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [March 3, 2021, 3:40am UTC](https://discourse.cmake.org/t/how-let-cmake-know-that-dependencies-must-firstly-be-from-a-certain-location/2875/4 "2021-03-03T03:40:35Z")

</div>

Also I just checked out your project very cool 😃

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [March 9, 2021, 3:28am UTC](https://discourse.cmake.org/t/how-let-cmake-know-that-dependencies-must-firstly-be-from-a-certain-location/2875/5 "2021-03-09T03:28:36Z")

</div>

Was I able to answer your question @abd ?
