espsss / reference / quick / compile-time-checks

Compile-time checks for chip, core and ESP-IDF version

One sketch for several chips and core versions needs #if on the right macros. Here is where each one comes from and what it holds, from ESP-IDF v5.5.5, arduino-esp32 3.3.12 and the Arduino platform specification.

In short

  • Chip: #if CONFIG_IDF_TARGET_ESP32S3 (one macro per chip, from sdkconfig.h); CPU family: CONFIG_IDF_TARGET_ARCH_XTENSA or CONFIG_IDF_TARGET_ARCH_RISCV.1
  • Peripheral: #if SOC_<FEATURE>_SUPPORTED from soc/soc_caps.h, for example SOC_USB_OTG_SUPPORTED.2
  • Versions: ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) and ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0).3
  • Arduino core and board: ARDUINO_ARCH_ESP32, and ARDUINO_<build.board> such as ARDUINO_ESP32S3_DEV for the board picked in the menu.4

Macros

MacroComes fromValueNotes
CONFIG_IDF_TARGET_ESP32S3sdkconfig.h (Kconfig)1 on that chip, undefined on othersCONFIG_IDF_TARGET_ESP32, …_ESP32S2, …_ESP32C3, …_ESP32C6, …_ESP32H2, …_ESP32P4 work the same way1
CONFIG_IDF_TARGETsdkconfig.h (Kconfig)string, e.g. "esp32s3"For printing; #if cannot compare strings1
CONFIG_IDF_TARGET_ARCH_XTENSA / _RISCVsdkconfig.h (Kconfig)1 for the chip's CPU familyESP32, S2, S3 select XTENSA; C2, C3, C5, C6, C61, H2, P4 select RISCV1
SOC_<FEATURE>_SUPPORTEDsoc/soc_caps.h (also as CONFIG_SOC_…)1 if the chip has it; undefined or 0 if not, so test it with #if, not #ifdefe.g. SOC_USB_OTG_SUPPORTED, SOC_TOUCH_SENSOR_SUPPORTED; counts like SOC_CPU_CORES_NUM2
ESP_IDF_VERSIONesp_idf_version.hinteger, compare with ESP_IDF_VERSION_VAL(5, 0, 0)Also ESP_IDF_VERSION_MAJOR / _MINOR / _PATCH5
ESP_ARDUINO_VERSIONesp_arduino_version.h (included by Arduino.h)integer, compare with ESP_ARDUINO_VERSION_VAL(3, 0, 0)Also ESP_ARDUINO_VERSION_MAJOR / _MINOR / _PATCH3
ESP_ARDUINO_VERSION_STResp_arduino_version.hstring, e.g. "3.3.12"Not in 2.0.17: guard with #ifdef3
ARDUINO_ARCH_ESP32Arduino build command (-DARDUINO_ARCH_{build.arch})definedSet for every board of the esp32 platform; build.arch is the platform architecture in upper case46
ARDUINO_<build.board>boards.txt → -DARDUINO_{build.board}defined, e.g. ARDUINO_ESP32S3_DEVDepends on the board selected in the menu (ESP32C3_DEV, ESP32_DEV, …)4
ARDUINO_BOARD / ARDUINO_VARIANTArduino build commandstrings, e.g. "ESP32S3_DEV" / "esp32s3"For printing4

Example

#include <esp_idf_version.h>
#include <soc/soc_caps.h>

#if !defined(ARDUINO_ARCH_ESP32)
#error "This sketch needs the arduino-esp32 core"
#endif

#if ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(3, 0, 0)
#error "This sketch needs arduino-esp32 3.x"
#endif

#if CONFIG_IDF_TARGET_ESP32
const char *family = "ESP32";
#elif CONFIG_IDF_TARGET_ESP32S3
const char *family = "ESP32-S3";
#elif CONFIG_IDF_TARGET_ARCH_RISCV
const char *family = "a RISC-V chip";
#else
const char *family = "another Xtensa chip";
#endif

void setup() {
  Serial.begin(115200);
  delay(2000);
  Serial.printf("%s (%s), board %s, core %s, ESP-IDF %s\n", family, CONFIG_IDF_TARGET,
                ARDUINO_BOARD, ESP_ARDUINO_VERSION_STR, esp_get_idf_version());
#if SOC_USB_OTG_SUPPORTED
  Serial.println("USB OTG peripheral: yes");
#else
  Serial.println("USB OTG peripheral: no");
#endif
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
  Serial.println("ESP-IDF 5.5 or newer");
#endif
#ifdef ARDUINO_ESP32S3_DEV
  Serial.println("Board menu: ESP32S3 Dev Module");
#endif
}

void loop() {}

Pitfalls

A missing include is not an error

An identifier that is not defined counts as 0 in #if. Without #include <soc/soc_caps.h> (or with a typo in a CONFIG_ name) the check is silently false.7

Strings cannot be compared in #if

CONFIG_IDF_TARGET and ARDUINO_BOARD are strings for printing. For #if use the per-chip CONFIG_IDF_TARGET_<CHIP> or ARDUINO_<BOARD> macros.1

ESP_ARDUINO_VERSION_STR is new in 3.x

arduino-esp32 2.0.17 has ESP_ARDUINO_VERSION and ESP_ARDUINO_VERSION_VAL but no ESP_ARDUINO_VERSION_STR. Wrap it in #ifdef if the sketch must also build on 2.x.8

Board macros follow the menu, not the chip

ARDUINO_ESP32S3_DEV is defined only when "ESP32S3 Dev Module" is selected; another ESP32-S3 board defines its own ARDUINO_<board>. Test the chip with CONFIG_IDF_TARGET_ESP32S3.9

Sources

Each number links here; open “What it confirms” for the exact quotes. Checked 2026-11-28.

  1. ESP-IDF v5.5.5: Kconfig primary
    What it confirms (5)
    • Compile-time checks for chip, core and ESP-IDF version: in short “config IDF_TARGET_ESP32S3 bool default "y" if IDF_TARGET="esp32s3" … config IDF_TARGET_ARCH_XTENSA … option names are prefixed with CONFIG_”
    • Compile-time checks for chip, core and ESP-IDF version: CONFIG_IDF_TARGET_ESP32S3 “config IDF_TARGET_ESP32S3 bool default "y" if IDF_TARGET="esp32s3" … config IDF_TARGET_ESP32C3 bool default "y" if IDF_TARGET="esp32c3" … option names are prefixed with CONFIG_”
    • Compile-time checks for chip, core and ESP-IDF version: CONFIG_IDF_TARGET “config IDF_TARGET … string default "$IDF_TARGET"”
    • Compile-time checks for chip, core and ESP-IDF version: CONFIG_IDF_TARGET_ARCH_XTENSA / _RISCV “config IDF_TARGET_ARCH_RISCV … config IDF_TARGET_ARCH_XTENSA … default "y" if IDF_TARGET="esp32" select IDF_TARGET_ARCH_XTENSA … default "y" if IDF_TARGET="esp32s2" select FREERTOS_UNICORE select IDF_TARGET_ARCH_XTENSA … default "y" if IDF_TARGET="esp32s3" select IDF_TARGET_ARCH_XTENSA … default "y" if IDF_TARGET="esp32c2" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32c3" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32c5" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32c6" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32c61" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32h2" select FREERTOS_UNICORE select IDF_TARGET_ARCH_RISCV … default "y" if IDF_TARGET="esp32p4" select IDF_TARGET_ARCH_RISCV”
    • Compile-time checks for chip, core and ESP-IDF version: pitfall: Strings cannot be compared in #if “string default "$IDF_TARGET" … -DARDUINO_BOARD="{build.board}"”
  2. ESP-IDF v5.5.5: components/soc/esp32s3/include/soc/soc_caps.h primary
    What it confirms (2)
    • Compile-time checks for chip, core and ESP-IDF version: in short “#define SOC_USB_OTG_SUPPORTED 1”
    • Compile-time checks for chip, core and ESP-IDF version: SOC_<FEATURE>_SUPPORTED “These defines are parsed and imported as kconfig variables … #define SOC_USB_OTG_SUPPORTED 1 … #define SOC_TOUCH_SENSOR_SUPPORTED 1 … #define SOC_CPU_CORES_NUM (1U) … #define SOC_MPU_REGION_RO_SUPPORTED 0”
  3. arduino-esp32 3.3.12: cores/esp32/esp_arduino_version.h primary
    What it confirms (3)
    • Compile-time checks for chip, core and ESP-IDF version: in short “To be used in comparisons, such as ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) … To be used in comparisons, such as ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)”
    • Compile-time checks for chip, core and ESP-IDF version: ESP_ARDUINO_VERSION “#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) … To be used in comparisons, such as ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) … #define ESP_ARDUINO_VERSION_MAJOR 3 … #include "esp_arduino_version.h"”
    • Compile-time checks for chip, core and ESP-IDF version: ESP_ARDUINO_VERSION_STR “* Current ARDUINO version, as string … #define ESP_ARDUINO_VERSION_STR df2str(ESP_ARDUINO_VERSION_MAJOR) "." df2str(ESP_ARDUINO_VERSION_MINOR) "." df2str(ESP_ARDUINO_VERSION_PATCH)”
  4. arduino-esp32 3.3.12: platform.txt primary
    What it confirms (4)
    • Compile-time checks for chip, core and ESP-IDF version: in short “-DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} … esp32s3.build.board=ESP32S3_DEV”
    • Compile-time checks for chip, core and ESP-IDF version: ARDUINO_ARCH_ESP32 “-DARDUINO_ARCH_{build.arch} … buildProperties.Set("build.arch", strings.ToUpper(b.PlatformRelease.Platform.Architecture)) … "architecture": "esp32",”
    • Compile-time checks for chip, core and ESP-IDF version: ARDUINO_<build.board> “-DARDUINO_{build.board} … esp32s3.build.board=ESP32S3_DEV … esp32c3.build.board=ESP32C3_DEV … esp32.build.board=ESP32_DEV … property is used to set a compile-time macro **ARDUINO\_{build.board}** to allow use of conditional code between `#ifdef`s”
    • Compile-time checks for chip, core and ESP-IDF version: ARDUINO_BOARD / ARDUINO_VARIANT “-DARDUINO_BOARD="{build.board}" -DARDUINO_VARIANT="{build.variant}" … esp32s3.build.board=ESP32S3_DEV … esp32s3.build.variant=esp32s3”
  5. ESP-IDF v5.5.5: components/esp_common/include/esp_idf_version.h primary
    What it confirms (1)
    • Compile-time checks for chip, core and ESP-IDF version: ESP_IDF_VERSION “#define ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) … To be used in comparisons, such as ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) … #define ESP_IDF_VERSION_MAJOR 5”
  6. arduino-esp32 3.3.12: libraries/BLE/src/BLEDevice.cpp primary
    What it confirms (1)
    • Compile-time checks for chip, core and ESP-IDF version: ARDUINO_ARCH_ESP32 “#if defined(ARDUINO_ARCH_ESP32)”
  7. cppreference: Conditional inclusion (#if, #ifdef) primary
    What it confirms (1)
    • Compile-time checks for chip, core and ESP-IDF version: pitfall: A missing include is not an error “each remaining identifier other than true and false is replaced with the preprocessing number 0”
  8. arduino-esp32 2.0.17: cores/esp32/esp_arduino_version.h primary
    What it confirms (1)
    • Compile-time checks for chip, core and ESP-IDF version: pitfall: ESP_ARDUINO_VERSION_STR is new in 3.x “#define ESP_ARDUINO_VERSION_MAJOR 2 … #define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))”
  9. arduino-esp32 3.3.12: boards.txt primary
    What it confirms (1)
    • Compile-time checks for chip, core and ESP-IDF version: pitfall: Board macros follow the menu, not the chip “esp32s3.name=ESP32S3 Dev Module … esp32s3.build.board=ESP32S3_DEV … property is used to set a compile-time macro **ARDUINO\_{build.board}**”