I've been intrigued by the idea of trying Emscripten for cross-compiling C++ code into JavaScript for some time. So I've decided to give it a try and also involved CMake to help me set up a testing pipeline for bringing an OpenGL/GLUT-based application (Hello Triangle! in this case) from C++ to JavaScript, all controlled by a simple self-contained build script written in Python (build.py).

As mentioned above, in order to be able to build the example, there're are some packages to install, namely: Emscripten SDK and CMake. Python (2.x) is also required but you can use the one bundled with Emscripten, just make sure both CMake & Python are added into PATH (to make them accessible from the command-line). Please note that the whole set-up has been tested on a Windows machine only, but it should be a matter of minutes to tweak it for other platforms as well (OSX & Linux).

In order to build the demo application, please start a new command prompt using emcmdprompt.bat (typically located in c:\Program Files\Emscripten\), then cd into the hello_triangle_emscripten directory and type build.py. The image bellow shows the steps and the output: