Setting language‐specific target options - IARSystems/cmake-tutorial GitHub Wiki

Introduction

When a CMake target uses multiple programming languages, the Assembler and the Compiler might require different options.

Applies to

  • CMake targets using multiple programming languages.

Description

A CMake target composed of mixed Assembly and C source code where the C portion of the application would require to be compiled with the full C Runtime Library (for its complete printf() capabilities), generator expressions (or simply "genex") can be used to specify that this option is only applicable when compiling C source files:

  • CMakeLists.txt:
target_compile_options(myTarget PRIVATE 
  $<$<COMPILE_LANGUAGE:C>:--dlib_config full> --cpu=cortex-m4)

In the above example C source files built for myTarget will be compiled with the full runtime library option and the CPU option whereas any Assembly source files will only get the CPU option.