fdecker
October 21, 2022, 12:27pm
1
Are the developers aware of this and doing anything to allow this? Or did I miss how to do it? I saw a suggestion somewhere in the old version of a kludge to create alternate board definitions. Is that the only way?
There is a way to set flags from the command line when using Arduino CLI.
There are some examples of that here in the arduino-cli compile command documentation:
https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_compile/
If you are interested in reading a lot of discussion about the subject in general, you can check this issue thread and all the related discussions linked off it:
opened 03:04PM - 20 Jul 20 UTC
type: enhancement
topic: documentation
criticality: high
topic: build-process
Arduino has established a convention of providing "extra_flags" properties in pl… atform.txt, which are intended to allow the compilation process to be customized by the addition of arbitrary flags in the compilation commands:
```
# This can be overridden in boards.txt
build.extra_flags=
# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
compiler.S.extra_flags=
compiler.cpp.extra_flags=
compiler.ar.extra_flags=
compiler.objcopy.eep.extra_flags=
compiler.elf2hex.extra_flags=
```
([example](https://github.com/arduino/ArduinoCore-avr/blob/1.8.3/platform.txt#L39-L49))
These are referenced in the appropriate compilation recipes in platform.txt ([example](https://github.com/arduino/ArduinoCore-avr/blob/1.8.3/platform.txt#L58)).
The empty definitions in platform.txt ensure that if the extra flags are not defined elsewhere, the compilation recipes referencing them will still work. They can be overrriden from any of the other platform configuration files:
- [boards.txt](https://arduino.github.io/arduino-cli/latest/platform-specification/#boardstxt)
- [boards.local.txt](https://arduino.github.io/arduino-cli/latest/platform-specification/#boardslocaltxt)
- [platform.local.txt](https://arduino.github.io/arduino-cli/latest/platform-specification/#platformlocaltxt)
- [global platform.txt](https://arduino.github.io/arduino-cli/latest/platform-specification/#global-platformtxt)
or from the command line:
- [`arduino-cli compile --build-property`](https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_compile/#options)
- [`arduino --pref`](https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#options)
---
From the comments, it seems that `build.extra_flags` is intended to be for the use of the boards platform developer, while the others are intended to be for the use of the user (because a platform developer has no need for platform.local.txt).
A common use case of these properties for the user would be to add `-D` flags (https://github.com/arduino/arduino-cli/issues/210#issuecomment-493892258, https://github.com/arduino/Arduino/issues/6344), but there are other uses.
However, the developer often has need for the recipe-specific properties, and so uses them in boards.txt ([example](https://github.com/MCUdude/MightyCore/blob/v2.0.5/avr/boards.txt#L103-L111)). This presents the problem that the user risks inadvertently overriding the flags defined by the boards platform if they use the "extra flags" properties to modify the compilation command.
---
A solution for this conflict could be to establish two sets of the properties: one set of properties for the developer, and another for the user. These should be clearly documented as being dedicated to the sole use by either the platform developer or the user.
These are only arbitrary properties, without any special use by the build system, so no changes would required in the build system. It's only a matter of setting an example for 3rd party platform developers by adding these additional properties to the `platform.txt`s of the official platforms with comments clearly explaining their intent. Ideally, the properties would also be documented in the [Arduino platform specification](https://arduino.github.io/arduino-cli/latest/platform-specification/) as well (https://github.com/arduino/arduino-cli/issues/985).
---
On a certain level, this does provide the user the global macro setting capability that has been often requested, and often rejected:
- https://github.com/arduino/arduino-builder/issues/15
- https://github.com/arduino/arduino-builder/pull/29
- https://github.com/arduino/arduino-builder/pull/282
- https://github.com/arduino/arduino-builder/issues/283
- https://github.com/arduino/arduino-builder/issues/354
- https://github.com/arduino/Arduino/issues/421
- https://github.com/arduino/Arduino/issues/2547
- https://github.com/arduino/Arduino/issues/3635
- https://github.com/arduino/Arduino/pull/3717
- https://github.com/arduino/Arduino/pull/3757
- https://github.com/arduino/Arduino/issues/4528
- https://github.com/arduino/Arduino/issues/5084
- https://github.com/arduino/Arduino/issues/5390
- https://github.com/arduino/Arduino/issues/7189
- https://github.com/arduino/Arduino/issues/11108
- https://github.com/arduino/arduino-cli/issues/159
- https://github.com/arduino/arduino-cli/issues/210
- https://github.com/arduino/arduino-cli/pull/1117
- https://github.com/arduino/arduino-cli/pull/1517
- https://github.com/arduino/tooling-rfcs/issues/9
- https://github.com/arduino/tooling-rfcs/issues/22
However, I think this proposal strikes the right balance of:
- Allowing advanced users to do advanced things
- Not exposing standard users to additional complexity that makes the Arduino development software less beginner friendly
- Being very easy for Arduino to implement
The concern has been that allowing users to set global macros will result in library developers unnecessarily using these as part of the API, making that API less beginner friendly (https://github.com/arduino/arduino-builder/issues/15#issuecomment-145558252). However, if the user is required to use a command line interface or create a specially formatted configuration file in a difficult to access location, the average user won't be interested, and so it will only make sense for a library developer to use this feature for advanced, rarely used features of the library (e.g., enable debug output for troubleshooting of the library). We have already had this "extra flags" capability [since 2014](https://github.com/arduino/ArduinoCore-avr/commit/2b9f022eaad0d107b1516c22ac02bdac4977223b), yet I haven't seen it result in any significant incorporation of user set global macros into the user-level API of Arduino libraries.
Juraj
October 21, 2022, 2:03pm
3
you could define a board for the project. only boards.txt is required.
you can the ensure with #ifdef in the sketch that this board is selected in Tools menu.
1 Like
The issue for our team is that we really need to "globally modify X" when you want it "project specific". And with this method, all our mods would be gone with the next IDE upgrade. What would seem to be an important feature is to be able to compile file1.cpp with -03 and file2.cpp with a different setting without having to use pragma defines.
system
Closed
April 19, 2023, 4:00pm
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.