Build options


Type: String | Multiple: No | Default: release

See extended documentation for Build Configurations.


Type: String | Multiple: Yes

These flags/options affect the preprocessing, compilation, assembly, and linking processes for C and C++ code. All compiler and linker flags can be used. Despite the name, CPPDEFINES (C PreProcesor) rows also apply to the C compiler.

For more detailed information about available compiler flags/options, please visit GCC Command Options official documentation.

This option can also be set by the global environment variable PLATFORMIO_BUILD_FLAGS.

Scopes (SCons Variables)


Affects build variable


-D name


Predefine name as a macro, with definition 1.

-D name=definition


The contents of definition are tokenized and processed as if they appeared during translation phase three in a #define directive.

-U name


Cancel any previous definition of name, either built in or provided with a -D option.



Bypass the compiler driver and pass option directly through to the preprocessor



Turn on all optional warnings which are desirable for normal code.



Make all warnings into hard errors. With this option, if any source code triggers warnings, the compilation will be aborted.



Suppress all warnings, including those which GNU CPP issues by default.

-include file


Process file as if #include "file" appeared as the first line of the primary source file.



Add the directory dir to the list of directories to be searched for header files.



Pass option as an option to the assembler. If option contains commas, it is split into multiple options at the commas.



Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas.



Search the library named library when linking



Add directory dir to the list of directories to be searched for -l.

Built-in Variables

You can inject the built-in variables into your build flags, such as:

  • $PYTHONEXE, full path to current Python interpreter

  • $UNIX_TIME, current time in Unix format

  • $PIOENV, name of build environment from “platformio.ini” (Project Configuration File)

  • $PIOPLATFORM, name of development platform

  • $PIOFRAMEWORK, a list of frameworks

  • $PROJECT_DIR, project directory

  • $PROJECT_CORE_DIR, PlatformIO Core directory, see core_dir

  • $PROJECT_BUILD_DIR, project build directory per all environments

  • $BUILD_DIR, build directory per current environment

See the full list of PlatformIO variables.

Please use target envdump for the pio run --target command to see ALL variable values for a build environment.


Sometimes you may want to convert a macro argument into a valid C string constant. In this case, you need to wrap a value with double quotes (") and escape double quotes (" -> \\") in the constant value.

Here is an example of a macro definition that uses stringification and build_flags. Please note that we enclosed the flag in the single quotes to prevent the shell evaluation:


build_flags =
    '-D MYSTRING="Text is \\"Quoted\\""'
    '-D MYFONT=&roboto14'


#include <stdio.h>


int main(void) {
    printf("MYSTRING=<%s>\n", MYSTRING);

If you use Advanced Scripting, we recommend benefiting from the env.StringifyMacro(value) helper function. In this case, you don’t need to apply any escaping, PlatformIO will do this for you:


extra_scripts =


    ("MYSTRING", env.StringifyMacro('Text is "Quoted"')),

Dynamic build flags

PlatformIO allows users to run an external command/script which outputs build flags into STDOUT by prepending the shell command with a ! character. PlatformIO will automatically replace commands with their output when appending flags to build environments.

You can use any shell or programming language.

This external command will be called on each pio run command before building/uploading process.

Use cases:

  • Macro with the latest VCS revision/tag “on-the-fly”

  • Generate dynamic headers (*.h)

  • Process media content before generating SPIFFS image

  • Make some changes to source code or related libraries


If you need more advanced control and would like to apply changes to a PlatformIO Build System environment, please refer to Advanced Scripting.


build_flags = !cmd_or_path_to_script

; Unix only, get output from internal command
build_flags = !echo '-D COMMIT_HASH=\\"'$(git log -1 --format=%%h)'\\"'

Use Case: Create a “PIO_SRC_REV” macro with the latest Git revision

This example includes a separate file named, to be placed in the same directory as platformio.ini.


build_flags = !python

import subprocess

revision = (
    subprocess.check_output(["git", "rev-parse", "HEAD"])
print("'-DGIT_REV=\"%s\"'" % revision)


build_flags =

build_flags =

; We dynamically change the value of "LAST_BUILD_TIME" macro,
; PlatformIO will not cache objects


If you need to control build flags that are specific for debug configuration please refer to debug_build_flags.


Type: String | Multiple: Yes

An option build_src_flags has the same behavior as build_flags but will be applied only for the project source files in the src_dir directory.

This option can also be set by the global environment variable PLATFORMIO_BUILD_SRC_FLAGS.


Type: String | Multiple: Yes

Selectively remove base/initial flags that were set by the development platform.

build_unflags = -Os -std=gnu++11
build_flags = -O2


Type: String (Templates) | Multiple: Yes

This option allows one to specify which source files should be included or excluded from src_dir for a build process. Filter supports two templates:

  • +<PATH> include template

  • -<PATH> exclude template

PATH is relative to src_dir. All patterns will be applied in their order of definition. GLOB Patterns are allowed.

By default, build_src_filter is predefined to +<*> -<.git/> -<.svn/>, meaning “include ALL files, then exclude the .git and svn repository folders.

This option can also be set by the global environment variable PLATFORMIO_BUILD_SRC_FILTER.


Type: String | Multiple: Yes

A list of targets which will be processed by the pio run command by default. You can enter more than one target, if separated by comma+space “, “.

Please follow to pio run --list-targets documentation for the other targets.


  1. Build a project using Release Configuration, upload the firmware, and start Serial Monitor automatically:

    targets = upload, monitor
  2. Build a project using Debug Configuration.

Tip! You can use these targets like an option to pio run --target command. For example:

# clean project
pio run -t clean

# dump current build environment
pio run --target envdump

When no targets are defined, PlatformIO will build only sources by default.