PS: AFAIK what's not possible with cmake is to do a "mixed build" where 
some parts of the build are compiled to WASM and some parts are compiled as 
native (or a different cross-compilation target). This is a general 
limitation of cmake (again - only as far as I know - maybe there's a way 
around the limitation).

On Thursday, 15 July 2021 at 11:39:15 UTC+2 Floh wrote:

> 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/6a4eb95a-f25d-4972-a5f0-72ad73bdccd4n%40googlegroups.com.

Reply via email to