Skip to content

Example of a CMake project that uses Cheerp to compile C++ to WebAssembly

Notifications You must be signed in to change notification settings

bates64/minimal-cmake-cheerp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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