squeezelite.cmake 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. if(NOT SDKCONFIG OR NOT IDF_PATH OR NOT IDF_TARGET )
  2. message(FATAL_ERROR "squeezelite should not be made outside of the main project !")
  3. endif()
  4. function(___register_flash target_name sub_type)
  5. partition_table_get_partition_info(otaapp_offset "--partition-type app --partition-subtype ${sub_type}" "offset")
  6. esptool_py_flash_project_args(${target_name} ${otaapp_offset} ${build_dir}/${target_name}.bin FLASH_IN_PROJECT)
  7. esptool_py_custom_target(${target_name}-flash ${target_name} "${target_name}")
  8. endfunction()
  9. function(___create_new_target target_name)
  10. idf_build_get_property(build_dir BUILD_DIR)
  11. set(target_elf ${target_name}.elf)
  12. # Create a dummy file to work around CMake requirement of having a source
  13. # file while adding an executable
  14. set(target_elf_src ${CMAKE_BINARY_DIR}/${target_name}_src.c)
  15. add_custom_command(OUTPUT ${target_elf_src}
  16. COMMAND ${CMAKE_COMMAND} -E touch ${target_elf_src}
  17. VERBATIM)
  18. add_custom_target(_${target_name}_elf DEPENDS "${target_elf_src}" )
  19. add_executable(${target_elf} "${target_elf_src}")
  20. add_dependencies(${target_elf} _${target_name}_elf)
  21. add_dependencies(${target_elf} "recovery.elf")
  22. set_property(TARGET ${target_elf} PROPERTY RECOVERY_BUILD 0 )
  23. set_property(TARGET ${target_elf} PROPERTY RECOVERY_PREFIX app_${target_name})
  24. idf_build_get_property(bca BUILD_COMPONENT_ALIASES)
  25. target_link_libraries(${target_elf} ${bca})
  26. set(target_name_mapfile "${target_name}.map")
  27. target_link_libraries(${target_elf} "-Wl,--cref -Wl,--Map=${CMAKE_BINARY_DIR}/${target_name_mapfile}")
  28. add_custom_command(
  29. TARGET ${target_elf}
  30. POST_BUILD
  31. COMMAND ${CMAKE_COMMAND} -E echo "Generated ${build_dir}/${target_name}.bin"
  32. #COMMAND echo ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${esptool_elf2image_args}
  33. #COMMAND echo ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS}
  34. COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS}
  35. -o "${build_dir}/${target_name}.bin" "${target_name}.elf"
  36. DEPENDS "${target_name}.elf"
  37. WORKING_DIRECTORY ${build_dir}
  38. COMMENT "Generating binary image from built executable"
  39. VERBATIM
  40. )
  41. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  42. ADDITIONAL_MAKE_CLEAN_FILES
  43. "${build_dir}/${target_name_mapfile}" "${build_dir}/${target_elf_src}" )
  44. endfunction()
  45. ___create_new_target(squeezelite )
  46. ___register_flash(squeezelite ota_0)