Skip to content
Latchkey

CMake "Could not find toolchain file Emscripten.cmake" in CI

Building a CMake project for wasm requires the Emscripten CMake toolchain file. When CMake is run without emcmake (or with a stale EMSDK path), it cannot locate Emscripten.cmake and configuration fails.

What this error means

CMake configure fails with "CMake Error ... Could not find toolchain file: .../cmake/Modules/Platform/Emscripten.cmake" when building for wasm.

emscripten
CMake Error at CMakeLists.txt:2 (project):
  Could not find toolchain file:
  /emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake

Common causes

CMake invoked without emcmake

The emcmake wrapper sets the toolchain file from the active EMSDK. Calling cmake directly leaves CMake with no Emscripten toolchain.

A stale or wrong EMSDK path

A hard-coded toolchain path points at an EMSDK location that does not exist on this runner, so the file is not found.

How to fix it

Configure through emcmake

  1. Activate emsdk and source emsdk_env.sh.
  2. Run CMake through the emcmake wrapper so the toolchain is set automatically.
  3. Build with cmake --build.
Terminal
source /emsdk/emsdk_env.sh
emcmake cmake -B build
cmake --build build

Pass the toolchain file from EMSDK explicitly

If you must call cmake directly, point it at the toolchain file using the EMSDK environment variable.

Terminal
cmake -B build \
  -DCMAKE_TOOLCHAIN_FILE="$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"

How to prevent it

  • Always configure wasm CMake builds through emcmake.
  • Derive the toolchain path from $EMSDK, never hard-code it.
  • Source emsdk_env.sh so EMSDK is set before CMake runs.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →