forked from nanoframework/nf-interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toolchain.ChibiOS.GCC.cmake
180 lines (134 loc) · 6.64 KB
/
toolchain.ChibiOS.GCC.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#
# Copyright (c) 2017 The nanoFramework project contributors
# See LICENSE file in the project root for full license information.
#
INCLUDE(CMakeForceCompiler)
# if( DEFINED CMAKE_CROSSCOMPILING )
# # subsequent toolchain loading is not really needed
# return()
# endif()
###################################################
# set C and C++ flags for compiler detection tests
###################################################
# IMPORTANT: these flags need to be removed after
# the compiler detection otherwise they'll get
# added to all compiler build calls and
# will colide with the use of nano.specs
###################################################
set(CMAKE_C_FLAGS_INIT "-specs=nosys.specs")
set(CMAKE_CXX_FLAGS_INIT "-specs=nosys.specs")
###################################################
# set toolchain directories
set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin)
set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/arm-none-eabi/include)
set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/arm-none-eabi/lib)
# the name of the operating system for which CMake is to build
set(CMAKE_SYSTEM_NAME Generic)
# name of the CPU CMake is building for
set(CMAKE_SYSTEM_PROCESSOR arm)
# macro to setup compilers
macro(SET_COMPILER_VAR var name)
find_program(CMAKE_${var} arm-none-eabi-${name} HINTS ${TOOLCHAIN_BIN_DIR} DOC "${name} tool")
endmacro()
# setup C compiler
if(NOT CMAKE_C_COMPILER)
SET_COMPILER_VAR(C_COMPILER gcc)
endif()
# setup C++ compiler
if(NOT CMAKE_CXX_COMPILER)
SET_COMPILER_VAR(CXX_COMPILER g++)
endif()
# setup Assembler compiler
SET_COMPILER_VAR(ASM-ATT_COMPILER as)
# other toolchain configurations
set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/arm-none-eabi-objcopy CACHE INTERNAL "objcopy tool")
set(CMAKE_OBJDUMP ${TOOLCHAIN_BIN_DIR}/arm-none-eabi-objdump CACHE INTERNAL "objdump tool")
set(CMAKE_SIZE ${TOOLCHAIN_BIN_DIR}/arm-none-eabi-size CACHE INTERNAL "size tool")
set(CMAKE_DEBUGER ${TOOLCHAIN_BIN_DIR}/arm-none-eabi-gdb CACHE INTERNAL "debuger")
# root paths to search on the filesystem for cross-compiling
set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/arm-none-eabi ${EXTRA_FIND_PATH})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# set required C and C++ standard for ALL targets
set(CMAKE_C_STANDARD 11 CACHE INTERNAL "C standard for all targets")
set(CMAKE_CXX_STANDARD 11 CACHE INTERNAL "C++ standard for all targets")
# set all C and C++ extensions to be OFF on ALL targets
# this forces the use of -std=c11 and -std=c++11 instead of -std=gnu11 and -std=gnu++11
set(CMAKE_C_EXTENSIONS OFF CACHE INTERNAL "C compiler extensions OFF")
set(CMAKE_CXX_EXTENSIONS OFF CACHE INTERNAL "C++ compiler extensions OFF")
function(NF_ADD_HEX_BIN_DUMP_TARGETS TARGET)
if(EXECUTABLE_OUTPUT_PATH)
set(FILENAME "${EXECUTABLE_OUTPUT_PATH}/${TARGET}")
else()
set(FILENAME "${TARGET}")
endif()
#get_filename_component(FNSHORT ${FILENAME} NAME_WE)
string(REGEX REPLACE "\\.[^.]*$" "" FNSHORT ${FILENAME})
# add targets for HEX, BIN and S19 formats with no output so they will always be built
add_custom_target(${TARGET}.hex DEPENDS ${TARGET} COMMAND ${CMAKE_OBJCOPY} -Oihex ${FILENAME} ${FNSHORT}.hex)
add_custom_target(${TARGET}.s19 DEPENDS ${TARGET} COMMAND ${CMAKE_OBJCOPY} -Osrec ${FILENAME} ${FNSHORT}.s19)
add_custom_target(${TARGET}.bin DEPENDS ${TARGET} COMMAND ${CMAKE_OBJCOPY} -Obinary ${FILENAME} ${FNSHORT}.bin)
add_custom_target(${TARGET}.dump DEPENDS ${TARGET} COMMAND ${CMAKE_OBJDUMP} -d -EL -S ${FILENAME} ${FNSHORT}.dump)
endfunction()
function(NF_PRINT_SIZE_OF_TARGETS TARGET)
if(EXECUTABLE_OUTPUT_PATH)
set(FILENAME "${EXECUTABLE_OUTPUT_PATH}/${TARGET}")
else()
set(FILENAME "${TARGET}")
endif()
add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_SIZE} -A -x ${FILENAME})
endfunction()
function(NF_SET_OPTIMIZATION_OPTIONS TARGET)
target_compile_options(${TARGET} PRIVATE
$<$<CONFIG:Debug>:-Og -femit-class-debug-always -g3 -ggdb>
$<$<CONFIG:Release>:-O3 -flto -fuse-linker-plugin -fno-fat-lto-objects>
$<$<CONFIG:MinSizeRel>:-Os -flto -fuse-linker-plugin -fno-fat-lto-objects>
$<$<CONFIG:RelWithDebInfo>:-Os -femit-class-debug-always -g3 -ggdb>
)
endfunction()
function(NF_SET_LINK_MAP TARGET)
# need to remove the .elf suffix from target name
string(FIND ${TARGET} "." TARGET_EXTENSION_DOT_INDEX)
string(SUBSTRING ${TARGET} 0 ${TARGET_EXTENSION_DOT_INDEX} TARGET_SHORT)
# add linker flags to generate map file
set_property(TARGET ${TARGET_SHORT}.elf APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-Map=${PROJECT_BINARY_DIR}/${TARGET_SHORT}.map,--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common")
endfunction()
function(NF_SET_COMPILER_DEFINITIONS TARGET)
# definition for platform
# (always ARM here)
# ChibiOS HAL community always include (nanoFramework overlay and official community contributions optionally)
target_compile_definitions(${TARGET} PUBLIC "-DPLATFORM_ARM -DHAL_USE_COMMUNITY")
# build types that have debugging capabilities AND are NOT RTM have to have the define 'NANOCLR_ENABLE_SOURCELEVELDEBUGGING'
if((NOT NF_BUILD_RTM) OR NF_FEATURE_DEBUGGER)
target_compile_definitions(${TARGET} PUBLIC "-DNANOCLR_ENABLE_SOURCELEVELDEBUGGING ")
endif()
# set compiler definition for RTM build option
if(NF_BUILD_RTM)
target_compile_definitions(${TARGET} PUBLIC -DBUILD_RTM)
endif()
# set compiler definition for using Application Domains feature
if(NF_FEATURE_USE_APPDOMAINS)
target_compile_definitions(${TARGET} PUBLIC -DNANOCLR_USE_APPDOMAINS)
endif()
# set compiler definition for implementing (or not) CRC32 in Wire Protocol
if(NF_WP_IMPLEMENTS_CRC32)
target_compile_definitions(${TARGET} PUBLIC -DWP_IMPLEMENTS_CRC32)
endif()
# set definition for Wire Protocol trace mask
target_compile_definitions(${TARGET} PUBLIC -DTRACE_MASK=${WP_TRACE_MASK})
# set compiler definition regarding inclusion of trace messages and checks on CLR
if(NF_PLATFORM_NO_CLR_TRACE)
target_compile_definitions(${TARGET} PUBLIC -DPLATFORM_NO_CLR_TRACE=1)
endif()
# set compiler definition regarding CLR IL inlining
if(NF_CLR_NO_IL_INLINE)
target_compile_definitions(${TARGET} PUBLIC -DNANOCLR_NO_IL_INLINE=1)
endif()
# include any extra compiler definitions coming from extra args
target_compile_definitions(${TARGET} PUBLIC ${ARGN})
endfunction()
function(NF_SET_LINKER_FILE TARGET LINKER_FILE_NAME)
# set linker file name
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "-T${LINKER_FILE_NAME}")
endfunction()