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

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, 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?

This thread (and that reply in particular) is probably what you’re looking for.

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>”)

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> 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?