project_include.cmake 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. endif()
  33. if(IDF_TARGET STREQUAL "esp32s2")
  34. set(TOOLCHAIN_FLAG ${idf_path}/components/ulp/cmake/toolchain-esp32s2-ulp.cmake)
  35. endif()
  36. externalproject_add(${app_name}
  37. SOURCE_DIR ${idf_path}/components/ulp/cmake
  38. BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${app_name}
  39. INSTALL_COMMAND ""
  40. CMAKE_ARGS -DCMAKE_GENERATOR=${CMAKE_GENERATOR}
  41. -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FLAG}
  42. -DULP_S_SOURCES=$<TARGET_PROPERTY:${app_name},ULP_SOURCES>
  43. -DULP_APP_NAME=${app_name}
  44. -DCOMPONENT_DIR=${COMPONENT_DIR}
  45. -DCOMPONENT_INCLUDES=$<TARGET_PROPERTY:${COMPONENT_TARGET},INTERFACE_INCLUDE_DIRECTORIES>
  46. -DIDF_PATH=${idf_path}
  47. -DSDKCONFIG_HEADER=${SDKCONFIG_HEADER}
  48. -DPYTHON=${python}
  49. ${extra_cmake_args}
  50. BUILD_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/${app_name} --target build
  51. BUILD_BYPRODUCTS ${ulp_artifacts} ${ulp_artifacts_extras} ${ulp_ps_sources}
  52. ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}
  53. BUILD_ALWAYS 1
  54. )
  55. set_property(TARGET ${app_name} PROPERTY ULP_SOURCES "${sources}")
  56. spaces2list(exp_dep_srcs)
  57. set_source_files_properties(${exp_dep_srcs} PROPERTIES OBJECT_DEPENDS ${ulp_artifacts})
  58. include_directories(${CMAKE_CURRENT_BINARY_DIR}/${app_name})
  59. add_custom_target(${app_name}_artifacts DEPENDS ${app_name})
  60. add_dependencies(${COMPONENT_LIB} ${app_name}_artifacts)
  61. target_linker_script(${COMPONENT_LIB} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}.ld)
  62. target_add_binary_data(${COMPONENT_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}.bin BINARY)
  63. endif()
  64. endfunction()