Skip to content

Latest commit

 

History

History
46 lines (31 loc) · 1.16 KB

README.md

File metadata and controls

46 lines (31 loc) · 1.16 KB

Minimal Cheerp CMake example

Discord server

This is a minimal example of a CMake project that uses Cheerp to compile 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:

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 into the build directory, and serve it with your favourite web server.

For example:

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.

cd build
node app.wasm