# Toolchains: Multiple files generated by add\_executable

**URL:** https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161
**Category:** Code
**Created:** [May 7, 2020, 1:01pm UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161 "2020-05-07T13:01:22Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Lectem](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lectem/32/380_2.png) [@Lectem](https://discourse.cmake.org/u/Lectem)
#### Post date: [May 7, 2020, 1:01pm UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161/1 "2020-05-07T13:01:22Z")

</div>

Is it possible to tell cmake that the toolchain will generate multiple files for executables?  
I’m thinking more specifically about emscripten which (might, depending on compile flags) generate both `.js` and `.wasm` files for a single target.

Right now the toolchain file only sets the `.js` suffix [here](https://github.com/emscripten-core/emscripten/blob/master/cmake/Modules/Platform/Emscripten.cmake#L224).

The impact I know of, caused by the .wasm file not being known by cmake are:

- The file won’t be removed when using the `clean` target
- The file won’t be copied when using `install(TARGETS )`

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 7, 2020, 3:24pm UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161/2 "2020-05-07T15:24:06Z")

</div>

It seems like some logic for Windows the dll/lib split may need to happen for Emscripten as well. @brad.king

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [May 7, 2020, 4:36pm UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161/3 "2020-05-07T16:36:17Z")

</div>

While the Windows dll/lib split is also a case of multiple files associated with an executable target, their semantic meaning is different than emscripten’s `.{js,wasm}` pair, IIUC.

Similar logic would be needed to support the latter case.

Which file is used to actually run the executable (possibly through `CMAKE_CROSSCOMPILING_EMULATOR`)? That should be considered the primary output artifact. We’d need some name/concept to describe the role of the second artifact.

---

<div class="post-metadata">

### Author: ![Lectem](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lectem/32/380_2.png) [@Lectem](https://discourse.cmake.org/u/Lectem)
#### Post date: [May 7, 2020, 8:49pm UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161/4 "2020-05-07T20:49:05Z")

</div>

> Which file is used to actually run the executable (possibly through `CMAKE_CROSSCOMPILING_EMULATOR` )?

The `.js` file is used to load the `.wasm` for bootstrapping, it acts as a launcher.  
But it is actually possible to ask emscripten to generate only the `.js` (if you don’t want webassembly support), `.wasm` if you don’t care about the small `.js` wrapper, and even a combination of html+js+wasm if you chose to use the default `.html` template.  
Those are not the defaults of the toolchain however, but can be triggered either using compile options or changing the target file extension (ie, change the `SUFFIX` property).

As for `CMAKE_CROSSCOMPILING_EMULATOR`, it seems node.js was chosen by the maintainers, and uses `.js` files.

In the end, the `.wasm` file is kind of a library that you can run through the `.js` file, but is not mandatory if you don’t target web assembly.  
I think it should be seen as a shared library that you can’t link (though I heard that there is now experimental support for shared libraries…).

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [May 8, 2020, 10:56am UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161/5 "2020-05-08T10:56:32Z")

</div>

Thanks for explaining. It sounds like the `.wasm` file can be treated as a resource associated with the `.js` executable. This is similar to the [RESOURCE](https://cmake.org/cmake/help/v3.17/prop_tgt/RESOURCE.html) target property used on macOS for additional App bundle resources. However, one distinction is that the `RESOURCE` property is just for additional files provided by the project. The `.wasm` file is generated as an additional output from the linker.

Since the `.wasm` file is associated with the toolchain settings rather than a project, I think it would make sense to define an abstraction for additional linker-generated artifacts that can be configured by the `Platform/*` and/or `Compiler/*` information modules. The generators would then know about the extra file and could include them in the list of link rule outputs, installation rules, etc.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [May 8, 2020, 3:21pm UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161/6 "2020-05-08T15:21:49Z")

</div>

The split debug symbols files that some split off the executable in POST\_BUILD would also fit into this. Especially if CMake gains built-in support for this one day.

---

<div class="post-metadata">

### Author: ![Lectem](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lectem/32/380_2.png) [@Lectem](https://discourse.cmake.org/u/Lectem)
#### Post date: [May 9, 2020, 12:47pm UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161/7 "2020-05-09T12:47:09Z")

</div>

Should I open an issue/feature request on gitlab for this ?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [May 11, 2020, 11:49am UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161/8 "2020-05-11T11:49:44Z")

</div>

@hsattler since debuginfo is a general cross-platform concept I think it would be better to model its artifacts explicitly. We have [CMake Issue 20256](https://gitlab.kitware.com/cmake/cmake/-/issues/20256) open for that already.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [May 11, 2020, 11:50am UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161/9 "2020-05-11T11:50:53Z")

</div>

@Lectem yes, please open an issue to track the emscripten case specifically, and mention the issue number back here for completeness.

---

<div class="post-metadata">

### Author: ![Lectem](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lectem/32/380_2.png) [@Lectem](https://discourse.cmake.org/u/Lectem)
#### Post date: [May 23, 2020, 2:55pm UTC](https://discourse.cmake.org/t/toolchains-multiple-files-generated-by-add-executable/1161/10 "2020-05-23T14:55:27Z")

</div>

Issue opened [20745](https://gitlab.kitware.com/cmake/cmake/-/issues/20745)
