# CMake compiler autodetection does not work for emscripten when generator is set to Visual Studio

**URL:** https://discourse.cmake.org/t/cmake-compiler-autodetection-does-not-work-for-emscripten-when-generator-is-set-to-visual-studio/13933
**Category:** Usage
**Tags:** os:windows
**Created:** [April 14, 2025, 11:30pm UTC](https://discourse.cmake.org/t/cmake-compiler-autodetection-does-not-work-for-emscripten-when-generator-is-set-to-visual-studio/13933 "2025-04-14T23:30:54Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![chasun](https://discourse.cmake.org/user_avatar/discourse.cmake.org/chasun/32/5506_2.png) [@chasun](https://discourse.cmake.org/u/chasun)
#### Post date: [April 14, 2025, 11:30pm UTC](https://discourse.cmake.org/t/cmake-compiler-autodetection-does-not-work-for-emscripten-when-generator-is-set-to-visual-studio/13933/1 "2025-04-14T23:30:54Z")

</div>

Actually I don’t know if it is a problem of cmake or emscripten. emscripten is a toolchain that compiles C/C++ code to webassembly so that they can be run in web browsers.  
Here is the toolchain cmake file that we need to use:

> <https://github.com/emscripten-core/emscripten/blob/main/cmake/Modules/Platform/Emscripten.cmake>

And here is my CMakeLists.txt:

```auto
cmake_minimum_required(VERSION 4.0)
project(playground C CXX)

message(STATUS "CMAKE_C_COMPILER:${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")

```

When I use it with NMake, everything works fine:

```auto
cmake -DCMAKE_TOOLCHAIN_FILE=C:\src\emsdk\upstream\emscripten\cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" ..

```

The output was:

```auto
-- The C compiler identification is Clang 21.0.0
-- The CXX compiler identification is Clang 21.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/src/emsdk/upstream/emscripten/emcc.bat - 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:/src/emsdk/upstream/emscripten/em++.bat - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_C_COMPILER:C:/src/emsdk/upstream/emscripten/emcc.bat
-- CMAKE_CXX_COMPILER_ID: Clang
-- Configuring done (3.7s)
-- Generating done (0.0s)
-- Build files have been written to: C:/src/t1/b

```

However, when I set the generator to Visual Studio, the values of “CMAKE\_C\_COMPILER” and “CMAKE\_C\_COMPILER\_ID” mismatch. CMake always thinks that CMAKE\_C\_COMPILER\_ID is MSVC.
