2

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.

10
  • What have you tried? Does setting CMAKE_CXX_COMPILER not work? Commented Aug 20, 2021 at 8:20
  • I tried set (CMAKE_C_COMPILER "C:/Program Files/LLVM/bin/clang.exe") set (CMAKE_CXX_COMPILER "C:/Program Files/LLVM/bin/clang++.exe") in the beginning of my CMakeLists.txt but that seems to be ignored. Commented Aug 20, 2021 at 8:29
  • @jayatubi: Have you tried other approaches, described in the answers to that question? E.g. set CC and CXX environment variable, or pass -D CMAKE_C_COMPILER and -D CMAKE_CXX_COMPILER options to cmake? Commented Aug 20, 2021 at 11:48
  • @Tsyvarev No. It always use the clang which was installed inside visual studio regardless what I set in the command line. Commented Aug 20, 2021 at 12:03
  • can you show us the output of "C:\Program Files\LLVM\bin\clang.exe" --version Commented Aug 31, 2021 at 11:39

1 Answer 1

1
+50

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.