In my cross-platform headers (https://github.com/floooh/sokol) the 
emscripten code path is selected with a config-define, and the required 
Javascript code is embedded right in the C source files via emscripten's 
EM_JS macro (for instance 
here: 
https://github.com/floooh/sokol/blob/a662517e772d30b0889d68d83e7ec7cb395d89be/sokol_audio.h#L1294).

That way the emscripten version looks exactly the same to a user of that 
library as the other platform-specific code paths: just a bunch a C sources 
which are added to a project as usual, configured with preprocessor defines.

I'm "delegating" the entire build system problem to the library user 
though. For my projects I'm using cmake with a custom toolchain file for 
emscripten, but the emscripten SDK also comes with one (
https://github.com/emscripten-core/emscripten/blob/master/cmake/Modules/Platform/Emscripten.cmake),
 
so it should be possible to add only minimal emscripten-specific code to 
the project's standard CMakeLists.txt file (or maybe even none at all).

Cheers,
-Floh.

On Tuesday, 31 March 2020 17:14:26 UTC+2, Chris Hafey wrote:
>
> Hi All,
>
> I would like to add a JS/WASM build of an existing C++ library (
> https://github.com/team-charls/charls) and am looking for best practices 
> on how to do so. Here are some options:
>
> 1) Create a new git repository that has the files files specific to the 
> JS/WASM build (e.g. CMakeLists.txt, js warpper, package.json, etc).  In 
> this case, I would checkout the C++ library as a subfolder (or use git 
> submodules) in this new project.  I like this because it is a clean 
> separation of concerns, but requires more work to keep things in sync.
> 2) Add the JS/WASM files to the existing repository.  This is nice because 
> its all one repository, but makes things more complicated for those that 
> just want the C/C++ version.  In this case, I would create a package.json 
> to the root and create a "js" directory at the root which contains the 
> JS/WASM specific bits (including the resulting JS/WASM code)
> 3) Combine the above two using a mono-repo pattern.
>
> Any thoughts would be appreciated, thanks!
>
> Chris
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/0966d92f-0467-4970-b270-f2a815a523dc%40googlegroups.com.

Reply via email to