squeezelite.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include($ENV{IDF_PATH}/components/esptool_py/project_include.cmake)
  2. if(NOT SDKCONFIG OR NOT IDF_PATH OR NOT IDF_TARGET )
  3. message(FATAL_ERROR "squeezelite should not be made outside of the main project !")
  4. endif()
  5. function(___output_debug_target bin_name )
  6. idf_build_get_property(build_dir BUILD_DIR)
  7. file(TO_CMAKE_PATH "${build_dir}" cm_build_dir)
  8. if( "${bin_name}" STREQUAL "_" )
  9. set(debug_file "dbg_project_args" )
  10. else()
  11. set(debug_file "dbg_${bin_name}" )
  12. endif()
  13. set(flash_debug_file "flash_${debug_file}" )
  14. set(flash_args_file "${cm_build_dir}/flash_project_args" )
  15. set(line_prefix "mon program_esp32 ${cm_build_dir}/" )
  16. file(READ ${flash_args_file} flash_args)
  17. list(APPEND dbg_cmds "mon reset halt")
  18. list(APPEND dbg_cmds "flushregs")
  19. list(APPEND dbg_cmds "set remote hardware-watchpoint-limit 2")
  20. STRING(REGEX REPLACE "\n" ";" SPLIT "${flash_args}")
  21. foreach(flash_arg_line ${SPLIT})
  22. string(REGEX MATCH "^(0[xX][^ ]*)[ ]*([^ ]*)" out_matches "${flash_arg_line}")
  23. if( ${CMAKE_MATCH_COUNT} )
  24. if( ( NOT "${CMAKE_MATCH_0}" STREQUAL "" ) AND ( "${bin_name}" STREQUAL "${CMAKE_MATCH_1}" ) OR ( "${bin_name}" STREQUAL "_" ) )
  25. list(APPEND flash_dbg_cmds "${line_prefix}/${CMAKE_MATCH_2} ${CMAKE_MATCH_1}")
  26. endif()
  27. if( ( NOT "${CMAKE_MATCH_0}" STREQUAL "" ) AND ( "${bin_name}" STREQUAL "${CMAKE_MATCH_2}" ) )
  28. list(APPEND dbg_cmds "mon esp32 appoffset ${CMAKE_MATCH_1}")
  29. endif()
  30. endif()
  31. endforeach()
  32. list(APPEND dbg_cmds_end "mon reset halt")
  33. list(APPEND dbg_cmds_end "flushregs")
  34. list(APPEND full_dbg_cmds "${dbg_cmds}")
  35. list(APPEND full_dbg_cmds "${dbg_cmds_end}")
  36. list(APPEND full_flash_dbg_cmds "${dbg_cmds}")
  37. list(APPEND full_flash_dbg_cmds "${flash_dbg_cmds}")
  38. list(APPEND full_flash_dbg_cmds "${dbg_cmds_end}")
  39. STRING(REGEX REPLACE ";" "\n" dbg_cmds_end "${dbg_cmds_end}")
  40. STRING(REGEX REPLACE ";" "\n" full_dbg_cmds "${full_dbg_cmds}")
  41. STRING(REGEX REPLACE ";" "\n" full_flash_dbg_cmds "${full_flash_dbg_cmds}")
  42. file(GENERATE OUTPUT "${cm_build_dir}${debug_file}" CONTENT "${full_dbg_cmds}")
  43. file(GENERATE OUTPUT "${cm_build_dir}${flash_debug_file}" CONTENT "${full_flash_dbg_cmds}")
  44. set_property(DIRECTORY ${cm_build_dir}
  45. APPEND PROPERTY
  46. ADDITIONAL_MAKE_CLEAN_FILES "${debug_file}" "${flash_debug_file}")
  47. endfunction()
  48. function(___register_flash target_name sub_type)
  49. partition_table_get_partition_info(otaapp_offset "--partition-type app --partition-subtype ${sub_type}" "offset")
  50. esptool_py_flash_project_args(${target_name} ${otaapp_offset} ${build_dir}/${target_name}.bin FLASH_IN_PROJECT)
  51. esptool_py_custom_target(${target_name}-flash ${target_name} "${target_name}")
  52. endfunction()
  53. function(___create_new_target target_name)
  54. idf_build_get_property(build_dir BUILD_DIR)
  55. set(target_elf ${target_name}.elf)
  56. # Create a dummy file to work around CMake requirement of having a source
  57. # file while adding an executable
  58. set(target_elf_src ${CMAKE_BINARY_DIR}/${target_name}_src.c)
  59. add_custom_command(OUTPUT ${target_elf_src}
  60. COMMAND ${CMAKE_COMMAND} -E touch ${target_elf_src}
  61. VERBATIM)
  62. add_custom_target(_${target_name}_elf DEPENDS "${target_elf_src}" )
  63. add_executable(${target_elf} "${target_elf_src}")
  64. add_dependencies(${target_elf} _${target_name}_elf)
  65. add_dependencies(${target_elf} "recovery.elf")
  66. set_property(TARGET ${target_elf} PROPERTY RECOVERY_BUILD 0 )
  67. set_property(TARGET ${target_elf} PROPERTY RECOVERY_PREFIX app_${target_name})
  68. idf_build_get_property(bca BUILD_COMPONENT_ALIASES)
  69. target_link_libraries(${target_elf} ${bca})
  70. set(target_name_mapfile "${target_name}.map")
  71. target_link_libraries(${target_elf} "-Wl,--cref -Wl,--Map=${CMAKE_BINARY_DIR}/${target_name_mapfile}")
  72. add_custom_command(
  73. TARGET ${target_elf}
  74. POST_BUILD
  75. COMMAND ${CMAKE_COMMAND} -E echo "Generated ${build_dir}/${target_name}.bin"
  76. #COMMAND echo ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${esptool_elf2image_args}
  77. #COMMAND echo ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS}
  78. COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS}
  79. -o "${build_dir}/${target_name}.bin" "${target_name}.elf"
  80. DEPENDS "${target_name}.elf"
  81. WORKING_DIRECTORY ${build_dir}
  82. COMMENT "Generating binary image from built executable"
  83. VERBATIM
  84. )
  85. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  86. ADDITIONAL_MAKE_CLEAN_FILES
  87. "${build_dir}/${target_name_mapfile}" "${build_dir}/${target_elf_src}" )
  88. endfunction()
  89. ___create_new_target(squeezelite )
  90. ___register_flash(squeezelite ota_0)
  91. ___output_debug_target("_")
  92. ___output_debug_target("squeezelite")
  93. ___output_debug_target("recovery")