-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
163 lines (138 loc) · 4.88 KB
/
CMakeLists.txt
File metadata and controls
163 lines (138 loc) · 4.88 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.27)
project(AllocatorLib
LANGUAGES C
VERSION 0.1.0
DESCRIPTION "Kernel memory allocation libary for Bolt"
)
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB_RECURSE SOURCES
source/*.c
source/*.h
executable/*.c
executable/*.h
main.c
)
add_executable(AllocatorLib ${SOURCES})
target_sources(
AllocatorLib
PRIVATE
${SOURCES}
)
target_include_directories(
AllocatorLib
PRIVATE
executable
include
)
target_compile_options(
AllocatorLib
PRIVATE
-Wall -Wextra -Werror
-Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -Wno-ignored-attributes
)
else ()
set(BOLT_TARGET_ARCH "x86_64" CACHE STRING "Target architecture")
set(BOLT_TARGET_MODE "KERNEL" CACHE STRING "Target mode e.g. KERNEL, USER")
set(BOLT_BUILD_TESTS OFF CACHE BOOL "Build tests")
include(GNUInstallDirs)
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Location of header files")
set(C_OPTIONS "")
list(APPEND C_OPTIONS "-Wall -Wextra -Werror")
list(APPEND C_OPTIONS "-Wno-unused-parameter" "-Wno-unused-function" "-Wno-unused-variable" "-Wno-ignored-attributes")
# Freestanding environment
list(APPEND C_OPTIONS "-ffreestanding" "-nostdlib" "-nostdinc")
# Stack protection are not possible in some cases.
list(APPEND C_OPTIONS "-fno-stack-protector" "-fno-stack-check")
# Disable features we cannot use in kernel mode
if (BOLT_TARGET_MODE STREQUAL "KERNEL")
list(APPEND C_OPTIONS "-mno-80387") # Disable FPU (Requires additional setup)
list(APPEND C_OPTIONS "-mno-mmx") # Disable MMX (Requires FPU)
list(APPEND C_OPTIONS "-mno-sse") # Disable SSE (Requires MMX)
list(APPEND C_OPTIONS "-mno-sse2") # Disable SSE2 (Requires MMX)
list(APPEND C_OPTIONS "-mno-red-zone") # Disable red zone, causes issues with interrupts
endif ()
target_include_directories(
AllocatorLib
PUBLIC
$(CMAKE_CURRENT_LIST_DIR)/include
PRIVATE
$(CMAKE_CURRENT_LIST_DIR)/source
)
file(GLOB_RECURSE SOURCES
source/*.c
source/*.h
)
add_library(AllocatorLib STATIC ${SOURCES})
if (BOLT_TARGET_MODE STREQUAL "KERNEL")
target_compile_definitions(
RuntimeLib
PUBLIC
-DBOLT_KERNEL=1
)
elseif (BOLT_TARGET_MODE STREQUAL "USER")
target_compile_definitions(
RuntimeLib
PUBLIC
-DBOLT_USER=1
)
else ()
message(FATAL_ERROR "Invalid target mode: ${BOLT_TARGET_MODE}")
endif ()
set_target_properties(
RuntimeLib
PROPERTIES
C_STANDARD 11
C_STANDARD_REQUIRED YES # Require C11
C_EXTENSIONS NO # Disable GNU extensions
C_VISIBILITY_PRESET hidden # Don't export symbols by default
)
target_compile_options(
RuntimeLib
PRIVATE
"$<$<COMPILE_LANGUAGE:C>:${C_OPTIONS}>"
)
# Testing
if (BOLT_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif ()
# Install
install(
TARGETS
RuntimeLib
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/RuntimeLibConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/RuntimeLibConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/RuntimeLib
PATH_VARS INCLUDE_INSTALL_DIR
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/RuntimeLibConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/RuntimeLibConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/RuntimeLibConfigVersion.cmake"
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/RuntimeLib
)
# CPack
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VENDOR "Bolt")
set(CPACK_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${BOLT_TARGET_ARCH}-${BOLT_TARGET_MODE}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/README.md")
set(CPACK_GENERATOR "ZIP")
include(CPack)
endif ()