-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoolchain-gcc_cortex-m3.cmake
131 lines (111 loc) · 3.99 KB
/
toolchain-gcc_cortex-m3.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#******************************************************************************
# Copyright 2020 Embedded Office GmbH & Co. KG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#*****************************************************************************
# The Generic system name is used for embedded targets in CMake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
# Because the cross-compiler cannot directly generate a binary without
# complaining, just test compiling a static library instead of an executable
# program
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
#*****************************************************************************
#* Define commands
set(CMAKE_C_COMPILER "arm-none-eabi-gcc.exe" CACHE FILEPATH "" FORCE)
set(CMAKE_ASM_COMPILER "arm-none-eabi-gcc.exe" CACHE FILEPATH "" FORCE)
set(CMAKE_LINKER "arm-none-eabi-gcc.exe" CACHE FILEPATH "" FORCE)
set(CMAKE_OBJCOPY "arm-none-eabi-objcopy.exe" CACHE FILEPATH "" FORCE)
set(CMAKE_OBJDUMP "arm-none-eabi-objdump.exe" CACHE FILEPATH "" FORCE)
#*****************************************************************************
#* Defince command line options
set(CMAKE_C_FLAGS
"-mthumb -mcpu=cortex-m3 -Wall -Wextra -Wpedantic -Werror -ffunction-sections -fdata-sections"
CACHE STRING "" FORCE
)
set(CMAKE_ASM_FLAGS
"${CMAKE_C_FLAGS} -x assembler-with-cpp"
CACHE STRING "" FORCE
)
set(
CMAKE_EXE_LINKER_FLAGS
"-mthumb -mcpu=cortex-m3 -nostartfiles -Wl,--gc-sections"
CACHE STRING "" FORCE
)
# additional flags depending on the config command line switch
set(CMAKE_C_FLAGS_DEBUG # --config Debug
"-O0 -g3 -gdwarf"
CACHE STRING ""
)
set(CMAKE_ASM_FLAGS_DEBUG
"-O0 -g3 -gdwarf"
CACHE STRING ""
)
set(
CMAKE_EXE_LINKER_FLAGS_DEBUG
"-g3 -gdwarf"
CACHE STRING "" FORCE
)
set(CMAKE_C_FLAGS_RELEASE # --config Release
"-O3"
CACHE STRING ""
)
set(CMAKE_ASM_FLAGS_RELEASE
"-O3"
CACHE STRING ""
)
set(CMAKE_C_FLAGS_MINSIZEREL # --config MinSizeRel
"-Os"
CACHE STRING ""
)
set(CMAKE_ASM_FLAGS_MINSIZEREL
"-Os"
CACHE STRING ""
)
set(CMAKE_C_FLAGS_RELWITHDEBINFO # --config RelWithDebInfo
"-O2 -g"
CACHE STRING ""
)
set(CMAKE_ASM_FLAGS_RELWITHDEBINFO
"-O2 -g"
CACHE STRING ""
)
# setup standard flags
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#*****************************************************************************
#* functions for application specific appending of mapfile and linker script
function(setOutfile target filename)
# define the output image filename:
set_target_properties(${target} PROPERTIES OUTPUT_NAME "${filename}")
set(CMAKE_EXECUTABLE_SUFFIX_C .elf CACHE STRING "")
# define the output location:
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/$<LOWER_CASE:$<CONFIG>>")
# place the mapfile with same base name and extension .map in same output directory:
target_link_options(${target}
PUBLIC
-Wl,-Map,$<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.map
-Xlinker
--cref
-Wl,--print-memory-usage
-specs=nosys.specs
)
endfunction()
function(setLinkerScript target filename)
# define the linker command file in linker options
target_link_options(${target}
PUBLIC
-T ${filename}.lds
)
endfunction()