Repository navigation
Expand file tree
/
Copy pathtoolchain.cmake
More file actions
105 lines (92 loc) · 3.38 KB
/
Copy pathtoolchain.cmake
File metadata and controls
105 lines (92 loc) · 3.38 KB
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
################################################################################
# Define standard flags
################################################################################
# Construct the linker flags
set(STANDARD_LINKER_FLAGS
# Link in a freestanding environment
-nostdlib -ffreestanding
# Define the architecture
--target=aarch64-none-elf
# Force static linkage
-fno-pie -static -Xlinker --apply-dynamic-relocs
# Force clang to use ld.lld-*
-fuse-ld=lld
# Extra optimization options
-Wl,--gc-sections -Wl,--as-needed
# Add in the global shared flags
${GLOBAL_COMPILE_FLAGS}
)
# Construct the common compiler flags
set(STANDARD_CXX_FLAGS
# Enable freestanding environment
-ffreestanding -nostdinc++ -nostdlib++
# Extra linking options
-fno-pie -static -Wno-gcc-compat -Wno-format
# Add in the global shared flags
${GLOBAL_COMPILE_FLAGS}
)
# Kernel C++ flags
set(KERNEL_CXX_FLAGS
${STANDARD_CXX_FLAGS}
# Pull in the configured kernel options
${KERNEL_EXTRA_COMPILE_FLAGS}
# Disable RTTI and C++ Exceptions
-fno-rtti -fno-exceptions
# Compile with all the warnings
-Wall -Wextra -Werror -Wno-vla-extension
# Disable general architecture features
-fno-omit-frame-pointer -fno-stack-protector -mno-red-zone
)
# Userspace C++ flags, both programs + libraries
set(USER_CXX_FLAGS
${STANDARD_CXX_FLAGS}
# Enable RTTI and force unwind table emission
-funwind-tables -fexceptions -frtti
# We should keep the frame pointer for stack traces
-fno-omit-frame-pointer
# Allow FPU in the architecture
-mcpu=cortex-a72+fp
# Un-define these built-in compiler definitions for libc/cxx/...
-Wno-builtin-macro-redefined
-U__STRICT_ANSI__
-U__STDCPP_THREADS__
)
list(SORT KERNEL_CXX_FLAGS)
list(REMOVE_DUPLICATES KERNEL_CXX_FLAGS)
list(SORT USER_CXX_FLAGS)
list(REMOVE_DUPLICATES USER_CXX_FLAGS)
################################################################################
# Toolchain setup
################################################################################
# Fake the assembler version, this has to be put before enable_language. We
# want to fake it because otherwise CMake takes forever to configure.
set(CMAKE_ASM_COMPILER_ID Clang)
# Do not let CMake add stupid flags, let us control all the flags
set(CMAKE_C_FLAGS "")
set(CMAKE_CXX_FLAGS "")
set(CMAKE_C_LINK_FLAGS "")
set(CMAKE_CXX_LINK_FLAGS "")
# Enable C, C++ and Assembly
enable_language(C CXX ASM)
# Force the linker to use Clang frontend, because flags are easier to set
if(MY_LINKER_OVERRIDE STREQUAL "")
set(CMAKE_LINKER ${CMAKE_CXX_COMPILER})
else()
set(CMAKE_LINKER ${MY_LINKER_OVERRIDE})
endif()
info_message("Using linker ${CMAKE_LINKER}")
set(CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_LINKER> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS> -o <TARGET> <CMAKE_CXX_LINK_FLAGS>"
)
set(CONFIG_USE_PRIVATE_LIBGCC TRUE)
# Set the compiler target separately since it can avoid cmake to add the flag
# "-arch arm64" for macOS
set(CMAKE_CXX_COMPILER_TARGET "aarch64-none-elf")
set(CMAKE_C_COMPILER_TARGET "aarch64-none-elf")
# Configure assembler command to use llvm-mc-*
string(JOIN " " STANDARD_ASM_FLAGS
-n --assemble --filetype=obj --triple=aarch64-none-elf
)
# If debug symbols is to be enabled in assembler, we need llvm-symbolizer,
# which unfortunately breaks :(
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> ${STANDARD_ASM_FLAGS} <SOURCE> -o <OBJECT>")