one project to produce two bins

User avatar
citoyx
Posts: 13
Joined: Sat Sep 28, 2019 10:14 am

one project to produce two bins

Postby citoyx » Fri Jun 05, 2020 6:01 pm

Hello, im running on git master branch ESP-IDF v4.2-dev-1660-g7d7521367

I have a little POC to play with a lora library. There is two C files : sender.c and receiver.c
I would like to be able to produce 2 bin files : sender.bin and receiver.bin from the same project and same build.

Is it possible ? If yes, how ?

ESP_renz
Posts: 18
Joined: Tue May 14, 2019 2:41 am

Re: one project to produce two bins

Postby ESP_renz » Wed Jun 10, 2020 4:12 am

Unfortunately, there is no easy way to do this at the moment - however this is a use case we are looking into. If you're comfortable with CMake and duplicating code in some components, it is possible to do so. For example:

Code: Select all

...
project(hello-world)

add_executable(exe2 other_main.c)						# other_main.c has the same contents as hello_world_main.c
target_link_libraries(exe2 idf::newlib idf::freertos idf::spi_flash idf::esp_system)
add_dependencies(exe2 hello-world.elf)

idf_build_get_property(build_dir BUILD_DIR)
add_custom_command(
    TARGET exe2 POST_BUILD
    COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${esptool_elf2image_args}
        -o "exe2.bin" "$<TARGET_FILE:exe2>"
    VERBATIM
    WORKING_DIRECTORY ${build_dir}
    )

The snippet above creates a 2nd executable, links against ESP-IDF components, and generates a binary file for the 2nd executable. The binary generation in particular is derived from `esptool_py/project_include.cmake`.

In your case the main project (hello-world in example above) could be the sender or reciever , and the other one becomes the 2nd executable (exe2).

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot], Majestic-12 [Bot] and 199 guests