-
Notifications
You must be signed in to change notification settings - Fork 18
/
utils.cmake
29 lines (24 loc) · 1.18 KB
/
utils.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
set(LD_DIR "${CMAKE_CURRENT_LIST_DIR}/ld/${target}")
function(__add_linker_script_and_dep target ldscript)
set(ldscript_path ${LD_DIR}/${ldscript})
target_link_libraries(${target} PRIVATE -T ${ldscript_path})
set_target_properties(${target} PROPERTIES LINK_DEPENDS ${ldscript_path})
endfunction()
function(add_linker_scripts target)
__add_linker_script_and_dep(${target} memory.ld)
__add_linker_script_and_dep(${target} common.ld)
__add_linker_script_and_dep(${target} romfuncs.ld)
endfunction()
function(add_map_file target filename)
set(mapfile "${CMAKE_BINARY_DIR}/${filename}")
target_link_libraries(${target} PRIVATE "-Wl,--Map=${mapfile}")
endfunction()
function(make_binary elf_target filename)
add_custom_target(${elf_target}-size ALL DEPENDS ${elf_target})
add_custom_command(TARGET ${elf_target}-size POST_BUILD COMMAND riscv-none-elf-size ${elf_target})
add_custom_target(${filename}-binary ALL DEPENDS ${filename})
add_custom_command(OUTPUT ${filename}
COMMAND ${CMAKE_OBJCOPY}
ARGS -v -O binary ${elf_target} ${CMAKE_BINARY_DIR}/${filename}
DEPENDS ${elf_target})
endfunction()