You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-31Lines changed: 32 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,17 +2,18 @@
2
2
3
3
CMake is an open-source, cross-platform family of tools maintained and supported by Kitware. Among its many features, it essentially provides [Makefile Generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#id11) and [Ninja Generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#id12) which compose scripts for cross-compiling C/C++ embedded software projects based on one or more `CMakeLists.txt` configuration files.
4
4
5
-
This tutorial offers a short introduction for those seeking information on how to start using the IAR C/C++ Compiler together with CMake from the command line. While this guide is based on the IAR Build Tools for Arm version 9.50.1 on Linux, it should work with other supported IAR products with no or minimal changes.
5
+
This tutorial offers a short introduction for those seeking information on how to start using the IAR C/C++ Compiler together with CMake from the command line. While this guide is based on the IAR Build Tools for Arm (CXARM) 9.60.4 on Linux, it should work with other supported IAR products with no or minimal changes.
6
6
7
7
## Prerequisites
8
8
Before you begin, you will need to download and install the IAR product, CMake and then clone this repository.
9
9
10
10
1) Download, install and activate[^1] your IAR product
| IAR Build Tools |[Contact us](https://iar.com/about/contact)|[for Arm](https://updates.iar.com/?product=BXARM) (or for others[^2]) |
15
-
| IAR Embedded Workbench |[Download](https://www.iar.com/products/free-trials/)|[for Arm](https://updates.iar.com/?product=EWARM) (or for others[^2]) |
12
+
| Product | Evaluation | IAR Subscribers (login required)
13
+
| - | - | -
14
+
| IAR Build Tools (CX) ☁️ | [Contact us](https://iar.com/about/contact) | [for Arm](https://updates.iar.com/?product=CXARM) (or for others[^2])
15
+
| IAR Build Tools (BX) | [Contact us](https://iar.com/about/contact) | [for Arm](https://updates.iar.com/?product=BXARM) (or for others[^2])
16
+
| IAR Embedded Workbench | [Try now](https://www.iar.com/embedded-development-tools/free-trials) | [for Arm](https://updates.iar.com/?product=EWARM) (or for others[^2])
16
17
17
18
2) Download and install [CMake](https://github.com/Kitware/CMake/releases/latest).
CMake uses the host platform's default compiler. When cross-compiling embedded applications, the compiler must be set manually via [`CMAKE_<lang>_COMPILER`](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html) variables for each supported language. Additionally, it is possible to specify a build tool via [`CMAKE_MAKE_PROGRAM`]():
60
61
61
-
| Variable | Description | Examples |
62
-
| - | - | -|
63
-
|`CMAKE_C_COMPILER`| Must point to the C Compiler executable |`"C:/Program Files/..../arm/bin/iccarm.exe"`<br>`"/opt/iarsystems/bxarm/arm/bin/iccarm"`|
64
-
|`CMAKE_CXX_COMPILER`| Must point to the C++ Compiler executable |`"C:/Program Files/..../arm/bin/iccarm.exe"`<br>`"/opt/iarsystems/bxarm/arm/bin/iccarm"`|
65
-
|`CMAKE_ASM_COMPILER`| Must point to the Assembler executable |`"C:/Program Files/..../arm/bin/iasmarm.exe"`<br>`"/opt/iarsystems/bxarm/arm/bin/iasmarm"`|
66
-
|`CMAKE_MAKE_PROGRAM`| Must point to the build tool executable |`"C:/Program Files/..../common/bin/ninja.exe"`<br>`"/opt/iarsystems/bxarm/common/bin/ninja"`|
62
+
| Variable | Description | Examples (for Arm)
63
+
| - | - | -
64
+
| `CMAKE_C_COMPILER` | Must point to the C Compiler executable | `"/opt/iar/cxarm/arm/bin/iccarm"`<br>`"/opt/iarsystems/bxarm/arm/bin/iccarm"`<br>`"C:/iar/..../arm/bin/iccarm.exe"`
65
+
| `CMAKE_CXX_COMPILER` | Must point to the C++ Compiler executable | `"/opt/iar/cxarm/arm/bin/iccarm"`<br>`"/opt/iarsystems/bxarm/arm/bin/iccarm"`<br>`"C:/iar/..../arm/bin/iccarm.exe"`<br>`"${CMAKE_C_COMPILER}"`
66
+
| `CMAKE_ASM_COMPILER` | Must point to the Assembler executable | `"/opt/iar/cxarm/arm/bin/iasmarm"`<br>`"/opt/iarsystems/bxarm/arm/bin/iasmarm"`<br>`"C:/iar/..../arm/bin/iasmarm.exe"`
67
+
| `CMAKE_MAKE_PROGRAM` | Must point to the build tool executable | `"/opt/iar/cxarm/common/bin/ninja"`<br>`"/opt/iarsystems/bxarm/common/bin/ninja"`<br>`"C:/iar/..../common/bin/ninja.exe"`
67
68
68
69
During the configuration phase, CMake reads these variables from:
69
-
- a separate file called "toolchain file" that you invoke `cmake` with `--toolchain /path/to/<filename>.cmake` (see provided example files [bxarm.cmake](tutorial/bxarm.cmake) and [ewarm.cmake](tutorial/ewarm.cmake)) -or-
70
-
- the [`CMAKE_TOOLCHAIN_FILE`](https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html) variable, when you invoke `cmake` with `-DCMAKE_TOOLCHAIN_FILE=/path/to/<filename>.cmake` (useful for earlier CMake versions) -or-
70
+
- a separate file called "toolchain file" that you invoke `cmake` with `--toolchain /path/to/<filename>.cmake` (see provided example files [cxarm.cmake](tutorial/cxarm.cmake), [bxarm.cmake](tutorial/bxarm.cmake) and [ewarm.cmake](tutorial/ewarm.cmake)) -or-
71
+
- the [`CMAKE_TOOLCHAIN_FILE`](https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html) variable, when you invoke `cmake` with `-DCMAKE_TOOLCHAIN_FILE=/path/to/<filename>.cmake` (useful CMake < 3.21) -or-
71
72
- invoking `cmake` with `-DCMAKE_<lang>_COMPILER=/path/to/icc<target>` -or-
72
73
- the user/system environment variables [`CC`](https://cmake.org/cmake/help/latest/envvar/CC.html), [`CXX`](https://cmake.org/cmake/help/latest/envvar/CXX.html) and [`ASM`](https://cmake.org/cmake/help/latest/envvar/ASM.html) which can be used to override the platform's default compiler -or-
73
74
- the IAR Embedded Workbench IDE 9.3 or later, shipped with IAR products starting from the IAR Embedded Workbench for Arm 9.50, where the available IAR toolchain environment is automatically set for CMake projects (See [this article](https://github.com/IARSystems/cmake-tutorial/wiki/Building-and-Debugging-from-the-Embedded-Workbench) for details).
74
75
75
76
### Configure and Build
76
77
We are ready to build our first project! Run CMake to configure the project and then build it with your chosen build tool.
77
78
78
-
- Before starting to use CMake, make sure your compiler is working and does not run into any [license issues](#issues). Example (for Arm):
79
+
- Before starting to use CMake, make sure your compiler is working properly. Example (for Arm):
79
80
```
80
81
/path/to/iccarm --version
81
82
```
@@ -85,10 +86,10 @@ We are ready to build our first project! Run CMake to configure the project and
85
86
mkdir build
86
87
```
87
88
88
-
- Next, navigate to that build directory and run CMake to configure the project and generate a native build system using the compiler specified in the `bxarm.cmake` toolchain file (if needed, edit the supplied toolchain file to match your tool):
89
+
- Next, navigate to that build directory and run CMake to configure the project and generate a native build system using the compiler specified in the `cxarm.cmake` toolchain file (if needed, edit the supplied toolchain file to match your tool):
89
90
```
90
91
cd build
91
-
cmake .. -G Ninja --toolchain ../bxarm.cmake
92
+
cmake .. -G Ninja --toolchain ../cxarm.cmake
92
93
```
93
94
94
95
- Then call CMake for building the executable using the build system:
@@ -100,19 +101,19 @@ cmake --build .
100
101
Let's test the application. To run the executable you will need the non-interactive[^3] command line interface for the IAR C-SPY Debugger (`cspybat`) with the proper drivers for the desired target. Amongst the many ways of accomplishing this, let's take advantage of the `add_test()` for testing the application in a Arm Cortex-M4 simulated target.
101
102
102
103
This section is interactive. In this example we will use Arm. So, you will need to update your Tutorial's `CMakeLists.txt`:
103
-
- Firstly add [`enable_testing()`](https://cmake.org/cmake/help/latest/command/enable_testing.html#command:enable_testing) to enable testing:
104
+
- Firstly add [`enable_testing()`](https://cmake.org/cmake/help/latest/command/enable_testing.html) to enable testing:
104
105
```cmake
105
106
enable_testing()
106
107
```
107
108
108
-
- Then use [`add_test()`](https://cmake.org/cmake/help/latest/command/add_test.html#add-test) to encapsulate the command line `cspybat` needs. In the example below, the parameters are adjusted for simulating a generic Arm Cortex-M4 target environment:
109
+
- Then use [`add_test()`](https://cmake.org/cmake/help/latest/command/add_test.html) to encapsulate the command line `cspybat` needs. In the example below, the parameters are adjusted for simulating a generic Arm Cortex-M4 target environment:
109
110
```cmake
110
111
add_test(NAME tutorialTest
111
-
COMMAND /opt/iarsystems/bxarm/common/bin/CSpyBat
112
+
COMMAND /opt/iar/cxarm/common/bin/CSpyBat
112
113
# C-SPY drivers for the Arm simulator via command line interface
# The target executable (built with debug information)
117
118
--debug_file=$<TARGET_FILE:tutorial>
118
119
# C-SPY driver options
@@ -123,7 +124,7 @@ add_test(NAME tutorialTest
123
124
>[!TIP]
124
125
>- Read this [article](https://github.com/iarsystems/cmake-tutorial/wiki/CTest-with-IAR-Embedded-Workbench-for-Arm) for the specifics when driving tests from IAR Embedded Workbench for Arm.
125
126
126
-
- Now use the [`PASS_REGULAR_EXPRESSION`](https://cmake.org/cmake/help/latest/prop_test/PASS_REGULAR_EXPRESSION.html#prop_test:PASS_REGULAR_EXPRESSION) test property to validate if the program emits the expected string to the standard output (`stdout`). In this case, verifying that `printf()` prints the expected message.
127
+
- Now use the [`PASS_REGULAR_EXPRESSION`](https://cmake.org/cmake/help/latest/prop_test/PASS_REGULAR_EXPRESSION.html) test property to validate if the program emits the expected string to the standard output (`stdout`). In this case, verifying that `printf()` prints the expected message.
- And finally we call CMake's [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html#manual:ctest(1)) which subsequently will execute `Tutorial.elf` using the IAR C-SPY Debugger for Arm:
137
+
- And finally we call CMake's [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html) which subsequently will execute `Tutorial.elf` using the IAR C-SPY Debugger for Arm:
137
138
```
138
139
ctest
139
140
```
@@ -151,7 +152,7 @@ For technical support contact [IAR Customer Support][url-iar-customer-support].
151
152
152
153
For questions related to this tutorial: try the [wiki][url-repo-wiki] or check [earlier issues][url-repo-issue-old]. If those don't help, create a [new issue][url-repo-issue-new] with detailed information.
153
154
154
-
[^1]: For more information, see the "Installation and Licensing" guide for your product. If you do not have a license, [contact us](https://iar.com/about/contact).
155
+
[^1]: For more information, see the "Installation and Licensing" guide for your product. If you are not a subscriber yet, [contact us](https://iar.com/about/contact).
155
156
[^2]: CMake has built-in IAR C/C++ Compiler support for the following non-Arm architectures: 8051, AVR, MSP430, RH850, RISC-V, RL78, RX, STM8 and V850.
156
157
[^3]: For interactively debugging of executable files (`*.elf`) using the C-SPY Debugger from the IAR Embedded Workbench IDE, read [this wiki article][url-wiki-ide-build-debug].
157
158
@@ -162,11 +163,11 @@ For questions related to this tutorial: try the [wiki][url-repo-wiki] or check [
0 commit comments