squeezelite.cmake 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. include($ENV{IDF_PATH}/tools/cmake/project.cmake)
  2. function(___register_flash partition_name sub_type)
  3. message(STATUS "Adding new build target (from build folder): ninja ${partition_name}-flash")
  4. partition_table_get_partition_info(otaapp_offset "--partition-type app --partition-subtype ${sub_type}" "offset")
  5. idf_component_get_property(main_args esptool_py FLASH_ARGS)
  6. idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
  7. esptool_py_flash_target(${partition_name}-flash "${main_args}" "${sub_args}")
  8. esptool_py_flash_target_image(${partition_name}-flash ${partition_name} "${otaapp_offset}" "${build_dir}/${partition_name}.bin")
  9. esptool_py_flash_target_image(flash ${partition_name} "${otaapp_offset}" "${build_dir}/${partition_name}.bin")
  10. endfunction()
  11. #
  12. # Removes the specified compile flag from the specified target.
  13. # _target - The target to remove the compile flag from
  14. # _flag - The compile flag to remove
  15. #
  16. # Pre: apply_global_cxx_flags_to_all_targets() must be invoked.
  17. #
  18. macro(remove_flag_from_target _target _flag)
  19. get_target_property(_target_cxx_flags ${_target} COMPILE_OPTIONS)
  20. if(_target_cxx_flags)
  21. list(REMOVE_ITEM _target_cxx_flags ${_flag})
  22. set_target_properties(${_target} PROPERTIES COMPILE_OPTIONS "${_target_cxx_flags}")
  23. endif()
  24. endmacro()
  25. function(___print_list pref listcontent)
  26. message("")
  27. message("${pref}")
  28. foreach(e ${listcontent})
  29. message("${pref} ${e}")
  30. endforeach()
  31. message("")
  32. endfunction()
  33. function(___create_new_target target_name)
  34. idf_build_get_property(build_dir BUILD_DIR)
  35. idf_build_get_property(python PYTHON)
  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. set(idf_size ${python} ${IDF_PATH}/tools/idf_size.py)
  76. if(DEFINED OUTPUT_JSON AND OUTPUT_JSON)
  77. list(APPEND idf_size "--json")
  78. endif()
  79. # Add size targets, depend on map file, run idf_size.py
  80. message(STATUS "Adding new build target (from build folder): ninja size-${target_name}")
  81. add_custom_target(size-${target_name}
  82. DEPENDS ${target_elf}
  83. COMMAND ${idf_size} ${target_name_mapfile}
  84. )
  85. message(STATUS "Adding new build target (from build folder): ninja size-files-${target_name}")
  86. add_custom_target(size-files-${target_name}
  87. DEPENDS ${target_elf}
  88. COMMAND ${idf_size} --files ${target_name_mapfile}
  89. )
  90. message(STATUS "Adding new build target (from build folder): ninja size-components-${target_name}")
  91. add_custom_target(size-components-${target_name}
  92. DEPENDS ${target_elf}
  93. COMMAND ${idf_size} --archives ${target_name_mapfile}
  94. )
  95. unset(idf_size)
  96. endfunction()
  97. ___create_new_target(squeezelite )
  98. ___register_flash(squeezelite ota_0)
  99. add_custom_target(_jtag_scripts ALL
  100. BYPRODUCTS "flash_dbg_project_args"
  101. POST_BUILD
  102. COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_debug_scripts.cmake"
  103. # COMMAND ${CMAKE_COMMAND} --graphviz=graph.dot .
  104. # $ sed -n 's/.*label="\(.*\)"\s.*/\1/p' graph.dot.foo > foo_dependencies.txt
  105. )
  106. add_dependencies(partition_table _jtag_scripts)
  107. idf_build_get_property(build_dir BUILD_DIR)
  108. add_custom_command(
  109. TARGET recovery.elf
  110. PRE_LINK
  111. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
  112. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol register_external ${build_dir}/esp-idf/squeezelite/libsqueezelite.a
  113. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol deregister_external ${build_dir}/esp-idf/squeezelite/libsqueezelite.a
  114. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol decode_restore ${build_dir}/esp-idf/squeezelite/libsqueezelite.a
  115. # COMMAND xtensa-esp32-elf-objcopy --strip-symbol start_ota ${build_dir}/esp-idf/app_squeezelite/libapp_squeezelite.a
  116. ## IDF-V4.2+ COMMAND xtensa-esp32-elf-objcopy --weaken-symbol main ${build_dir}/esp-idf/squeezelite/libsqueezelite.a
  117. COMMAND xtensa-esp32-elf-objcopy --globalize-symbol find_command_by_name ${build_dir}/esp-idf/console/libconsole.a
  118. VERBATIM
  119. )
  120. file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ota_data_initial.bin DESTINATION ${build_dir} )
  121. add_custom_command(
  122. TARGET squeezelite.elf
  123. PRE_LINK
  124. # COMMAND xtensa-esp32-elf-objcopy --strip-symbol start_ota ${build_dir}/esp-idf/app_recovery/libapp_recovery.a
  125. COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
  126. COMMAND xtensa-esp32-elf-objcopy --globalize-symbol find_command_by_name ${build_dir}/esp-idf/console/libconsole.a
  127. ## IDF-V4.2+ COMMAND xtensa-esp32-elf-objcopy --weaken-symbol main ${build_dir}/esp-idf/app_recovery/libapp_recovery.a
  128. VERBATIM
  129. )