Building Magnum with Emscripten on Windows

~ 3 Minute Read.

At Vhite Rab­bit I’ve been us­ing Mag­num to build Em­scripten based web projects for quite a while. Since the Ocu­lus Rift con­strains me to Win­dows for de­vel­op­ment and some­times things are hard to set up there, I here­by share the way to com­pile Mag­num with Em­scripten on Win­dows that worked for us—may it be of use to you.

Set­ting Up Em­scripten

One of the Em­scripten main­tain­ers, juj, pro­vides a won­der­ful tool to get this done pain­less­ly: ems­dk.

Just go ahead and clone the repos­i­to­ry:

git clone
cd emsdk

To down­load and in­stall em­scripten and all its de­pen­den­cies run the fol­low­ing com­mands:

emsdk udpate
emsdk install latest
emsdk activate latest

The last com­mand will set up your em­scripten en­vi­ron­ment that will be avail­able with emcmdprompt.bat. You will use that to run all cmake com­mands for com­pil­ing mag­num from.

Com­pil­ing Cor­rade for Desk­top

Since Mag­num us­es the corrade-rc tool pro­vid­ed by cor­rade, you will need to com­pile cor­rade for both desk­top and Em­scripten. I rec­om­mend do­ing this via vcp­kg, since that is eas­i­est on Win­dows:

vcpkg install corrade[core,rc]

Fi­nal­ly make sure to ei­ther make it avail­able on your path or set CORRADE_RC_EXECUTABLE in the fol­low­ing build steps.

Com­pil­ing Mag­num

I cre­at­ed a batch script for this, be­cause it is rather an­noy­ing to have to re­run all com­mands man­u­al­ly when you up­date mag­num and cor­rade—if you use mag­num-ex­tras, mag­num-plug­ins and mag­num-in­te­gra­tion, that’s five repos­i­to­ries!

First, make sure you cloned mag­num with sub­mod­ules, though:

git clone --recurse-submodules git://
git clone --recurse-submodules git://
git clone --recurse-submodules git://
git clone --recurse-submodules git://
git clone --recurse-submodules git://

Ob­vi­ous­ly on­ly clone what you need, if you don’t use Magnum::Ui for ex­am­ple, you will not need “mag­num-ex­tras”. You will need to have nin­ja on your path and then we’re ready to get com­pil­ing!

@echo off

set BUILD_DIR=build-emc
if not exist "corrade\%BUILD_DIR%" mkdir corrade\%BUILD_DIR%
if not exist "magnum\%BUILD_DIR%" mkdir magnum\%BUILD_DIR%
if not exist "magnum-plugins\%BUILD_DIR%" mkdir magnum-plugins\%BUILD_DIR%
if not exist "magnum-extras\%BUILD_DIR%" mkdir magnum-extras\%BUILD_DIR%
if not exist "magnum-examples\%BUILD_DIR%" mkdir magnum-examples\%BUILD_DIR%

rem This is the path magnum example apps will be deployed to.
set "DEPLOY_PREFIX=%cd%\deploy"
if not exist "%DEPLOY_PREFIX%" mkdir "%DEPLOY_PREFIX%"

rem This converts the emscripten path set in your environment by emcmdprompt by replacing all \ with /

set CMAKE_BUILD_CMD=cmake --build . --target install

cd corrade\%BUILD_DIR%

cd ../../magnum\%BUILD_DIR%

cd ../../magnum-plugins\%BUILD_DIR%

cd ../../magnum-extras\%BUILD_DIR%

cd ../../magnum-examples\%BUILD_DIR%


Be sure to ad­just those CMake vari­ables to your de­sire, build­ing ex­act­ly what you want from mag­num.

Build­ing Your Project

Build­ing your own project is not much dif­fer­ent from build­ing mag­num it­self. Cre­ate a build di­rec­to­ry and nav­i­gate to it in the emcmdprompt.bat. Then use some­thing like the fol­low­ing to con­fig­ure your project.


cmake --build . --target install

Good luck!

Writ­ten in 18 min­utes, ed­it­ed in 10 min­utes.