2018-04-18 02:57:45 +00:00
|
|
|
# Utilities for supporting linker script generation in the build system
|
|
|
|
|
2019-04-26 05:42:10 +00:00
|
|
|
# ldgen_set_variables
|
2018-04-18 02:57:45 +00:00
|
|
|
#
|
|
|
|
# Create the custom target to attach the fragment files and template files
|
|
|
|
# for the build to.
|
|
|
|
function(ldgen_set_variables)
|
2019-04-26 05:42:10 +00:00
|
|
|
add_custom_target(ldgen)
|
2018-04-18 02:57:45 +00:00
|
|
|
endfunction()
|
|
|
|
|
2019-04-26 05:42:10 +00:00
|
|
|
# ldgen_add_fragment_files
|
2018-04-18 02:57:45 +00:00
|
|
|
#
|
|
|
|
# Add one or more linker fragment files, and append it to the list of fragment
|
|
|
|
# files found so far.
|
2019-04-26 05:42:10 +00:00
|
|
|
function(ldgen_add_fragment_files component fragment_files)
|
2018-04-18 02:57:45 +00:00
|
|
|
spaces2list(fragment_files)
|
|
|
|
|
|
|
|
foreach(fragment_file ${fragment_files})
|
2019-04-26 05:42:10 +00:00
|
|
|
get_filename_component(_fragment_file ${fragment_file} ABSOLUTE)
|
|
|
|
list(APPEND _fragment_files ${_fragment_file})
|
2018-04-18 02:57:45 +00:00
|
|
|
endforeach()
|
|
|
|
|
2019-04-26 05:42:10 +00:00
|
|
|
set_property(TARGET ldgen APPEND PROPERTY FRAGMENT_FILES ${_fragment_files})
|
2018-11-27 05:26:15 +00:00
|
|
|
endfunction()
|
2018-04-18 02:57:45 +00:00
|
|
|
|
2019-04-26 05:42:10 +00:00
|
|
|
# ldgen_component_add
|
2018-11-27 05:26:15 +00:00
|
|
|
#
|
2019-04-26 05:42:10 +00:00
|
|
|
# Add component to known libraries for linker script generation
|
|
|
|
function(ldgen_component_add component_lib)
|
|
|
|
set_property(TARGET ldgen APPEND PROPERTY OUTPUT_LIBRARIES "$<TARGET_FILE:${component_lib}>")
|
|
|
|
set_property(TARGET ldgen APPEND PROPERTY LIBRARIES ${component_lib})
|
2018-04-18 02:57:45 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# ldgen_process_template
|
|
|
|
#
|
|
|
|
# Passes a linker script template to the linker script generation tool for
|
|
|
|
# processing
|
|
|
|
function(ldgen_process_template template output)
|
2019-04-26 05:42:10 +00:00
|
|
|
get_property(output_libraries TARGET ldgen PROPERTY OUTPUT_LIBRARIES)
|
|
|
|
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/ldgen_libraries.in CONTENT "$<JOIN:${output_libraries},\n>")
|
|
|
|
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/ldgen_libraries INPUT ${CMAKE_BINARY_DIR}/ldgen_libraries.in)
|
|
|
|
|
|
|
|
get_filename_component(filename "${template}" NAME_WE)
|
|
|
|
|
|
|
|
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
|
|
APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
|
|
|
|
"${CMAKE_BINARY_DIR}/ldgen_libraries.in"
|
|
|
|
"${CMAKE_BINARY_DIR}/ldgen_libraries")
|
2018-12-01 14:22:45 +00:00
|
|
|
|
2018-04-18 02:57:45 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${output}
|
2019-03-12 05:31:44 +00:00
|
|
|
COMMAND ${PYTHON} ${IDF_PATH}/tools/ldgen/ldgen.py
|
2018-04-18 02:57:45 +00:00
|
|
|
--config ${SDKCONFIG}
|
|
|
|
--fragments "$<JOIN:$<TARGET_PROPERTY:ldgen,FRAGMENT_FILES>,\t>"
|
|
|
|
--input ${template}
|
|
|
|
--output ${output}
|
2019-04-26 05:42:10 +00:00
|
|
|
--kconfig ${ROOT_KCONFIG}
|
2018-04-18 02:57:45 +00:00
|
|
|
--env "COMPONENT_KCONFIGS=${COMPONENT_KCONFIGS}"
|
|
|
|
--env "COMPONENT_KCONFIGS_PROJBUILD=${COMPONENT_KCONFIGS_PROJBUILD}"
|
|
|
|
--env "IDF_CMAKE=y"
|
2019-01-11 06:29:59 +00:00
|
|
|
--env "IDF_PATH=${IDF_PATH}"
|
2018-04-18 02:57:45 +00:00
|
|
|
--env "IDF_TARGET=${IDF_TARGET}"
|
2019-04-26 05:42:10 +00:00
|
|
|
--libraries-file ${CMAKE_BINARY_DIR}/ldgen_libraries
|
|
|
|
--objdump ${CMAKE_OBJDUMP}
|
|
|
|
DEPENDS ${template} $<TARGET_PROPERTY:ldgen,FRAGMENT_FILES>
|
|
|
|
$<TARGET_PROPERTY:ldgen,LIBRARIES> ${SDKCONFIG}
|
2018-04-18 02:57:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
get_filename_component(output_name ${output} NAME)
|
|
|
|
add_custom_target(ldgen_${output_name}_script DEPENDS ${output})
|
|
|
|
add_dependencies(ldgen ldgen_${output_name}_script)
|
|
|
|
endfunction()
|
|
|
|
|
2019-04-26 05:42:10 +00:00
|
|
|
# ldgen_add_dependencies
|
2018-04-18 02:57:45 +00:00
|
|
|
#
|
2019-04-26 05:42:10 +00:00
|
|
|
# Add dependency of project executable to ldgen custom target.
|
2018-11-11 07:36:10 +00:00
|
|
|
function(ldgen_add_dependencies)
|
|
|
|
if(IDF_PROJECT_EXECUTABLE)
|
|
|
|
add_dependencies(${IDF_PROJECT_EXECUTABLE} ldgen)
|
|
|
|
endif()
|
2019-04-26 05:42:10 +00:00
|
|
|
endfunction()
|