ldgen.cmake 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Utilities for supporting linker script generation in the build system
  2. # __ldgen_add_fragment_files
  3. #
  4. # Add one or more linker fragment files, and append it to the list of fragment
  5. # files found so far.
  6. function(__ldgen_add_fragment_files fragment_files)
  7. spaces2list(fragment_files)
  8. foreach(fragment_file ${fragment_files})
  9. get_filename_component(abs_path ${fragment_file} ABSOLUTE)
  10. list(APPEND _fragment_files ${abs_path})
  11. endforeach()
  12. idf_build_set_property(__LDGEN_FRAGMENT_FILES "${_fragment_files}" APPEND)
  13. endfunction()
  14. # __ldgen_add_component
  15. #
  16. # Generate sections info for specified target to be used in linker script generation
  17. function(__ldgen_add_component component_lib)
  18. idf_build_set_property(__LDGEN_LIBRARIES "$<TARGET_FILE:${component_lib}>" APPEND)
  19. idf_build_set_property(__LDGEN_DEPENDS ${component_lib} APPEND)
  20. endfunction()
  21. # __ldgen_process_template
  22. #
  23. # Passes a linker script template to the linker script generation tool for
  24. # processing
  25. function(__ldgen_process_template template output)
  26. idf_build_get_property(idf_target IDF_TARGET)
  27. idf_build_get_property(idf_path IDF_PATH)
  28. idf_build_get_property(build_dir BUILD_DIR)
  29. idf_build_get_property(ldgen_libraries __LDGEN_LIBRARIES GENERATOR_EXPRESSION)
  30. file(GENERATE OUTPUT ${build_dir}/ldgen_libraries.in CONTENT $<JOIN:${ldgen_libraries},\n>)
  31. file(GENERATE OUTPUT ${build_dir}/ldgen_libraries INPUT ${build_dir}/ldgen_libraries.in)
  32. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  33. APPEND PROPERTY ADDITIONAL_CLEAN_FILES
  34. "${build_dir}/ldgen_libraries.in"
  35. "${build_dir}/ldgen_libraries")
  36. idf_build_get_property(ldgen_fragment_files __LDGEN_FRAGMENT_FILES GENERATOR_EXPRESSION)
  37. idf_build_get_property(ldgen_depends __LDGEN_DEPENDS GENERATOR_EXPRESSION)
  38. # Create command to invoke the linker script generator tool.
  39. idf_build_get_property(sdkconfig SDKCONFIG)
  40. idf_build_get_property(root_kconfig __ROOT_KCONFIG)
  41. idf_build_get_property(python PYTHON)
  42. idf_build_get_property(config_env_path CONFIG_ENV_PATH)
  43. if($ENV{LDGEN_CHECK_MAPPING})
  44. set(ldgen_check "--check-mapping"
  45. "--check-mapping-exceptions" "${idf_path}/tools/ci/check_ldgen_mapping_exceptions.txt")
  46. message(STATUS "Mapping check enabled in ldgen")
  47. endif()
  48. add_custom_command(
  49. OUTPUT ${output}
  50. COMMAND ${python} "${idf_path}/tools/ldgen/ldgen.py"
  51. --config "${sdkconfig}"
  52. --fragments-list "${ldgen_fragment_files}"
  53. --input "${template}"
  54. --output "${output}"
  55. --kconfig "${root_kconfig}"
  56. --env-file "${config_env_path}"
  57. --libraries-file "${build_dir}/ldgen_libraries"
  58. --objdump "${CMAKE_OBJDUMP}"
  59. ${ldgen_check}
  60. DEPENDS ${template} ${ldgen_fragment_files} ${ldgen_depends} ${SDKCONFIG}
  61. VERBATIM
  62. )
  63. get_filename_component(_name ${output} NAME)
  64. add_custom_target(__ldgen_output_${_name} DEPENDS ${output})
  65. add_dependencies(__idf_build_target __ldgen_output_${_name})
  66. idf_build_set_property(__LINK_DEPENDS ${output} APPEND)
  67. endfunction()