I have the same code base for ESP-32 and M5-Stick-C-Plus. But there are a couple #ifdef around specific sections (such as M5.Lcd.print).
I have a global Defines.h that specifies which configuration is being compiled.
I now want to specify the option at the compile level (but in a makefile).
I want to define ** ESP_M5_SMART_CLICKER_CONFIGURATION** which is specific to the M5.
compileM5:
/opt/homebrew/bin/arduino-cli compile "build.extra_flags=\"-DESP_M5_SMART_CLICKER_CONFIGURATION\"" --fqbn esp32:esp32:m5stick-c | tee output
But after trying the various build.extra_flag syntax, when compiling for the M5 the ESP32 doesn't get defined, and a compile error shows up in library file: M5StickCPlus.h
#error “This library only supports boards with ESP32 processor.”
Example Defines.h file included in all my code. Currently I comment out the option I want.
//turn on or off which configuration is desired..
//#define ESP_M5_SMART_CLICKER_CONFIGURATION
//#define ESP_32_FEEDER
If instead this is modified in the file included, the compile works fine.
So somehow the build.extra_flags is wiping out other defines. One comment in my research showed that these flags should only be used by the platform builders (or things like I'm seeing show up).
With GitHub, I wanted a single install without having to modify that Defines.h file for each different build.
boards.txt is the domain of the platform author, so if the purpose of the flag is to make board-specific build command customizations defined in the individual boards definitions, then that property is not intended to be used by the user and you are risking just such a usage collision if you decide to modify it as a user.
There is another set of "extra_flags" properties, and the comment on those indicates to me they are intended for the user:
# 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=
compiler.libraries.ldflags=
The platform.local.txt file is intended to allow the user to modify a platform configuration without touching the primary files. The platform author would have no need to use that file since platform.txt is their domain. So properties intended for use in platform.local.txt must be reserved for the user. They are both more flexible and more inconvenient than the build.extra_flags property in that they are specific to the compilation commands for a given language (e.g., compiler.cpp.extra_flags is only used when compiling C++ and Arduino Language files), but you can always define multiple if you need to do something like set a define for C++ and C files.
Something you should be aware of is that some platform authors have been naughty and also used these properties internally (even though there is no need for that since they are able to define an unlimited number of such arbitrary properties for their own use. In those platforms, you will run into this same problem of a use collision when your custom definition overwrites the one from the platform. You are of course welcome to copy the definition from the platform and append your additional flags to that.
Arduino holds much of the blame for such encroachment on the user's properties because they have never documented these flags beyond the obscure and vague comments in the platform.txt file. There is discussion on this situation here:
One more question: How do I provide these -D commands to the Arduino SDK? As I switch back and forth often, changing platforms.txt isn't a good solution. Or even the preferences.txt file requires re-starting Ardunio.
You can't provide arbitrary compilation command flags via the Arduino IDE GUI. You can only do it from the command line or the boards platform configuration files.
This was done intentionally by Arduino to encourage library authors to provide users with friendly interfaces rather than preprocessor-based messes.
Anyway, in my original question, I have the same code base for two distinct executables. Arduino setup the environment constraints (eg. src folder) which is fine.
But I want to be able to easily, and friendly without messes, compile between the two options using the Arduino IDE (not command line).
Make a board definition with custom board options that define the -D flags you need. Then you can select which you want from the Tools menu in the Arduino IDE:
You can reference all the resources from the stock ESP32 boards platform (which they can also install via Boards Manager), so your custom platform can consist of a boards.txt file alone.
Or if you are not interested in going the Boards Manager route, you can distribute a boards.local.txt file to them with instructions for them to drop it into the ESP32 platform installation folder.
Per, it doesn't work for esp32 and esp8266 core. problem is the tools folder. {it should be renamed to system). and the other problem is that tools are in tools (system) and not installed in the right tools folder.
Thanks @Juraj. I remember the ESP8266 issue, but didn't extrapolate that to ESP32 platform as well.
The boards.local.txt solution is unaffected by the problem.
As for the creation of a referencing platform, it seems that it will work fine if you copy the entire tools folder from the stock ESP32 platform to your own platform. Other than that, the only file needed is a boards.txt.
Thanks for the query. Yes the GitHub continuous integration is what I'm looking for. I haven't worked it yet, but actually don't see how unless the arduino compiler can be placed at the GitHub server. That would be powerful.
Anyway, I did have good success with the makefile compiling various options as stated earlier. That at least lets me send of a couple compiles to make sure the code works with various define configurations.
thanks.
It can be done easily, and is already done by hundreds of Arduino project repositories.
GitHub actions provides you with a selection of virtual machines. You can run anything you like on those machines. "Actions" are pre-packaged reusable components you can build your workflow from, and so these are the most convenient way to use GitHub Actions, but you are also welcome to just run shell commands directly as you need or prefer. So essentially anything you can do in a headless manner on your local machine you can do on GitHub Actions as well.
I'll share some options in order of my own preference:
arduino/compile-sketches action
This action provides a simple yet flexible interface to:
Install sketch dependencies
Compile sketches
Collect compilation results data
This is the approach used in all of the official Arduino firmware repositories.
High level introduction:
Example of a workflow compiling the examples of the "Arduino_ConnectionHandler" library for a selection of boards including ESP32:
This action installs Arduino CLI in the GitHub Actions runner machine. It is then up to you to use Arduino CLI however you like in subsequent steps of the job.
Install and use Arduino CLI directly from the runner shell
As I mentioned, you can execute commands in the runner shell just the same as you would on your machine. This approach will tend to result in a more complex workflow that takes more effort to maintain, especially if you are using it in multiple projects. But you have full control over the behavior.
I don't have personal experience with these, but they are popular alternatives created by talented members of the Arduino community so worth a mention:
ArminJo/arduino-test-compile action
Adafruit's build script
This is not an action, but a script Adafruit installs and runs via GitHub Actions workflows in their ~200 Arduino project repositories. It seems somewhat specific to their own requirements, but quite a few 3rd party projects are using it.
The origins of this project go all the way back to the days when Travis CI was the go to automation service. Adafruit was a pioneer in the use of Travis CI for automated testing of Arduino projects and their work served as a valuable reference even though I found the scripts did not meet my own specific needs.