Hi William,
Sorry, I looked into this and then forgot to reply on the post.
For IDF v3.3, you can add something to your project CMakeLists.txt like this:
Code: Select all
get_filename_component(idf_project_name ${IDF_PROJECT_EXECUTABLE} NAME_WE)
set(app_bin "${CMAKE_BINARY_DIR}/${idf_project_name}.bin")
add_custom_command(OUTPUT /tmp/app.bin
DEPENDS "${app_bin}"
COMMAND "${CMAKE_COMMAND}" -E copy "${app_bin}" /tmp/app.bin
COMMENT "Copying ${app_bin} to /tmp/app.bin")
add_custom_target(copy_app_binary ALL DEPENDS /tmp/app.bin)
add_dependencies(copy_app_binary app)
EDIT: Fixed code to copy .bin file not ELF file.
This will trigger for the default "all" target (ie cmake --build, or "idf.py build"). If you pass CMake a specific list of targets then copy_app_binary needs to be one of them.
For IDF V4.0, the process is a little bit different and more fiddly because we don't have an IDF build property for the app .bin file path. But this works:
Code: Select all
idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(elf_name EXECUTABLE_NAME GENERATOR_EXPRESSION)
set(app_bin "${build_dir}/${elf_name}.bin")
add_custom_command(OUTPUT /tmp/app.bin
DEPENDS "${build_dir}/.bin_timestamp"
COMMAND "${CMAKE_COMMAND}" -E copy "${app_bin}" /tmp/app.bin
COMMENT "Copying binary to /tmp/app.bin")
add_custom_target(copy_app_binary ALL DEPENDS /tmp/app.bin)
add_dependencies(copy_app_binary gen_project_binary)
BTW, if you need to support both ways in one project then you can do something like
Code: Select all
if(IDF_VERSION_MAJOR EQUAL 4)
# V4 logic
else()
# V3.x logic
endif()