-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
163 lines (130 loc) · 6.62 KB
/
CMakeLists.txt
File metadata and controls
163 lines (130 loc) · 6.62 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
cmake_minimum_required(VERSION 3.22)
project(retrorocket C ASM ASM_NASM)
set_property(GLOBAL PROPERTY RULE_MESSAGES ON)
set_property(GLOBAL PROPERTY TARGET_MESSAGES OFF)
option(USE_E1000 "Use the e1000 NIC driver in QEMU instead of rtl8139" ON)
option(PROFILE_KERNEL "Profile the kernel, and output callgrind compatible file via COM1" OFF)
option(MEMORY_TRACE "Trace memory allocations and track leaks" OFF)
set(HARD_DISK_IMAGE "../../harddisk0" CACHE STRING "Path to hard disk image when running QEMU")
add_compile_definitions(Z_SOLO)
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_C_LINK_EXECUTABLE "ld -m elf_x86_64 -nostdlib -no-pie --export-dynamic -T ${CMAKE_CURRENT_SOURCE_DIR}/buildtools/linker.ld <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_ASM_FLAGS "-pipe -g -fno-PIC -Wall -Wextra -Wl,--export-dynamic -Wno-unused-parameter -Wno-int-to-pointer-cast -nostdlib -ffreestanding -nostartfiles -nodefaultlibs -mcmodel=large -mno-red-zone -fno-stack-protector -fno-stack-check")
set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
include("${CMAKE_SOURCE_DIR}/cmake/custom_targets.cmake")
file(GLOB_RECURSE SOURCES "src/*.c")
file(GLOB ASSEMBLY "asm/*")
set(CMAKE_C_FLAGS "-pipe -g -mpopcnt -fno-PIC -Wno-builtin-macro-redefined -std=c17 -Wall -Wextra -Wno-deprecated-declarations -Wno-unused-parameter -Wno-pointer-to-int-cast -Wno-discarded-qualifiers -Wno-int-conversion -Wno-int-to-pointer-cast -nostdlib -mno-mmx -mno-3dnow -ffreestanding -nostartfiles -nodefaultlibs -mcmodel=kernel -mno-red-zone -Wno-address-of-packed-member -fno-builtin-memcpy -fno-stack-protector -fno-stack-check")
if(PROFILE_KERNEL)
add_compile_definitions(PROFILE_KERNEL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finstrument-functions")
set_source_files_properties(
src/profiler.c src/serial.c src/memory_trace.c
PROPERTIES COMPILE_FLAGS "-fno-instrument-functions"
)
endif()
if(MEMORY_TRACE)
add_compile_definitions(MEMORY_TRACE)
endif()
include_directories("include")
include_directories("limine")
include_directories("uacpi/include")
include_directories(${UACPI_INCLUDES})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/iso)
include(uacpi/uacpi.cmake)
add_executable(kernel.bin ${SOURCES} ${ASSEMBLY})
target_sources(kernel.bin PRIVATE ${UACPI_SOURCES})
target_include_directories(kernel.bin PRIVATE ${UACPI_INCLUDES})
add_link_options("-m elf_x86_64 -nostdlib -no-pie -T buildtools/linker.ld")
add_custom_target(ISO ALL DEPENDS ${CMAKE_BINARY_DIR}/rr.iso)
copy_config(limine.conf limine.conf)
copy_config(limine-bios.sys limine/limine-bios.sys)
copy_config(limine-bios-cd.bin limine/limine-bios-cd.bin)
copy_config(limine-uefi-cd.bin limine/limine-uefi-cd.bin)
file(GLOB_RECURSE image_list CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/os/images/*")
set(IMAGE_TARGETS "")
foreach (image ${image_list})
if (NOT IS_DIRECTORY "${image}")
file(RELATIVE_PATH image_rel "${CMAKE_SOURCE_DIR}/os/images" "${image}")
string(REPLACE "/" "_" image_target "${image_rel}")
copy_image("${image_rel}" "${image_rel}")
list(APPEND IMAGE_TARGETS "img_${image_target}")
endif()
endforeach()
symbols("kernel.sym" "kernel.bin")
run("run.sh")
debug("debug.sh")
set(BASIC_PROGRAM_TARGETS "")
set(BASIC_PROGRAM_OUTPUTS "")
file(GLOB_RECURSE basic_program_list CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/os/programs/*.rrbasic")
foreach (basic_program ${basic_program_list})
if (NOT IS_DIRECTORY "${basic_program}")
file(RELATIVE_PATH basic_name "${CMAKE_SOURCE_DIR}/os/programs" "${basic_program}")
string(REPLACE "/" "_" basic_target "${basic_name}")
copy_basic("${basic_name}" "${basic_name}")
list(APPEND BASIC_PROGRAM_TARGETS "basic_${basic_target}")
endif()
endforeach()
set(KEYMAP_TARGETS "")
set(TIMEZONE_TARGETS "")
set(WEB_TARGETS "")
file(GLOB_RECURSE web_list RELATIVE ${CMAKE_SOURCE_DIR}/os/system ${CMAKE_SOURCE_DIR}/os/system/*)
foreach(web ${web_list})
copy_system_web(${web})
string(REPLACE "/" "_" WEB_NAME ${web})
list(APPEND WEB_TARGETS "web_${WEB_NAME}")
endforeach()
set(CONFIG_TARGETS "")
# --- Build loadable modules from modules/<name>/*.c into iso/system/modules/<name>.ko
file(GLOB MODULE_DIRS RELATIVE ${CMAKE_SOURCE_DIR}/modules ${CMAKE_SOURCE_DIR}/modules/*)
set(MODULE_TARGETS "")
set(MODULE_KO_FILES "") # collect .ko outputs so ISO rule can depend on them
foreach(mod ${MODULE_DIRS})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/modules/${mod})
file(GLOB mod_srcs CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/modules/${mod}/*.c)
if (mod_srcs)
# Compile module sources as an object target with large code model etc.
add_library(mod_${mod} OBJECT ${mod_srcs})
target_compile_options(mod_${mod} PRIVATE
-ffreestanding -fno-pic -fno-plt -mcmodel=large -mno-red-zone
-fvisibility=hidden -fno-asynchronous-unwind-tables -fno-exceptions
)
target_include_directories(mod_${mod} PRIVATE ${UACPI_INCLUDES})
# Link to a single ET_REL (.ko) using ld -r
set(MOD_OUT ${CMAKE_BINARY_DIR}/iso/system/modules/${mod}.ko)
add_custom_command(
OUTPUT ${MOD_OUT}
COMMAND_EXPAND_LISTS
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/iso/system/modules
COMMAND ${CMAKE_LINKER} -r -o ${MOD_OUT} $<TARGET_OBJECTS:mod_${mod}>
DEPENDS $<TARGET_OBJECTS:mod_${mod}>
VERBATIM
)
add_custom_target(module_${mod} ALL DEPENDS ${MOD_OUT})
add_dependencies(module_${mod} mod_${mod})
add_dependencies(ISO module_${mod})
list(APPEND MODULE_TARGETS module_${mod})
list(APPEND MODULE_KO_FILES ${MOD_OUT})
endif()
endif()
endforeach()
# make a single stamp that depends on all .ko files and inject it into iso() deps via IMAGE_TARGETS
set(MODULES_STAMP ${CMAKE_BINARY_DIR}/.modules.stamp)
add_custom_command(OUTPUT ${MODULES_STAMP}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/iso/system/modules
COMMAND ${CMAKE_COMMAND} -E touch ${MODULES_STAMP}
DEPENDS ${MODULE_KO_FILES}
VERBATIM
)
list(APPEND IMAGE_TARGETS ${MODULES_STAMP})
set(LICENSE_DST ${CMAKE_BINARY_DIR}/iso/system/license)
add_custom_command(
OUTPUT ${LICENSE_DST}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/iso/system
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/LICENSE ${LICENSE_DST}
DEPENDS ${CMAKE_SOURCE_DIR}/LICENSE
VERBATIM
)
list(APPEND IMAGE_TARGETS ${LICENSE_DST})
iso("rr.iso" "kernel.sym")