squeezelite.cmake 2.5 KB

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