project_include.cmake 3.4 KB

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