-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
175 lines (134 loc) · 5.06 KB
/
CMakeLists.txt
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
########################################################################################################################
# file: CMakeLists.txt
#
# usage:
# Edit "VARIABLES"-section to suit project requirements.
# Build instructions:
# cmake -S ./ -B ./build/ -D CMAKE_BUILD_TYPE=Debug -D CMAKE_TOOLCHAIN_FILE=./riscv-gcc.cmake
# cmake --build ./build/ --target all
#
# Building on Windows:
# cmake -S ./ -B ./build/ -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug -D CMAKE_TOOLCHAIN_FILE=./riscv-gcc.cmake
# cmake --build ./build/ --target all
# Cleaning:
# cmake --build ./build/ --target clean
# Install:
# cmake --build ./build/ --target install
########################################################################################################################
cmake_minimum_required(VERSION 3.10)
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
project(baremetal-ide LANGUAGES ASM C CXX)
#################################
# Options
#################################
option(BAREMETAL_BUILD_RISCV "Build for RISC-V platform" ON )
option(BAREMETAL_BUILD_X86 "Build for x86 platform" OFF )
option(CHIP "Build for a specific platform" OFF )
option(PROF_COV "Build with profiling and coverage" OFF )
option(GCNO_ONLY "Only build gcno files" OFF )
option(USE_PGO "Build with profile guided optimization" OFF )
#################################
# Toolchain Targets
#################################
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
#################################
# Flags
#################################
# CPU architecture
set(ARCH "rv64imafd")
set(ABI "lp64d")
set(CMODEL "medany")
set(ARCH_FLAGS -march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL})
# spec
set(SPECS "nosys.specs")
set(SPEC_FLAGS -specs=${SPECS})
# convert CHIP to lowercase
string(TOLOWER ${CHIP} CHIP)
# linker script
# HACK: ideally this should be handled by glossy, but currently i couldn't
# figure out a way to propagate the LINKER_SCRIPT variable to the compile and link commands
if (NOT CHIP)
message(STATUS "Chip not specified, using default configuration")
set(CHIP "default")
set(LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/glossy/glossy.ld")
else()
set(LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/platform/${CHIP}/${CHIP}.ld")
endif()
add_subdirectory(${CMAKE_SOURCE_DIR}/platform/${CHIP})
add_compile_options(-O1)
add_compile_options(-Wall -Wextra)
if (PROF_COV)
message(STATUS "Building with profiling and coverage")
add_compile_options(-fprofile-arcs -ftest-coverage)
endif()
if (GCNO_ONLY)
message(STATUS "Building only gcno files")
add_compile_options(-ftest-coverage)
endif()
if (USE_PGO)
add_compile_options(-fprofile-use)
endif()
add_compile_options(-fno-builtin)
# add_compile_options(-ffunction-sections -fdata-sections -fno-common -fno-builtin-printf -fno-pie)
# add_compile_options(-Wall -Wextra -Warray-bounds -Wno-unused-parameter -Wcast-qual)
add_compile_options(${ARCH_FLAGS})
add_compile_options(${SPEC_FLAGS})
add_link_options(-static)
# add_link_options(-ffunction-sections -fdata-sections -fno-common -fno-builtin-printf -fno-pie)
# add_link_options(-Wall -Wextra -Warray-bounds -Wno-unused-parameter -Wcast-qual)
add_link_options(-nostartfiles)
add_link_options(${ARCH_FLAGS})
add_link_options(${SPEC_FLAGS})
add_link_options(-T ${LINKER_SCRIPT})
# add_link_options(-rtlib=compiler-rt)
# add_link_options(-Wl,--rtlib-path=/scratch/iansseijelly/riscv-llvm-install/lib/linux/libclang_rt.builtins-riscv64.a)
if (PROF_COV)
add_link_options(-lgcov)
endif()
#################################
# Build
#################################
add_executable(app
app/src/main.c
)
target_include_directories(app PUBLIC app/include)
# add std lib path
include_directories(/scratch/iansseijelly/chipyard/.conda-env/riscv-tools/riscv64-unknown-elf/include)
link_directories(/scratch/iansseijelly/chipyard/.conda-env/riscv-tools/riscv64-unknown-elf/lib)
#################################
# Dependencies
#################################
add_subdirectory(driver)
add_subdirectory(glossy)
add_subdirectory(lib)
add_subdirectory(examples)
target_link_libraries(app PRIVATE
-L${CMAKE_BINARY_DIR}/glossy -Wl,--whole-archive glossy -Wl,--no-whole-archive
)
if (PROF_COV)
target_link_libraries(app PRIVATE gcov)
endif()
#################################
# Library Installation
#################################
set(CMAKE_INSTALL_PREFIX "$ENV{RISCV}/riscv64-unknown-elf")
set_property(TARGET glossy PROPERTY PUBLIC_HEADER
glossy/include/riscv.h
glossy/include/riscv_encoding.h
glossy/include/riscv_interrupt.h
)
set_property(TARGET glossy PROPERTY RESOURCE
glossy/glossy.ld
glossy/glossy.specs
)
install(TARGETS glossy
LIBRARY DESTINATION "lib"
PUBLIC_HEADER DESTINATION "include"
RESOURCE DESTINATION "lib"
)
install(TARGETS htif
LIBRARY DESTINATION "lib"
PUBLIC_HEADER DESTINATION "include"
RESOURCE DESTINATION "lib"
)