1# For each supported target, a memory.ld.in and sections.ld.in is processed and dictate the 2# memory layout of the app. 3# 4# memory.ld.in goes through the preprocessor 5# sections.ld.in goes through linker script generator 6 7idf_build_get_property(target IDF_TARGET) 8idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER) 9 10set(ld_input "${CMAKE_CURRENT_LIST_DIR}/${target}/memory.ld.in") 11set(ld_output "${CMAKE_CURRENT_BINARY_DIR}/ld/memory.ld") 12target_linker_script(${COMPONENT_LIB} INTERFACE "${ld_output}") 13 14file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ld") 15 16# Process the template file through the linker script generation mechanism, and use the output for linking the 17# final binary 18target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/${target}/sections.ld.in" 19 PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/sections.ld") 20 21idf_build_get_property(config_dir CONFIG_DIR) 22# Preprocess memory.ld.in linker script to include configuration, becomes memory.ld 23add_custom_command( 24 OUTPUT ${ld_output} 25 COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o ${ld_output} -I ${config_dir} 26 -I "${CMAKE_CURRENT_LIST_DIR}" ${ld_input} 27 MAIN_DEPENDENCY ${ld_input} 28 DEPENDS ${sdkconfig_header} 29 COMMENT "Generating memory.ld linker script..." 30 VERBATIM) 31 32add_custom_target(memory_ld DEPENDS ${ld_output}) 33add_dependencies(${COMPONENT_LIB} memory_ld) 34