blob: 8ac8dc047379a8e80d72e963d65be07a232a5cc5 (
plain)
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
|
cmake_minimum_required(VERSION "3.27")
project("kernel"
DESCRIPTION "An educational OS kernel"
HOMEPAGE_URL "https://gitlab.ost.ch/teachos/kernel"
VERSION "0.0.1"
LANGUAGES ASM C CXX
)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules")
include("ElfTransformations")
include("GenerateBootableIso")
include("CTest")
include("EnableCoverage")
#[============================================================================[
# External Dependencies
#]============================================================================]
include("FetchContent")
if (BUILD_TESTING)
FetchContent_Declare(
"Catch2"
URL "https://github.com/catchorg/Catch2/archive/refs/tags/v3.7.1.tar.gz"
URL_HASH "SHA256=c991b247a1a0d7bb9c39aa35faf0fe9e19764213f28ffba3109388e62ee0269c"
EXCLUDE_FROM_ALL
FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable("Catch2")
add_compile_definitions("CATCH_CONFIG_NO_COUNTER")
endif()
#[============================================================================[
# Global Build System Options
#]============================================================================]
option(TEACHOS_ENABLE_LINTING "Enable linting during build" ON)
option(TEACHOS_GENERATE_DOCS "Generate documentation during build" ON)
option(TEACHOS_ENABLE_TEST_SANITIZERS "Enable sanitizers for test executables" ON)
option(TEACHOS_ENABLE_TEST_TSAN "Enable TSan for the test executable" OFF)
#[============================================================================[
# Global Build System Configuration
#]============================================================================]
if(POLICY CMP0209)
cmake_policy(SET CMP0209 NEW)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION YES)
set(CMAKE_CXX_STANDARD "23")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
add_compile_options(
"$<$<CXX_COMPILER_ID:GNU>:-Wall>"
"$<$<CXX_COMPILER_ID:GNU>:-Wextra>"
"$<$<CXX_COMPILER_ID:GNU>:-Werror>"
"$<$<CXX_COMPILER_ID:GNU>:-pedantic-errors>"
)
#[============================================================================[
# Global Linting Configuration
#]============================================================================]
find_program(CLANG_TIDY_EXE NAMES
"clang-tidy-23"
"clang-tidy-22"
"clang-tidy-21"
"clang-tidy"
)
if(CLANG_TIDY_EXE AND TEACHOS_ENABLE_LINTING)
set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY_EXE}")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
endif()
#[============================================================================[
# Global Documentation Configuration
#]============================================================================]
find_package(Doxygen "1.10")
if(Doxygen_FOUND AND TEACHOS_GENERATE_DOCS)
doxygen_add_docs("docs"
ALL
COMMENT "Generating documentation"
CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile"
)
endif()
#[============================================================================[
# Build Host Testing
#]============================================================================]
if(BUILD_TESTING)
if(TARGET "Catch2" AND TARGET "Catch2WithMain")
set_target_properties("Catch2" "Catch2WithMain" PROPERTIES
C_CLANG_TIDY ""
CXX_CLANG_TIDY ""
)
endif()
if(TEACHOS_ENABLE_TEST_SANITIZERS AND TEACHOS_ENABLE_TEST_TSAN)
message(FATAL_ERROR "TEACHOS_ENABLE_TEST_SANITIZERS and TEACHOS_ENABLE_TEST_TSAN are mutually exclusive")
elseif(TEACHOS_ENABLE_TEST_SANITIZERS)
add_compile_options("$<$<CXX_COMPILER_ID:GNU>:-fsanitize=undefined,address>")
add_link_options("$<$<CXX_COMPILER_ID:GNU>:-fsanitize=undefined,address,leak>")
elseif(TEACHOS_ENABLE_TEST_TSAN)
add_compile_options("$<$<CXX_COMPILER_ID:GNU>:-fsanitize=thread;-g>")
add_link_options("$<$<CXX_COMPILER_ID:GNU>:-fsanitize=thread>")
endif()
endif()
#[============================================================================[
# Global Targets
#]============================================================================]
if(CMAKE_CROSSCOMPILING)
add_subdirectory("arch/${CMAKE_SYSTEM_PROCESSOR}")
endif()
add_subdirectory("kapi")
add_subdirectory("kernel")
add_subdirectory("libs")
|