squeezelite.cmake 6.4 KB

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