Skip to content

Emscripten builds for web apps

Jose Luis Blanco-Claraco edited this page Jul 24, 2022 · 25 revisions

Crosscompiling MRPT to a JS library

Prerequisites

Install Emscripten: https://emscripten.org/docs/getting_started/downloads.html

Optional: Install nodejs to be able to run tests automatically with make run_test_*:

sudo apt install nodejs

Build

cd mrpt
mkdir build-ems
cd    build-ems

cmake .. \
  -DCMAKE_TOOLCHAIN_FILE=$HOME/code/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \
  -DCMAKE_EXE_LINKER_FLAGS="-s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 -s USE_GLFW=3 -s FULL_ES2=1 -s FULL_ES3=1  -s MAX_WEBGL_VERSION=2 -s TOTAL_MEMORY=16MB" \
  -DCMAKE_CXX_FLAGS="-s NO_DISABLE_EXCEPTION_CATCHING -s USE_LIBJPEG=1 -s USE_LIBPNG=1 -s USE_ZLIB=1 -O3" \
  -DCMAKE_REQUIRED_FLAGS="-s USE_LIBJPEG=1 -s USE_LIBPNG=1 -s USE_ZLIB=1 -s USE_GLFW=3  -s FULL_ES2=1 -s FULL_ES3=1" \
  -DMRPT_EIGEN_USE_EMBEDDED_VERSION=ON \
  -DMRPT_HAS_OPENNI2=OFF \
  -DMRPT_AUTODETECT_SIMD=OFF \
  -DDISABLE_ASSIMP=ON \
  -DMRPT_WITH_XSENS=OFF \
  -DMRPT_WITH_ROBOPEAK_LIDAR=OFF \
  -DDISABLE_FFMPEG=ON \
  -DDISABLE_LIBDC1394=On \
  -DMRPT_WITH_KINECT=Off \
  -DROBOTO_BOLD_TTF_FILE=/usr/share/fonts/truetype/roboto-fontface/roboto/Roboto-Bold.ttf \
  -DROBOTO_REGULAR_TTF_FILE=/usr/share/fonts/truetype/roboto-fontface/roboto/Roboto-Regular.ttf \
  -DENTYPO_TTF_FILE=$(pwd)/../3rdparty/nanogui/resources/entypo.ttf

make

TODO:

  • Add support for ASSIMP and OpenCV as WAsm-built libs too.

Threads:

  -DCMAKE_CXX_FLAGS="-s USE_PTHREADS"

Crosscompiling wxWidgets

mkdir wxWidgets/build-emscripten
cd    wxWidgets/build-emscripten

cmake .. \
  -DCMAKE_TOOLCHAIN_FILE=$HOME/code/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \
  -DCMAKE_CXX_FLAGS="-s USE_LIBJPEG=1 -s USE_LIBPNG=1 -s USE_SDL=2 -s USE_ZLIB=1" \
  -DCMAKE_REQUIRED_FLAGS="-s USE_LIBJPEG=1 -s USE_LIBPNG=1 -s USE_SDL=2 -s USE_ZLIB=1"

make