component_ulp_common.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. if(NOT CMAKE_BUILD_EARLY_EXPANSION)
  2. spaces2list(ULP_S_SOURCES)
  3. foreach(ulp_s_source ${ULP_S_SOURCES})
  4. get_filename_component(ulp_s_source ${ulp_s_source} ABSOLUTE)
  5. list(APPEND ulp_s_sources ${ulp_s_source})
  6. endforeach()
  7. foreach(ulp_s_source ${ulp_s_sources})
  8. get_filename_component(ulp_ps_source ${ulp_s_source} NAME_WE)
  9. set(ulp_ps_output ${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}/${ulp_ps_source}.ulp.S)
  10. list(APPEND ulp_ps_sources ${ulp_ps_output})
  11. endforeach()
  12. set(ulp_artifacts_prefix ${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}/${ULP_APP_NAME})
  13. set(ulp_artifacts ${ulp_artifacts_prefix}.bin
  14. ${ulp_artifacts_prefix}.ld
  15. ${ulp_artifacts_prefix}.h)
  16. set(ulp_artifacts_extras ${ulp_artifacts_prefix}.map
  17. ${ulp_artifacts_prefix}.sym
  18. ${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}/esp32.ulp.ld)
  19. # Replace the separator for the list of ULP source files that will be passed to
  20. # the external ULP project. This is a workaround to the bug https://public.kitware.com/Bug/view.php?id=16137.
  21. string(REPLACE ";" "|" ulp_s_sources "${ulp_s_sources}")
  22. idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
  23. idf_build_get_property(idf_path IDF_PATH)
  24. idf_build_get_property(python PYTHON)
  25. externalproject_add(${ULP_APP_NAME}
  26. SOURCE_DIR ${idf_path}/components/ulp/cmake
  27. BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}
  28. INSTALL_COMMAND ""
  29. CMAKE_ARGS -DCMAKE_GENERATOR=${CMAKE_GENERATOR}
  30. -DCMAKE_TOOLCHAIN_FILE=${idf_path}/components/ulp/cmake/toolchain-ulp.cmake
  31. -DULP_S_SOURCES=${ulp_s_sources} -DULP_APP_NAME=${ULP_APP_NAME}
  32. -DCOMPONENT_DIR=${COMPONENT_DIR}
  33. # Even though this resolves to a ';' separated list, this is fine. This must be special behavior
  34. # for generator expressions.
  35. -DCOMPONENT_INCLUDES=$<TARGET_PROPERTY:${COMPONENT_LIB},INTERFACE_INCLUDE_DIRECTORIES>
  36. -DIDF_PATH=${idf_path}
  37. -DSDKCONFIG=${sdkconfig_header}
  38. -DPYTHON=${python}
  39. BUILD_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME} --target build
  40. BUILD_BYPRODUCTS ${ulp_artifacts} ${ulp_artifacts_extras} ${ulp_ps_sources}
  41. ${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}/${ULP_APP_NAME}
  42. BUILD_ALWAYS 1
  43. LIST_SEPARATOR |
  44. )
  45. spaces2list(ULP_EXP_DEP_SRCS)
  46. set_source_files_properties(${ULP_EXP_DEP_SRCS} PROPERTIES OBJECT_DEPENDS ${ulp_artifacts})
  47. include_directories(${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME})
  48. add_custom_target(${ULP_APP_NAME}_artifacts DEPENDS ${ULP_APP_NAME})
  49. add_dependencies(${COMPONENT_LIB} ${ULP_APP_NAME}_artifacts)
  50. target_linker_script(${COMPONENT_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}/${ULP_APP_NAME}.ld)
  51. target_add_binary_data(${COMPONENT_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}/${ULP_APP_NAME}.bin BINARY)
  52. endif()