Building and Debugging from the Embedded Workbench - iarsystems/cmake-tutorial GitHub Wiki
Introduction
CMake projects can be built and debugged directly from the IAR Embedded Workbench IDE according to the table below.
Product | Product Version | Shared ComponentsVersion | Release Date | Comment |
---|---|---|---|---|
IAR Embedded Workbench for Arm | v9.60.2 | v9.3.5.864 | September 3, 2024 | CMake oficially supported for importing, building, analyzing, and debugging projects directly from within the IAR Embedded Workbench IDE. |
IAR Embedded Workbench for Arm | v9.50.1 | v9.3.2.391 | December 7, 2023 | Initial experimental CMake support in the IAR Embedded Workbench IDE. |
Helpful Resources
Description
For using CMake projects with the IDE you will need CMake version 3.26 or later. It has to be installed separately, before launching the IDE.
The IDE does not require a toolchain file. This is automatically handled by the IDE.
Procedure
Creating a new CMake project from the IDE
- Choose Project → Create New Project in the main menu.
- Choose the CMake for Arm "Tool chain".
- Finally choose the desired "Project template" (e.g.,
CMake
).
- Save the project file as
<project-name>.ewp
. - Save the workspace as
<workspace-name>.eww
.
Notice that the CMake template project comes with a main.c
source and a CMakeLists.txt
project:
- Choose a build configuration containing debug information:
- Build and Debug the project with the IAR C-SPY Simulator (Project → Download and Debug (
CTRL
+D
)).
Opening an existing CMake project from the IDE
The Tutorial
project from the cmake-tutorial repository will be used:
- Choose Project → Create New Project in the main menu.
- Choose the CMake for Arm "Tool chain".
- Choose Import CMakeLists.txt.
- Nagivate to an existing project's top-level CMakeLists.txt (e.g.,
/path/to/cmake-tutorial/tutorial/CMakeLists.txt
) and Open it.
-
Save the project file as
tutorial.ewp
. -
Make sure a build configuration containing debug information is selected:
- Build and Debug the project with the IAR C-SPY Simulator (Project → Download and Debug (
CTRL
+D
)). - Save the workspace as
tutorial.eww
.
Analyzing the project with the IAR C-STAT
IAR C-STAT is a code quality analysis add-on that can be enabled for the IAR Embedded Workbench or for the IAR Build Tools.
- Terminate the debugging session (Debug → Stop Debugging (
CTRL
+SHIFT
+D
)). - Right-click on the project name and choose Options....
- In the project options, under Static Analysis, choose Select C-STAT Checks.
- Enable MISRAC2012 and close the window by clicking
OK
. - Click
OK
once more to close the Options for node "tutorial" window.
- Right-click on the project name and choose C-STAT Static Analysis → Analyze project.
The C-STAT Messages window will show up with a list of detected MISRA C violations this project contains. Double clicking on each message will take the code editor to the offending line:
- Select any of the messages and hit
F1
for online help with the full description for the violation:
Tweaking CMake tool configurations
You can find a new options page dedicated to the CMake configuration details, under Project → Options → CMake/CMSIS-Toolbox → CMake:
The "Override tools in env" frame allows you to set CC
, CXX
and ASM
to use earlier versions of the IAR C/C++ Compiler while still using the current IDE and its debugger.
[!IMPORTANT] When overriding the tools using these environment variables, CMake automatically switches to the corresponding linker found in the same path as the selected compiler.
Summary
Starting from IAR Embedded Workbench for Arm version 9.50.1, it is possible to build, analyze and debug CMake projects directly from the IDE.