# Suggested way to add mapfile output to a project with multiple target toolchains?

**URL:** https://discourse.cmake.org/t/suggested-way-to-add-mapfile-output-to-a-project-with-multiple-target-toolchains/2342
**Category:** Code
**Created:** [December 10, 2020, 7:45pm UTC](https://discourse.cmake.org/t/suggested-way-to-add-mapfile-output-to-a-project-with-multiple-target-toolchains/2342 "2020-12-10T19:45:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Russell\_Schultz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/russell_schultz/32/282_2.png) [@Russell\_Schultz](https://discourse.cmake.org/u/Russell_Schultz)
#### Post date: [December 10, 2020, 7:45pm UTC](https://discourse.cmake.org/t/suggested-way-to-add-mapfile-output-to-a-project-with-multiple-target-toolchains/2342/1 "2020-12-10T19:45:33Z")

</div>

I have a multi-toolchain development environment (IAR-ARM, MSVC, and Tensilica-Clang) and mapfile are invaluable to embedded development.

In each toolchain file, I’m able to set default linker flags, etc, but in general the argument required for the mapfile flag requires a filename. I can put a fixed filename (like output.map), but that doesn’t work very well.

Because cmake/ninja runs at the root of the build directory that’s where the mapfile ends up. I’d prefer to make it show up next to the output binary with the same name, but .map.

I’ve yet to find a way to add to CMAKE\_EXE\_LINKER\_FLAGS something that takes into account “current output directory” or anything like that.

How do I do this, without wrapping add\_exectuable() and adding the toolchain specific flag based on the toolchain in use?

---

<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: [December 11, 2020, 2:31pm UTC](https://discourse.cmake.org/t/suggested-way-to-add-mapfile-output-to-a-project-with-multiple-target-toolchains/2342/2 "2020-12-11T14:31:55Z")

</div>

[This thread](https://discourse.cmake.org/t/how-to-get-listing-file-when-cross-compile/2297/5) (and that reply in particular) is probably what you’re looking for.

---

<div class="post-metadata">

### Author: ![Russell\_Schultz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/russell_schultz/32/282_2.png) [@Russell\_Schultz](https://discourse.cmake.org/u/Russell_Schultz)
#### Post date: [December 11, 2020, 2:59pm UTC](https://discourse.cmake.org/t/suggested-way-to-add-mapfile-output-to-a-project-with-multiple-target-toolchains/2342/3 "2020-12-11T14:59:47Z")

</div>

Maybe. I’ve found that generator expressions aren’t expanded in CMAKE\_EXE\_LINKER\_FLAGS.

set(CMAKE\_EXE\_LINKER\_FLAGS “–std=c++11 -Wl,-Map=$\<TARGET\_FILE\_DIR:tgt\>mapfile.map”)

leads to

`[build] cmd.exe /C "cd . && C:\usr\xtensa\XtDevTools\install\tools\RI-2020.4-win32\XtensaTools\bin\xt-clang++.exe -Os -g --std=c++11 -Wl,-Map=$<TARGET_FILE_DIR:tgt>mapfile.map modules/heaps/simple_allocator/tests/test1/CMakeFiles/simple_allocator_test1_reference.dir/src/simple_allocator_test.cpp.obj -o modules\heaps\simple_allocator\tests\test1\simple_allocator_test1_reference.elf test_framework/google_test/libgtest_rtos_main.a modules/heaps/simple_allocator/libsimple_allocator_reference.a test_framework/google_test/libgtest_core.a modules/rtos/librtos.a modules/rtos/librtos_freertos_hifi5.a modules/rtos/rtos_submodules/freertos/libfreertos_hifi5.a modules/heaps/allocator/liballocator_reference.a && cd ."`

Am I doing something wrong?
