forked from hermit-os/libhermit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
238 lines (186 loc) · 6.77 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
cmake_minimum_required(VERSION 3.7)
include(ExternalProject)
include(cmake/HermitCore.cmake)
project (HermitCore)
### Kernel
# generate config files
add_subdirectory(include/hermit)
add_kernel_module_sources("kernel" "kernel/*.c")
add_kernel_module_sources("libkern" "libkern/*.c")
add_kernel_module_sources("mm" "mm/*.c")
if("${TARGET_ARCH}" STREQUAL "x86_64-hermit")
add_kernel_module_sources("drivers" "drivers/net/*.c")
else()
add_kernel_module_sources("drivers" "drivers/net/uhyve-net.c")
endif()
set(LWIP_SRC lwip/src)
add_kernel_module_sources("lwip" "${LWIP_SRC}/api/*.c")
add_kernel_module_sources("lwip" "${LWIP_SRC}/arch/*.c")
add_kernel_module_sources("lwip" "${LWIP_SRC}/core/*.c")
add_kernel_module_sources("lwip" "${LWIP_SRC}/core/ipv4/*.c")
add_kernel_module_sources("lwip" "${LWIP_SRC}/core/ipv6/*.c")
add_kernel_module_sources("lwip" "${LWIP_SRC}/netif/*.c")
get_kernel_modules(KERNEL_MODULES)
foreach(MODULE ${KERNEL_MODULES})
get_kernel_module_sources(SOURCES ${MODULE})
# maintain list of all objects that will end up in libhermit.a
list(APPEND KERNEL_OBJECTS $<TARGET_OBJECTS:${MODULE}>)
add_library(${MODULE} OBJECT ${SOURCES})
# this is kernel code
target_compile_definitions(${MODULE}
PRIVATE -D__KERNEL__)
target_compile_definitions(${MODULE}
PRIVATE -DMAX_ARGC_ENVC=${MAX_ARGC_ENVC})
target_compile_options(${MODULE}
PRIVATE ${HERMIT_KERNEL_FLAGS})
target_include_directories(${MODULE}
PUBLIC ${HERMIT_KERNEL_INCLUDES})
# suppress all LwIP compiler warnings. Not our code, so we cannot fix
if("${MODULE}" STREQUAL "lwip")
target_compile_options(${MODULE}
PRIVATE -w)
endif()
endforeach()
if("${TARGET_ARCH}" STREQUAL "aarch64-hermit")
# add arch/aarch64 and its objects
add_subdirectory(arch/aarch64)
list(APPEND KERNEL_OBJECTS
$<TARGET_OBJECTS:${AARCH64_KERNEL_C_TARGET}>)
else()
# add arch/x86_64 and its objects
add_subdirectory(arch/x86_64)
list(APPEND KERNEL_OBJECTS
$<TARGET_OBJECTS:${X86_KERNEL_ASM_TARGET}>
$<TARGET_OBJECTS:${X86_KERNEL_C_TARGET}>)
endif()
# finally build libhermit.a
add_library(hermit-bootstrap STATIC ${KERNEL_OBJECTS})
set_target_properties(hermit-bootstrap PROPERTIES
ARCHIVE_OUTPUT_NAME hermit)
# after compiling ASM sources, we need to post-process them. Adding this
# dependency makes sure that this is done before hermit is linked
if("${TARGET_ARCH}" STREQUAL "aarch64-hermit")
add_dependencies(hermit-bootstrap ${AARCH64_KERNEL_TARGET})
else()
add_dependencies(hermit-bootstrap ${X86_KERNEL_TARGET})
endif()
add_custom_command(
TARGET
hermit-bootstrap POST_BUILD
# rename sections in final library
COMMAND
${CMAKE_OBJCOPY} --rename-section .bss=.kbss
--rename-section .text=.ktext
--rename-section .data=.kdata
$<TARGET_FILE:hermit-bootstrap>
# copy libhermit.a into local prefix directory so that all subsequent
# targets can link against the freshly built version (as opposed to
# linking against the one supplied by the toolchain)
COMMAND
${CMAKE_COMMAND} -E make_directory ${LOCAL_PREFIX_ARCH_LIB_DIR}
COMMAND
${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:hermit-bootstrap>
${LOCAL_PREFIX_ARCH_LIB_DIR}/
# and also copy headers into local prefix
COMMAND
${CMAKE_COMMAND} -E make_directory ${LOCAL_PREFIX_ARCH_INCLUDE_DIR}/hermit
COMMAND
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/include/hermit/*.h
${LOCAL_PREFIX_ARCH_INCLUDE_DIR}/hermit/
COMMAND
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/include/hermit/*.asm
${LOCAL_PREFIX_ARCH_INCLUDE_DIR}/hermit/)
# deploy libhermit.a and headers for package creation
install(TARGETS hermit-bootstrap
DESTINATION ${TARGET_ARCH}/lib
COMPONENT bootstrap)
install(DIRECTORY include/hermit
DESTINATION ${TARGET_ARCH}/include/
COMPONENT bootstrap
FILES_MATCHING
PATTERN *.h)
install(FILES tools/init.sh
DESTINATION tools)
# provide custom target to only install libhermit without its runtimes which is
# needed during the compilation of the cross toolchain
add_custom_target(hermit-bootstrap-install
DEPENDS
hermit-bootstrap ${ARCH_KERNEL_TARGET}
COMMAND
${CMAKE_COMMAND}
-DCMAKE_INSTALL_COMPONENT=bootstrap
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-P cmake_install.cmake)
# The target 'hermit' includes the HermitCore kernel and several runtimes.
# Applications should depend on this target if they link against HermitCore.
add_custom_target(hermit
DEPENDS hermit-bootstrap)
### External projects
#
# Build projects externally and deploy into temporary common prefix, will later
# be relocated for installation
## HermitCore's own tools such as Qemu/KVM proxy
build_external(caves ${HERMIT_ROOT}/caves "")
if("${TARGET_ARCH}" STREQUAL "x86_64-hermit")
build_external(arch_x86_loader ${HERMIT_ROOT}/arch/x86_64/loader "")
## iRCCE
build_external(ircce ${HERMIT_ROOT}/usr/ircce "")
add_dependencies(hermit ircce)
## XRay profiler
build_external(xray ${HERMIT_ROOT}/usr/xray "")
add_dependencies(hermit xray)
## end of x86 specific part
endif()
## Tests and benchmarks
build_external(tests ${HERMIT_ROOT}/usr/tests hermit)
build_external(benchmarks ${HERMIT_ROOT}/usr/benchmarks hermit)
if("${TARGET_ARCH}" STREQUAL "x86_64-hermit")
build_external(openmpbench ${HERMIT_ROOT}/usr/openmpbench hermit)
endif()
## relocate the local prefix to our install destination
install(DIRECTORY ${LOCAL_PREFIX_DIR}/
DESTINATION ${CMAKE_INSTALL_PREFIX}/
USE_SOURCE_PERMISSIONS)
### QEmu
# Start HermitCore as multi-kernel in a QEmu VM
add_custom_target(qemu
COMMAND
qemu-system-x86_64
-machine accel=kvm -cpu host
-smp 10 -m 8G -numa node,nodeid=0,cpus=0-4 -numa node,nodeid=1,cpus=5-9
-kernel ${HERMIT_ROOT}/config/bzImage
-append "root=/dev/ram0 rootfstype=ramfs init=init console=ttyS0"
-net nic,model=rtl8139 -net user -net dump
-nographic -monitor telnet:127.0.0.1:1235,server,nowait
-fsdev local,security_model=none,id=fsdev0,path=${LOCAL_PREFIX_DIR}
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hermit
-s
USES_TERMINAL VERBATIM)
# create a QEmu target that depends on everything
get_property(_TARGETS
DIRECTORY .
PROPERTY BUILDSYSTEM_TARGETS)
add_custom_target(qemu-dep
DEPENDS
${_TARGETS} qemu)
### Packaging
set(CPACK_PACKAGE_NAME libhermit)
set(CPACK_SYSTEM_NAME all)
set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 2)
set(CPACK_PACKAGE_VERSION_PATCH 10)
set(CPACK_PACKAGE_CONTACT "Stefan Lankes <slankes@eonerc.rwth-aachen.de>")
# build .deb, .rpm and .tar.bz2 packages
set(CPACK_GENERATOR DEB;RPM;TBZ2)
# needed in order for tests and bechmark to use correct install prefix
set(CPACK_SET_DESTDIR on)
## Debian specific
# not dependent on Debian system architecture
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE all)
## RPM specific
# libhermit is currently not relocatable
set(CPACK_PACKAGE_RELOCATABLE FALSE)
include(CPack)