"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.