How to use cmake on windows with vs2019 and custom installed llvm?

Viewed 389

I found someone mentioned to use such command line to use cmake with vs2019 and llvm toolset:

cmake -G "Visual Studio 2019" -T ClangCL

However, this would use the llvm version, which is 11.0 for now, was installed by the visual studio instanller.

I want to use a new version, thus 12.0, of llvm which I already installed somewhere else but I don't know how to make cmake and vs to use that.


UPDATE:

What I tried to set the compiler via command line:

E:\my_proj>cmake -G "Visual Studio 16 2019" -A x64 -T "ClangCL" -DCMAKE_C_COMPILER="C:\Program Files\LLVM\bin\clang.exe" -DCMAKE_CXX_COMPILER="C:\Program Files\LLVM\bin\clang++.exe" .
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- The C compiler identification is Clang 11.0.0 with MSVC-like command-line
-- The CXX compiler identification is Clang 11.0.0 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-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/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done

As you could see the cmake picked the clang from the vs installed location and ignored the command line.

1 Answers

As described below, setting CMAKE flags explicitly has no effect when using VS generator. Thus choosing the default compiler installed by Visual Studio installer.

The VS generator produces .vcxproj files and uses MSBuild to actually drive the build. The values of CMAKE_{C,CXX}_COMPILER are computed automatically from the compiler MSBuild chooses so setting them has no effect.

Related