@@ -15,13 +15,26 @@ if(DEFINED IDF_VERSION_MAJOR)
1515 endif ()
1616endif ()
1717
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} )
2218get_filename_component (memfault_firmware_sdk_dir ../../../../ ABSOLUTE )
19+ # If we found the Memfault SDK, include it in the build
20+ if (EXISTS ${memfault_firmware_sdk_dir} /ports/esp_idf/memfault.cmake)
21+ include (${memfault_firmware_sdk_dir} /ports/esp_idf/memfault.cmake)
22+ else ()
23+ # Otherwise, append this to the main/idf_component.yml file:
24+ # memfault/memfault-firmware-sdk: "*"
25+ # Ideally we'd push an environment variable and use a conditional dependency
26+ # https://docs.espressif.com/projects/idf-component-manager/en/latest/reference/manifest_file.html#conditional-dependencies
27+ # But that requires idf-component-manager v2+, which is not available on all
28+ # esp-idf versions
29+
30+ # if the string "memfault/memfault-firmware-sdk" isn't in the file, append it:
31+ file (READ ${CMAKE_CURRENT_SOURCE_DIR} /main/idf_component.yml idf_component_yml)
32+ if (NOT idf_component_yml MATCHES "memfault/memfault-firmware-sdk" )
33+ file (APPEND ${CMAKE_CURRENT_SOURCE_DIR} /main/idf_component.yml
34+ " memfault/memfault-firmware-sdk: \" *\"\n "
35+ )
36+ endif ()
2337endif ()
24- include (${memfault_firmware_sdk_dir} /ports/esp_idf/memfault.cmake)
2538
2639# NOTE: This include also applies global compiler options, make sure
2740# this happens first before defining other targets!
@@ -65,19 +78,32 @@ if (INVALID_PARTITION_TABLE)
6578endif ()
6679
6780if (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- )
81+ # Set MEMFAULT_IDF_VERSION, used for version-specific logic later.
82+ if (IDF_VERSION_MAJOR)
83+ set (MEMFAULT_IDF_VERSION "${IDF_VERSION_MAJOR} .${IDF_VERSION_MINOR} .${IDF_VERSION_PATCH} " )
84+ else ()
85+ # pre-4.0 doesn't have version information available to cmake, so set it to
86+ # the lowest compatible version
87+ set (MEMFAULT_IDF_VERSION "3.3.5" )
88+ endif ()
89+
90+ # As of Memfault SDK v1.12.0, adding the Memfault Build ID is done in the
91+ # memfault component for ESP-IDF >=4.2.5.
92+ if (MEMFAULT_IDF_VERSION VERSION_LESS "4.2.5" )
93+ # Add the Memfault Build ID so each build can have a unique version.
94+ set (IDF_PROJECT_EXECUTABLE ${PROJECT_NAME} .elf)
95+ add_custom_command (TARGET ${IDF_PROJECT_EXECUTABLE}
96+ POST_BUILD
97+ # Compute and insert the build id
98+ COMMAND python ${memfault_firmware_sdk_dir} /scripts/fw_build_id.py ${IDF_PROJECT_EXECUTABLE}
99+ # Save a copy of the ELF that includes the 'log_fmt' section
100+ BYPRODUCTS ${IDF_PROJECT_EXECUTABLE} .memfault_log_fmt
101+ # Compress debug sections; this reduces the elf file size from ~10MB -> ~4.8MB
102+ COMMAND ${CMAKE_OBJCOPY} --compress-debug-sections ${IDF_PROJECT_EXECUTABLE}
103+ COMMAND ${CMAKE_COMMAND} -E copy ${IDF_PROJECT_EXECUTABLE} ${IDF_PROJECT_EXECUTABLE} .memfault_log_fmt
104+ COMMAND ${CMAKE_COMMAND} -E echo "*** NOTE: the symbol file to upload to app.memfault.com is ${IDF_PROJECT_EXECUTABLE} .memfault_log_fmt ***"
105+ # Remove the 'log_fmt' compact log section, which confuses elf2image
106+ COMMAND ${CMAKE_OBJCOPY} --remove-section log_fmt ${IDF_PROJECT_EXECUTABLE}
107+ )
108+ endif ()
83109endif () # NOT CONFIG_MEMFAULT_DISABLE
0 commit comments