-
Notifications
You must be signed in to change notification settings - Fork 19
IAR Environment Variables in CMake
Felipe Torrezan edited this page Feb 21, 2024
·
11 revisions
The IAR Embedded Workbench IDE provides environment variables such as for "Project directory" ($PROJ_DIR$) or for "Product directory" ($TOOLKIT_DIR$) for classic projects. These are called "Argument Variables". As per IAR Embedded Workbench for Arm 9.50.1, these Argument Variables are not propagated to CMake projects.
- IAR Argument Variables
get_filename_component()CMAKE_<lang>_COMPILERPROJECT_SOURCE_DIRset()unset()
It is possible to use CMake Variables to mimic any desired IAR Argument Variables in a CMake Project so that its environment becomes more familiar.
Notice that referencing IAR Argument Variables is syntactically different from referencing CMake Variables:
| IAR Argument Variable | CMake Variable |
|---|---|
$VARIABLE_NAME$ |
${VARIABLE_NAME} |
- In your
CMakeLists.txtset the following snippet to extract the parent directory of the selected compiler:
# Set the TOOLKIT_DIR variable for the CMakeLists
get_filename_component(BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
get_filename_component(TOOLKIT_DIR ${BIN_DIR} PATH)
unset(BIN_DIR)- Then you can use the
${TOOLKIT_DIR}variable to reference that directory in your CMake project. For example:
target_link_options(MyTarget PRIVATE --semihosting --config ${TOOLKIT_DIR}/config/generic.icf)- In CMake,
PROJECT_SOURCE_DIRcan be used to emulatePROJ_DIR:
set(PROJ_DIR ${PROJECT_SOURCE_DIR})- Then you can simply use the
${PROJ_DIR}variable to reference that directory in your CMake project. For example:
target_link_options(MyTarget PRIVATE --semihosting --config ${PROJ_DIR}/MyCustomLinkerConfiguration.icf)This is the cmake-tutorial wiki. Back to Wiki Home
- IAR Compiler options in a CMake project
- IAR ILINK options in a CMake project
- Language-specific target options
- Selecting build types
- Using Ninja Multi-Config
- Filing a build log
- Multi-file compilation
- Invoking IAR binary utilities
- Use the IAR ELF Tool to convert executable targets to their binary formats
- Using IAR Build Tools with CMake Presets