squeezelite.cmake 4.1 KB

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