mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
feat(cmakev2/size): add idf_create_size_report function
The idf_create_size_report function allows for the creation of size report targets based on the generated link map file. The size report targets are created using the TARGET option name: "<target>", "<target>-files", and "<target>-components". These size report targets are added to the idf_default_project with the TARGET set to "size", resulting in the creation of "size", "size-files", and "size-components" targets for the default project. Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
@@ -36,6 +36,7 @@ include(compat)
|
||||
include(ldgen)
|
||||
include(dfu)
|
||||
include(uf2)
|
||||
include(size)
|
||||
include(GetGitRevisionDescription)
|
||||
# For backward compatibility, since externalproject_add is used by
|
||||
# project_include.cmake in the bootloader component. The ExternalProject
|
||||
|
||||
@@ -765,6 +765,11 @@ function(__project_default)
|
||||
idf_create_uf2("${executable}"
|
||||
TARGET uf2-app
|
||||
APP_ONLY)
|
||||
|
||||
if(TARGET "${executable}_mapfile")
|
||||
idf_create_size_report("${executable}_mapfile"
|
||||
TARGET size)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
#[[api
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#[[
|
||||
.. cmakev2:function:: idf_create_size_report
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
idf_create_size_report(<mapfile>
|
||||
TARGET <target>)
|
||||
|
||||
*mapfile[in]*
|
||||
|
||||
The mapfile target generated by the idf_build_executable function.
|
||||
|
||||
*TARGET[in]*
|
||||
|
||||
The base name for the size report targets to be created. In addition to
|
||||
the default size report, which will be available under the target name
|
||||
specified in the ``TARGET`` option, two more detailed targets,
|
||||
"<target>-files" and "<target>-components", will also be created.
|
||||
|
||||
Create size report targets for the specified ``mapfile`` target. The
|
||||
``TARGET`` option specifies the name of the default size report target, but
|
||||
two more targets with detailed reports are also created. For example, if
|
||||
``TARGET`` is set to "size," three targets "size", "size-files", and
|
||||
"size-components" will be created.
|
||||
#]]
|
||||
function(idf_create_size_report mapfile_target)
|
||||
set(options)
|
||||
set(one_value TARGET)
|
||||
set(multi_value)
|
||||
cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN})
|
||||
|
||||
if(NOT DEFINED ARG_TARGET)
|
||||
idf_die("TARGET option is required")
|
||||
endif()
|
||||
|
||||
get_target_property(mapfile "${mapfile_target}" MAPFILE_PATH)
|
||||
if(NOT mapfile)
|
||||
idf_die("Mapfile target '${mapfile_target}' is missing 'MAPFILE_PATH' property.")
|
||||
endif()
|
||||
|
||||
idf_build_get_property(idf_path IDF_PATH)
|
||||
idf_build_get_property(python PYTHON)
|
||||
|
||||
set(idf_size ${python} -m esp_idf_size)
|
||||
|
||||
add_custom_target(${ARG_TARGET}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-D "IDF_SIZE_TOOL=${idf_size}"
|
||||
-D "MAP_FILE=${mapfile}"
|
||||
-D "OUTPUT_JSON=${OUTPUT_JSON}"
|
||||
-P "${idf_path}/tools/cmake/run_size_tool.cmake"
|
||||
DEPENDS ${mapfile_target}
|
||||
USES_TERMINAL
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_target(${ARG_TARGET}-files
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-D "IDF_SIZE_TOOL=${idf_size}"
|
||||
-D "IDF_SIZE_MODE=--files"
|
||||
-D "MAP_FILE=${mapfile}"
|
||||
-D "OUTPUT_JSON=${OUTPUT_JSON}"
|
||||
-P "${idf_path}/tools/cmake/run_size_tool.cmake"
|
||||
DEPENDS ${mapfile_target}
|
||||
USES_TERMINAL
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_target(${ARG_TARGET}-components
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-D "IDF_SIZE_TOOL=${idf_size}"
|
||||
-D "IDF_SIZE_MODE=--archives"
|
||||
-D "MAP_FILE=${mapfile}"
|
||||
-D "OUTPUT_JSON=${OUTPUT_JSON}"
|
||||
-P "${idf_path}/tools/cmake/run_size_tool.cmake"
|
||||
DEPENDS ${mapfile_target}
|
||||
USES_TERMINAL
|
||||
VERBATIM
|
||||
)
|
||||
endfunction()
|
||||
@@ -235,6 +235,11 @@ function(test_executable)
|
||||
idf_create_confserver(fatfs_example
|
||||
TARGET confserver-fatfs)
|
||||
|
||||
if(TARGET fatfs_example_mapfile)
|
||||
idf_create_size_report(fatfs_example_mapfile
|
||||
TARGET fatfs-size)
|
||||
endif()
|
||||
|
||||
|
||||
idf_build_executable(hello_world_example
|
||||
COMPONENTS hello_world_example
|
||||
@@ -252,6 +257,11 @@ function(test_executable)
|
||||
OUTPUT_FILE project_description_hello_world.json)
|
||||
idf_create_confserver(hello_world_example
|
||||
TARGET confserver-hello_world)
|
||||
|
||||
if(TARGET hello_world_example_mapfile)
|
||||
idf_create_size_report(hello_world_example_mapfile
|
||||
TARGET hello-size)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Run tests
|
||||
|
||||
Reference in New Issue
Block a user