squeezelite.cmake 4.8 KB

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