Emscripten buliding OpenCascade WebGl example

Hello I am having trouble building the WebGL example for the past couple hours. I wanted to know first if for Emscripten do I need to build it from source or can I just follow the Installation instructions using the emsdk. (https://emscripten.org/docs/getting_started/downloads.html)

The only reason I have not decided to build Emscripten from source is that I need to build LLVM first and that will take many hours on my machine. But if its required to build it from source ill do it.

Currently I just installed Emscripten using the installations instructions using the emsdk.

I had an issue with FreeType but It was fixed just by building from source.

As far as I understand its not stated here (https://dev.opencascade.org/doc/overview/html/occt_samples_webgl.html)

English is not my first language so the English can be hard for me. Anyways thanks in advance

EDIT #1: I went ahead and endured the long build time for LLVM and I think I got Emscripten built from source. Ill have to play around tomorrow to see if I can get the WebGl example to work

Dmitrii Pasukhin's picture

Hello, which OS do you use? As for a Win MinGW has enoungh installed packages to work with. In that case you only need to build FreeType.

I can't understand your quastion. But as for a Guide, we will update that. Thank you. We have extended solution based on EMSDK, but it is commercial viewer.

Best regards, Dmitrii.

Alfredo Gutierrez's picture

Hello Dmitrii,

I am having problems building the webGL example. The original question was asking if I needed to build emscripten from source or just use the quick installer for it. The same issue exist whether I use one or the other.

I am using linux mint as my operating system. Im going to list the changes I have made so far.

I have done the following
- build Emscripten from source (which I can verify it works with one of their tutorials)
- I build FreeType from source.

I built the current OCCT environment with the following command.

sudo cmake -DINSTALL_DIR=/usr/local/occt_static_build -DUSE_FREETYPE=ON -DUSE_VTK=OFF -DUSE_FREEIMAGE=ON -DUSE_OPENGL=ON -DUSE_TCL=OFF -DUSE_TK=OFF -DBUILD_MODULE_DETools=OFF -DBUILD_MODULE_Draw=OFF -DUSE_RAPIDJSON=ON -DUSE_DRACO=OFF -DBUILD_LIBRARY_TYPE="Static" ..

I added the following paths in my ".bashrc" file

export CPATH="$CPATH:/home/alfredo/builds/emscripten/cache/sysroot/include"
export CPATH="$CPATH:/usr/local/occt_static_build/include/opencascade"
export LD_LIBRARY_PATH=/usr/local/occt_static_build/lib:$LD_LIBRARY_PATH

in the CMakeLists.txt file I removed the following line (since no matter what I did I could not fix it)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --bind")

running make with that line of code gave me this error

Consolidate compiler generated dependencies of target occt-webgl-sample
[ 33%] Building CXX object CMakeFiles/occt-webgl-sample.dir/WasmOcctView.cpp.o
c++: error: unrecognized command line option ‘--bind’
make[2]: *** [CMakeFiles/occt-webgl-sample.dir/build.make:76: CMakeFiles/occt-webgl-sample.dir/WasmOcctView.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/occt-webgl-sample.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

I added the following line in the CMakeLists.txt in order to get more information out. and also set the freetype dir and OCCT dir

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --verbose")
set(freetype_DIR "/usr/local/lib/cmake/freetype/")
set(OpenCASCADE_DIR "/usr/local/occt_static_build/lib/cmake/opencascade")

Now if I change my director to be the webgl I do the following

$ mkdir build
$ cd bulid
$ cmake ..
$ make

then I get the following error (https://gist.github.com/notalfredo/674974351ddf2382064e1cf9cec605ef). The error is so long I just made it a github gist.
That is where I am now. Dont know how to approach the problem from here (yet).

I know you mentioned the guide will be updated. A updated guide will be very nice. Since I feel like the instructions are hard to follow.

EDIT #1: I came up with a possible solution in my head I have some time right now to test to see if it has any promises. Basically what I think I need to do is call cmake but with Emscripten which will explain this line in the guide "${EMSDK}/fastcomp/emscripten/cmake/Modules/Platform/Emscripten.cmake" and which would explain why the --bind flag wasnt working. Ill have to test it ill make a follow up comment if that was what was causing the issue.

Alfredo Gutierrez's picture

The issue ended up being that I was not following the instructions correctly. In step 4 of the guide (https://dev.opencascade.org/doc/overview/html/occt_samples_webgl.html) it says

Perform building and installation steps.
> ${EMSDK}/fastcomp/emscripten/cmake/Modules/Platform/Emscripten.cmake

It was unclear to me when I first read the instructions but it was not until I opened up the file I realized what I did wrong. Near the top of the Emscripten.cmake file it says to follow the following instructions.

# To use this toolchain file with CMake, invoke CMake with the following command
# line parameters:
# cmake -DCMAKE_TOOLCHAIN_FILE=<EmscriptenRoot>/cmake/Modules/Platform/Emscripten.cmake
# -DCMAKE_BUILD_TYPE=<Debug|RelWithDebInfo|Release|MinSizeRel>
# -G "Unix Makefiles" (Linux and macOS)
# -G "MinGW Makefiles" (Windows)
# <path/to/CMakeLists.txt> # Note, pass in here ONLY the path to the file, not the filename 'CMakeLists.txt' itself.

This fixed the issues in this original post. I am having new errors in this build process BUT I will make a new post for that as its not the question asked in this original post.