The "easy way" is to use the emcmake wrapper that comes with the Emscripten 
SDK, AFAIK what this does is invoke CMake with an Emscripten specific 
toolchain file (which lives 
here: 
https://github.com/emscripten-core/emscripten/blob/main/cmake/Modules/Platform/Emscripten.cmake).

I have an example for this here (see the emscripten build instructions in 
the readme, and checkout the CMakeLists.txt file which has some emscripten 
specific settings):

https://github.com/floooh/pacman.c

The next option is to skip the emcmake wrapper and use the SDK's toolchain 
file, or your own variation of this toolchain file. The starting point is 
to run cmake giving it emscripten's toolchain file:

cmake -DCMAKE_TOOLCHAIN_FILE=[path to emsdk toolchain file] ..

AFAIK including a toolchain file in the CMakeLists.txt file based on a 
CMake option suffers from a chicken-egg situation, it's more robust to set 
the toolchain file as part of the command line invocation.

This is basically a "cmake crosscompiling scenario" with a custom toolchain 
file (as opposed to cmake's builtin cross compiling targets). CMake's 
documentation for this is here:

https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html

Cheers!
On Thursday, 15 July 2021 at 09:54:47 UTC+2 niro...@gmail.com wrote:

> Hi,
>
> I would like to integrate emscripten and to build a library compiled to 
> WASM on a complex C++ project.
>
> The best flow for me will be integrated it on the main flow on the cmake 
> configure, meaning: if a user set a flag to true (let say 
> BUILD_TO_WASM=true) than the cmake will be built as WASM, otherwise it will 
> build with the default OS toolchain.
>
> I can't find much documantation on how to integrate emscripten into cmake 
> (I want to avoid using emconfigure/emmake)
>
> How can it be done?
> "ExternalProject_Add"?
>
> any reference for such a build?
>
> Thanks
> Nir
>

-- 
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 emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/e17ba55c-f54f-44fb-9a4d-0a10924a6534n%40googlegroups.com.

Reply via email to