project_include.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # ulp_embed_binary
  2. #
  3. # Create ULP binary and embed into the application.
  4. function(ulp_embed_binary app_name s_sources exp_dep_srcs)
  5. if(NOT CMAKE_BUILD_EARLY_EXPANSION)
  6. spaces2list(s_sources)
  7. foreach(source ${s_sources})
  8. get_filename_component(source ${source} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_LIST_DIR})
  9. list(APPEND sources ${source})
  10. endforeach()
  11. foreach(source ${sources})
  12. get_filename_component(ps_source ${source} NAME_WE)
  13. set(ps_output ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${ps_source}.ulp.S)
  14. list(APPEND ps_sources ${ps_output})
  15. endforeach()
  16. set(ulp_artifacts_prefix ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name})
  17. set(ulp_artifacts ${ulp_artifacts_prefix}.bin
  18. ${ulp_artifacts_prefix}.ld
  19. ${ulp_artifacts_prefix}.h)
  20. set(ulp_artifacts_extras ${ulp_artifacts_prefix}.map
  21. ${ulp_artifacts_prefix}.sym
  22. ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/esp32.ulp.ld)
  23. # Replace the separator for the list of ULP source files that will be passed to
  24. # the external ULP project. This is a workaround to the bug https://public.kitware.com/Bug/view.php?id=16137.
  25. string(REPLACE ";" "|" ulp_s_sources "${ulp_s_sources}")
  26. idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
  27. idf_build_get_property(idf_path IDF_PATH)
  28. idf_build_get_property(python PYTHON)
  29. idf_build_get_property(extra_cmake_args EXTRA_CMAKE_ARGS)
  30. if(IDF_TARGET STREQUAL "esp32")
  31. set(TOOLCHAIN_FLAG ${idf_path}/components/ulp/cmake/toolchain-esp32-ulp.cmake)
  32. set(ULP_IS_RISCV OFF)
  33. endif()
  34. if(IDF_TARGET STREQUAL "esp32s2")
  35. if(CONFIG_ESP32S2_ULP_COPROC_RISCV STREQUAL "y")
  36. set(TOOLCHAIN_FLAG ${idf_path}/components/ulp/cmake/toolchain-esp32s2-ulp-riscv.cmake)
  37. set(ULP_IS_RISCV ON)
  38. else()
  39. set(TOOLCHAIN_FLAG ${idf_path}/components/ulp/cmake/toolchain-esp32s2-ulp.cmake)
  40. set(ULP_IS_RISCV OFF)
  41. endif()
  42. endif()
  43. externalproject_add(${app_name}
  44. SOURCE_DIR ${idf_path}/components/ulp/cmake
  45. BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${app_name}
  46. INSTALL_COMMAND ""
  47. CMAKE_ARGS -DCMAKE_GENERATOR=${CMAKE_GENERATOR}
  48. -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FLAG}
  49. -DULP_S_SOURCES=$<TARGET_PROPERTY:${app_name},ULP_SOURCES>
  50. -DULP_APP_NAME=${app_name}
  51. -DCOMPONENT_DIR=${COMPONENT_DIR}
  52. -DCOMPONENT_INCLUDES=$<TARGET_PROPERTY:${COMPONENT_TARGET},INTERFACE_INCLUDE_DIRECTORIES>
  53. -DIDF_PATH=${idf_path}
  54. -DSDKCONFIG_HEADER=${SDKCONFIG_HEADER}
  55. -DPYTHON=${python}
  56. -DULP_COCPU_IS_RISCV=${ULP_IS_RISCV}
  57. ${extra_cmake_args}
  58. BUILD_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/${app_name} --target build
  59. BUILD_BYPRODUCTS ${ulp_artifacts} ${ulp_artifacts_extras} ${ulp_ps_sources}
  60. ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}
  61. BUILD_ALWAYS 1
  62. )
  63. set_property(TARGET ${app_name} PROPERTY ULP_SOURCES "${sources}")
  64. spaces2list(exp_dep_srcs)
  65. set_source_files_properties(${exp_dep_srcs} PROPERTIES OBJECT_DEPENDS ${ulp_artifacts})
  66. include_directories(${CMAKE_CURRENT_BINARY_DIR}/${app_name})
  67. add_custom_target(${app_name}_artifacts DEPENDS ${app_name})
  68. add_dependencies(${COMPONENT_LIB} ${app_name}_artifacts)
  69. target_linker_script(${COMPONENT_LIB} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}.ld)
  70. target_add_binary_data(${COMPONENT_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}.bin BINARY)
  71. endif()
  72. endfunction()