On Windows 10 with VS2017 and LLVM installed
and CMAKE just takes VC compiler as default and ignores both set
command in the CMakeLists.txt and command line -DCMAKE_CXX_COMPILER
I have no idea how to make it use LLVM Clang
I checked out many existing questions but they do not work for me
CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
set(CMAKE_CXX_COMPILER "C:\\Program Files\\LLVM\\bin\\Clang++")
project(CMakeTest1 VERSION 0.0.0 LANGUAGES CXX)
aux_source_directory(. MAINDIR)
add_executable(CMakeTest1 ${MAINDIR})
main.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
running command with git bash
***@DESKTOP-8KJ4J0H MINGW64 /d/CMakeTest1
$ cmake -DCMAKE_CXX_COMPILER="C:\Program Files\LLVM\bin\Clang++" .
-- Building for: Visual Studio 15 2017
-- The CXX compiler identification is MSVC 19.13.26129.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/CMakeTest1
my CXX compiler identification is forced to be MSVC and cannot be changed by any method.
no idea why
EDITED: what i wanna strongly declare is, i swear and clearly know that i CLEANED ALL GENERATED FILES form the folder and there are ONLY JUST CMakeLists.txt and main.cpp existing. and I DON'T WANT TO BE ASSUMED having old cache files unremoved