Unable to set compiler using windows

I have CC and CXX set to clang and clang++, however CMAKE is using MSVC instead. I’ve scoured stack overflow and other places and can’t seem to find anyone else running into this problem.

///c_template on  master ≡  ~2                                  594ms ⌛ 11:57:46  
❯ echo $CC
clang

///c_template on  master ≡  ~2                                           11:57:49  
❯ echo $CXX
clang++

///c_template on  master ≡  ~2                                  156ms ⌛ 11:57:53  
❯ make test
cmake -S . -B build
-- Building for: Visual Studio 17 2022
-- The C compiler identification is MSVC 19.35.32215.0
-- The CXX compiler identification is MSVC 19.35.32215.0
-- The ASM compiler identification is MSVC
-- Found assembler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.35.32215/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/2022/BuildTools/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done

I’ve reproduced the issue in a github action. I’m sure I’ve missed something, but I don’t know what it is.

AFAIK When using the Visual Studio generator, you can only used compilers known by VS, not any command line compiler. They’re selected by -T, in your case it should be -T ClangCL

Alternatively you can use another generator, like Ninja, with -G Ninja.
Then the environment variables will be considered.

see too Best Practice for Ninja build Visual Studio?

Changing the generator worked for building with different compilers. Thanks!

Still running into other issues as I play with CMake on Windows.

Maybe I’ll start another thread with a more general topic