-
Notifications
You must be signed in to change notification settings - Fork 8
/
toolchain-arm-none-eabi.cmake
76 lines (64 loc) · 3.06 KB
/
toolchain-arm-none-eabi.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
##
## Author: Johannes Bruder
## https://github.com/jobroe/cmake-arm-embedded/
##
##
## CMake arm-none-eabi toolchain file
##
# Append current directory to CMAKE_MODULE_PATH for making device specific cmake modules visible
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
# Target definition
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
#---------------------------------------------------------------------------------------
# Set toolchain paths
#---------------------------------------------------------------------------------------
set(TOOLCHAIN arm-none-eabi)
if(NOT DEFINED TOOLCHAIN_PREFIX)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
find_path(TOOLCHAIN_PREFIX_FULL
NAMES "${TOOLCHAIN}-gcc"
PATHS "/usr/bin" "/usr/local/bin"
)
# remove '/bin'
file(REAL_PATH "${TOOLCHAIN_PREFIX_FULL}/.." TOOLCHAIN_PREFIX)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
set(TOOLCHAIN_PREFIX "/usr/local")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
# HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ARM\GNU Arm Embedded Toolchain 10.3-2021.10\InstallFolder
# C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10
find_path(TOOLCHAIN_PREFIX
NAMES bin/arm-none-eabi-gcc.exe
PATHS [HKLM\\SOFTWARE\\WOW6432Node\\ARM\\$\{AppRootNameStr\};InstallFolder]
)
else()
set(TOOLCHAIN_PREFIX "/usr")
endif()
endif()
message(STATUS "Will use toolchain at " ${TOOLCHAIN_PREFIX})
set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin)
set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include)
set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib)
# Set system depended extensions
if(WIN32)
set(TOOLCHAIN_EXT ".exe" )
else()
set(TOOLCHAIN_EXT "" )
endif()
# Perform compiler test with static library
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
#---------------------------------------------------------------------------------------
# Set compilers
#---------------------------------------------------------------------------------------
set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "C Compiler")
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler")
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler")
set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objcopy${TOOLCHAIN_EXT} CACHE INTERNAL "Utility to transform binary")
set(CMAKE_OBJDUMP ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objdump${TOOLCHAIN_EXT} CACHE INTERNAL "Utility to display binary information")
set(CMAKE_SIZE ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-size${TOOLCHAIN_EXT} CACHE INTERNAL "Utility to display binary size")
set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${${TOOLCHAIN}} ${CMAKE_PREFIX_PATH})
# This should be safe to set for a bare-metal cross-compiler
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)