-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoolchain.cmake
42 lines (42 loc) · 1.66 KB
/
toolchain.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
###############################
# Toolchain
message("TOOL_CHAIN_PREFIX=${TOOL_CHAIN_PREFIX}")
# input required
if (NOT TOOL_CHAIN_PREFIX)
message(FATAL_ERROR "TOOL_CHAIN_PREFIX required but not set")
endif ()
# standard
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# cross options
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
# search programs
find_program(CMAKE_ASM_COMPILER NAMES ${TOOL_CHAIN_PREFIX}-gcc)
find_program(CMAKE_C_COMPILER NAMES ${TOOL_CHAIN_PREFIX}-gcc)
find_program(CMAKE_CXX_COMPILER NAMES ${TOOL_CHAIN_PREFIX}-g++)
find_program(CMAKE_OBJCOPY NAMES ${TOOL_CHAIN_PREFIX}-objcopy)
# set(CMAKE_ASM_COMPILER ${TOOL_CHAIN_PREFIX}-gcc)
# set(CMAKE_C_COMPILER ${TOOL_CHAIN_PREFIX}-gcc)
# set(CMAKE_CXX_COMPILER ${TOOL_CHAIN_PREFIX}-g++)
# set(CMAKE_OBJCOPY ${TOOL_CHAIN_PREFIX}-objcopy)
message("CMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER}")
message("CMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
message("CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
message("CMAKE_OBJCOPY=${CMAKE_OBJCOPY}")
# check tools
if ((NOT CMAKE_ASM_COMPILER) OR (NOT CMAKE_C_COMPILER) OR (NOT CMAKE_CXX_COMPILER) OR (NOT CMAKE_OBJCOPY))
message(FATAL_ERROR "Valid toolchain not found")
endif ()
# get sysroot
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-sysroot
OUTPUT_VARIABLE ARM_GCC_SYSROOT OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CMAKE_SYSROOT ${ARM_GCC_SYSROOT})
# set root path
set(CMAKE_FIND_ROOT_PATH ${CMAKE_C_COMPILER})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)