File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed
Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 1+ # include the linkerscript generator needed to preprocess the linkerscripts
2+ include (${CMAKE_SOURCE_DIR} /targets/arm/linkerscript/linkerscript.cmake)
3+
14# set the sources
25set (SOURCES
36 ${CMAKE_CURRENT_SOURCE_DIR} /main.cpp
@@ -40,8 +43,7 @@ target_link_libraries(klib_project PUBLIC target_cpu)
4043target_link_libraries (klib_project PUBLIC m)
4144
4245# link to the linkerscript of the target cpu
43- target_link_options (klib_project PUBLIC "-T${TARGET_LINKERSCRIPT} " )
44- set_target_properties (klib_project PROPERTIES LINK_DEPENDS ${TARGET_LINKERSCRIPT} )
46+ add_linkerscript(klib_project ${TARGET_LINKERSCRIPT} )
4547
4648# add the project directory to the include directories
4749include_directories (${CMAKE_CURRENT_SOURCE_DIR} )
Original file line number Diff line number Diff line change 1+ # helper function to preprocess a linker script. This allows
2+ # using C preprocessor in the linkerscript files (including
3+ # macroes, conditionals, etc)
4+ function (add_linkerscript target linkerscript options )
5+ set (output "${CMAKE_BINARY_DIR} /linkerscript.ld" )
6+ set (CURRENT_DIR "${CMAKE_SOURCE_DIR} /targets/arm/linkerscript" )
7+
8+ # run the preprocessor on the linkerscript
9+ add_custom_command (
10+ OUTPUT ${output}
11+ # run the linkerscript through the C preprocessor. Force include the base linkerscript template.
12+ COMMAND ${CMAKE_C_COMPILER} -E -P -x c ${linkerscript} -o ${output} -include ${CURRENT_DIR} /linkerscript.ld ${options}
13+ DEPENDS ${linkerscript} ${CURRENT_DIR} /linkerscript.ld
14+ COMMENT "Preprocessing linker script ${linkerscript} "
15+ VERBATIM
16+ )
17+
18+ # create a custom target to generate the linkerscript
19+ add_custom_target (generate_linkerscript DEPENDS "${output} " )
20+ add_dependencies (${target} generate_linkerscript)
21+
22+ # add the linkerscript to the target
23+ target_link_options (${target} PUBLIC "-T${output} " )
24+ set_target_properties (${target} PROPERTIES LINK_DEPENDS ${output} )
25+ endfunction ()
26+
Original file line number Diff line number Diff line change 1+ /* macro to define the vectors section. Should be pointed to the correct memory region */
2+ #define VECTORS () \
3+ .vectors (READONLY) : \
4+ { \
5+ . = ALIGN (4 ); \
6+ /* vector table */ \
7+ KEEP (*(.vectors .vectors .*)); \
8+ . = ALIGN (4 ); \
9+ }
You can’t perform that action at this time.
0 commit comments