-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_ConfigureCortexFlags.cmake
104 lines (82 loc) · 3.23 KB
/
_ConfigureCortexFlags.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
# Copyright (C) 2019 Third Pin LLC
# www.thirdpin.io
#
# Written by:
# Dmitrii Lisin <[email protected]>
# Ilya Stolyarov <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
macro(configure_cortex_flags CORTEX_NAME)
# Flags to prepare code to cleaning by linker
set(DEAD_CODEDATA_REMOVAL_FLAGS "-fno-common -ffunction-sections -fdata-sections")
# -fuse-cxa-atexit Register destructors for objects
# with static storage duration with the _cxa_atexit function rather
# than the atexit function.
# This option is required for fully standards-compliant handling
# of static destructors, but only works if
# your C library supports _cxa_atexit.
#
# Newlib nano unsupport it so disable it.
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} ${DEAD_CODEDATA_REMOVAL_FLAGS}")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} ${DEAD_CODEDATA_REMOVAL_FLAGS} -fno-rtti -fno-exceptions -fno-unwind-tables -fno-threadsafe-statics")
set(CMAKE_ASM_FLAGS_INIT "${CMAKE_ASM_FLAGS_INIT} -x assembler-with-cpp")
if (${CORTEX_NAME} STREQUAL "cortex-m4")
set(COMPILE_FLAGS
"-mcpu=cortex-m4 -march=armv7e-m -mthumb \
-mfloat-abi=hard -mfpu=fpv4-sp-d16"
)
set(CMAKE_C_FLAGS_INIT
"${CMAKE_C_FLAGS_INIT} ${COMPILE_FLAGS}"
)
set(CMAKE_CXX_FLAGS_INIT
"${CMAKE_CXX_FLAGS_INIT} ${COMPILE_FLAGS}"
)
elseif (${CORTEX_NAME} STREQUAL "cortex-m3")
set(COMPILE_FLAGS
"-mcpu=cortex-m3 -march=armv7-m -mthumb -msoft-float"
)
set(CMAKE_C_FLAGS_INIT
"${CMAKE_C_FLAGS_INIT} ${COMPILE_FLAGS}"
)
set(CMAKE_CXX_FLAGS_INIT
"${CMAKE_CXX_FLAGS_INIT} ${COMPILE_FLAGS}"
)
elseif (${CORTEX_NAME} STREQUAL "cortex-m0")
set(COMPILE_FLAGS
"-mcpu=cortex-m0 -march=armv6-m -mthumb -msoft-float"
)
set(CMAKE_C_FLAGS_INIT
"${CMAKE_C_FLAGS_INIT} ${COMPILE_FLAGS}"
)
set(CMAKE_CXX_FLAGS_INIT
"${CMAKE_CXX_FLAGS_INIT} ${COMPILE_FLAGS}"
)
elseif (${CORTEX_NAME} STREQUAL "cortex-a9")
set(COMPILE_FLAGS
"-mcpu=cortex-a9 -march=armv7-a -mthumb -mfloat-abi=hard -mfpu=neon"
)
set(CMAKE_C_FLAGS_INIT
"${CMAKE_C_FLAGS_INIT} ${COMPILE_FLAGS}"
)
set(CMAKE_CXX_FLAGS_INIT
"${CMAKE_CXX_FLAGS_INIT} ${COMPILE_FLAGS}"
)
else ()
message(WARNING
"Processor not recognised, "
"compiler flags not configured."
)
endif ()
set(BUILD_SHARED_LIBS OFF)
endmacro()