emscripten-core / emscripten-core/emscripten
Native Emscripten Support in CMake
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I’m posting this to clarify the current transition regarding Emscripten support in CMake. This is useful for developers who use emscripten with `cmake`. It would also help to get the communitiy's needs and wants discussed.
We started working on this really just so that [VTK.wasm](https://kitware.github.io/vtk-wasm/) can be built and distributed as shared libraries. It would be unfair to do this work with just VTK in mind because this undertaking will have a big effect on other projects too.
**Native Support (CMake 4.2+):** You can build without `emcmake` by using `-DCMAKE_SYSTEM_NAME=Emscripten`. This supports the `-DBUILD_SHARED_LIBS=ON`, provided you pass the correct linker flags (`-sSIDE_MODULE=1` for libs, `-sMAIN_MODULE=1` for executables).
**When to still use `emcmake`**: Upstream support is not yet complete. If you need to find dependencies in the emsdk sysroot (e.g., `find_package(OpenGL)`) among other things, you must still use the `emcmake` wrapper. This is tracked upstream in [Issue #27460](https://gitlab.kitware.com/cmake/cmake/-/issues/27460).
Relevant MRs:
[cmake/cmake#10832](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10832) (Platform modules)
[cmake/cmake#11206](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/11206) (Drop hard-coded flags)
[cmake/cmake#11204](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/11204) (support downstream toolchain)
Mega issue upstream:
[cmake/cmake!18423](https://gitlab.kitware.com/cmake/cmake/-/issues/18423)
Contributor guide
Assessment
This issue has not been assessed yet.