-
Notifications
You must be signed in to change notification settings - Fork 0
/
toolchain_common.cmake
61 lines (52 loc) · 2.44 KB
/
toolchain_common.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
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR riscv)
set(TARGET riscv${RISCV_XLEN}-unknown-elf)
list(JOIN RISCV_EXTENSIONS "" RISCV_EXTENSIONS_JOINED)
set(MARCH rv${RISCV_XLEN}i${RISCV_EXTENSIONS_JOINED})
list(FIND RISCV_EXTENSIONS d HAVE_RISCV_DOUBLE)
list(FIND RISCV_EXTENSIONS f HAVE_RISCV_FLOAT)
if("${HAVE_RISCV_DOUBLE}" GREATER "-1")
set(RISCV_ABI_FLOAT d)
set(RISCV_FLEN 64)
elseif("${HAVE_RISCV_FLOAT}" GREATER "-1")
set(RISCV_ABI_FLOAT f)
set(RISCV_FLEN 32)
else()
set(RISCV_SOFT_FLOAT "-Xclang -msoft-float")
unset(RISCV_ABI_FLOAT)
set(RISCV_FLEN 0)
endif()
if("${RISCV_XLEN}" EQUAL "32")
set(MABI ilp${RISCV_XLEN}${RISCV_ABI_FLOAT})
else()
set(MABI lp${RISCV_XLEN}${RISCV_ABI_FLOAT})
endif()
set(MCMODEL medany)
set(RISCV_EXTENSIONS_MATTR_LIST ${RISCV_EXTENSIONS})
list(TRANSFORM RISCV_EXTENSIONS_MATTR_LIST REPLACE "^(.+)$" ",-mllvm=--mattr=+\\1")
list(JOIN RISCV_EXTENSIONS_MATTR_LIST " -Wl" RISCV_EXTENSIONS_WL_MATTR)
cmake_path(SET RISCV_TOOLCHAIN_DIR NORMALIZE ${CMAKE_CURRENT_LIST_DIR})
set(LLVM_PREFIX ${RISCV_TOOLCHAIN_DIR}/bin/)
set(LLVM_SUFFIX "")
set(RISCV_COMMON_FLAGS "-march=${MARCH} -mabi=${MABI} -mcmodel=${MCMODEL} -mno-relax -mtune=rocket-rv${RISCV_XLEN}")
set(CMAKE_C_COMPILER_TARGET ${TARGET})
set(CMAKE_CXX_COMPILER_TARGET ${TARGET})
set(CMAKE_ASM_COMPILER_TARGET ${TARGET})
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS} ${RISCV_COMMON_FLAGS} ${RISCV_SOFT_FLOAT}")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS} ${RISCV_COMMON_FLAGS} ${RISCV_SOFT_FLOAT}")
set(CMAKE_ASM_FLAGS_INIT "${CMAKE_ASM_FLAGS} ${RISCV_COMMON_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld -nostdlib -static -Wl,-mllvm=--target-abi=${MABI} -Wl${RISCV_EXTENSIONS_WL_MATTR}")
set(CMAKE_C_COMPILER ${LLVM_PREFIX}clang${LLVM_SUFFIX})
set(CMAKE_CXX_COMPILER ${LLVM_PREFIX}clang++${LLVM_SUFFIX})
set(CMAKE_ASM_COMPILER ${LLVM_PREFIX}clang${LLVM_SUFFIX})
set(CMAKE_ADDR2LINE ${LLVM_PREFIX}llvm-addr2line${LLVM_SUFFIX})
set(CMAKE_AR ${LLVM_PREFIX}llvm-ar${LLVM_SUFFIX})
set(CMAKE_NM ${LLVM_PREFIX}llvm-nm${LLVM_SUFFIX})
set(CMAKE_RANLIB ${LLVM_PREFIX}llvm-ranlib${LLVM_SUFFIX})
set(CMAKE_READELF ${LLVM_PREFIX}llvm-readelf${LLVM_SUFFIX})
set(CMAKE_OBJCOPY ${LLVM_PREFIX}llvm-objcopy${LLVM_SUFFIX})
set(CMAKE_OBJDUMP ${LLVM_PREFIX}llvm-objdump${LLVM_SUFFIX})
set(CMAKE_STRIP ${LLVM_PREFIX}llvm-strip${LLVM_SUFFIX})
set(CMAKE_SIZE ${LLVM_PREFIX}llvm-size${LLVM_SUFFIX})
set(CMAKE_LINKER ${LLVM_PREFIX}lld${LLVM_SUFFIX})