# \[3.31.6\] Toolchain file gets parsed twice

**URL:** https://discourse.cmake.org/t/3-31-6-toolchain-file-gets-parsed-twice/13950
**Category:** Development
**Created:** [April 17, 2025, 12:14pm UTC](https://discourse.cmake.org/t/3-31-6-toolchain-file-gets-parsed-twice/13950 "2025-04-17T12:14:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Boldviking](https://discourse.cmake.org/user_avatar/discourse.cmake.org/boldviking/32/5510_2.png) [@Boldviking](https://discourse.cmake.org/u/Boldviking)
#### Post date: [April 17, 2025, 12:14pm UTC](https://discourse.cmake.org/t/3-31-6-toolchain-file-gets-parsed-twice/13950/1 "2025-04-17T12:14:00Z")

</div>

Hello everyone.

I have been using cmake for quite some time and I really enjoy it.

However today we stumbled upon an issue that got us thinking a bit.

Its about toolchain files and how they get loaded. Now we never really had any issues with toolchain files, it usually works out of the box.

Yet today we observed that when loading a toolchain file that it gets parsed twice by cmake.

To recreate this, I setup a simple hello world project and added a simple toolchain file to it as well.  
The toolchain file contains a single message(STATUS HELLO\_WORLD)

When loading this toolchain file via cmake -DCMAKE\_TOOLCHAIN\_FILE=toolchain.cmake we observed that the message gets printed twice. As such the toolchain file gets parsed twice.

Is this intended behavior? It might be fine as toolchain files usually set things to a specific value, as such when they run twice we just set those values again. However I have seen some toolchain files out there that append CXX Flags and similar.

At the end of the day having extra flags usually does not matter, but it is concerning.

We also did go through the cmake documentation again, but we could not find any information on why this behavior would exists (unless we just missed it xD)

For reference the cmake I used was 3.31.6

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [April 19, 2025, 11:41am UTC](https://discourse.cmake.org/t/3-31-6-toolchain-file-gets-parsed-twice/13950/2 "2025-04-19T11:41:20Z")

</div>

Perhaps the documentation of [CMAKE\_TOOLCHAIN\_FILE](https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html) need some improvement, about when it’s used.  
The behavior is documented at the [project](https://cmake.org/cmake/help/latest/command/project.html) command:

> If [`CMAKE_TOOLCHAIN_FILE`](https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html#variable:CMAKE_TOOLCHAIN_FILE) is set, read it at least once. It may be read multiple times and it may also be read again when enabling languages later (see below).

---

<div class="post-metadata">

### Author: ![Boldviking](https://discourse.cmake.org/user_avatar/discourse.cmake.org/boldviking/32/5510_2.png) [@Boldviking](https://discourse.cmake.org/u/Boldviking)
#### Post date: [April 22, 2025, 10:49am UTC](https://discourse.cmake.org/t/3-31-6-toolchain-file-gets-parsed-twice/13950/3 "2025-04-22T10:49:34Z")

</div>

I did not check the project article for this behavior.  
Yes maybe some kind of hint in the TOOLCHAIN article would have been nice :).

Thank you very much for the hint :).

---

<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: [July 20, 2025, 2:42am UTC](https://discourse.cmake.org/t/3-31-6-toolchain-file-gets-parsed-twice/13950/4 "2025-07-20T02:42:08Z")

</div>

I believe that internal `try_compile` runs will also read the toolchain file. Can you log `${CMAKE_PROJECT_NAME}` as well? If it is `cmTC_*`, that is a `try_compile` project reading it.
