squeezelite.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. function(___register_flash target_name sub_type)
  2. partition_table_get_partition_info(otaapp_offset "--partition-type app --partition-subtype ${sub_type}" "offset")
  3. esptool_py_flash_project_args(${target_name} ${otaapp_offset} ${build_dir}/${target_name}.bin FLASH_IN_PROJECT)
  4. esptool_py_custom_target(${target_name}-flash ${target_name} "${target_name}")
  5. endfunction()
  6. #
  7. # Removes the specified compile flag from the specified target.
  8. # _target - The target to remove the compile flag from
  9. # _flag - The compile flag to remove
  10. #
  11. # Pre: apply_global_cxx_flags_to_all_targets() must be invoked.
  12. #
  13. macro(remove_flag_from_target _target _flag)
  14. get_target_property(_target_cxx_flags ${_target} COMPILE_OPTIONS)
  15. if(_target_cxx_flags)
  16. list(REMOVE_ITEM _target_cxx_flags ${_flag})
  17. set_target_properties(${_target} PROPERTIES COMPILE_OPTIONS "${_target_cxx_flags}")
  18. endif()
  19. endmacro()
  20. function(___print_list pref listcontent)
  21. message("")
  22. message("${pref}")
  23. foreach(e ${listcontent})
  24. message("${pref} ${e}")
  25. endforeach()
  26. message("")
  27. endfunction()
  28. function(___create_new_target target_name)
  29. idf_build_get_property(build_dir BUILD_DIR)
  30. file(TO_CMAKE_PATH "${IDF_PATH}" idf_path)
  31. set(target_elf ${target_name}.elf)
  32. # Create a dummy file to work around CMake requirement of having a source
  33. # file while adding an executable
  34. set(target_elf_src ${CMAKE_BINARY_DIR}/${target_name}_src.c)
  35. add_custom_command(OUTPUT ${target_elf_src}
  36. BUILD
  37. COMMAND ${CMAKE_COMMAND} -E touch ${target_elf_src}
  38. VERBATIM)
  39. add_custom_target(_${target_name}_elf DEPENDS "${target_elf_src}" )
  40. add_executable(${target_elf} "${target_elf_src}")
  41. add_dependencies(${target_elf} _${target_name}_elf)
  42. add_dependencies(${target_elf} "recovery.elf")
  43. set_property(TARGET ${target_elf} PROPERTY RECOVERY_PREFIX app_${target_name})
  44. set(ESPTOOLPY_ELF2IMAGE_OPTIONS --elf-sha256-offset 0xb0)
  45. # Remove app_recovery so that app_squeezelite and dependencies are properly resolved
  46. idf_build_get_property(bca BUILD_COMPONENT_ALIASES)
  47. list(REMOVE_ITEM bca "idf::app_recovery")
  48. list(REMOVE_ITEM bca "idf::app_squeezelite")
  49. target_link_libraries(${target_elf} ${bca})
  50. target_link_libraries(${target_elf} idf::app_squeezelite)
  51. set(target_name_mapfile "${target_name}.map")
  52. target_link_libraries(${target_elf} "-Wl,--cref -Wl,--Map=${CMAKE_BINARY_DIR}/${target_name_mapfile}")
  53. # idf_build_get_property(link_depends __LINK_DEPENDS)
  54. # idf_build_get_property(link_options LINK_OPTIONS)
  55. # idf_build_get_property(ldgen_libraries __LDGEN_LIBRARIES GENERATOR_EXPRESSION)
  56. add_custom_command(
  57. TARGET ${target_elf}
  58. POST_BUILD
  59. COMMAND ${CMAKE_COMMAND} -E echo "Generating ${build_dir}/${target_name}.bin"
  60. COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS} -o "${build_dir}/${target_name}.bin" "${target_name}.elf"
  61. DEPENDS "${target_name}.elf"
  62. WORKING_DIRECTORY ${build_dir}
  63. COMMENT "Generating binary image from built executable"
  64. VERBATIM
  65. )
  66. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  67. ADDITIONAL_MAKE_CLEAN_FILES
  68. "${build_dir}/${target_name_mapfile}" "${build_dir}/${target_elf_src}" )
  69. endfunction()
  70. ___create_new_target(squeezelite )
  71. ___register_flash(squeezelite ota_0)
  72. add_custom_target(_jtag_scripts ALL
  73. BYPRODUCTS "flash_dbg_project_args"
  74. POST_BUILD
  75. COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_debug_scripts.cmake"
  76. # COMMAND ${CMAKE_COMMAND} --graphviz=graph.dot .
  77. # $ sed -n 's/.*label="\(.*\)"\s.*/\1/p' graph.dot.foo > foo_dependencies.txt
  78. )
  79. add_dependencies(partition_table _jtag_scripts)
  80. idf_build_get_property(build_dir BUILD_DIR)
  81. add_custom_command(
  82. TARGET recovery.elf
  83. PRE_LINK
  84. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
  85. VERBATIM
  86. )
  87. add_custom_command(
  88. TARGET squeezelite.elf
  89. PRE_LINK
  90. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
  91. VERBATIM
  92. )