-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
CMakeLists.txt
231 lines (195 loc) · 9.67 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
cmake_minimum_required (VERSION 3.13.4)
if (__BUILD_UNIT_TESTS)
project (vali-testing C)
include(CMakeParseArguments)
function (add_unit_test)
cmake_parse_arguments(
UNIT_TEST # prefix of output variables
"" # list of names of the boolean arguments (only defined ones will be true)
"FILE" # list of names of mono-valued arguments
"INCLUDES;DEFINES;LIBS" # list of names of multi-valued arguments (output variables are lists)
${ARGN} # arguments of the function to parse, here we take the all original ones
)
string (REPLACE ".c" "" TEST_FILENAME ${UNIT_TEST_FILE})
string (REPLACE "_test." "." TEST_FILE ${UNIT_TEST_FILE})
list (REMOVE_ITEM UNIT_TEST_INCLUDES "${CMAKE_SOURCE_DIR}/librt/libc/include")
add_executable (${TEST_FILENAME} ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/${UNIT_TEST_FILE})
target_include_directories(${TEST_FILENAME} PRIVATE ${UNIT_TEST_INCLUDES} ${CMAKE_SOURCE_DIR}/testing/include)
target_compile_definitions(${TEST_FILENAME} PRIVATE ${UNIT_TEST_DEFINES})
target_link_libraries (${TEST_FILENAME} PRIVATE cmocka ${UNIT_TEST_LIBS})
add_test (NAME ${TEST_FILENAME} COMMAND ${TEST_FILENAME})
endfunction ()
if (${VALI_ARCH} STREQUAL "amd64")
add_definitions (-m64 -DMOLLENOS -DTESTING)
elseif (${VALI_ARCH} STREQUAL "i386")
add_definitions (-m32 -DMOLLENOS -DTESTING)
else ()
message (FATAL_ERROR "Unsupported unit test architecture: ${VALI_ARCH}")
endif ()
# enable testing
enable_testing()
add_subdirectory(testing)
# a lot of support libraries reside here, so add this first
add_subdirectory(librt)
# add all projects that support unit tests
add_subdirectory(kernel)
#add_subdirectory(services)
return()
endif ()
# Enable the system image switch
set (VALI_BUILD ON)
set (VALI_BOOTSTRAP ON)
include (cmake/SetupEnvironment.cmake)
project (ValiOS)
# Setup options and defaults
option (VALI_ENABLE_KERNEL_TRACE "Enable debug tracing in the kernel" ON)
option (VALI_ENABLE_SMP "Enable support for multiple cores" ON)
option (VALI_ENABLE_DEBUG_CONSOLE "Enable the debug console on boot instead of splash" ON)
option (VALI_ENABLE_DEBUG_MODE "Enter the debug console mode after boot instead of normal system startup" ON)
option (VALI_ENABLE_NESTED_IRQS "Enable nested IRQs instead of traditional single IRQs" OFF)
option (VALI_ENABLE_SIGNALS "Enable support for thread signals" ON)
option (VALI_ENABLE_DRIVERS "Allow loading drivers, otherwise boot stops after loading services" ON)
option (VALI_ENABLE_EHCI "Enable support for USB 2.0" ON)
option (VALI_ENABLE_EHCI_64BIT "Enable support for USB 2.0 64 bit addressing mode" OFF)
option (VALI_BUILD_UNIT_TESTS "Build unit tests" OFF)
set (VALI_INIT_APP "vioarr.run" CACHE STRING "The application to execute for system initialization")
set (VALI_ARCH "amd64" CACHE STRING "Platform architecture to build Vali for")
set_property (CACHE VALI_ARCH PROPERTY STRINGS i386 amd64)
set (ENV{VALI_ARCH} ${VALI_ARCH})
# Set paths and define the structure of the initial system image
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set (VALI_PATH_DEPLOY ${CMAKE_BINARY_DIR}/deploy)
set (VALI_PATH_DEPLOY_HDD ${CMAKE_BINARY_DIR}/deploy/hdd)
set (VALI_PATH_DEPLOY_BOOT ${CMAKE_BINARY_DIR}/deploy/hdd/boot)
set (VALI_PATH_DEPLOY_SYSTEM ${CMAKE_BINARY_DIR}/deploy/hdd/system)
set (VALI_PATH_DEPLOY_SYSTEM_BIN ${CMAKE_BINARY_DIR}/deploy/hdd/system/bin)
set (VALI_PATH_DEPLOY_SYSTEM_SRV ${CMAKE_BINARY_DIR}/deploy/hdd/system/services)
set (VALI_PATH_DEPLOY_SYSTEM_MODS ${CMAKE_BINARY_DIR}/deploy/hdd/system/modules)
set (VALI_PATH_DEPLOY_SHARED ${CMAKE_BINARY_DIR}/deploy/hdd/shared)
set (VALI_PATH_DEPLOY_SHARED_BIN ${CMAKE_BINARY_DIR}/deploy/hdd/shared/bin)
set (VALI_PATH_DEPLOY_SHARED_LIB ${CMAKE_BINARY_DIR}/deploy/hdd/shared/lib)
set (VALI_PATH_DEPLOY_SHARED_INC ${CMAKE_BINARY_DIR}/deploy/hdd/shared/include)
set (VALI_PATH_DEPLOY_SHARED_MAPS ${CMAKE_BINARY_DIR}/deploy/hdd/shared/maps)
set (VALI_PATH_DEPLOY_SHARED_SHARE ${CMAKE_BINARY_DIR}/deploy/hdd/shared/share)
# Setup utility macros for targets
macro (deploy_target_to_initrd RDTARGET)
add_custom_command (TARGET ${RDTARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${RDTARGET}> ${VALI_PATH_DEPLOY_SYSTEM_BIN}
)
endmacro ()
macro (deploy_file_to_initrd)
if (${ARGC} GREATER_EQUAL 3)
set (FILES_TO_DEPLOY "${ARGN}")
list (POP_FRONT FILES_TO_DEPLOY) # target
list (POP_FRONT FILES_TO_DEPLOY) # path
get_target_property(D2RD_SOURCE_DIR ${ARGV0} SOURCE_DIR)
foreach (RD_FILE ${FILES_TO_DEPLOY})
add_custom_command (TARGET ${ARGV0} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${D2RD_SOURCE_DIR}/${RD_FILE}" "${VALI_PATH_DEPLOY_SYSTEM}/${ARGV1}"
)
endforeach ()
else ()
message (STATUS "usage: deploy_file_to_initrd <target> <path> files ...")
message (FATAL_ERROR "Invalid number of arguments (${ARGC}) for deploy_file_to_initrd")
endif ()
endmacro ()
# Setup tools
set (TOOL_RD ${CMAKE_BINARY_DIR}/tools/host/bin/mkvafs)
set (TOOL_DU ${CMAKE_BINARY_DIR}/tools/host/bin/osbuilder)
set (TOOL_LZ ${CMAKE_BINARY_DIR}/tools/host/bin/lzss)
# Create neccessary directories
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_HDD})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_BOOT})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_SYSTEM})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_SYSTEM_BIN})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_SYSTEM_SRV})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_SYSTEM_MODS})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_SHARED})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_SHARED_BIN})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_SHARED_LIB})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_SHARED_INC})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_SHARED_MAPS})
file (MAKE_DIRECTORY ${VALI_PATH_DEPLOY_SHARED_SHARE})
# Read the project version
file(READ "VERSION" VALI_VERSION)
# Configure projects that are specified
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${VALI_ARCH}PlatformConfig.cmake")
message (FATAL_ERROR "The specified platform ${VALI_ARCH} has no configuration file")
endif ()
include (cmake/HandleFeatureFlags.cmake)
include (cmake/${VALI_ARCH}PlatformConfig.cmake)
# Configure bootloader
add_subdirectory (boot)
# Generate all the neccessary files for the builds
add_subdirectory (protocols)
include_directories (${CMAKE_BINARY_DIR}/protocols)
# Configure the runtime libraries
add_subdirectory (librt)
# Configure the kernel project
add_subdirectory (kernel)
# Build services
add_subdirectory (services)
# Build modules
add_subdirectory (modules)
# Build tools
add_subdirectory (tools)
# Build userspace applications
# these are not the entire userspace that exists, most of these applications
# are just utility apps and small test programs that exists only to test a single
# feature or implementation. To run these you must have the entire userspace up and
# running as we have no terminal environment builtin.
add_subdirectory (apps)
# build unit tests
if (VALI_BUILD_UNIT_TESTS)
include (ExternalProject)
ExternalProject_Add(unit_tests
SOURCE_DIR ${CMAKE_SOURCE_DIR}
CMAKE_CACHE_ARGS
-DVALI_ARCH:STRING=${VALI_ARCH}
-D__BUILD_UNIT_TESTS:BOOL=ON
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/testing
)
endif ()
# Installation and utility targets
add_custom_target (install_prepare
COMMAND ${TOOL_RD} --arch ${VALI_ARCH} --compression aplib --out ${VALI_PATH_DEPLOY_BOOT}/initrd.mos ${VALI_PATH_DEPLOY_SYSTEM}
COMMAND ${TOOL_LZ} c ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/kernel.mos ${VALI_PATH_DEPLOY_BOOT}/kernel.mos
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:phoenix> ${VALI_PATH_DEPLOY_BOOT}
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/tools/utils.py --cp --source ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} --dest ${VALI_PATH_DEPLOY_SHARED_BIN} --pattern *.dll
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/tools/utils.py --cp --source ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} --dest ${VALI_PATH_DEPLOY_SHARED_LIB} --pattern *.lib
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/tools/utils.py --cp --source ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} --dest ${VALI_PATH_DEPLOY_SHARED_MAPS} --pattern *.map
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_dependencies(install_prepare imager rd lzss)
add_custom_target (install_img
COMMAND ${TOOL_DU} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/models/vali-gpt.yaml --target img
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_dependencies(install_img install_prepare)
add_custom_target (install_vmdk
COMMAND ${TOOL_DU} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/models/vali-gpt.yaml --target vmdk
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_dependencies(install_vmdk install_prepare)
add_custom_command(
OUTPUT always_run.special disk_usb.img
COMMAND ${CMAKE_COMMAND} -E copy disk.img disk_usb.img
)
add_custom_target (run_bochs
COMMAND bochs -q -f ${CMAKE_CURRENT_SOURCE_DIR}/tools/setup.bochsrc
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS disk_usb.img
)
add_custom_target (run_qemu
COMMAND qemu-system-x86_64
-D ./log.txt -monitor stdio -smp 1 -m 4096
-bios /usr/share/OVMF/OVMF_CODE.fd
-drive if=virtio,file=disk.img,format=raw
-net none -no-reboot
-serial file:./qserial.txt
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
USES_TERMINAL
)