Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
316 lines (273 loc) · 11.1 KB
/
Copy pathCMakeLists.txt
File metadata and controls
316 lines (273 loc) · 11.1 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
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# CMakeLists.txt
#
# Copyright (c) 2024-2025 Omar Berrow
cmake_minimum_required(VERSION 3.10)
# Boolean options.
option (OBOS_UP "Make a Uniprocessor-Build of obos.")
option (OBOS_ENABLE_UBSAN "Enables UBSan.")
option (OBOS_ENABLE_KASAN "Enables KAsan.")
option (OBOS_ENABLE_FANALYZER "(Developers only) Enables the compiler's static analyzer")
option (OBOS_ENABLE_WERROR "(Developers only) Enables the -Werror option")
option (OBOS_USE_CLANG "Use clang instead of GCC to build.")
option (OBOS_NVS_SAVE_S3 "Enable compile-time support for saving NVS before S3" ON)
option (OBOS_ENABLE_LOCK_PROFILING "(Experimental) Enable profiling for locks.")
option (OBOS_ENABLE_PROFILER "(Experimental) Enable profiling.")
option (OBOS_LAZY_IRQL "Enables lazy IRQL. Recommended if the main target of the kernel is a hypervisor, where writing to cr8 can be slow.")
option (OBOS_USE_OBOS_GCC "Uses arch-obos-gcc instead of obos-elf-gcc. Ignored if OBOS_USE_CLANG is true.")
option (OBOS_COMPILE_USER_UTILS "Compiles user examples" ${OBOS_USE_OBOS_GCC})
option (OBOS_ONLY_COMPILE_USER_UTILS "Only compile user utilities" OFF)
option (OBOS_USE_LIMINE "Use Limine instead of Hyper on supported architectures" OFF)
option (OBOS_ENABLE_UHDA "Whether to include uHDA" ON)
option (OBOS_DEBUG_FREE_SIZE "Whether to check for mismatching allocation and free sizes in the allocator" OFF)
set (OBOS_LAZY_IRQL OFF)
if (NOT OBOS_USE_OBOS_GCC AND OBOS_COMPILE_USER_UTILS)
message(WARNING "OBOS_COMPILE_USER_UTILS must be OFF if OBOS_USE_OBOS_GCC is OFF")
set(OBOS_COMPILE_USER_UTILS OFF)
endif()
if (OBOS_USE_CLANG AND OBOS_COMPILE_USER_UTILS)
message(WARNING "OBOS_COMPILE_USER_UTILS must be OFF if OBOS_USE_CLANG is ON")
set(OBOS_COMPILE_USER_UTILS OFF)
endif()
# String options
# NOTE: Unless we add FORCE to the end, CMake shouldn't override user values.
set (OUTPUT_DIR ${CMAKE_SOURCE_DIR}/out CACHE STRING "The output directory.")
set (OBOS_PAGE_REPLACEMENT_ALGORITHM "Aging" CACHE STRING "(Kernel developers only) The page replacement algorithm used by the MM.")
set (OBOS_DEV_PREFIX "/dev" CACHE STRING "Directory where the kernel places devices.")
set (OBOS_PERM_PREFIX "/sys/perm" CACHE STRING "Directory where the kernel checks for capabilities")
set (OBOS_CLANG_SUFFIX "" CACHE STRING "Some Linux distributions add a suffix to various clang and LLVM commands, such as the version used. Specify that suffix, if needed")
file (TO_CMAKE_PATH "${OUTPUT_DIR}" OUTPUT_DIR)
file (TO_NATIVE_PATH "${OUTPUT_DIR}" OUTPUT_DIR)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
# set(CMAKE_CXX_FLAGS_RELEASE "-O3" CACHE STRING "Flags used by the CXX compiler during RELEASE builds.")
# set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g" CACHE STRING "Flags used by the CXX compiler during RELWITHDEBINFO builds.")
# set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os" CACHE STRING "Flags used by the CXX compiler during MINSIZEREL builds.")
project(
OBOS
LANGUAGES C CXX ASM
DESCRIPTION "Hybrid Kernel with driver loading."
HOMEPAGE_URL https://github.com/OBOS-dev/obos
)
set (LIBGCC "${LIBGCC_TARGET}" CACHE STRING "A path to a libgcc binary for the target, if one does not exist yet")
if (OBOS_ARCHITECTURE STREQUAL "x86_64")
enable_language(ASM_NASM)
else()
enable_language(ASM-ATT)
endif()
if (OBOS_USE_CLANG)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Wno-error=unknown-pragmas>
$<$<COMPILE_LANGUAGE:C,CXX>:-Wno-unknown-pragmas>
$<$<COMPILE_LANGUAGE:C,CXX>:-Wno-error=unknown-attributes>
$<$<COMPILE_LANGUAGE:C,CXX>:-Wno-unknown-warning-option>
$<$<COMPILE_LANGUAGE:C,CXX>:-Wno-error=c23-extensions>)
if (OBOS_ENABLE_KASAN)
set (OBOS_ENABLE_KASAN OFF)
message (WARNING "OBOS does not support Clang's ASAN implementation. If you really care about this, make a PR, as I don't.")
endif()
endif()
# Download dependencies.
# NOTE: As dependencies are added, please add them to the .gitignore file.
# If a dependency cmake file is included, and OBOS_REFRESH_DEPENDENCIES is false, the cmake file shall not download or make any file operations, and only set any cache variables related
# to the dependency (eg. limine_install, zydis_c, uacpi_cmake_file, etc.)
if (EXISTS ${CMAKE_SOURCE_DIR}/dependencies/needs_download.cmake)
include (dependencies/needs_download.cmake)
else()
set (OBOS_REFRESH_DEPENDENCIES true)
endif()
set (OBOSKRNL_EXTERNAL_INCLUDES "${CMAKE_SOURCE_DIR}/dependencies/include")
if (OBOS_REFRESH_DEPENDENCIES)
file(MAKE_DIRECTORY "dependencies/include")
if (OBOS_ARCHITECTURE STREQUAL "x86_64")
message("Fetching Hyper.")
include("dependencies/hyper.cmake")
endif()
if (OBOS_USE_LIMINE)
message("Fetching Limine.")
include("dependencies/limine.cmake")
endif()
message("Fetching uACPI.")
include ("dependencies/uacpi.cmake")
message("Fetching flanterm.")
include ("dependencies/flanterm.cmake")
if (OBOS_ENABLE_UHDA)
message("Fetching uHDA.")
include ("dependencies/uhda.cmake")
endif()
message("Fetching e1000 driver.")
include ("dependencies/freebsd-e1000.cmake")
file (WRITE "${CMAKE_SOURCE_DIR}/dependencies/needs_download.cmake"
"# This file is auto-generated.\n# Set this variable to true or delete this file to refresh all dependencies.\nset (OBOS_REFRESH_DEPENDENCIES false)"
)
else()
if (NOT EXISTS hyper_install AND OBOS_ARCHITECTURE STREQUAL "x86_64")
include("dependencies/hyper.cmake")
endif()
if (OBOS_USE_LIMINE AND NOT EXISTS limine_exe)
include("dependencies/limine.cmake")
endif()
if (NOT EXISTS uacpi_cmake_file)
include("dependencies/uacpi.cmake")
endif()
include("dependencies/flanterm.cmake")
include("dependencies/uhda.cmake")
include("dependencies/freebsd-e1000.cmake")
endif()
if (OBOS_UP)
add_compile_definitions(OBOS_UP=1)
endif()
if (OBOS_DEBUG_FREE_SIZE)
add_compile_definitions(OBOS_DEBUG_FREE_SIZE=1)
endif()
if (OBOS_NVS_SAVE_S3)
set (OBOS_NVS_SAVE_S3 "1")
else()
set (OBOS_NVS_SAVE_S3 "0")
endif()
add_compile_definitions(OBOS_NVS_SAVE_S3=${OBOS_NVS_SAVE_S3})
if (OBOS_LAZY_IRQL)
set (OBOS_LAZY_IRQL "1")
else()
set (OBOS_LAZY_IRQL "0")
endif()
add_compile_definitions(OBOS_LAZY_IRQL=${OBOS_LAZY_IRQL})
if (OBOS_USE_LIMINE)
set (OBOS_USE_LIMINE "1")
else()
set (OBOS_USE_LIMINE "0")
endif()
add_compile_definitions(OBOS_USE_LIMINE=${OBOS_USE_LIMINE})
if (OBOS_ENABLE_LOCK_PROFILING)
set (OBOS_ENABLE_LOCK_PROFILING "1")
else()
set (OBOS_ENABLE_LOCK_PROFILING "0")
endif()
add_compile_definitions(OBOS_ENABLE_LOCK_PROFILING=${OBOS_ENABLE_LOCK_PROFILING})
if (OBOS_ENABLE_PROFILER)
set (OBOS_ENABLE_PROFILER "1")
else()
set (OBOS_ENABLE_PROFILER "0")
endif()
add_compile_definitions(OBOS_ENABLE_PROFILING=${OBOS_ENABLE_PROFILER})
add_compile_definitions(OBOS_BINARY_DIRECTORY="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
add_compile_definitions(OBOS_ARCHITECTURE_BITS=${OBOS_ARCHITECTURE_BITS})
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-fno-strict-aliasing>)
execute_process(COMMAND
"${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh --always --abbrev=40 --dirty
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_SHA1
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# the date of the commit
execute_process(COMMAND
"${GIT_EXECUTABLE}" log -1 --format=%ad --date=local
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_DATE
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
add_compile_definitions (GIT_SHA1="${GIT_SHA1}" GIT_DATE="${GIT_DATE}")
add_compile_definitions (OBOS_ARCHITECTURE_ENDIANNESS="${OBOS_ARCHITECTURE_ENDIANNESS}")
#list (APPEND oboskrnl_sources "sanitizers/ubsan.c")
if (OBOS_ENABLE_UBSAN)
add_compile_options(
$<$<COMPILE_LANGUAGE:C>:-fsanitize=undefined>
)
set (OBOS_ENABLE_UBSAN "1")
else()
set (OBOS_ENABLE_UBSAN "0")
endif()
add_compile_definitions(OBOS_UBSAN_ENABLED=${OBOS_ENABLE_UBSAN})
#list (APPEND oboskrnl_sources "sanitizers/asan.c")
if (OBOS_ENABLE_UHDA)
set (OBOS_ENABLE_UHDA "1")
else()
set (OBOS_ENABLE_UHDA "0")
endif()
add_compile_definitions(OBOS_ENABLE_UHDA=${OBOS_ENABLE_UHDA})
add_compile_definitions(OBOS_IRQL_COUNT=${OBOS_IRQL_COUNT})
add_compile_definitions(
$<$<CONFIG:Debug>:OBOS_DEBUG>
$<$<CONFIG:Release>:OBOS_RELEASE>
$<$<CONFIG:RelWithDebInfo>:OBOS_RELEASE>
$<$<CONFIG:MinSizeRel>:OBOS_RELEASE>
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(OBOS_DEBUG "1")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR
CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR
CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
set(OBOS_RELEASE "1")
endif()
string(TOUPPER "${OBOS_PAGE_REPLACEMENT_ALGORITHM}" OBOS_PAGE_REPLACEMENT_ALGORITHM)
set(OBOS_PAGE_REPLACEMENT_ALGORITHM_DEFINE "OBOS_PAGE_REPLACEMENT_")
string(APPEND OBOS_PAGE_REPLACEMENT_ALGORITHM_DEFINE "${OBOS_PAGE_REPLACEMENT_ALGORITHM}")
add_compile_definitions(${OBOS_PAGE_REPLACEMENT_ALGORITHM_DEFINE}=1)
string(APPEND OBOS_PAGE_REPLACEMENT_ALGORITHM "\"")
string(PREPEND OBOS_PAGE_REPLACEMENT_ALGORITHM "\"")
add_compile_definitions(OBOS_PAGE_REPLACEMENT_ALGORITHM=${OBOS_PAGE_REPLACEMENT_ALGORITHM})
set_property(GLOBAL PROPERTY C_STANDARD 17
PROPERTY C_STANDARD_REQUIRED true
PROPERTY C_EXTENSIONS ON)
if (OBOS_ENABLE_WERROR AND NOT OBOS_ENABLE_FANALYZER)
add_compile_options("-Werror" $<$<COMPILE_LANGUAGE:C>:-Wno-error=unused-function> $<$<COMPILE_LANGUAGE:C>:-Wno-error=unused-parameter>)
endif()
if (OBOS_ENABLE_FANALYZER)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fanalyzer>)
endif()
if (OBOS_ENABLE_FANALYZER AND OBOS_ENABLE_WERROR)
message(WARNING "OBOS_ENABLE_FANALYZER and OBOS_ENABLE_WERROR are mutually exclusive. Preferring OBOS_ENABLE_FANALYZER.")
endif()
# Now done somewhere else.
# if (NOT DEFINED OBOS_DEV_PREFIX)
# set(OBOS_DEV_PREFIX "/dev/")
# endif()
configure_file(${CMAKE_SOURCE_DIR}/src/inc/dev_prefix.h.in ${CMAKE_SOURCE_DIR}/src/oboskrnl/inc/dev_prefix.h @ONLY)
add_compile_definitions(
OBOS_ARCHITECTURE_HAS_ACPI=${OBOS_ARCHITECTURE_HAS_ACPI}
OBOS_ARCHITECTURE_HAS_PCI=${OBOS_ARCHITECTURE_HAS_PCI}
OBOS_PERM_PREFIX="${OBOS_PERM_PREFIX}"
)
if (OBOS_USE_OBOS_GCC AND OBOS_COMPILE_USER_UTILS)
add_subdirectory("src/init")
endif()
if (OBOS_COMPILE_USER_UTILS)
add_subdirectory("src/user-utilities")
endif()
if (OBOS_ONLY_COMPILE_USER_UTILS)
return()
endif()
if (OBOS_ENABLE_KASAN)
add_compile_options(
$<$<COMPILE_LANGUAGE:C>:-fsanitize=kernel-address>
)
set (OBOS_ENABLE_KASAN "1")
else()
set (OBOS_ENABLE_KASAN "0")
endif()
add_compile_definitions(OBOS_KASAN_ENABLED=${OBOS_ENABLE_KASAN})
# Include the kernel
add_subdirectory("src/oboskrnl")
if (OBOS_ARCHITECTURE STREQUAL "m68k")
add_subdirectory("src/oboskrnl/arch/m68k/loader")
endif()
if (OBOS_ARCHITECTURE_HAS_ACPI)
add_subdirectory("src/uACPI")
endif()
if (OBOS_ENABLE_UHDA)
add_subdirectory("src/uHDA")
endif()
add_subdirectory("src/sanitizers")
# Include drivers
if (OBOS_ARCHITECTURE_HAS_ACPI)
get_target_property(uacpi_INCLUDES uacpi INCLUDE_DIRECTORIES)
include_directories(${uacpi_INCLUDES})
endif()
add_subdirectory("src/drivers/generic/libps2")
add_subdirectory("src/drivers/generic/initrd")
add_subdirectory("src/drivers/generic/extfs")
add_subdirectory("src/drivers/test_driver")
add_subdirectory("src/drivers/generic/ahci")
add_subdirectory("src/drivers/generic/r8169")
add_subdirectory("src/drivers/generic/freebsd-e1000")
if (OBOS_ARCHITECTURE STREQUAL "x86_64")
add_subdirectory("src/drivers/x86/bochs_vbe")
add_subdirectory("src/drivers/x86/uart")
add_subdirectory("src/drivers/x86/i8042")
endif()