-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
90 lines (72 loc) · 2.85 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
cmake_minimum_required(VERSION 3.27)
project(crescent CXX ASM)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)
set(ARCH "x86_64" CACHE STRING "Architecture to compile for")
include(qacpi/lib.cmake)
add_executable(crescent
src/main.cpp
)
target_include_directories(crescent PRIVATE
src
src/std
include
)
target_compile_options(crescent PRIVATE
-Wall -Wextra -Werror=switch -Werror=return-type
-nostdinc++ -fno-exceptions -fno-threadsafe-statics -fno-rtti -fsized-deallocation
-ffreestanding -fno-strict-aliasing -Wframe-larger-than=4096 -fno-eliminate-unused-debug-types
-Wno-invalid-offsetof -Wno-unused-parameter -Wno-unused-const-variable
)
if(NOT ARCH STREQUAL "user")
target_compile_options(crescent PRIVATE
-mgeneral-regs-only -fno-stack-protector
-fno-omit-frame-pointer -mno-red-zone
)
target_link_options(crescent PRIVATE
-static -nostdlib -Wl,--fatal-warnings
-Wl,--export-dynamic -Wl,--build-id=none
)
endif()
add_subdirectory(src)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(crescent PRIVATE -Wno-unused-command-line-argument)
endif()
if(ARCH STREQUAL "x86_64")
target_compile_options(crescent PRIVATE -fPIE)
target_compile_definitions(crescent PRIVATE ARCH_X86_64)
target_link_options(crescent PRIVATE -T ${PROJECT_SOURCE_DIR}/lds/x86_64.ld -static-pie)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(crescent PRIVATE -fsanitize=undefined -fsanitize-minimal-runtime)
endif()
target_link_libraries(crescent PRIVATE qacpi::qacpi qacpi::events)
include(cmake/image_x86_64.cmake)
elseif(ARCH STREQUAL "aarch64")
target_compile_options(crescent PRIVATE -fno-PIE -mno-unaligned-access)
target_link_options(crescent PRIVATE -T ${PROJECT_SOURCE_DIR}/lds/aarch64.ld)
target_compile_definitions(crescent PRIVATE ARCH_AARCH64)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(crescent PRIVATE -fsanitize=undefined -fsanitize-minimal-runtime)
endif()
include(cmake/image_aarch64.cmake)
elseif(ARCH STREQUAL "user")
target_compile_options(crescent PRIVATE -fPIE -fsanitize=undefined,address)
target_link_options(crescent PRIVATE -fsanitize=undefined,address)
target_compile_definitions(crescent PRIVATE ARCH_USER)
include(cmake/image_user.cmake)
else()
message(FATAL_ERROR "Unsupported architecture ${ARCH}")
endif()
include(CMakeOptions.cmake)
add_subdirectory(libs)
add_subdirectory(apps)
add_custom_command(OUTPUT sysroot/fonts/Tamsyn8x16r.psf
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/sysroot/fonts"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/fonts/Tamsyn8x16r.psf" "${CMAKE_BINARY_DIR}/sysroot/fonts"
DEPENDS fonts/Tamsyn8x16r.psf
)
add_custom_command(OUTPUT initramfs.tar
COMMAND tar -cf initramfs.tar -C ${CMAKE_BINARY_DIR}/sysroot/ .
DEPENDS ${APPS} ${LIBS} sysroot/fonts/Tamsyn8x16r.psf
)