# CMAKE\_TOOLCHAIN\_FILE properly updated by profiles but still somehow cached after switching

**URL:** https://discourse.cmake.org/t/cmake-toolchain-file-properly-updated-by-profiles-but-still-somehow-cached-after-switching/5713
**Category:** Usage
**Created:** [May 23, 2022, 3:20pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-properly-updated-by-profiles-but-still-somehow-cached-after-switching/5713 "2022-05-23T15:20:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jebolicious](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jebolicious/32/2443_2.png) [@Jebolicious](https://discourse.cmake.org/u/Jebolicious)
#### Post date: [May 23, 2022, 3:20pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-properly-updated-by-profiles-but-still-somehow-cached-after-switching/5713/1 "2022-05-23T15:20:51Z")

</div>

Hi,

I’m fairly new to CMake but quickly diving into its features.

As we are compiling for MCU’s we’re using arm-none-eabi as the primary toolchain. However, our unit tests are executed on x86, requiring multiple toolchains to be used by our build pipeline.

I tried to incorporate everything into one CMake tree by using the ‘new’ CMake profiles and got pretty far, the only thing I couldn’t get around is switching between toolchains without deep cleaning the CMake build directory (to remove the caches).

Is this by design or am I missing a step? Or is there a better way?

I made sure to switch the CMAKE\_TOOLCHAIN\_FILE variable before the project() call and I can see that it is set correctly by the profiles but somehow the first entry of the variable sticks. Which presents me with the messages I placed in the toolchain file that was first used.

Thanks!

Kind regards,

Jebo

---

<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: [May 23, 2022, 7:51pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-properly-updated-by-profiles-but-still-somehow-cached-after-switching/5713/2 "2022-05-23T19:51:43Z")

</div>

> [@Jebolicious](#):
>
> Is this by design

Yes. This is a decision made _long_ ago: there is only one toolchain per language.

> [@Jebolicious](#):
>
> I made sure to switch the CMAKE\_TOOLCHAIN\_FILE variable before the project()

CMake caches the toolchain information and as such, `CMAKE_TOOLCHAIN_FILE` really only does anything (reliable) on the first configure. If CMake detects a compiler change, it recommends to clean `CMakeCache.txt`.

I would recommend using an `ExternalProject_add` setup which configures one build tree for a local build to test and a second for the target platform.

---

<div class="post-metadata">

### Author: ![Jebolicious](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jebolicious/32/2443_2.png) [@Jebolicious](https://discourse.cmake.org/u/Jebolicious)
#### Post date: [May 23, 2022, 8:27pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-properly-updated-by-profiles-but-still-somehow-cached-after-switching/5713/3 "2022-05-23T20:27:23Z")

</div>

Thank you for your quick reply!

Good to know! Then I don’t have to continue down that road anymore.

You mentioned per language, does that mean C/C++ as a language or are C and C++ seperated? Because our application code is written and compiled in C and our tests are GoogleTest, so C++. Would that make it possible?

I will definitely take a look at ExternalProject\_add, thank you for the suggestion!

---

<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: [May 23, 2022, 9:43pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-properly-updated-by-profiles-but-still-somehow-cached-after-switching/5713/4 "2022-05-23T21:43:13Z")

</div>

> [@Jebolicious](#):
>
> You mentioned per language, does that mean C/C++ as a language or are C and C++ seperated? Because our application code is written and compiled in C and our tests are GoogleTest, so C++. Would that make it possible?

C and C++ are two different languages to CMake. You can certainly use `gcc` and `clang++` if you like (though it is rare to mix-and-match AFAIK).
