Skip to content

IAR Compiler options in a CMake project

Felipe Torrezan edited this page Oct 6, 2025 · 7 revisions

The IAR C/C++ Compiler comes with a vast amount of options that are described in detail in its accompanying Development Guide. Below you will find a non-exhaustive compendium of frequently used options, alongside their respective meanings, where and how you can use them in your CMake projects.

Architecture-agnostic options

Some compiler options are available regardless of the chosen target architecture. Below you will find relevant information.

  • -I <path> specifies a directory that the compiler should search for header files. In CMake, this option can be specified in target_include_directories() where one or more directories can be specified for the target.

  • -D <symbol>[=value] defines a preprocessor symbol. An unspecified value defaults to 1. In CMake, this option can be specified in target_compile_definitions() where one or more symbols can be specified for the target.

  • -r or --debug compiles an object with debug information. That information is relevant for when debugging an executable target with the IAR C-SPY Debugger. In CMake, this option is generally handled by build configurations and its default build configurations for debugging (Debug and RelWithDebInfo) will include it by default.

  • -O[n|l*|m|h|hs|hz] controls the optimization level when compiling the code, from "none" to "high", where -Ol (low) is the default and the same as "none" except for the lifespan of all non-static variables reduced to their scope. In CMake, this option is generally handled by build configurations and information specific to the IAR C/C++ Compiler is available here.

  • -f <filename>.xcl extends the command line with the contents of <filename>.xcl. In CMake, this option is automatically used whenever the resulting command line would otherwise fail for exceeding the operating system's maximum command line length (e.g. when there are way too many long paths).

  • --endian={little*|big} specifies the endianess in the byte order. In CMake, this option can be specified in target_compile_options().

  • --no_wrap_diagnostics will prevent line breaks in compiler diagnostic messages. In CMake, it is a recommended option for environments where these messages will be logged. It can be specified in target_compile_options().

  • --c++ enables C++ source code compilation. In CMake, this option is automatically handled when <LANG> is CXX.

  • --libc++ enables C++ Runtime Library support for C++17. In CMake, this option can be used in target_compile_options().

  • --dlib_config[=gnu|extended|full] is used to select the DLIB C/C++ Runtime Library configuration that the compiler should use. In CMake, this option can be specified in target_compile_options() and apply to C and/or C++ sources. The $<COMPILE_LANGUAGE> generator expression can be used to limit this option to C and C++. Example:

target_compile_options(tgt PRIVATE 
  $<$<COMPILE_LANGUAGE:C,CXX>:--dlib_config=full> # DLIB cannot be used with --libc++
  # other options... )
  • --mfc enables multi-file compilation for compiling multiple files at once. For using it with CMake, refer to Multi-file compilation.

Architecture-specific options

IAR C/C++ Compiler for Arm (iccarm)

Below you will find details about iccarm's options available specifically for Arm targets.

  • --cpu=<core> selects the target CPU (Central Processing Unit) core for which the IAR compiler should generate code. The command iccarm --cpu=list reveals a list of accepted <core> parameters. The default <core> is cortex-m3. In CMake, this option can be specified in target_compile_options(). Example:
target_compile_options(tgt PRIVATE 
  --cpu=cortex-m7 
  # other options... )
  • --fpu=<type> is used to select the target FPU (Floating Point Unit) for which the IAR compiler should generate code. The command iccarm --fpu=list reveals a list of accepted <type> parameters. The default <type> is none. In CMake, this option can be specified in target_compile_options(). Example:
target_compile_options(tgt PRIVATE 
  --fpu=VFPv5_SP # Single-precision variant 5 FPU
  # other options... )

IAR C/C++ Compiler for RISC-V (iccriscv)

Below you will find details about iccriscv's options available specifically for RISC-V targets.

  • --core=<core_spec> selects the target CPU core specification, including its standard and vendor extensions (e.g. RV32IMFDCN), for which the IAR compiler should generate code. The default <core_spec> is RV32IM. In CMake, this option can be specified in target_compile_options(). Example:
target_compile_options(tgt PRIVATE 
  --core=RV32IMAC
  # other options... )

IAR C/C++ Compiler for Renesas RL78 (iccrl78)

Below you will find details about iccrl78's options available specifically for Renesas RL78 targets.

  • --core=[s1|s2|s3*] selects the target RL78 CPU core for which the IAR compiler should generate code. In CMake, this option can be specified in target_compile_options().

IAR C/C++ Compiler for Renesas RX (iccrx)

Below you will find details about iccrx's options available specifically for Renesas RX targets.

  • --core=[rxv1*|rxv2|rxv3] selects the target RX CPU core for which the IAR compiler should generate code. In CMake, this option can be specified in target_compile_options().

Related resources

Clone this wiki locally