1+ # The Generic system name is used for embedded targets (targets without OS) in
2+ # CMake
3+ set (CMAKE_SYSTEM_NAME Generic)
4+ set (CMAKE_SYSTEM_PROCESSOR ARM)
5+
6+ # Supress Error when trying to test the compiler
7+ set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
8+ set (BUILD_SHARED_LIBS OFF )
9+
10+ # set minimum version of CMake.
11+ cmake_minimum_required (VERSION 3.22 )
12+
13+ # set project name and version
14+ project (klib VERSION 0.0.1)
15+
16+ # provide the klib directory for the project (repo root, one level up)
17+ set (KLIB_DIR ${CMAKE_CURRENT_LIST_DIR } /..)
18+
19+ # include klib and all common toolchain + target setup from the klib repo root.
20+ # This configures the build-type flags, includes the target cpu (creating the
21+ # target_cpu / target_cpu_options targets), defines the add_linkerscript()
22+ # helper and builds the klib library target.
23+ # Note: KLIB_DIR needs to point to your klib installation folder.
24+ include (${KLIB_DIR} /CMakeLists.txt )
25+
126# set the sources
2- set (SOURCES
27+ set (SOURCES
328 ${CMAKE_CURRENT_SOURCE_DIR } /main.cpp
429 ${CMAKE_CURRENT_SOURCE_DIR } /button.cpp
530
631 # example for including the startup.cpp
7- ${CMAKE_SOURCE_DIR } /targets/chip/${TARGET_CPU} /startup.cpp
32+ ${KLIB_DIR } /targets/chip/${TARGET_CPU} /startup.cpp
833)
934
1035set (HEADERS)
@@ -14,12 +39,6 @@ add_executable(klib_project
1439 ${SOURCES} ${HEADERS}
1540)
1641
17- # enable LTO
18- target_compile_options (klib PUBLIC "-flto" )
19- target_compile_options (klib PUBLIC "-fuse-linker-plugin" )
20- target_link_options (klib PUBLIC "-flto" )
21- target_link_options (klib PUBLIC "-fuse-linker-plugin" )
22-
2342# set the output filename
2443set_target_properties (klib_project PROPERTIES OUTPUT_NAME "klib" SUFFIX ".elf" )
2544
@@ -33,7 +52,7 @@ target_compile_definitions(klib PUBLIC "KLIB_DEFAULT_COUT=rtt")
3352target_compile_definitions (klib PUBLIC "KLIB_DEFAULT_CIN=rtt" )
3453
3554# override the rtt buffer size (not required and not used when no segger rtt is used)
36- target_compile_definitions (klib PUBLIC "BUFFER_SIZE_UP=512 " )
55+ target_compile_definitions (klib PUBLIC "BUFFER_SIZE_UP=256 " )
3756target_compile_definitions (klib PUBLIC "BUFFER_SIZE_DOWN=16" )
3857
3958# set if we should support certain callbacks
@@ -49,13 +68,12 @@ target_link_libraries(klib_project PUBLIC m)
4968set (TARGET_LINKERSCRIPT ${CMAKE_CURRENT_SOURCE_DIR } /linkerscript.ld)
5069
5170# link to the linkerscript of the target cpu
52- target_link_options (klib_project PUBLIC "-T${TARGET_LINKERSCRIPT} " )
53- set_target_properties (klib_project PROPERTIES LINK_DEPENDS ${TARGET_LINKERSCRIPT} )
71+ add_linkerscript (klib_project ${TARGET_LINKERSCRIPT} "" )
5472
5573# add the project directory to the include directories
56- include_directories (${CMAKE_CURRENT_SOURCE_DIR } )
74+ include_directories (${CMAKE_CURRENT_SOURCE_DIR } )
5775
58- # Custom commands for processing the build binary and show some statistics and debug info
76+ # Custom commands for processing the build binary and show some statistics and debug info
5977add_custom_command (TARGET klib_project DEPENDS ${CMAKE_BINARY_DIR } /klib.elf POST_BUILD COMMAND arm-none-eabi-objcopy ARGS -O binary -R .bss -R .stack klib.elf klib.bin )
6078add_custom_command (TARGET klib_project DEPENDS ${CMAKE_BINARY_DIR } /klib.elf POST_BUILD COMMAND arm-none-eabi-objcopy ARGS -O ihex -R .bss -R .stack klib.elf klib.hex )
6179add_custom_command (TARGET klib_project DEPENDS ${CMAKE_BINARY_DIR } /klib.elf POST_BUILD COMMAND arm-none-eabi-objdump ARGS -C -S klib.elf > klib.lss )
0 commit comments