squeezelite.cmake 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. idf_build_get_property(python PYTHON)
  37. file(TO_CMAKE_PATH "${IDF_PATH}" idf_path)
  38. set(target_elf ${target_name}.elf)
  39. # Create a dummy file to work around CMake requirement of having a source
  40. # file while adding an executable
  41. set(target_elf_src ${CMAKE_BINARY_DIR}/${target_name}_src.c)
  42. add_custom_command(OUTPUT ${target_elf_src}
  43. BUILD
  44. COMMAND ${CMAKE_COMMAND} -E touch ${target_elf_src}
  45. VERBATIM)
  46. add_custom_target(_${target_name}_elf DEPENDS "${target_elf_src}" )
  47. add_executable(${target_elf} "${target_elf_src}")
  48. add_dependencies(${target_elf} _${target_name}_elf)
  49. add_dependencies(${target_elf} "recovery.elf")
  50. set_property(TARGET ${target_elf} PROPERTY RECOVERY_PREFIX app_${target_name})
  51. set(ESPTOOLPY_ELF2IMAGE_OPTIONS --elf-sha256-offset 0xb0)
  52. # Remove app_recovery so that app_squeezelite and dependencies are properly resolved
  53. idf_build_get_property(bca BUILD_COMPONENT_ALIASES)
  54. list(REMOVE_ITEM bca "idf::app_recovery")
  55. list(REMOVE_ITEM bca "idf::app_squeezelite")
  56. target_link_libraries(${target_elf} ${bca})
  57. target_link_libraries(${target_elf} idf::app_squeezelite)
  58. set(target_name_mapfile "${target_name}.map")
  59. target_link_libraries(${target_elf} "-Wl,--cref -Wl,--Map=${CMAKE_BINARY_DIR}/${target_name_mapfile}")
  60. # idf_build_get_property(link_depends __LINK_DEPENDS)
  61. # idf_build_get_property(link_options LINK_OPTIONS)
  62. # idf_build_get_property(ldgen_libraries __LDGEN_LIBRARIES GENERATOR_EXPRESSION)
  63. add_custom_command(
  64. TARGET ${target_elf}
  65. POST_BUILD
  66. COMMAND ${CMAKE_COMMAND} -E echo "Generating ${build_dir}/${target_name}.bin"
  67. COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS} -o "${build_dir}/${target_name}.bin" "${target_name}.elf"
  68. DEPENDS "${target_name}.elf"
  69. WORKING_DIRECTORY ${build_dir}
  70. COMMENT "Generating binary image from built executable"
  71. VERBATIM
  72. )
  73. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  74. ADDITIONAL_MAKE_CLEAN_FILES
  75. "${build_dir}/${target_name_mapfile}" "${build_dir}/${target_elf_src}" )
  76. set(idf_size ${python} ${IDF_PATH}/tools/idf_size.py)
  77. if(DEFINED OUTPUT_JSON AND OUTPUT_JSON)
  78. list(APPEND idf_size "--json")
  79. endif()
  80. # Add size targets, depend on map file, run idf_size.py
  81. message(STATUS "adding new target : idf.py size-${target_name}")
  82. add_custom_target(size-${target_name}
  83. DEPENDS ${target_elf}
  84. COMMAND ${idf_size} ${target_name_mapfile}
  85. )
  86. message(STATUS "adding new target : idf.py size-files-${target_name}")
  87. add_custom_target(size-files-${target_name}
  88. DEPENDS ${target_elf}
  89. COMMAND ${idf_size} --files ${target_name_mapfile}
  90. )
  91. message(STATUS "adding new target : idf.py size-components-${target_name}")
  92. add_custom_target(size-components-${target_name}
  93. DEPENDS ${target_elf}
  94. COMMAND ${idf_size} --archives ${target_name_mapfile}
  95. )
  96. unset(idf_size)
  97. endfunction()
  98. ___create_new_target(squeezelite )
  99. ___register_flash(squeezelite ota_0)
  100. add_custom_target(_jtag_scripts ALL
  101. BYPRODUCTS "flash_dbg_project_args"
  102. POST_BUILD
  103. COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_debug_scripts.cmake"
  104. # COMMAND ${CMAKE_COMMAND} --graphviz=graph.dot .
  105. # $ sed -n 's/.*label="\(.*\)"\s.*/\1/p' graph.dot.foo > foo_dependencies.txt
  106. )
  107. add_dependencies(partition_table _jtag_scripts)
  108. idf_build_get_property(build_dir BUILD_DIR)
  109. add_custom_command(
  110. TARGET recovery.elf
  111. PRE_LINK
  112. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
  113. # COMMAND xtensa-esp32-elf-objcopy --strip-symbol start_ota ${build_dir}/esp-idf/app_squeezelite/libapp_squeezelite.a
  114. ## IDF-V4.2+ COMMAND xtensa-esp32-elf-objcopy --weaken-symbol main ${build_dir}/esp-idf/squeezelite/libsqueezelite.a
  115. COMMAND xtensa-esp32-elf-objcopy --globalize-symbol find_command_by_name ${build_dir}/esp-idf/console/libconsole.a
  116. VERBATIM
  117. )
  118. add_custom_command(
  119. TARGET squeezelite.elf
  120. PRE_LINK
  121. # COMMAND xtensa-esp32-elf-objcopy --strip-symbol start_ota ${build_dir}/esp-idf/app_recovery/libapp_recovery.a
  122. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
  123. COMMAND xtensa-esp32-elf-objcopy --globalize-symbol find_command_by_name ${build_dir}/esp-idf/console/libconsole.a
  124. ## IDF-V4.2+ COMMAND xtensa-esp32-elf-objcopy --weaken-symbol main ${build_dir}/esp-idf/app_recovery/libapp_recovery.a
  125. VERBATIM
  126. )