forked from openbfdev/bfdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
245 lines (203 loc) · 5.59 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright(c) 2023 ffashion <helloworldffashion@gmail.com>
# Copyright(c) 2023 John Sanpe <sanpeqf@gmail.com>
#
cmake_minimum_required(VERSION 3.9)
project(bfdev VERSION "1.0" LANGUAGES C)
include(GNUInstallDirs)
include(CheckIncludeFiles)
include(CheckCXXSymbolExists)
include(CheckFunctionExists)
include(CheckCSourceCompiles)
set(BFDEV_ARCH dummy)
set(BFDEV_NAME sirius)
set(BFDEV_EXTREVERSION -devel)
set(BFDEV_VERSION ${CMAKE_PROJECT_VERSION_MAJOR})
string(APPEND BFDEV_VERSION . ${CMAKE_PROJECT_VERSION_MINOR})
if(CMAKE_PROJECT_VERSION_PATCH)
string(APPEND BFDEV_VERSION . ${CMAKE_PROJECT_VERSION_PATCH})
endif()
if(CMAKE_PROJECT_VERSION_TWEAK)
string(APPEND BFDEV_VERSION . ${CMAKE_PROJECT_VERSION_TWEAK})
endif()
if(BFDEV_EXTREVERSION)
string(APPEND BFDEV_VERSION ${BFDEV_EXTREVERSION})
endif()
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(BFDEV_HEADER_PATH ${PROJECT_SOURCE_DIR}/include)
set(BFDEV_SOURCE_PATH ${PROJECT_SOURCE_DIR}/src)
set(BFDEV_DOCUMENT_PATH ${PROJECT_SOURCE_DIR}/docs)
set(BFDEV_GENERATED_PATH ${PROJECT_BINARY_DIR}/generated)
set(BFDEV_ARCH_PATH ${PROJECT_SOURCE_DIR}/arch/${BFDEV_ARCH})
set(BFDEV_ARCH_HEADER_PATH ${BFDEV_ARCH_PATH}/include)
include(scripts/asm-generic.cmake)
include(scripts/hostrule.cmake)
include(scripts/commit.cmake)
commit_hash(BFDEV_COMMITID)
commit_branch(BFDEV_BRANCH)
option(BFDEV_DEVEL "Enable development mode" OFF)
option(BFDEV_EXAMPLES "Build examples" OFF)
option(BFDEV_STRICT "Enable strict compilation" ON)
option(BFDEV_ASAN "Enable Address Sanitizer" OFF)
option(BFDEV_UBSAN "Enable Undefined Behaviour Sanitizer" OFF)
option(BFDEV_DBGLIST "Dynamic debug list" ON)
option(BFDEV_DBGSLIST "Dynamic debug slist" ON)
option(BFDEV_DBGHLIST "Dynamic debug hlist" ON)
option(BFDEV_DBGILIST "Dynamic debug ilist" ON)
option(BFDEV_DBGRBTREE "Dynamic debug rbtree" ON)
if(BFDEV_DEVEL)
set(BFDEV_EXAMPLES ON)
set(BFDEV_ASAN ON)
set(BFDEV_UBSAN ON)
endif()
asm_generic(
bfdev/asm-generic/
${BFDEV_GENERATED_PATH}/bfdev/asm
${BFDEV_ARCH_HEADER_PATH}/bfdev/asm
${BFDEV_HEADER_PATH}/bfdev/asm-generic
)
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_BINARY_DIR}/generated)
add_subdirectory(scripts)
file(GLOB BFDEV_HEADER
${BFDEV_HEADER_PATH}/bfdev/*.h
)
file(GLOB BFDEV_ASM_HEADER
${BFDEV_HEADER_PATH}/bfdev/asm-generic/*.h
)
file(GLOB BFDEV_ARCH_ASM_HEADER
${BFDEV_ARCH_HEADER_PATH}/bfdev/asm/*.h
)
file(GLOB BFDEV_GENERATED_HEADER
${BFDEV_GENERATED_PATH}/*.h
)
include(${BFDEV_SOURCE_PATH}/build.cmake)
include(${BFDEV_ARCH_PATH}/build.cmake)
add_definitions(
" -std=gnu17"
" -Wall"
" -Wextra"
" -Wno-override-init"
" -Wno-unused-parameter"
" -Wno-sign-compare"
" -Wno-pointer-sign"
" -Wno-null-pointer-arithmetic"
" -fvisibility=hidden"
)
if(BFDEV_STRICT)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} \
-Werror"
)
endif()
if(BFDEV_ASAN)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} \
-fsanitize=address \
-fsanitize=undefined \
-fsanitize-recover=all \
-fno-omit-frame-pointer \
-fno-stack-protector"
)
if(NOT APPLE)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} \
-fsanitize=leak"
)
endif()
endif()
if(BFDEV_UBSAN)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} \
-fsanitize=alignment \
-fsanitize=bounds \
-fsanitize=shift \
-fsanitize=integer-divide-by-zero \
-fsanitize=unreachable \
-fsanitize=bool \
-fsanitize=enum \
-fsanitize-undefined-trap-on-error"
)
endif()
if(BFDEV_DBGLIST)
set(BFDEV_DEBUG_LIST ON)
endif()
if(BFDEV_DBGSLIST)
set(BFDEV_DEBUG_SLIST ON)
endif()
if(BFDEV_DBGHLIST)
set(BFDEV_DEBUG_HLIST ON)
endif()
if(BFDEV_DBGILIST)
set(BFDEV_DEBUG_ILIST ON)
endif()
if(BFDEV_DBGRBTREE)
set(BFDEV_DEBUG_RBTREE ON)
endif()
set(BFDEV_LIBRARY
${BFDEV_HEADER}
${BFDEV_ASM_HEADER}
${BFDEV_ARCH_ASM_HEADER}
${BFDEV_GENERATED_HEADER}
${BFDEV_INCLUDE}
${BFDEV_SOURCE}
${BFDEV_ARCH_SOURCE}
)
configure_file(
${CMAKE_MODULE_PATH}/config.h.in
${PROJECT_BINARY_DIR}/generated/bfdev/config.h
)
macro(bfdev_dependencies target)
add_dependencies(
${target}
gen-crc8
gen-crc16
gen-crc16be
gen-crc32
gen-crc32be
gen-crc64
gen-crc64be
)
endmacro()
add_library(bfdev_object OBJECT ${BFDEV_LIBRARY})
bfdev_dependencies(bfdev_object)
add_library(bfdev ALIAS bfdev_object)
if(BFDEV_EXAMPLES)
enable_testing()
add_subdirectory(examples)
endif()
if(${CMAKE_PROJECT_NAME} STREQUAL "bfdev")
add_library(bfdev_static STATIC ${BFDEV_LIBRARY})
add_library(bfdev_shared SHARED ${BFDEV_LIBRARY})
bfdev_dependencies(bfdev_static)
bfdev_dependencies(bfdev_shared)
set_target_properties(bfdev_static
PROPERTIES
OUTPUT_NAME bfdev
LINKER_LANGUAGE C
)
set_target_properties(bfdev_shared
PROPERTIES VERSION 1.0 SOVERSION 1
OUTPUT_NAME bfdev
MACOSX_RPATH ON
LINKER_LANGUAGE C
)
install(DIRECTORY
${BFDEV_HEADER_PATH}/bfdev
${BFDEV_GENERATED_PATH}/bfdev
${BFDEV_ARCH_HEADER_PATH}/bfdev
DESTINATION
"${CMAKE_INSTALL_INCLUDEDIR}"
)
install(DIRECTORY
${BFDEV_DOCUMENT_PATH}
DESTINATION
"${CMAKE_INSTALL_DOCDIR}"
)
install(TARGETS
bfdev_static bfdev_shared
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()