This is a minimal example of a CMake project that uses Cheerp to compile main.cpp to WebAssembly and JavaScript.
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 ..
makeThis will build app.js and app.wasm in the build directory.
Copy index.html into the build directory, and serve it with your favourite web server.
For example:
cd build
cp ../index.html .
npx viteBecause we only use the console.log function, we can run the WebAssembly module with Node.js.
cd build
node app.wasm