squeezelite.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. # Remove app_recovery so that app_squeezelite and dependencies are properly resolved
  45. idf_build_get_property(bca BUILD_COMPONENT_ALIASES)
  46. list(REMOVE_ITEM bca "idf::app_recovery")
  47. list(REMOVE_ITEM bca "idf::app_squeezelite")
  48. target_link_libraries(${target_elf} ${bca})
  49. target_link_libraries(${target_elf} idf::app_squeezelite)
  50. set(target_name_mapfile "${target_name}.map")
  51. target_link_libraries(${target_elf} "-Wl,--cref -Wl,--Map=${CMAKE_BINARY_DIR}/${target_name_mapfile}")
  52. # idf_build_get_property(link_depends __LINK_DEPENDS)
  53. # idf_build_get_property(link_options LINK_OPTIONS)
  54. # idf_build_get_property(ldgen_libraries __LDGEN_LIBRARIES GENERATOR_EXPRESSION)
  55. add_custom_command(
  56. TARGET ${target_elf}
  57. POST_BUILD
  58. COMMAND ${CMAKE_COMMAND} -E echo "Generating ${build_dir}/${target_name}.bin"
  59. COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS} -o "${build_dir}/${target_name}.bin" "${target_name}.elf"
  60. DEPENDS "${target_name}.elf"
  61. WORKING_DIRECTORY ${build_dir}
  62. COMMENT "Generating binary image from built executable"
  63. VERBATIM
  64. )
  65. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  66. ADDITIONAL_MAKE_CLEAN_FILES
  67. "${build_dir}/${target_name_mapfile}" "${build_dir}/${target_elf_src}" )
  68. endfunction()
  69. ___create_new_target(squeezelite )
  70. ___register_flash(squeezelite ota_0)
  71. add_custom_target(_jtag_scripts ALL
  72. BYPRODUCTS "flash_dbg_project_args"
  73. POST_BUILD
  74. COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_debug_scripts.cmake"
  75. # COMMAND ${CMAKE_COMMAND} --graphviz=graph.dot .
  76. # $ sed -n 's/.*label="\(.*\)"\s.*/\1/p' graph.dot.foo > foo_dependencies.txt
  77. )
  78. add_dependencies(partition_table _jtag_scripts)
  79. idf_build_get_property(build_dir BUILD_DIR)
  80. add_custom_command(
  81. TARGET recovery.elf
  82. PRE_LINK
  83. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
  84. VERBATIM
  85. )
  86. add_custom_command(
  87. TARGET squeezelite.elf
  88. PRE_LINK
  89. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
  90. VERBATIM
  91. )