@@ -37,6 +37,10 @@ function(idf_build_set_property property value)
3737 set (multi_value)
3838 cmake_parse_arguments (ARG "${options} " "${one_value} " "${multi_value} " ${ARGN} )
3939
40+ if ("${property} " STREQUAL MINIMAL_BUILD)
41+ idf_warn("Build property 'MINIMAL_BUILD' is obsolete and will be ignored" )
42+ endif ()
43+
4044 set (append )
4145 if (ARG_APPEND)
4246 set (append APPEND )
@@ -503,15 +507,27 @@ endfunction()
503507
504508 Optional ``executable`` suffix.
505509
510+ *MAPFILE_TARGET[in,opt]*
511+
512+ Name of the target for the map file. If provided, the link map file is
513+ generated for the specified executable, and the ``MAPFILE_TARGET``
514+ target name is created for it. The ``MAPFILE_PATH`` property with the
515+ link map file path is added to the ``MAPFILE_TARGET`` target. This can
516+ be used for other targets that depend on the link map file. The link map file
517+ is not generated on Darwin host, so the target ``MAPFILE_TARGET`` may not
518+ be created if link map file is not generated.
519+
506520 Create a new executable target using the name specified in the
507521 ``executable`` argument, and link it to the library created with the
508522 component names provided in the ``COMPONENTS`` option. If the
509523 ``COMPONENTS`` option is not set, all discovered components are added to
510- the library. Optinaly set the executable name and suffix.
524+ the library. Optionally set the executable name and suffix. The executable
525+ library target name is added to the ``LIBRARY_INTERFACE`` executable
526+ property.
511527#]]
512528function (idf_build_executable executable)
513529 set (options )
514- set (one_value NAME SUFFIX )
530+ set (one_value NAME SUFFIX MAPFILE_TARGET )
515531 set (multi_value COMPONENTS)
516532 cmake_parse_arguments (ARG "${options} " "${one_value} " "${multi_value} " ${ARGN} )
517533
@@ -534,15 +550,29 @@ function(idf_build_executable executable)
534550 endif ()
535551 add_executable (${executable} "${executable_src} " )
536552
537- if (ARG_NAME)
538- set_target_properties (${executable} PROPERTIES OUTPUT_NAME ${ARG_NAME} )
539- endif ()
553+ set_target_properties (${executable} PROPERTIES OUTPUT_NAME ${ARG_NAME} )
540554
541555 if (ARG_SUFFIX)
542556 set_target_properties (${executable} PROPERTIES SUFFIX ${ARG_SUFFIX} )
543557 endif ()
544558
545559 target_link_libraries (${executable} PRIVATE ${library} )
560+
561+ idf_build_get_property(linker_type LINKER_TYPE)
562+ if (ARG_MAPFILE_TARGET AND "${linker_type} " STREQUAL "GNU" )
563+ set (mapfile "${CMAKE_BINARY_DIR} /${ARG_NAME} .map" )
564+ target_link_options (${executable} PRIVATE "LINKER:--Map=${mapfile} " )
565+ add_custom_command (
566+ OUTPUT "${mapfile} "
567+ DEPENDS ${executable}
568+ )
569+ add_custom_target (${ARG_MAPFILE_TARGET}
570+ DEPENDS "${mapfile} "
571+ )
572+ set_target_properties (${ARG_MAPFILE_TARGET} PROPERTIES MAPFILE_PATH ${mapfile} )
573+ endif ()
574+
575+ set_target_properties (${executable} PROPERTIES LIBRARY_INTERFACE ${library} )
546576endfunction ()
547577
548578#[[
@@ -647,28 +677,34 @@ endfunction()
647677
648678 .. code-block:: cmake
649679
650- idf_build_generate_metadata(<executable >
680+ idf_build_generate_metadata(<binary >
651681 [FILE <file>])
652682
653- *executable [in]*
683+ *binary [in]*
654684
655- Executable target for which to generate a metadata file.
685+ Binary target for which to generate a metadata file.
656686
657687 *OUTPUT_FILE[in,opt]*
658688
659689 Optional output file path for storing the metadata. If not provided,
660690 the default path ``<build>/project_description.json`` is used.
661691
662- Generate metadata for the specified ``executable `` and store it in the
692+ Generate metadata for the specified ``binary `` and store it in the
663693 specified ``FILE``. If no ``FILE`` is provided, the default location
664694 ``<build>/project_description.json`` will be used.
665695#]]
666- function (idf_build_generate_metadata executable )
696+ function (idf_build_generate_metadata binary )
667697 set (options )
668698 set (one_value OUTPUT_FILE)
669699 set (multi_value)
670700 cmake_parse_arguments (ARG "${options} " "${one_value} " "${multi_value} " ${ARGN} )
671701
702+ # The EXECUTABLE_TARGET property is set by the idf_build_binary or
703+ # the idf_sign_binary function.
704+ get_target_property (executable "${binary} " EXECUTABLE_TARGET)
705+ if (NOT executable)
706+ idf_die("Binary target '${binary} ' is missing 'EXECUTABLE_TARGET' property." )
707+ endif ()
672708 __get_executable_library_or_die(TARGET "${executable} " OUTPUT library)
673709
674710 idf_build_get_property(PROJECT_NAME PROJECT_NAME )
@@ -679,9 +715,13 @@ function(idf_build_generate_metadata executable)
679715 idf_build_get_property(SDKCONFIG SDKCONFIG)
680716 idf_build_get_property(SDKCONFIG_DEFAULTS SDKCONFIG_DEFAULTS)
681717 set (PROJECT_EXECUTABLE "$<TARGET_FILE_NAME:${executable} >" )
682- # The PROJECT_BIN executable property must be set by the idf_build_binary
683- # function.
684- get_target_property (PROJECT_BIN "${executable} " EXECUTABLE_BINARY)
718+ # The BINARY_PATH property is set by the idf_build_binary or
719+ # the idf_sign_binary function.
720+ get_target_property (binary_path ${binary} BINARY_PATH)
721+ if (NOT binary_path)
722+ idf_die("Binary target '${binary} ' is missing 'BINARY_PATH' property." )
723+ endif ()
724+ get_filename_component (PROJECT_BIN "${binary_path} " NAME )
685725 if (NOT PROJECT_BIN)
686726 set (PROJECT_BIN "" )
687727 endif ()
@@ -767,8 +807,9 @@ endfunction()
767807 Create a binary image for the specified ``executable`` target and save it
768808 in the file specified with the ``OUTPUT_FILE`` option. A custom target
769809 named ``TARGET`` will be created for the generated binary image. The path
770- of the generated binary image will be also stored in the ``BINARY_PATH``
771- property of the ``TARGET``.
810+ of the generated binary image will be stored in the ``BINARY_PATH``
811+ property and the executable target in the ``EXECUTABLE_TARGET`` property of
812+ the ``TARGET``.
772813#]]
773814function (idf_build_binary executable)
774815 set (options )
@@ -828,13 +869,13 @@ function(idf_build_binary executable)
828869 # Create a custom target to generate the binary file
829870 add_custom_target (${ARG_TARGET} DEPENDS "${ARG_OUTPUT_FILE} " )
830871
831- # The EXECUTABLE_BINARY property is used by idf_build_generate_metadata to
832- # store the name of the binary image.
833- set_target_properties (${executable} PROPERTIES EXECUTABLE_BINARY ${binary_name} )
834-
835872 # Store the path of the binary file in the BINARY_PATH property of the
836873 # custom binary target, which is used by the idf_flash_binary.
837874 set_target_properties (${ARG_TARGET} PROPERTIES BINARY_PATH ${ARG_OUTPUT_FILE} )
875+
876+ # Store executable target name in the EXECUTABLE_TARGET property. This is used
877+ # by the idf_build_generate_metadata function.
878+ set_target_properties (${ARG_TARGET} PROPERTIES EXECUTABLE_TARGET ${executable} )
838879endfunction ()
839880
840881#[[
@@ -870,9 +911,10 @@ endfunction()
870911
871912 Sign binary image specified by ``binary`` target with ``KEYFILE`` and save
872913 it in the file specified with the `OUTPUT_FILE` option. A custom target
873- named ``TARGET`` will be created for the signed binary image. The path of
874- the signed binary image will be also stored in the ``BINARY_PATH`` property
875- of the ``TARGET``.
914+ named ``TARGET`` will be created for the signed binary image. The path of
915+ the signed binary image will be stored in the ``BINARY_PATH`` property and
916+ the executable target in the ``EXECUTABLE_TARGET`` property of the
917+ ``TARGET``.
876918#]]
877919function (idf_sign_binary binary)
878920 set (options )
@@ -936,6 +978,14 @@ function(idf_sign_binary binary)
936978 # Store the path of the binary file in the BINARY_PATH property of the
937979 # custom signed binary target, which is used by the idf_flash_binary.
938980 set_target_properties (${ARG_TARGET} PROPERTIES BINARY_PATH ${ARG_OUTPUT_FILE} )
981+
982+ # Store executable target name in the EXECUTABLE_TARGET property. This is used
983+ # by the idf_build_generate_metadata function.
984+ get_target_property (executable "${binary} " EXECUTABLE_TARGET)
985+ if (NOT executable)
986+ idf_die("Binary target '${binary} ' is missing 'EXECUTABLE_TARGET' property." )
987+ endif ()
988+ set_target_properties (${ARG_TARGET} PROPERTIES EXECUTABLE_TARGET ${executable} )
939989endfunction ()
940990
941991#[[
0 commit comments