generated from feabhas/cmake-target
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolchain-STM32F407.cmake
66 lines (54 loc) · 2.29 KB
/
toolchain-STM32F407.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
# set CMAKE_SYSTEM_NAME to define build as CMAKE_CROSSCOMPILING
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION Cortex-M4-STM32F407)
set(CMAKE_SYSTEM_PROCESSOR arm)
# settinge either of the compilers builds the absolute paths for the other tools:
# ar, nm, objcopy, objdump, ranlib, readelf -- but not as, ld, size
# if the compiler cannot be found the try_compile() function will fail the build
# set(CMAKE_C_COMPILER arm-none-eabi-gcc)
# set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
# we need to get compiler path itself, for the toolchain
# but still rely on try_compile to check we have a valid compiler
find_program(CROSS_GCC_PATH arm-none-eabi-gcc)
get_filename_component(TOOLCHAIN ${CROSS_GCC_PATH} PATH)
set(CMAKE_C_COMPILER ${TOOLCHAIN}/arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN}/arm-none-eabi-g++)
set(TOOLCHAIN_AS ${TOOLCHAIN}/arm-none-eabi-as CACHE STRING "arm-none-eabi-as")
set(TOOLCHAIN_LD ${TOOLCHAIN}/arm-none-eabi-ld CACHE STRING "arm-none-eabi-ld")
set(TOOLCHAIN_SIZE ${TOOLCHAIN}/arm-none-eabi-size CACHE STRING "arm-none-eabi-size")
# --specs=nano.specs is both a compiler and linker option
set(ARM_OPTIONS -mcpu=cortex-m4 -mfloat-abi=soft --specs=nano.specs)
add_compile_options(
${ARM_OPTIONS}
-fmessage-length=0
-funsigned-char
-ffunction-sections
-fdata-sections
# -fno-exceptions
# -fno-move-loop-invariants -fstack-usage
-MMD
-MP)
add_compile_definitions(
STM32F407xx
USE_FULL_ASSERT
$<$<CONFIG:DEBUG>:TRACE>
# OS_USE_TRACE_SEMIHOSTING_DEBUG # semi-hosting options mutually exclusive
$<$<CONFIG:DEBUG>:OS_USE_TRACE_SEMIHOSTING_STDOUT>
$<$<CONFIG:DEBUG>:OS_USE_SEMIHOSTING>)
# use this to avoid running the linker during test compilation
# set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# use these options to verify the linker can create an ELF file
# when not doing a static link
add_link_options(
${ARM_OPTIONS}
$<$<CONFIG:DEBUG>:--specs=rdimon.specs> # use the semihosted version of the syscalls
$<$<CONFIG:RELEASE>:--specs=nosys.specs>
$<$<CONFIG:DEBUG>:-u_printf_float>
$<$<CONFIG:DEBUG>:-u_scanf_float>
-nostartfiles
LINKER:--gc-sections
LINKER:--build-id)
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(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)