[3.31.6] Toolchain file gets parsed twice

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