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.
CMake Error at CMakeLists.txt:2 (project):
Could not find toolchain file:
/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmakeCommon 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
- Activate emsdk and source
emsdk_env.sh. - Run CMake through the
emcmakewrapper so the toolchain is set automatically. - Build with
cmake --build.
source /emsdk/emsdk_env.sh
emcmake cmake -B build
cmake --build buildPass the toolchain file from EMSDK explicitly
If you must call cmake directly, point it at the toolchain file using the EMSDK environment variable.
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.shso EMSDK is set before CMake runs.