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
+87-27Lines changed: 87 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,13 @@
1
1
# Arduino CMake Toolchain
2
2
3
-
**Arduino CMake toolchain** is a CMake toolchain for cross-compiling CMake based projects for all Arduino compatible boards (AVR, ESP32 etc.). Of course, this means all the benefits of CMake for Arduino compilation, like using your favourite IDE, configuration checks (e.g. `try_compile`, `CheckTypeSize`), etc. This also brings the Arduino compilation to professional users, who are limited by the Arduino IDE compilation.
3
+
**Arduino CMake toolchain** is a CMake toolchain for cross-compiling CMake based projects for all Arduino compatible
4
+
boards (AVR, ESP32 etc.). Of course, this means all the benefits of CMake for Arduino compilation, like using your
5
+
favourite IDE, configuration checks (e.g. `try_compile`, `CheckTypeSize`), etc. This also brings the Arduino compilation
6
+
to professional users, who are limited by the Arduino IDE compilation.
- Generate build_opts.h file in cmake binary dear to pass cpp compiler check
22
+
- Generate build_opts.h file in cmake binary dear to pass cpp compiler check
20
23
21
24
## Project Roots
22
25
23
-
[Arduino-CMake-NG](https://github.com/arduino-cmake/Arduino-CMake-NG) is a great project, which could have prevented me from writing yet another Arduino CMake toolchain. However, as claimed by the project, Arduino-CMake-NG could not be easily utilized/modified for other Arduino compatible boards other than AVR, like ESP32, due to the fact that it does not fully work the way Arduino IDE works and has lot of AVR specific stuff. An other important limitation is related to portability. Arduino-CMake-NG provides Arduino specific CMake interface, requiring CMake scripts to be written/modified specifically for Arduino, rather than just passing `-D CMAKE_TOOLCHAIN_FILE=/path/to/Arduino-toolchain.cmake` to a generic CMake project.
26
+
[Arduino-CMake-NG](https://github.com/arduino-cmake/Arduino-CMake-NG) is a great project, which could have prevented me
27
+
from writing yet another Arduino CMake toolchain. However, as claimed by the project, Arduino-CMake-NG could not be
28
+
easily utilized/modified for other Arduino compatible boards other than AVR, like ESP32, due to the fact that it does
29
+
not fully work the way Arduino IDE works and has lot of AVR specific stuff. An other important limitation is related to
30
+
portability. Arduino-CMake-NG provides Arduino specific CMake interface, requiring CMake scripts to be written/modified
31
+
specifically for Arduino, rather than just passing `-D CMAKE_TOOLCHAIN_FILE=/path/to/Arduino-toolchain.cmake` to a
32
+
generic CMake project.
24
33
25
-
My initial expectation was to contribute to Arduino-CMake-NG to fix the above limitations, but had to redo a lot of core logic making it very incompatible (including the usage). Also, the project Arduino-CMake-NG seems to be no longer maintained. I would like to acknowledge the authors who contributed directly/indirectly to Arduino-CMake-NG, and thus indirectly contributed to this project.
34
+
My initial expectation was to contribute to Arduino-CMake-NG to fix the above limitations, but had to redo a lot of core
35
+
logic making it very incompatible (including the usage). Also, the project Arduino-CMake-NG seems to be no longer
36
+
maintained. I would like to acknowledge the authors who contributed directly/indirectly to Arduino-CMake-NG, and thus
37
+
indirectly contributed to this project.
26
38
27
39
## Features
28
40
29
41
-[x] CMake Arduino toolchain (passed to CMake using `-D CMAKE_TOOLCHAIN_FILE=/path/to/Arduino-toolchain.cmake)`
30
42
-[x] Support for all Arduino compatible platforms (such as **AVR**, **ESP32** etc.)
31
43
-[x] Generic CMake scripting interface without requiring Arduino specific functions
32
44
-[x] Arduino IDE compatible build (e.g. use of build rules and flags in board.local.txt, pre/postbuild hooks etc.)
33
-
-[x] Selection of board and board-specific menu options as in Arduino IDE tools menu (See `ARDUINO_BOARD_OPTIONS_FILE`)
45
+
-[x] Selection of board and board-specific menu options as in Arduino IDE tools menu (
46
+
See `ARDUINO_BOARD_OPTIONS_FILE`)
34
47
-[x] Generate Arduino HEX binaries and upload to Arduino boards (See `target_enable_arduino_upload`)
35
48
-[x] Upload using serial port
36
49
-[x] Remote provisioning through network
@@ -52,27 +65,46 @@ The provided toolchain file (Arduino-toolchain.cmake) is passed to cmake as folo
Note: As this is cross compilation, use any cross compilation compatible generator, like makefile generators (e.g. `-G "NMake Makefiles"` or `-G "MinGW Makefiles"` on Windows command prompt or `-G "Unix Makefiles"` on UNIX compatible prompts etc.).
56
68
57
-
The above command generates a file **BoardOptions.cmake** in the build directory, that enumerates all the installed Arduino boards (installed through Arduino IDE or any other board manager) and their menu options. Select the Arduino board and any non-default options for the board from the BoardOptions.cmake (Or from cmake-gui), and then reinvoke the same command above.
69
+
Note: As this is cross compilation, use any cross compilation compatible generator, like makefile generators (
70
+
e.g. `-G "NMake Makefiles"` or `-G "MinGW Makefiles"` on Windows command prompt or `-G "Unix Makefiles"` on UNIX
71
+
compatible prompts etc.).
58
72
59
-
If you already have a customized BoardOptions.cmake file for the Arduino Board, you can use that instead, without waiting for the generation of BoardOptions.cmake, as given below.
73
+
The above command generates a file **BoardOptions.cmake** in the build directory, that enumerates all the installed
74
+
Arduino boards (installed through Arduino IDE or any other board manager) and their menu options. Select the Arduino
75
+
board and any non-default options for the board from the BoardOptions.cmake (Or from cmake-gui), and then reinvoke the
76
+
same command above.
77
+
78
+
If you already have a customized BoardOptions.cmake file for the Arduino Board, you can use that instead, without
79
+
waiting for the generation of BoardOptions.cmake, as given below.
1. After the cmake generation is successful, changing the menu options in BoardOptions.cmake may work, but changing the board itself may not be allowed by CMake because the compiler, ABI, features determination and any cache dependencies may not be retriggered again.
67
-
1. CMake does not support build for multiple architectures in the same build tree. If a project requires to build applications for more than one type of Arduino boards, refer to CMake documentation for multiple architecture build.
68
-
1. When this toolchain is used, executables (added with `add_executable`) have the entry points setup()/loop() and not main(). Need to include "Arduino.h" for these entry points.
69
-
1. If your source files are compiled for both Arduino and other platforms like linux, then the CMake flag `ARDUINO` and the compiler flag `ARDUINO` can be used for script/code portability. Other Arduino board/architecture specific standard flags can also be used.
86
+
87
+
1. After the cmake generation is successful, changing the menu options in BoardOptions.cmake may work, but changing the
88
+
board itself may not be allowed by CMake because the compiler, ABI, features determination and any cache dependencies
89
+
may not be retriggered again.
90
+
1. CMake does not support build for multiple architectures in the same build tree. If a project requires to build
91
+
applications for more than one type of Arduino boards, refer to CMake documentation for multiple architecture build.
92
+
1. When this toolchain is used, executables (added with `add_executable`) have the entry points setup()/loop() and not
93
+
main(). Need to include "Arduino.h" for these entry points.
94
+
1. If your source files are compiled for both Arduino and other platforms like linux, then the CMake flag `ARDUINO` and
95
+
the compiler flag `ARDUINO` can be used for script/code portability. Other Arduino board/architecture specific
96
+
standard flags can also be used.
70
97
71
98
### Linking with Arduino code/libraries (`target_link_arduino_libraries`)
72
99
73
-
`<CMAKE_SOURCE_DIR>/CMakeLists.txt` and any other dependent CMake scripts of the project contain the standard CMake scripting using `add_library`, `add_executable` etc. without Arduino specific changes. Refer to CMake documentation for the same. However when the project source code depends on the Arduino code or libraries (i.e. if the corresponding header files are included), then appropriate linking is required, as expected. This is done using `target_link_arduino_libraries` as explained below.
100
+
`<CMAKE_SOURCE_DIR>/CMakeLists.txt` and any other dependent CMake scripts of the project contain the standard CMake
101
+
scripting using `add_library`, `add_executable` etc. without Arduino specific changes. Refer to CMake documentation for
102
+
the same. However, when the project source code depends on the Arduino code or libraries (i.e. if the corresponding
103
+
header files are included), then appropriate linking is required, as expected. This is done
104
+
using `target_link_arduino_libraries` as explained below.
74
105
75
-
If Arduino.h is included in your source files, then the target must be linked against the 'core' Arduino library as follows.
106
+
If Arduino.h is included in your source files, then the target must be linked against the 'core' Arduino library as
107
+
follows.
76
108
77
109
```cmake
78
110
add_library(my_library my_library.c) # my_library.c includes Arduino.h
1.*Wire* and *core* in the above examples are not CMake targets. They are just Arduino library names (case-sensitive).
99
-
1. It is required only to specify the direct dependencies. Any deeper dependencies are automatically identified and linked. For example, if *SD.h* is included, it is sufficient to link with *SD*, even if *SD* depends on other Arduino libraries, like *SPI*.
133
+
1. It is required only to specify the direct dependencies. Any deeper dependencies are automatically identified and
134
+
linked. For example, if *SD.h* is included, it is sufficient to link with *SD*, even if *SD* depends on other Arduino
135
+
libraries, like *SPI*.
100
136
101
-
These examples illustrates simple usage, but powerful enough for most use cases. However more advanced control and customization of Arduino libraries should be possible. Please refer to the [Examples](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/tree/master/Examples) folder, as well as the API documentation of `target_link_arduino_libraries` (Currently documented as comments in [BoardBuildTargets.cmake](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/blob/master/Arduino/System/BoardBuildTargets.cmake)).
137
+
These examples illustrate simple usage, but powerful enough for most use cases. However, more advanced control and
138
+
customization of Arduino libraries should be possible. Please refer to
139
+
the [Examples](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/tree/master/Examples) folder, as well as the API
140
+
documentation of `target_link_arduino_libraries` (Currently documented as comments
141
+
in [BoardBuildTargets.cmake](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/blob/master/Arduino/System/BoardBuildTargets.cmake)).
102
142
103
143
### Uploading to the target board (`target_enable_arduino_upload`)
104
144
105
-
If support for generating HEX binary and uploading it to the board is required, then a call to `target_enable_arduino_upload` is required for each executable target, as shown below.
145
+
If support for generating HEX binary and uploading it to the board is required, then a call
146
+
to `target_enable_arduino_upload` is required for each executable target, as shown below.
106
147
107
148
```cmake
108
149
add_executable(my_executable my_executable.c)
@@ -136,39 +177,58 @@ Using the programmer, bootloader can be flashed as below
136
177
137
178
## Serial port monitoring
138
179
139
-
Currently there is no support available for this within this toolchain. However any external serial port monitor can be used (e.g. Putty). External serial monitor may need to be closed before upload and reopened after upload, because both use the same serial port.
180
+
Currently there is no support available for this within this toolchain. However any external serial port monitor can be
181
+
used (e.g. Putty). External serial monitor may need to be closed before upload and reopened after upload, because both
182
+
use the same serial port.
140
183
141
184
## Known issues
142
185
143
-
Many of the issues in the master branch have been fixed in release-1.1-dev branch. Although not tested to be fully stable, release-1.1-dev is stable enough to try out and report any futher issues before it gets merged into master.
186
+
Many of the issues in the master branch have been fixed in release-1.1-dev branch. Although not tested to be fully
187
+
stable, release-1.1-dev is stable enough to try out and report any further issues before it gets merged into master.
144
188
145
189
Below are the list of known issues in the master branch.
146
190
147
191
**1. Uploaded application does not work on some boards**
148
192
149
-
Caused by build linking issue that does not link some object files related to platform variant sources contained in the core library. Affects any Arduino platform that has variant source files in addition to the variant header files.
193
+
Caused by build linking issue that does not link some object files related to platform variant sources contained in the
194
+
core library. Affects any Arduino platform that has variant source files in addition to the variant header files.
150
195
151
-
Resolution: Please try with release-1.1-dev branch or otherwise, temporary fixes are available in the branches [fix/variant_link_alt1](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/tree/fix/variant_link_alt1) and [fix/variant_link_alt2](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/tree/fix/variant_link_alt2).
196
+
Resolution: Please try with release-1.1-dev branch or otherwise, temporary fixes are available in the
and [fix/variant_link_alt2](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/tree/fix/variant_link_alt2).
152
199
153
-
**Compromises when using the fix/variant_link_alt1 fix**: (1) CMake version must be above 3.13, (2) Application needs to link with core directly, like in [Examples/01_hello_world](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/tree/master/Examples/01_hello_world), and not like in [Examples/03_portable_app](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/tree/master/Examples/03_portable_app) which links transitively.
200
+
**Compromises when using the fix/variant_link_alt1 fix**: (1) CMake version must be above 3.13, (2) Application needs to
201
+
link with core directly, like
202
+
in [Examples/01_hello_world](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/tree/master/Examples/01_hello_world),
203
+
and not like
204
+
in [Examples/03_portable_app](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/tree/master/Examples/03_portable_app)
205
+
which links transitively.
154
206
155
-
**Compromises when using the fix/variant_link_alt2 fix**: Need to retrigger cmake and do rebuild, after the first successful build, if transitive linking of core is used in the project. May get "source some_file.o not found error" in CMake during the first invocation of CMake that can be ignored.
207
+
**Compromises when using the fix/variant_link_alt2 fix**: Need to retrigger cmake and do rebuild, after the first
208
+
successful build, if transitive linking of core is used in the project. May get "source some_file.o not found error" in
209
+
CMake during the first invocation of CMake that can be ignored.
156
210
157
211
**2. Build/link issue on some 3rd party platforms**
158
212
159
213
Resolution: Please try with release-1.1-dev branch.
160
214
161
215
**3. Some libraries are not detected by *target_link_arduino_libraries***
162
216
163
-
Currently, *target_link_arduino_libraries* takes only include names (i.e. the name of the header file without extension). If the include name does not match with the library name (as mentioned in *library.properties* of the library), the detection of the library fails \(Refer issue [#19](https://github.com/a9183756-gh/Arduino-CMake-Toolchain/issues/19)\).
217
+
Currently, *target_link_arduino_libraries* takes only include names (i.e. the name of the header file without
218
+
extension). If the include name does not match with the library name (as mentioned in *library.properties* of the
219
+
library), the detection of the library fails \(Refer
Workaround: Rename the library folder to the include name and use include name in *target_link_arduino_libraries*.
166
223
167
224
Resolution: Please try with release-1.1-dev branch.
168
225
169
226
## How it works
170
227
171
-
This toolchain follows the build process described in [Arduino Build Process](https://arduino.github.io/arduino-cli/sketch-build-process/), and processes the JSON, platform.txt and boards.txt files correponding to the Arduino platform as specified in the documentation [Arduino IDE 1.5 3rd party Hardware specification](https://arduino.github.io/arduino-cli/platform-specification/).
228
+
This toolchain follows the build process described
229
+
in [Arduino Build Process](https://arduino.github.io/arduino-cli/sketch-build-process/), and processes the JSON,
230
+
platform.txt and boards.txt files corresponding to the Arduino platform as specified in the
231
+
documentation [Arduino IDE 1.5 3rd party Hardware specification](https://arduino.github.io/arduino-cli/platform-specification/).
0 commit comments