Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bates64/minimal-cmake-cheerp
Example of a CMake project that uses Cheerp to compile C++ to WebAssembly
https://github.com/bates64/minimal-cmake-cheerp
cheerp cmake cmake-examples cpp javascript js wasm webassembly
Last synced: 14 days ago
JSON representation
Example of a CMake project that uses Cheerp to compile C++ to WebAssembly
- Host: GitHub
- URL: https://github.com/bates64/minimal-cmake-cheerp
- Owner: bates64
- Created: 2023-08-23T11:40:16.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-23T11:54:29.000Z (over 1 year ago)
- Last Synced: 2024-10-22T07:03:30.367Z (2 months ago)
- Topics: cheerp, cmake, cmake-examples, cpp, javascript, js, wasm, webassembly
- Language: Makefile
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Minimal Cheerp CMake example
[![Discord server](https://img.shields.io/discord/988743885121548329?color=%237289DA&logo=discord&logoColor=ffffff)](https://discord.gg/3UfTSbWdYy)
This is a minimal example of a CMake project that uses [Cheerp](https://labs.leaningtech.com/cheerp) to compile [main.cpp](/main.cpp) to WebAssembly and JavaScript.
## Building
Set the `CHEERP` environment variable to the path of your Cheerp installation. For example:
- On Linux: `export CHEERP=/opt/cheerp`
- On macOS: `export CHEERP=/Applications/cheerp`
- On Windows: `set CHEERP=C:\cheerp`Then run the following commands to configure and build the project:
```bash
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=$CHEERP/share/cmake/Modules/CheerpWasmToolchain.cmake ..
make
```This will build `app.js` and `app.wasm` in the `build` directory.
## Running
### In the browser
Copy [index.html](/index.html) into the `build` directory, and serve it with your favourite web server.
For example:
```bash
cd build
cp ../index.html .
npx vite
```### With Node.js
Because we only use the `console.log` function, we can run the WebAssembly module with Node.js.
```bash
cd build
node app.wasm
```