Provide better help when trying to change CMAKE_<LANG>_COMPILER
It is invalid in CMake to change the CMAKE_<LANG>_COMPILER
variables (like CMAKE_C_COMPILER
). Right now the behavior is to give a confusing error and then continue to try to configure, which results in lots more inevitable errors spitting out useless text that further hides the salient information. This leads to lots of confused users. The ParaView project often gets questions from lost users trying to use a particular compiler, and I'm sure most other CMake projects have the same issue. Thus, when CMake detects that one of the CMAKE_<LANG>_COMPILER
, it should (1) print out a more descriptive error and (2) completely halt the configure script.
Print a more descriptive error
Right now, if a user tries to change one of the CMAKE_<LANG>_COMPILER
you get an error like the following:
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= /usr/bin/gcc
There is no way for a user to correctly interpret what to do once encountering this error. The error message should be much more descriptive and give clear instructions on how to achieve what the user is trying to do. The error message should look something more like this.
You have attempted to change the C compiler by changing the CMAKE_C_COMPILER variable.
CMake does not allow you to change the compiler after the initial configuration pass.
If you want to change the C compiler, you must delete CMakeCache.txt (or your build
directory) and start configuring from scratch. If you are running the CMake GUI
(cmake-gui), then the GUI will ask you which compiler to use on the first configure.
If you are using the command line (cmake or ccmake), you can specify the compiler
either through command line arguments or environment variables. To use CMake command
line arguments, use the -D argument to set the CMAKE_C_COMPILER.
cmake -D CMAKE_C_COMPILER=/usr/bin/gcc <path-to-source>
To use environment variables, set the CC environment variable before running cmake.
How you set environment variables depends on your shell, but the following works on
many.
export CC=/usr/bin/gcc
cmake <path-to-source>
Remember, for any of these to work YOU MUST DELETE YOUR CMakeCache.txt CACHE FILE!
Halt the configure script
Another problem with the current error is that once you encounter it (at the beginning of the configure pass), the script continues to run. Because changing CMAKE_<LANG>_COMPILER
totally messes things up, you inevitably get more errors. These useless errors obfuscate what the real issue is and only serve to confuse users. Thus, when CMake detects one of the CMAKE_<LANG>_COMPILER
variables have changed, it should print out an error message and immediately quit.