Skip to content

Commit 64d82d8

Browse files
author
Felipe Torrezan
authored
Documentation update (#15)
- Better highlight on what needs to be changed in the toolchain file - Using in-place references for source code in the minimal project and toolchain file - Added ready-to-use hello-world in examples/arm
1 parent 2c476dc commit 64d82d8

3 files changed

Lines changed: 46 additions & 40 deletions

File tree

README.md

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ To build a project developed with the IAR Compiler using CMake we need at least
3333
### Configuring the toolchain file
3434
By default, CMake uses what it assumes to be the host platform's default compiler. When the application targets an embedded platform (known as cross-compiling), a toolchain file `<toolchain-file>.cmake` can be used to indicate the desired toolchain's location for its compiler and assembler. This section provides a simple generic template for the __IAR C/C++ Compilers__.
3535

36-
On the [examples/iar-toolchain.cmake](examples/iar-toolchain.cmake) file from the repository you have cloned, perform the following changes to match your system:
37-
* Update [__CMAKE_SYSTEM_PROCESSOR__](examples/iar-toolchain.cmake#L5) replacing `<arch>` by the corresponding compiler's target architecture: `430`, `8051`, `arm`, `avr`, `riscv`, `rx`, `rh850`, `rl78`, `stm8` or `v850`.
36+
On the example toolchain file from the repository you have cloned, set the following variables to match the product installed in your system:
37+
* Set `CMAKE_SYSTEM_PROCESSOR`:
3838

39-
* Update [__IAR_INSTALL_DIR__](examples/iar-toolchain.cmake#L8) to match the corresponding location where the active product was __installed__ on __your__ system, adjusting as needed.
39+
https://github.com/IARSystems/cmake-tutorial/blob/2c476dc240bf2c0c86bf144863eccdba0c0d38de/examples/iar-toolchain.cmake#L3-L5
40+
41+
* Set `IAR_INSTALL_DIR`:
42+
43+
https://github.com/IARSystems/cmake-tutorial/blob/2c476dc240bf2c0c86bf144863eccdba0c0d38de/examples/iar-toolchain.cmake#L7-L8
4044

4145
<details> <summary><b>Notes on IAR_INSTALL_DIR</b> (Click to unfold)</summary>
4246

@@ -52,48 +56,23 @@ On the [examples/iar-toolchain.cmake](examples/iar-toolchain.cmake) file from th
5256
5357
</details>
5458

55-
### Configuring a minimal project
56-
A project is defined by one or more CMakeLists.txt file(s). Let's understand how a project can be configured with a simple example for the Arm target architecture.
59+
### A minimal project
60+
A CMake project is defined by one or more CMakeLists.txt file(s). Let's understand how a simple `hello-world` project can be configured for the Arm target architecture.
5761

58-
* Inside the [examples/arm](examples/arm) directory, create a new subdirectory named __hello-world__:
62+
* Change to the `hello-world` project:
5963
```
60-
> cd /path/to/cmake-tutorial/examples/arm
61-
> mkdir hello-world
62-
> cd hello-world
63-
```
64-
* Create the __CMakeLists.txt__ file:
65-
```cmake
66-
# CMake requires to set its minimum required version
67-
cmake_minimum_required(VERSION 3.23)
68-
69-
# Set the project name, enabling its required languages (e.g. ASM, C and/or CXX)
70-
project(simpleProject LANGUAGES C)
71-
72-
# Add a executable target named "hello-world"
73-
add_executable(hello-world
74-
# Target sources
75-
main.c)
76-
77-
# Set the target's compiler options
78-
target_compile_options(hello-world PRIVATE --cpu=Cortex-M4 --fpu=VFPv4_sp --dlib_config normal)
79-
80-
# Set the target's linker options
81-
target_link_options(hello-world PRIVATE --semihosting --config ${TOOLKIT_DIR}/config/linker/ST/stm32f407xG.icf)
64+
cd /path/to/cmake-tutorial/examples/arm/hello-world
8265
```
66+
67+
* Verify the contents of the __CMakeLists.txt__ file:
68+
69+
https://github.com/IARSystems/cmake-tutorial/blob/985f597765bd1186867b4157af3d1afde6531943/examples/arm/hello-world/CMakeLists.txt#L1-L16
70+
8371
> :bulb: Adjust the target compile/link options for architectures other than __arm__.
8472
85-
* Finally create a simple __main.c__ source file:
86-
```c
87-
#include <intrinsics.h>
88-
#include <stdio.h>
89-
90-
void main() {
91-
while (1) {
92-
printf("Hello world!\n");
93-
__no_operation();
94-
}
95-
}
96-
```
73+
* Verify the contents of the __main.c__ source file:
74+
75+
https://github.com/IARSystems/cmake-tutorial/blob/985f597765bd1186867b4157af3d1afde6531943/examples/arm/hello-world/main.c#L1-L9
9776

9877
### Configuring the build system generator
9978
Once we have our minimal project with a suitable toolchain file, we invoke CMake to configure our build environment for when cross-compiling, choosing which _build system generator_ and which _toolchain file_ should be used for the project.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# CMake requires to set its minimum required version
2+
cmake_minimum_required(VERSION 3.23)
3+
4+
# Set the project name, enabling its required languages (e.g. ASM, C and/or CXX)
5+
project(simpleProject LANGUAGES C)
6+
7+
# Add a executable target named "hello-world"
8+
add_executable(hello-world
9+
# Target sources
10+
main.c)
11+
12+
# Set the target's compiler options
13+
target_compile_options(hello-world PRIVATE --cpu=Cortex-M4 --fpu=VFPv4_sp --dlib_config normal)
14+
15+
# Set the target's linker options
16+
target_link_options(hello-world PRIVATE --semihosting --config ${TOOLKIT_DIR}/config/linker/ST/stm32f407xG.icf)
17+

examples/arm/hello-world/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <intrinsics.h>
2+
#include <stdio.h>
3+
4+
void main() {
5+
while (1) {
6+
printf("Hello world!\n");
7+
__no_operation();
8+
}
9+
}
10+

0 commit comments

Comments
 (0)