-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
96 lines (77 loc) · 3.57 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
cmake_minimum_required(VERSION 2.8)
project(kernell)
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 1)
set(CMAKE_CXX_STANDAED 17)
set(KERNEL_BIN "x86_64-kernel.bin")
set(CMAKE_BINARY_DIR ${PROJECT_SOURCE_DIR}/build)
set(LINKER_SCRIPT ${PROJECT_SOURCE_DIR}/src/arch/x86_64/linker.ld)
set(GRUB_CFG ${PROJECT_SOURCE_DIR}/src/arch/x86_64/grub.cfg)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-red-zone -mcmodel=large -mno-sse -ffreestanding -fno-exceptions -fno-rtti -nostdlib -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mno-red-zone -mcmodel=large -mno-sse -ffreestanding -nostdlib -fno-pic -fno-pie -Werror")
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -felf64")
set(CMAKE_LINKER_FLAGS "-n -T ${LINKER_SCRIPT}")
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_LINKER_FLAGS} <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_LINKER_FLAGS} <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
set(CMAKE_LINKER "/usr/bin/ld")
set(CMAKE_VERBOSE_MAKEFILE ON)
enable_language(ASM_NASM)
file(GLOB_RECURSE kernel_SRC "./include/*.h" "./src/*.c")
file(GLOB_RECURSE kernel_ASM "./src/*.asm" "./src/*.S" "./src/*.s")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/arch/x86_64
${CMAKE_CURRENT_SOURCE_DIR}/include/memory
${CMAKE_CURRENT_SOURCE_DIR}/include/drivers
${CMAKE_CURRENT_SOURCE_DIR}/include/drivers/block_device
${CMAKE_CURRENT_SOURCE_DIR}/include/drivers/char_device
${CMAKE_CURRENT_SOURCE_DIR}/include/sync
${CMAKE_CURRENT_SOURCE_DIR}/include/context
${CMAKE_CURRENT_SOURCE_DIR}/include/fs
${CMAKE_CURRENT_SOURCE_DIR}/include/fs/ext2
${CMAKE_CURRENT_SOURCE_DIR}/include/syscall
)
add_executable(
${KERNEL_BIN}
${kernel_ASM}
${kernel_SRC}
)
set_target_properties(${KERNEL_BIN} PROPERTIES CMAKE_LINKER "/usr/bin/ld")
add_custom_command(TARGET ${KERNEL_BIN} POST_BUILD
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/build/isofiles/boot/grub
COMMAND cp ${KERNEL_BIN} ${CMAKE_BINARY_DIR}/build/isofiles/boot/${KERNEL_BIN}
COMMAND cp ${GRUB_CFG} ${CMAKE_BINARY_DIR}/build/isofiles/boot/grub
COMMAND grub-mkrescue -o kernel.iso ${CMAKE_BINARY_DIR}/build/isofiles
COMMAND rm -r ${CMAKE_BINARY_DIR}/build/
COMMAND cp ${CMAKE_BINARY_DIR}/../trace_stack ./
)
add_custom_target(run
qemu-system-x86_64 -smp 4 -cpu host -enable-kvm -no-reboot -no-shutdown -cdrom kernel.iso -curses -m 4G -drive id=disk,format=raw,file=disk.img
)
add_custom_target(debug
COMMAND touch .gdbinit
COMMAND echo "target remote localhost:1234" > .gdbinit
COMMAND echo "symbol-file ${KERNEL_BIN}" >> .gdbinit
COMMAND qemu-system-x86_64 -cpu host -enable-kvm -smp 4 -no-shutdown -no-reboot -cdrom kernel.iso -curses -m 4G -drive id=disk,format=raw,file=disk.img -s -S
)
add_custom_target(debug_qemu
COMMAND touch .gdbinit
COMMAND echo "target remote localhost:1234" > .gdbinit
COMMAND echo "symbol-file ${KERNEL_BIN}" >> .gdbinit
COMMAND qemu-system-x86_64 -smp 4 -d int -no-shutdown -no-reboot -cdrom kernel.iso -vnc :1 -m 4G -drive id=disk,format=raw,file=disk.img -s -S
)
add_custom_target(count_line
find ../ -name '*.[ch]' | xargs wc -l
)
add_custom_target(build_image
COMMAND qemu-img create -f raw -o size=500M disk.img
COMMAND mkfs.ext2 disk.img
COMMAND echo "copy initfs to disk..."
COMMAND mkdir -p mnt
COMMAND sudo mount disk.img ./mnt
COMMAND sudo cp -r ./initfs/. ./mnt
)