CMake should warn when CMAKE_CXX_COMPILER is ignored
When using the Visual Studio (default) generator on Windows the CMAKE_C_COMPILER
and CMAKE_CXX_COMPILER
(and probably other variables) are completely ignored since the generator specifies them.
Example:
D:\CodeBlocks\CMakeExample\build>cmake .. -DCMAKE_CXX_COMPILER=clang.exe -DCMAKE_C_COMPILER=clang.exe
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.28.29915.0
-- The CXX compiler identification is MSVC 19.28.29915.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/CodeBlocks/CMakeExample/build
I would expect a warning similar to when you specify a variable that's unused:
CMake Warning:
Manually-specified variables were overwritten by the generator and ignored:
CMAKE_C_COMPILER
CMAKE_CXX_COMPILER