An open API service indexing awesome lists of open source software.

https://github.com/leaningtech/cheerp-utils

Cheerp headers and utils
https://github.com/leaningtech/cheerp-utils

Last synced: 4 months ago
JSON representation

Cheerp headers and utils

Awesome Lists containing this project

README

          

Cheerp: A C++ compiler for the Web
------------------------------------------

Cheerp is a tool to bring C++ programming to the Web. It can generate a seamless
combination of JavaScript, WebAssembly and Asm.js from a single C++ codebase.

Installation
------------------------------------------

Depending on your platform, cheerp needs to be unpacked in a different path:

Windows

c:\cheerp\

Mac OS

/Applications/cheerp

Linux

/opt/cheerp

In the following instructions /opt/cheerp/ is assumed.

Usage
------------------------------------------

Cheerp is integrated in the LLVM/clang infrastructure.
To build client side JavaScript code from C++ source files

/opt/cheerp/bin/clang -O3 -target cheerp -o

Building objects file separately and linking only at the end is also possible.

/opt/cheerp/bin/clang++ -O3 -c -target cheerp -o
/opt/cheerp/bin/clang++ -O3 -c -target cheerp -o
/opt/cheerp/bin/clang++ -target cheerp -o

Libraries can be built as well, they are stored using LLVM binary representation

/opt/cheerp/bin/clang++ -O3 -c -target cheerp -o
/opt/cheerp/bin/clang++ -O3 -c -target cheerp -o
/opt/cheerp/bin/llvm-link ... -o

A cmake toolchain file is provided in /opt/cheerp/share/cmake/Modules/CheerpToolchain.cmake
it's possible to cross-compile cmake projects for the Cheerp platform using the syntax

cmake -DCMAKE_TOOLCHAIN_FILE=/opt/cheerp/share/cmake/Modules/CheerpToolchain.cmake

Please note that, currently, only building static libraries is supported.

Code conventions
------------------------------------------

Global variables and types that are provided by the browser
environment are accessible through the 'client' namespace

client::document.addEventListener(...)

Of course, being a regular C++ namespace you can reduce
code verbosity by

using namespace client;

The relevant headers that defines client interfaces are

#include //Misc client side stuff
#include //Complete DOM/HTML5 interface
#include //WebGL interface

By convention the method that will be called first on the
client side should have the following signature

void webMain()

NOTE: As usual in JavaScript programming the script will be
loaded before the DOM is completely loaded, and so webMain will
be called on an incomplete document, to execute a callback after
loading is complete you can do this

void loadCallback()
{
...
}

void webMain()
{
document.addEventListener("DOMContentLoaded",Callback(loadCallback));
}

In a similar way you can bind to any other DOM event

Properties of DOM objects are always accessed through setters/getters

{
auto body = document.get_body();
}

Small examples are included in /opt/cheerp/share/cheerp/examples/

Limitations as of this version
------------------------------------------

None known