Mixing emcc and 'host' toolchains in CMake?

23 views
Skip to first unread message

Steven Johnson

unread,
Jul 8, 2020, 1:32:38 PM7/8/20
to emscripte...@googlegroups.com

(This question is more CMake-related than Emscripten-related, but I suspect someone else on this list may have encountered it, so thought I'd ask here...)

TL;DR: Has anyone attempted to use both the Emscripten toolchain and the 'host' toolchain (eg gcc, clang) in the same CMake project?

Some of the tooling in this project (e.g. our crosscompiler tool that produces .wasm) really needs to be compiled natively, while other parts (e.g. the test suite) needs to be compiled via Emscripten. IIUC, CMake has a pretty hard distinction of "one toolchain per language per project, period" (unlike, say, Blaze/Bazel, which makes this distinction easy).

There are various ways to work around this (CMake's ExternalProject, splitting our project into multiple CMake projects, etc) but they all have nontrivial drawbacks, so I thought I'd check to see if anyone has found an approach that is simpler to implement and maintain.

Thomas Lively

unread,
Jul 8, 2020, 4:43:05 PM7/8/20
to emscripte...@googlegroups.com
I don't have a solution, but if anyone else does I would also be very interested in hearing about it. Right now we have to separate Binaryen's native and Emscripten builds and it would be very convenient if we could do both at once.

--
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-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAM%3Ddnvec5z_n7w5THU1%2B0%2BZ5DJ984b9AdPdWN_3HQ6NJx7kYTg%40mail.gmail.com.

Shachar Langbeheim

unread,
Jul 9, 2020, 1:26:19 AM7/9/20
to emscripten-discuss
In our project we have a single cmake project, with multiple targets - backend & tests executables are built with clang, wasm with emscripten. It works ok - not perfect, because we still need to add a lot of if statements to handle the different files that belong in different executables, and the different compilation and linking flags for each target, but it works.

--

Steven Johnson

unread,
Jul 9, 2020, 1:06:10 PM7/9/20
to emscripte...@googlegroups.com
On Wed, Jul 8, 2020 at 10:26 PM Shachar Langbeheim <nih...@gmail.com> wrote:
> In our project we have a single cmake project, with multiple targets - backend & tests executables are built with clang, wasm with emscripten. It works ok - not perfect, because we still need to add a lot of if statements to handle the different files that belong in different executables, and the different compilation and linking flags for each target, but it works.

Interesting, I didn't think that was possible, at least not with the
standard CMake commands. Do you just use `add_custom_command` to drive
command-line tools directly, rather than (e.g.) `add_library()` and
friends?

Shachar Langbeheim

unread,
Jul 12, 2020, 1:55:10 AM7/12/20
to emscripten-discuss
No, but we make judicious use of the if(CMAKE_SYSTEM_NAME STREQUAL Emscripten) conditional, to separate Emscripten flows from non-emscripten flows.

--
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-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages