embed_target_output

Embeds the output of one target into another target.

Syntax

embed_target_output(
    FROM_TARGET <internal name>
    IN_TARGETS <target list>
    SECTION <section name>

    GENERATED_HEADER <header file name>
)

Overview

The embed_target_output statement embeds a binary image produced by one target into another target(s). It is similar to the add_embedded_resource statement and can be used to embed bootloaders into programs.

Parameters

FROM_TARGET
Specifies the target name that will be embedded into the other target(s). The target must be created with the add_bsp_based_executable command with the GENERATE_BIN flag enabled.

IN_TARGETS
Specifies the list of targets, separated by spaces, where the output of FROM_TARGET will be embedded

SECTION
Specifies the section where the output of FROM_TARGET will be placed. Defaults to .rodata.

GENERATED_HEADER
Optional. Specifies the name of the generated header file that will contain the declaration of the resource as a variable. Defaults to EmbeddedResources.h.

Remarks

VisualGDB will automatically generate this statement when you use the Add->Embed Another Target command in Solution Explorer.

Examples

The following example embeds the output from Bootloader into MainApplication:

add_bsp_based_executable(NAME Bootloader
                         SOURCES BootloaderDemo.cpp system_stm32f4xx.c
                         GENERATE_BIN
                         LINKER_SCRIPT bootloader.lds)

add_bsp_based_executable(NAME MainApplication
                         SOURCES TargetApplication.cpp system_stm32f4xx.c
                         LINKER_SCRIPT application.lds)

embed_target_output(FROM_TARGET Bootloader
                    IN_TARGETS MainApplication
                    SECTION .bootldr)

The application.lds linker script should contain the following section:

.bootldr :
{
    . = ALIGN(4);
    KEEP(*(.bootldr))
    FILL(0xFFFFFF)
    . = 0x4000;
} > FLASH

See our Bootloader Tutorial with Advanced CMake for a detailed step-by-step example.

See also

Auxiliary Statements, add_embedded_resource, bsp_configure_code_coverage, register_imported_project