Skip to content

IAR Environment Variables in CMake

Felipe Torrezan edited this page May 2, 2025 · 11 revisions

Introduction

The IAR Embedded Workbench IDE classic project format (*.ewp) provides internal environment variables such as for "Project directory" ($PROJ_DIR$) or for "Product directory" ($TOOLKIT_DIR$). These are called "Argument Variables" and they are not automatically propagated to CMake projects.

Helpful Resources

Description

In your CMakeLists.txt use the following CMake commands after project() to get the corresponding IAR IDE Argument Variables counterparts, assuming that the project is using the C language:

# Get the IAR IDE Argument Variables in CMake
cmake_path(GET CMAKE_C_COMPILER PARENT_PATH COMPILER_DIR)
cmake_path(GET COMPILER_DIR PARENT_PATH TOOLKIT_DIR)
cmake_path(GET TOOLKIT_DIR PARENT_PATH EW_DIR)
set(PROJ_DIR "${PROJECT_SOURCE_DIR}")
set(PROJ_FNAME ${PROJECT_NAME})

Note

Referencing CMake Variables differs syntactically from referencing IAR Argument Variables:

IAR Argument Variable CMake Variable
$VARIABLE_NAME$ ${VARIABLE_NAME}

Example

  • Now you can use these variables to reference those paths and resources in your CMake project. For example:
project(MyProject C ASM)
# ...
# Get the IAR IDE Argument Variables in CMake
# ...
target_link_options(MyTarget1 PRIVATE --semihosting --config ${TOOLKIT_DIR}/config/generic.icf)
# ...
target_link_options(MyTarget2 PRIVATE --semihosting --config ${PROJ_DIR}/${PROJ_FNAME}.icf)

Summary

It is possible to render almost any desired IAR Argument Variables in a CMake project so that its environment becomes more familiar.

Clone this wiki locally