# CMakeLists.txt : clang++ generating WASM ?

**URL:** <https://discourse.cmake.org/t/cmakelists-txt-clang-generating-wasm/9758>\
**Category:** Code\
**Created:** [January 2, 2024, 8:04pm UTC](https://discourse.cmake.org/t/cmakelists-txt-clang-generating-wasm/9758 "2024-01-02T20:04:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_Yue](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nicholas_yue/32/464_2.png) [@Nicholas\_Yue](https://discourse.cmake.org/u/Nicholas_Yue)\
**Post date:** [January 2, 2024, 8:04pm UTC](https://discourse.cmake.org/t/cmakelists-txt-clang-generating-wasm/9758/1 "2024-01-02T20:04:01Z")

</div>

I am looking into direct generation of \*.wasm via clang/clang++ (currently using 17)

My usage experience with CMake has generally been generating \*.o, \*.so and executable.

I do have a Makefile way of doing things (clang → WASM) but was hoping to leverage CMake if possible.

I am aware of the existence of emscripten-cmake however, I am not using the emscripten approach.

Cheers

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [January 3, 2024, 10:13am UTC](https://discourse.cmake.org/t/cmakelists-txt-clang-generating-wasm/9758/2 "2024-01-03T10:13:05Z")

</div>

> not using the emscripten approach

You mean, you’d like to compile a C++ project into WebAssembly _without_ using Emscripten compiler? I would actually be curious to learn how does one do that.

I have an example project for the “opposite” case - that is _with_ using Emscripten compiler - but looks like it won’t be of interest for you then.

---

<div class="post-metadata">

**Author:** ![Nicholas\_Yue](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nicholas_yue/32/464_2.png) [@Nicholas\_Yue](https://discourse.cmake.org/u/Nicholas_Yue)\
**Post date:** [January 3, 2024, 5:17pm UTC](https://discourse.cmake.org/t/cmakelists-txt-clang-generating-wasm/9758/3 "2024-01-03T17:17:24Z")

</div>

> **[Compile C to WebAssembly (WASM) and run it in the browser](https://dev.to/begoon/compile-c-to-webassembly-wasm-and-run-it-in-the-browser-h1l)**
>
> Introduction A popular toolchain to compile C to WASM is emscripten. It provides bindings...

My use case and requirements fit within the above, YMMV.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [January 11, 2024, 1:16pm UTC](https://discourse.cmake.org/t/cmakelists-txt-clang-generating-wasm/9758/4 "2024-01-11T13:16:20Z")

</div>

It looks like a toolchain file would be needed. There, you can set the executable extension to `.wasm` (as it is linker output that is WASM-loadable, not the `.o` file). You can probably start from an Emscripten toolchain and adapt it as needed.
