-
Notifications
You must be signed in to change notification settings - Fork 0
/
cortexm0.cmake
85 lines (68 loc) · 3.77 KB
/
cortexm0.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#[[processor specific but project independent parts of a CMake cortexM build.
include this file in the processor specific cmake file and include that in your project specific cmakelist.txt
see also postable.cmake, this guy sets that guy up but you have to do some defining in between this file and that one.
also sometimes you need to run just this file to get the compiler settings cached.
]]
#kill a warning: qt sets this when it launches cmake, but we don't produce QT stuff so we got a warning.
UNSET(QT_QMAKE_EXECUTABLE)
# Magic settings. Without it CMake tries to run test programs on the host platform, which fails of course.
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR Cortex-M0)
SET(gcccpu cortex-m0plus)
SET(TARGET arm-arm-none-eabi)
#we use a cross compiler, your OS *might* have a usable one, but I downloaded one from developer.arm.com:
SET(BINROOT /d/bin/gcc-arm-none-eabi/bin/)
# specify the cross compiler but don't let cmake test it, it tries to run a program on the host which doesn't work for microcontroller builds
SET(CMAKE_C_COMPILER_WORKS 1)
SET(CMAKE_C_COMPILER ${BINROOT}arm-none-eabi-gcc)
SET(CMAKE_CXX_COMPILER_WORKS 1)
SET(CMAKE_CXX_COMPILER ${BINROOT}arm-none-eabi-g++)
SET(AS ${BINROOT}arm-none-eabi-as)
SET(AR ${BINROOT}arm-none-eabi-ar)
SET(OBJCOPY ${BINROOT}arm-none-eabi-objcopy)
SET(OBJDUMP ${BINROOT}arm-none-eabi-objdump)
SET(SIZE ${BINROOT}arm-none-eabi-size)
# CMSIS heritage defines:
ADD_DEFINITIONS(-D__CORTEX_M=0)
ADD_DEFINITIONS(-D__FPU_PRESENT=0)
ADD_DEFINITIONS(-D__MPU_PRESENT=0)
#had to add this to get .s files to be processed:
ENABLE_LANGUAGE(ASM)
#wildy guessing on trying to get correct asm language:
SET(CMAKE_ASM_COMPILER_TARGET ${gcccpu})
#cli stuff common to assembler and compiler:
SET(gcc_arch "-mcpu=${gcccpu} ")
SET(CMAKE_ASM_FLAGS " ${gcc_arch} ")
#stuff common to C and C++. the -sections allows the linker to finely prune the output.
SET(ccli_common " ${gcc_arch} -fdata-sections -ffunction-sections -Wall -ffreestanding")
#3rd party code such as STM's HAL does extensive type punning of integers to addresses:
SET(CMAKE_C_FLAGS "${ccli_common} -std=c11 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast " CACHE INTERNAL "c compiler flags")
# -Wno-unknown-pragmas added to hide spew from clang pragmas that hide clang spew. phew!
SET(CMAKE_CXX_FLAGS "${ccli_common} -std=c++17 -Wno-unknown-pragmas -fno-rtti -fno-exceptions -fno-threadsafe-statics -MD " CACHE INTERNAL "cxx compiler flags")
# build the vector table file, set LAST_IRQ in your processor definition cmake file.
#can't figure out how to invoke this function, until then will continue to use a bash script mkIrqs.
#FUNCTION(GENIRQTABLE lastirq)
# SET(linkfile "//Table for $lastirq interrupts")
# FOREACH (anirq RANGE ${lastirq})
# LIST(APPEND linkfile "stub( ${anirq} )\;\n")
# ENDFOREACH ()
# LIST(APPEND linkfile "Handler VectorTable[] __attribute__((section(\".vectors.3\"))) = {")
# FOREACH (anirq RANGE ${lastirq})
# LIST(APPEND linkfile "" IrqName (${anirq}) ,"\n")
# ENDFOREACH ()
# LIST(APPEND linkfile "};")
# MESSAGE($(linkfile))
#ENDFUNCTION()
# every project needs cstartup, and we wish to optimize it independent of whether the rest of the project gets optimized
LIST(APPEND SOURCES
cortexm/cstartup.cpp
)
# we minimize the startup code, it is clear enough to not need to be debugged.
set_source_files_properties(cortexm/cstartup.cpp PROPERTIES COMPILE_OPTIONS "-g0;-O2;-fomit-frame-pointer")
# build the vector table file, set LAST_IRQ in your processor definition cmake file. You may have to manually delete this file when building for a different chip.
ADD_CUSTOM_COMMAND(
OUTPUT ${PROJECT_SOURCE_DIR}/nvicTable.inc
COMMAND cortexm/mkIrqs ${LAST_IRQ} >nvicTable.inc
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS ../cortexm/mkIrqs ${CMAKE_CURRENT_LIST_FILE}
)