# How to use a cached variable in a toolchain file?

**URL:** https://discourse.cmake.org/t/how-to-use-a-cached-variable-in-a-toolchain-file/7444
**Category:** Usage
**Created:** [February 10, 2023, 12:43pm UTC](https://discourse.cmake.org/t/how-to-use-a-cached-variable-in-a-toolchain-file/7444 "2023-02-10T12:43:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [February 10, 2023, 12:43pm UTC](https://discourse.cmake.org/t/how-to-use-a-cached-variable-in-a-toolchain-file/7444/1 "2023-02-10T12:43:06Z")

</div>

Hi, I am using a toolchain file for an Arm toolchain. It works fine. However, it specifies a certain compiler path which is true for developers, but incorrect for our CI system. Perhaps I should specify a second toolchain for the CI case, but that would mean I have to have a second set of presets that select the second toolchain. I would like one set of common presets and to use a separate cached variable to specify which compiler path entry in the toolchain file to use. That variable should assume a default value so that the developers don’t have to specify it.

So, in CMakeLists.txt I have:

> set(Use\_Arm\_Dev\_Studio\_default ON)  
> option(Use\_Arm\_Dev\_Studio “Use Arm Development Studio installation (ON), use Arm Compiler for Embedded installation (OFF)” “${Use\_Arm\_Dev\_Studio\_default}”)

and in the toolchain I have:

> if (Use\_Arm\_Dev\_Studio)  
> # Use Arm Development Studio installation (typically used by developers)  
> set(ARM\_DEV\_STUDIO\_PATH “C:/Program Files/Arm/Development Studio”)  
> else ()  
> # paths for CI case  
> # snip  
> endif (Use\_Arm\_Dev\_Studio)

The problem I have is that Use\_Arm\_Dev\_Studio is not initialized in the default (unspecified case). So I have to generate the build files twice.

Can I initialize an option variable before the toolchain is used? Or is there a better way to do this?

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [February 11, 2023, 12:58am UTC](https://discourse.cmake.org/t/how-to-use-a-cached-variable-in-a-toolchain-file/7444/2 "2023-02-11T00:58:07Z")

</div>

In the CI system can you set an environment variable? Then you can use `$ENV{var}` in the if statement in the toolchain file.

Or you could setup the CI system to run `cmake -DCI_settings=ON` and use that in the `if` statement.

---

<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: [February 13, 2023, 5:18am UTC](https://discourse.cmake.org/t/how-to-use-a-cached-variable-in-a-toolchain-file/7444/3 "2023-02-13T05:18:00Z")

</div>

CI systems usually set `CI` or the like in the environment; the toolchain can detect this and do its different logic there.

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [February 13, 2023, 3:31pm UTC](https://discourse.cmake.org/t/how-to-use-a-cached-variable-in-a-toolchain-file/7444/4 "2023-02-13T15:31:29Z")

</div>

Thank you both for your help.
