# Override setting from CMAKE\_TOOLCHAIN\_FILE

**URL:** https://discourse.cmake.org/t/override-setting-from-cmake-toolchain-file/5368
**Category:** Usage
**Created:** [April 4, 2022, 8:58pm UTC](https://discourse.cmake.org/t/override-setting-from-cmake-toolchain-file/5368 "2022-04-04T20:58:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![gpanders](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/e19adc/32.png) [@gpanders](https://discourse.cmake.org/u/gpanders)
#### Post date: [April 4, 2022, 8:58pm UTC](https://discourse.cmake.org/t/override-setting-from-cmake-toolchain-file/5368/1 "2022-04-04T20:58:32Z")

</div>

I am using a toolchain file from OpenEmbedded (Yocto Linux). It’s contents include the following:

```cmake
set( CMAKE_FIND_ROOT_PATH $ENV{OECORE_TARGET_SYSROOT} $ENV{OECORE_NATIVE_SYSROOT} )
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )

```

I would like to change `CMAKE_FIND_ROOT_PATH_MODE_PACKAGE` back to `BOTH` for an external project that I’m using as a dependency (I cannot modify the toolchain file itself). I have this:

```cmake
ExternalProject_Add(
      foo
      URL ${CMAKE_CURRENT_SOURCE_DIR}/foo-v4.8.1.tar.gz
      URL_MD5 5a1785b0491a6f420e63d940bf701772
      CMAKE_CACHE_ARGS
         "-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE:STRING=BOTH"
      INSTALL_COMMAND ""
  )

```

However, it looks like my `CMAKE_CACHE_ARGS` in `ExternalProject_Add` are still being overwritten by the toolchain file.

How can I override a value set in the toolchain file, without modifying the toolchain file itself?

---

<div class="post-metadata">

### Author: ![gpanders](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/e19adc/32.png) [@gpanders](https://discourse.cmake.org/u/gpanders)
#### Post date: [April 4, 2022, 9:45pm UTC](https://discourse.cmake.org/t/override-setting-from-cmake-toolchain-file/5368/2 "2022-04-04T21:45:45Z")

</div>

I’ve “solved” this in the meantime by explicitly adding

```cmake
  "-DCMAKE_TOOLCHAIN_FILE:STRING="

```

to the `CMAKE_CACHE_ARGS`. This seems to work since the external project no longer uses the toolchain file (and thus no longer sets the `CMAKE_FIND_ROOT_PATH_MODE_PACKAGE` variable), but it still inherits all of the cross compilation options from the superproject.

---

<div class="post-metadata">

### Author: ![iDings](https://discourse.cmake.org/user_avatar/discourse.cmake.org/idings/32/5683_2.png) [@iDings](https://discourse.cmake.org/u/iDings)
#### Post date: [July 22, 2025, 1:34pm UTC](https://discourse.cmake.org/t/override-setting-from-cmake-toolchain-file/5368/3 "2025-07-22T13:34:23Z")

</div>

Found a nice way to override toolchain.cmake, override the setting on an configure:prepend task

```auto
echo "set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH )" >> ${WORKDIR}/toolchain.cmake

```

> **[apt\_2.4.5.bb « apt « recipes-devtools « meta - openembedded-core -...](https://git.openembedded.org/openembedded-core/tree/meta/recipes-devtools/apt/apt_2.4.5.bb?h=mickledore#n62)**
