Building a native plugin from source

Hi,

I have a project that I have to export to WebGL. In that project I’m using a native plugin built in C++ using CMake to instruct how to build itself and how to discover its dependencies.

The Unity project works in almost every platform except for the WebGL. As WebGL doesn’t allow to load dll files, I need to build the plugin from the source code so the code can get converted to js code.

So far I’m using a dummy cpp file (that I put in Assets/Plugins/WebGL folder) that the only thing that does it is to include the main source files of my plugin source folder.

The problem comes when I need to resolve things like “#include ” where its location is well-known when I use CMake to build the library but it isn’t when I include them directly from unity. The project also defines dependencies and those dependencies also used CMake to generate their compilation rules.

So the questions are:
How can I define the includes folders so they can be used when building the library from Unity (similar to how ‘include_directories’ does it in CMake) and how can define dependencies (similar to ‘add_subdirectory’) for dependency discovery.

You can pass additional compiler arguments via emscriptenArgs using an Editor script. In this case, what you need is -I:

PlayerSettings.SetPropertyString("emscriptenArgs", " -Imy_library_headers_directory", BuildTargetGroup.WebGL);

I should mention that as of Unity 5.5, the PlayerSettings.SetProperty… API is deprecated. You should now use:

PlayerSettings.WebGL.emscriptenArgs = " -Imy_library_headers_directory";

Hope that helps.

@Marco-Trivellato I am unable to address the include path with PlayerSettings.WebGL.emscriptenArgs. Also, I am able to successfuly compile .bc file with emcc command and -I parameter. But .bc file isn’t working either.