Skip to content

Displaying the IAR Linker summary

Felipe Torrezan edited this page Jan 28, 2024 · 6 revisions

Introduction

Starting from CMake 3.27.0 onwards, the linker's --silent flag is not hardcoded. Sometimes it is convenient to get the linker's resource consumption summary when building with CMake. A CMake option can be used for such purpose.

Description

By default, CMake will suppress the output provided by the underlying tools. For example, when building with "Unix Makefiles":

$ cmake --build build
-- The C compiler identification is IAR ARM 9.40.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/iarsystems/bxarm/arm/bin/iccarm - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done (1.6s)
-- Generating done (0.1s)
-- Build files have been written to: /.../cmake-tutorial/examples/arm/hello-world/build
[ 50%] Building C object CMakeFiles/hello-world.dir/main.o
[100%] Linking C executable hello-world.elf
[100%] Built target hello-world

Modifying the toolchain file

To display the summary by default, append the following snippet to the toolchain file:

option(ISPLAY_LINKER_SUMMARY "Display linker resource usage" ON)
if(ISPLAY_LINKER_SUMMARY)
  string(REGEX REPLACE "(^| )(--silent|-S)($| )" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
endif()

Result

When building a project using the the option snippet.

$ cmake --build build
-- The C compiler identification is IAR ARM 9.40.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/iarsystems/bxarm/arm/bin/iccarm - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done (1.6s)
-- Generating done (0.1s)
-- Build files have been written to: /.../cmake-tutorial/examples/arm/hello-world/build
[ 50%] Building C object CMakeFiles/hello-world.dir/main.o
[100%] Linking C executable hello-world.elf

   IAR ELF Linker V9.32.2.340/LNX for ARM BX
   Copyright 2007-2023 IAR Systems AB.

  1'006 bytes of readonly  code memory
     46 bytes of readonly  data memory
  8'200 bytes of readwrite data memory

Errors: none
Warnings: none

Link time:   0.01 (CPU)   0.03 (elapsed)
[100%] Built target hello-world

Temporarily disabling the summary

CMake options are cached durign the configuration stage. One method to temporarily disable the ISPLAY_LINKER_SUMMARY option:

  1. Remove build/CMakeCache.txt.
  2. Re-configure the toolchain with the option turned off:
$ cmake -Bbuild -DISPLAY_LINKER_SUMMARY=OFF --toolchain ../../iar-toolchain.cmake
-- The C compiler identification is IAR ARM 9.40.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/iarsystems/bxarm/arm/bin/iccarm - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done (1.5s)
-- Generating done (0.1s)
-- Build files have been written to: /.../cmake-tutorial/examples/arm/hello-world/build
  1. Rebuild the project:
$ cmake --build build --clean-first
[ 50%] Building C object CMakeFiles/hello-world.dir/main.o
[100%] Linking C executable hello-world.elf
[100%] Built target hello-world

Clone this wiki locally