Search code examples
c++cmakecgalemscripten

Using emscripten with CMake in a simple(?) project


So I've got a fairly simple C++ program that uses CGAL and is built with CMake. I can build and run it successfully without emscripten:

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -G "Unix Makefiles" .
[output looks good]
make
[command works]

Everything there is fine and I can run the output, however when I try using Emscripten like this (which has worked for me in the past):

cmake -DCMAKE_TOOLCHAIN_FILE=/home/brenden/emsdk_portable/emscripten/master/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -G "Unix Makefiles" .
[output looks good]
make
main.cpp:2:10: fatal error: 'CGAL/Triangulation_3.h' file not found
#include <CGAL/Triangulation_3.h>
         ^
1 error generated.
ERROR    root: compiler frontend failed to generate LLVM bitcode, halting
make[2]: *** [CMakeFiles/cgal_test.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/cgal_test.dir/all] Error 2
make: *** [all] Error 2

This obviously doesn't work.

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 2.8)
project(cgal_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(cgal_test ${SOURCE_FILES})
target_link_libraries(cgal_test CGAL gmp)

Any ideas? All the CGAL libraries and headers are in usr/local/, so I'm sort of at a loss as to what's going on.


Solution

  • Hmmm, so it turns out that you can't just link in a library, the emscripten docs point out that you "...build the libraries to bitcode and then compile library and main program bitcode together to JavaScript."

    That sounds silly and painful but I guess that's the answer.