diff --git a/cmake/linker-map.cmake b/cmake/linker-map.cmake new file mode 100644 index 0000000..7544f59 --- /dev/null +++ b/cmake/linker-map.cmake @@ -0,0 +1,12 @@ +set(command ${CMAKE_C_COMPILER} ${flags} -Wl,--version) + + +function(add_linker_map_for_target TARGET) + if (APPLE) + # LLVM only understands this flag. + # The map output differs from GNU ld. + target_link_options(${TARGET} PRIVATE "-Wl,-map,${TARGET}.map") + else() + target_link_options(${TARGET} PRIVATE "-Wl,-Map=${TARGET}.map") + endif() +endfunction() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b0a66d5..dbb0f5b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,12 +1,13 @@ +include(../cmake/linker-map.cmake) ####################################### # NFC example add_executable(nfc nfc.c) -target_link_options(nfc PRIVATE "-Wl,-Map=nfc.map") +add_linker_map_for_target(nfc) target_link_libraries(nfc ${PRODUCT_NAME}) add_executable(nfc_simulator nfc_simulator.c) -target_link_options(nfc_simulator PRIVATE "-Wl,-Map=nfc.map") +add_linker_map_for_target(nfc_simulator) target_link_libraries(nfc_simulator ${PRODUCT_NAME}) ####################################### diff --git a/examples/measurements/CMakeLists.txt b/examples/measurements/CMakeLists.txt index 9e84b51..4c66d1b 100644 --- a/examples/measurements/CMakeLists.txt +++ b/examples/measurements/CMakeLists.txt @@ -1,8 +1,10 @@ +include(../../cmake/linker-map.cmake) + set(measurement_dependencies gpio.c) function(add_measurement name) add_executable(${name} "${name}.c" ${measurement_dependencies}) - target_link_options(${name} PRIVATE "-Wl,-Map=${name}.map") + add_linker_map_for_target(${name}) target_link_libraries(${name} ${PRODUCT_NAME}) endfunction()