"Configure will be re-run and you may have to reset some variables"

Hi.

When changing compiler from clang to gcc, I have the following message:

You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= gcc
CMAKE_CXX_COMPILER= g++

That seems good by it seems also that my user defined variable are lost.
To be more specific, my CMakeList contains:

set(SANITIZE "Off" CACHE STRING "Sanitize (On/Off <default>)")
IF (SANITIZE STREQUAL "Off")
	MESSAGE("Debug Sanitize Off")
ELSE()
	MESSAGE("Debug Sanitize On")
ENDIF()

I set SANITIZE On from command line but when running with the compiler change, I have following behavior:

Debug Sanitize On
...
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= clang
CMAKE_CXX_COMPILER= clang++
...
-- The CXX compiler identification is Clang
...
Debug Sanitize Off

Is there a way, when CMake deletes its cache, to ensure that cache variable are reset to the values given on command line?
Or, possible workaround, make cmake fail in this situation, which I may detect, then I may “manually” clean the cache and relaunch my command line?

Regards
A.

This feature (and potentially some of the many issues which reference it) is highly related.

Sorry Mr. Boeckel, I fail to see how it can be of use in my case.

My only workaround so far is to have a script parsing the cache before calling cmake and destroying it all-together if the compiler is different in it is different from the requested one.

It’s a bit expansive…

The other way around, why, when cmake flush its cache in this situation, he does not seem to reuse the user command line option?
If it is considered that this these options are faulty, wouldn’t it be a pragmatic solution to issue a warning (exit code != 0) or even an error and give a command line option to let the user flush the cache himself?

regards
A.

Because CMake does not track this at all right now.

Why is this not considered a bug?

I’m using the CMake system that Espressif wrote for their ESP-IDF framework, and I need to set two variables: SDKCONFIG and SDKCONFIG_DEFAULTS. So I run:

cmake -DSDKCONFIG=… -DSDKCONFIG_DEFAULTS=…

If the build/ directory does not exist this works fine. But if it already exists, CMake tells me:

[cmake] You have changed variables that require your cache to be deleted.
[cmake] Configure will be re-run and you may have to reset some variables.
[cmake] The following variables have changed:
[cmake] CMAKE_C_COMPILER= /home/geleg/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp-elf-gcc
[cmake] CMAKE_CXX_COMPILER= /home/geleg/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp-elf-g++
[cmake] CMAKE_C_COMPILER= /home/geleg/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp-elf-gcc
[cmake] CMAKE_CXX_COMPILER= /home/geleg/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp-elf-g++
[cmake] CMAKE_C_COMPILER= /home/geleg/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp-elf-gcc

(Those variables have in fact not actually changed, but I suppose they were just overwritten with the same value.)

And then CMake reruns without my custom values for SDKCONFIG and SDKCONFIG_DEFAULTS. If I pass them to CMake via the command line, why does CMake not use them in the second pass? I would clearly expect that.