Skip to content

Commit 5cfbd58

Browse files
committed
added cmakelists to build everything
1 parent 70f9fc7 commit 5cfbd58

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# set minimum version of CMake.
2+
cmake_minimum_required(VERSION 3.13)
3+
4+
# The Generic system name is used for embedded targets (targets without OS) in
5+
# CMake
6+
set(CMAKE_SYSTEM_NAME Generic)
7+
set(CMAKE_SYSTEM_PROCESSOR ARM)
8+
9+
# Supress Error when trying to test the compiler
10+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
11+
set(BUILD_SHARED_LIBS OFF)
12+
13+
# set project name and version
14+
project(flash_loader VERSION 0.0.1)
15+
16+
# enable assembly
17+
enable_language(ASM)
18+
19+
set(SOURCES
20+
${CMAKE_SOURCE_DIR}/entry/entry.c
21+
${CMAKE_SOURCE_DIR}/entry/cortex-vector.cpp
22+
${CMAKE_SOURCE_DIR}/flash/main.cpp
23+
${CMAKE_SOURCE_DIR}/flash/flash_device.cpp
24+
)
25+
26+
set(HEADERS
27+
${CMAKE_SOURCE_DIR}/entry/entry.hpp
28+
)
29+
30+
# add our executable
31+
add_executable(flash_loader
32+
${SOURCES} ${HEADERS}
33+
)
34+
35+
# enable C++20 support for the library
36+
target_compile_features(flash_loader PUBLIC cxx_std_20)
37+
38+
# set the output filename
39+
set_target_properties(flash_loader PROPERTIES OUTPUT_NAME "flash_loader" SUFFIX ".elf")
40+
41+
# compiler optimisations
42+
target_compile_options(flash_loader PRIVATE "-g")
43+
target_compile_options(flash_loader PRIVATE "-Os")
44+
45+
# set the cpu options for the compiler
46+
target_compile_options(flash_loader PRIVATE "-march=armv7e-m")
47+
target_compile_options(flash_loader PRIVATE "-mcpu=cortex-m4")
48+
target_compile_options(flash_loader PRIVATE "-mthumb")
49+
50+
# other compiler settings
51+
target_compile_options(flash_loader PRIVATE "-Wno-attributes")
52+
target_compile_options(flash_loader PRIVATE "-fno-non-call-exceptions")
53+
target_compile_options(flash_loader PRIVATE "-fno-common")
54+
target_compile_options(flash_loader PRIVATE "-ffunction-sections")
55+
target_compile_options(flash_loader PRIVATE "-fdata-sections")
56+
target_compile_options(flash_loader PRIVATE "-fno-exceptions")
57+
target_compile_options(flash_loader PRIVATE "-Wno-maybe-uninitialized")
58+
target_compile_options(flash_loader PRIVATE "-Wno-unused-local-typedefs")
59+
target_compile_options(flash_loader PRIVATE "-Wno-unused-but-set-variable")
60+
target_compile_options(flash_loader PRIVATE "-Wno-unused-function")
61+
target_compile_options(flash_loader PRIVATE "-fomit-frame-pointer")
62+
target_compile_options(flash_loader PRIVATE "-Wall")
63+
target_compile_options(flash_loader PRIVATE "-Werror")
64+
65+
# set the c++ only options
66+
target_compile_options(flash_loader PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>)
67+
target_compile_options(flash_loader PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
68+
target_compile_options(flash_loader PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fconcepts>)
69+
target_compile_options(flash_loader PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-get-exception-ptr>)
70+
target_compile_options(flash_loader PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>)
71+
72+
# set the cpu options for the linker
73+
target_link_options(flash_loader PRIVATE "-march=armv7e-m")
74+
target_link_options(flash_loader PRIVATE "-mcpu=cortex-m4")
75+
target_link_options(flash_loader PRIVATE "-mthumb")
76+
77+
# other linker options
78+
target_link_options(flash_loader PRIVATE "-ffunction-sections")
79+
target_link_options(flash_loader PRIVATE "-fdata-sections")
80+
target_link_options(flash_loader PUBLIC "-nostdlib")
81+
target_link_options(flash_loader PUBLIC "-nodefaultlibs")
82+
target_link_options(flash_loader PUBLIC "-nostartfiles")
83+
target_link_options(flash_loader PUBLIC "-Wl,--gc-sections")
84+
target_link_options(flash_loader PUBLIC "-Wl,-fatal-warnings")
85+
target_link_options(flash_loader PUBLIC "-Wl,-cref,-Map=flash_loader.map")
86+
target_link_options(flash_loader PUBLIC "-Wl,--print-memory-usage")
87+
88+
# link to the linkerscript of the target cpu
89+
target_link_options(flash_loader PUBLIC "-T${CMAKE_SOURCE_DIR}/linkerscript.ld")
90+
91+
# Custom commands for processing the build binary and show some statistics and debug info
92+
add_custom_command(TARGET flash_loader DEPENDS ${CMAKE_BINARY_DIR}/flash_loader.elf POST_BUILD COMMAND arm-none-eabi-objcopy ARGS -O binary -R .bss -R .stack flash_loader.elf flash_loader.bin)
93+
add_custom_command(TARGET flash_loader DEPENDS ${CMAKE_BINARY_DIR}/flash_loader.elf POST_BUILD COMMAND arm-none-eabi-objdump ARGS -C -S flash_loader.elf > flash_loader.lss)
94+
add_custom_command(TARGET flash_loader DEPENDS ${CMAKE_BINARY_DIR}/flash_loader.elf POST_BUILD COMMAND arm-none-eabi-objdump ARGS -C -sj .flash_device -sj .bss -sj .data -sj .rodata -S flash_loader.elf > flash_loader.memory)
95+
add_custom_command(TARGET flash_loader DEPENDS ${CMAKE_BINARY_DIR}/flash_loader.elf POST_BUILD COMMAND arm-none-eabi-size ARGS -A flash_loader.elf -x)

0 commit comments

Comments
 (0)