@@ -15,19 +15,33 @@ if(DEFINED IDF_VERSION_MAJOR)
1515 endif ()
1616endif ()
1717
18- # Look for the Memfault SDK in a subdirectory first
19- get_filename_component (memfault_firmare_sdk_dir third-party/memfault-firmware-sdk ABSOLUTE )
20- if (NOT EXISTS ${memfault_firmare_sdk_dir} )
21- get_filename_component (memfault_firmare_sdk_dir ../../../../ ABSOLUTE )
18+ # Look for the Memfault SDK in a subdirectory first, when this app is used
19+ # standalone (not from within the Memfault SDK)
20+ get_filename_component (memfault_firmware_sdk_dir third-party/memfault-firmware-sdk ABSOLUTE )
21+ if (NOT EXISTS ${memfault_firmware_sdk_dir} )
22+ get_filename_component (memfault_firmware_sdk_dir ../../../../ ABSOLUTE )
2223endif ()
23- include (${memfault_firmare_sdk_dir } /ports/esp_idf/memfault.cmake)
24+ include (${memfault_firmware_sdk_dir } /ports/esp_idf/memfault.cmake)
2425
2526# NOTE: This include also applies global compiler options, make sure
2627# this happens first before defining other targets!
2728# The esp-idf project() macro creates a project_name.elf target:
2829include ($ENV{IDF_PATH} /tools/cmake/project.cmake)
30+
31+ # Wrap the mbedtls netif read/write functions, for instrumentation.
32+ # These MUST be before the project() function below, or they are ignored
33+ if (IDF_VERSION_MAJOR VERSION_GREATER_EQUAL 4)
34+ idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=mbedtls_net_send,--wrap=mbedtls_net_recv" APPEND )
35+ endif ()
36+
2937project (${PROJECT_NAME} )
3038
39+ # Enable a compilation error if any deprecated APIs are used. This helps detect
40+ # bleeding edge changes in the ESP-IDF.
41+ if (IDF_VERSION_MAJOR VERSION_GREATER_EQUAL 5)
42+ idf_build_set_property(COMPILE_OPTIONS "-Werror=deprecated-declarations" APPEND )
43+ endif ()
44+
3145# Check for invalid partition table configurations
3246if (
3347 CONFIG_APP_MEMFAULT_TRANSPORT_HTTP AND
@@ -50,16 +64,20 @@ if (INVALID_PARTITION_TABLE)
5064 )
5165endif ()
5266
53- # Add the Memfault Build ID so each build can have a unique version.
54- set (IDF_PROJECT_EXECUTABLE ${PROJECT_NAME} .elf)
55- add_custom_command (TARGET ${IDF_PROJECT_EXECUTABLE}
56- POST_BUILD
57- # Compute and insert the build id
58- COMMAND python ${memfault_firmare_sdk_dir} /scripts/fw_build_id.py ${IDF_PROJECT_EXECUTABLE}
59- # Save a copy of the ELF that includes the 'log_fmt' section
60- BYPRODUCTS ${IDF_PROJECT_EXECUTABLE} .memfault_log_fmt
61- COMMAND ${CMAKE_COMMAND} -E copy ${IDF_PROJECT_EXECUTABLE} ${IDF_PROJECT_EXECUTABLE} .memfault_log_fmt
62- COMMAND ${CMAKE_COMMAND} -E echo "*** NOTE: the symbol file to upload to app.memfault.com is ${IDF_PROJECT_EXECUTABLE} .memfault_log_fmt ***"
63- # Remove the 'log_fmt' compact log section, which confuses elf2image
64- COMMAND ${CMAKE_OBJCOPY} --remove-section log_fmt ${IDF_PROJECT_EXECUTABLE}
65- )
67+ if (CONFIG_MEMFAULT)
68+ # Add the Memfault Build ID so each build can have a unique version.
69+ set (IDF_PROJECT_EXECUTABLE ${PROJECT_NAME} .elf)
70+ add_custom_command (TARGET ${IDF_PROJECT_EXECUTABLE}
71+ POST_BUILD
72+ # Compute and insert the build id
73+ COMMAND python ${memfault_firmware_sdk_dir} /scripts/fw_build_id.py ${IDF_PROJECT_EXECUTABLE}
74+ # Save a copy of the ELF that includes the 'log_fmt' section
75+ BYPRODUCTS ${IDF_PROJECT_EXECUTABLE} .memfault_log_fmt
76+ # Compress debug sections; this reduces the elf file size from ~10MB -> ~4.8MB
77+ COMMAND ${CMAKE_OBJCOPY} --compress-debug-sections ${IDF_PROJECT_EXECUTABLE}
78+ COMMAND ${CMAKE_COMMAND} -E copy ${IDF_PROJECT_EXECUTABLE} ${IDF_PROJECT_EXECUTABLE} .memfault_log_fmt
79+ COMMAND ${CMAKE_COMMAND} -E echo "*** NOTE: the symbol file to upload to app.memfault.com is ${IDF_PROJECT_EXECUTABLE} .memfault_log_fmt ***"
80+ # Remove the 'log_fmt' compact log section, which confuses elf2image
81+ COMMAND ${CMAKE_OBJCOPY} --remove-section log_fmt ${IDF_PROJECT_EXECUTABLE}
82+ )
83+ endif () # NOT CONFIG_MEMFAULT_DISABLE
0 commit comments