1# The following lines of boilerplate have to be in your project's CMakeLists
2# in this exact order for cmake to work correctly
3cmake_minimum_required(VERSION 3.5)
4
5set(COMPONENTS esptool_py main)
6include($ENV{IDF_PATH}/tools/cmake/project.cmake)
7
8project(test_panic)
9
10# Enable UBSAN checks
11#
12# shift-base sanitizer is disabled due to the following pattern found in register header files:
13#   #define SOME_FIELD  0xFFFF
14#   #define SOME_FIELD_M  ((SOME_FIELD_V)<<(SOME_FIELD_S))
15#   #define SOME_FIELD_V  0xFFFF
16#   #define SOME_FIELD_S  16
17# here SOME_FIELD_V doesn't have an unsigned (U) prefix, so the compiler flags
18# SOME_FIELD_M expansion (0xFFFF << 16) as generating integer overflow.
19#
20set(ubsan_options "-fsanitize=undefined" "-fno-sanitize=shift-base")
21
22# Only enable UBSAN for a few components related to the panic test,
23# due to RAM size limitations.
24foreach(component main espcoredump esp_system spi_flash
25                  esp_common esp_hw_support soc hal freertos)
26    idf_component_get_property(lib ${component} COMPONENT_LIB)
27    target_compile_options(${lib} PRIVATE ${ubsan_options})
28endforeach()
29