Is include order deterministic when setting `PLATFORMIO_SRC_BUILD_FLAGS`?

I’m looking to include some device-specific configurations as header files if they exist, and fall back to a default if the headers don’t exist. This would be flexible based on the computing unit’s hostname (i.e. unit01, unit02, etc.).

I set up my PLATFORMIO_SRC_BUILD_FLAGS environment variable as the following:

export PLATFORMIO_SRC_BUILD_FLAGS="-I include/unit_config/$(hostname -s) -I include/unit_config/default"

I have the following directory structure under include/unit_config:

├── default
│   ├── device1_config.h
│   └── device2_config.h
├── unit01
│   ├── device1_config.h
│   └── device2_config.h
├── unit02
│   └── device1_config.h
├── unit03
│   └── device2_config.h

As far as I can tell, this should load unit-specific device configurations if they exist under the unit folders, and the default configurations if the unit-specific device configurations don’t exist. No matter how many times I #include "device1_config.h, I should always load the unit-specific file if it exists.

I have two concerns: can I rely on the order provided in PLATFORMIO_SRC_BUILD_FLAGS to be deterministic? Is there a standard, less-hacky approach to including headers based on the specific hardware platform?


You need multiple build environments and src_filter.

I’m encountering a similar situation, except mine goes like this:

TextLCD lib (325) contains a file “TextLCD_Config.h” which must be customized to accommodate standard configuration use cases. Therefore, I tried to copy this config file and customize the copy, instructing the compiler to pick mine first. So far, it does not.