forked from maharmstone/btrfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
371 lines (301 loc) · 11 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
cmake_minimum_required(VERSION 3.15)
project(btrfs VERSION 1.9.0)
option(WITH_TEST "Compile test program" ON)
# btrfs.sys
set(ZSTD_SRC_FILES src/zstd/entropy_common.c
src/zstd/error_private.c
src/zstd/fse_compress.c
src/zstd/fse_decompress.c
src/zstd/hist.c
src/zstd/huf_compress.c
src/zstd/huf_decompress.c
src/zstd/zstd_common.c
src/zstd/zstd_compress.c
src/zstd/zstd_compress_literals.c
src/zstd/zstd_compress_sequences.c
src/zstd/zstd_compress_superblock.c
src/zstd/zstd_ddict.c
src/zstd/zstd_decompress.c
src/zstd/zstd_decompress_block.c
src/zstd/zstd_double_fast.c
src/zstd/zstd_fast.c
src/zstd/zstd_lazy.c
src/zstd/zstd_ldm.c
src/zstd/zstd_opt.c)
set(ZLIB_SRC_FILES src/zlib/adler32.c
src/zlib/deflate.c
src/zlib/inffast.c
src/zlib/inflate.c
src/zlib/inftrees.c
src/zlib/trees.c
src/zlib/zutil.c)
set(SRC_FILES src/balance.c
src/blake2b-ref.c
src/boot.c
src/btrfs.c
src/cache.c
src/calcthread.c
src/compress.c
src/crc32c.c
src/create.c
src/devctrl.c
src/dirctrl.c
src/extent-tree.c
src/fastio.c
src/fileinfo.c
src/flushthread.c
src/free-space.c
src/fsctl.c
src/fsrtl.c
src/galois.c
src/pnp.c
src/read.c
src/registry.c
src/reparse.c
src/scrub.c
src/search.c
src/security.c
src/send.c
src/sha256.c
src/treefuncs.c
src/volume.c
src/worker-thread.c
src/write.c
src/xxhash.c
${CMAKE_CURRENT_BINARY_DIR}/btrfs.rc
${ZSTD_SRC_FILES}
${ZLIB_SRC_FILES})
if(MSVC) # cmake bug 15170
if(MSVC_C_ARCHITECTURE_ID STREQUAL "X86")
set(CMAKE_SYSTEM_PROCESSOR "x86")
elseif(MSVC_C_ARCHITECTURE_ID STREQUAL "x64")
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
elseif(MSVC_C_ARCHITECTURE_ID STREQUAL "ARMV7")
set(CMAKE_SYSTEM_PROCESSOR "arm")
elseif(MSVC_C_ARCHITECTURE_ID STREQUAL "ARM64")
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
endif()
endif()
# Work around bug in MSVC version of cmake - see https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4257
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "")
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "")
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "")
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "")
set(CMAKE_ASM_MASM_FLAGS "/Zd")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
if(MSVC)
enable_language(ASM_MASM)
set(SRC_FILES ${SRC_FILES}
src/crc32c-masm.asm
src/xor-masm.asm)
else()
enable_language(ASM)
set(SRC_FILES ${SRC_FILES}
src/crc32c-gas.S
src/xor-gas.S)
endif()
endif()
if(MSVC AND (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64"))
# see cmake bug 24317 if armasm64 fails (should be fixed in CMake 3.29)
enable_language(ASM_MARMASM)
set(SRC_FILES ${SRC_FILES}
src/crc32c-aarch64.asm)
endif()
configure_file(src/btrfs.rc.in btrfs.rc)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
add_definitions(-D_AMD64_)
set(MS_ARCH "x64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
add_definitions(-D_X86_)
set(MS_ARCH "x86")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
add_definitions(-D_ARM_)
set(MS_ARCH "arm")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
add_definitions(-D_ARM64_)
set(MS_ARCH "arm64")
endif()
if(MSVC)
include_directories("$ENV{WindowsSdkDir}Include\\$ENV{WindowsSDKLibVersion}km")
link_directories("$ENV{WindowsSdkDir}Lib\\$ENV{WindowsSDKLibVersion}km\\${MS_ARCH}")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND WIN32)
include_directories("${CMAKE_FIND_ROOT_PATH}/usr/include/ddk")
endif()
add_library(btrfs SHARED ${SRC_FILES})
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-D_DEBUG)
endif()
if(NOT MSVC)
target_compile_options(btrfs PUBLIC -U__NO_INLINE__)
add_definitions(-D__USE_MINGW_ANSI_STDIO=0)
endif()
target_compile_definitions(btrfs PUBLIC _KERNEL_MODE WIN9X_COMPAT_SPINLOCK)
if(MSVC)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
target_compile_options(btrfs PUBLIC /Gz) # stdcall
endif()
target_link_libraries(btrfs ntoskrnl hal)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
target_link_libraries(btrfs bufferoverflowfastfailk)
else()
target_link_libraries(btrfs BufferOverflowK)
endif()
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
target_link_libraries(btrfs armrt)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
target_link_libraries(btrfs arm64rt)
endif()
target_link_libraries(btrfs rtlver)
target_link_options(btrfs PUBLIC /SUBSYSTEM:NATIVE /NODEFAULTLIB /MANIFEST:NO /Driver /ENTRY:DriverEntry)
# strip out flags for MSVC's runtime checks
string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
else()
target_compile_options(btrfs PUBLIC -Wall -Werror-implicit-function-declaration -Werror=incompatible-pointer-types -Wno-expansion-to-defined -Wunused-parameter -Wtype-limits -Wextra)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(btrfs PUBLIC -Werror=cast-function-type -Wold-style-declaration)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(btrfs PUBLIC -Wno-pragma-pack) # ignore warning in mingw headers
endif()
target_link_libraries(btrfs ntoskrnl hal gcc)
target_link_options(btrfs PUBLIC -nostdlib -Wl,--subsystem,native -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -Wl,--exclude-all-symbols)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
target_link_options(btrfs PUBLIC -Wl,--entry,_DriverEntry@8)
else()
target_link_options(btrfs PUBLIC -Wl,--entry,DriverEntry)
endif()
endif()
set_target_properties(btrfs PROPERTIES PREFIX "")
set_target_properties(btrfs PROPERTIES SUFFIX ".sys")
# --------------------------------------
# shellbtrfs.dll
set(SHELLEXT_SRC_FILES src/shellext/balance.cpp
src/shellext/contextmenu.cpp
src/shellext/devices.cpp
src/shellext/factory.cpp
src/shellext/iconoverlay.cpp
src/shellext/main.cpp
src/shellext/mountmgr.cpp
src/shellext/propsheet.cpp
src/shellext/recv.cpp
src/shellext/scrub.cpp
src/shellext/send.cpp
src/shellext/volpropsheet.cpp
src/crc32c.c
src/shellext/shellbtrfs.def
${CMAKE_CURRENT_BINARY_DIR}/shellbtrfs.rc)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
if(MSVC)
enable_language(ASM_MASM)
set(SHELLEXT_SRC_FILES ${SHELLEXT_SRC_FILES} src/crc32c-masm.asm)
else()
enable_language(ASM)
set(SHELLEXT_SRC_FILES ${SHELLEXT_SRC_FILES} src/crc32c-gas.S)
endif()
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
configure_file(src/shellext/shellbtrfs.rc.in shellbtrfs.rc)
add_library(shellbtrfs SHARED ${SHELLEXT_SRC_FILES})
if(NOT MSVC)
target_link_options(shellbtrfs PUBLIC -static -static-libgcc)
target_link_libraries(shellbtrfs pthread)
target_compile_options(shellbtrfs PUBLIC -Wall -Wno-expansion-to-defined -Wunused-parameter -Wtype-limits -Wextra)
else()
target_compile_options(shellbtrfs PUBLIC /EHsc)
target_link_options(shellbtrfs PUBLIC /MANIFEST:NO)
endif()
target_link_libraries(shellbtrfs comctl32 ntdll setupapi uxtheme shlwapi windowscodecs gdi32 advapi32 shell32 ole32)
if(MSVC AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
target_compile_options(shellbtrfs PUBLIC /Gz) # stdcall
endif()
set_target_properties(shellbtrfs PROPERTIES PREFIX "")
if(MSVC)
set_property(TARGET shellbtrfs PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
# --------------------------------------
# ubtrfs.dll
set(UBTRFS_SRC_FILES src/ubtrfs/ubtrfs.c
src/crc32c.c
src/xxhash.c
src/sha256.c
src/blake2b-ref.c
src/ubtrfs/ubtrfs.def
${CMAKE_CURRENT_BINARY_DIR}/ubtrfs.rc)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
if(MSVC)
enable_language(ASM_MASM)
set(UBTRFS_SRC_FILES ${UBTRFS_SRC_FILES} src/crc32c-masm.asm)
else()
enable_language(ASM)
set(UBTRFS_SRC_FILES ${UBTRFS_SRC_FILES} src/crc32c-gas.S)
endif()
endif()
configure_file(src/ubtrfs/ubtrfs.rc.in ubtrfs.rc)
add_library(ubtrfs SHARED ${UBTRFS_SRC_FILES})
if(MSVC)
set_property(TARGET ubtrfs PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_compile_definitions(ubtrfs PUBLIC _USRDLL)
target_link_libraries(ubtrfs ntdll advapi32)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(ubtrfs PUBLIC -Wno-pragma-pack) # ignore warning in mingw headers
endif()
if(MSVC AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
target_compile_options(ubtrfs PUBLIC /Gz) # stdcall
endif()
if(NOT MSVC)
target_compile_options(ubtrfs PUBLIC -Werror-implicit-function-declaration)
target_link_options(ubtrfs PUBLIC -static -static-libgcc -static-libstdc++)
endif()
set_target_properties(ubtrfs PROPERTIES PREFIX "")
# --------------------------------------
# mkbtrfs.exe
set(MKBTRFS_SRC_FILES src/mkbtrfs/mkbtrfs.c
${CMAKE_CURRENT_BINARY_DIR}/mkbtrfs.rc)
configure_file(src/mkbtrfs/mkbtrfs.rc.in mkbtrfs.rc)
add_executable(mkbtrfs ${MKBTRFS_SRC_FILES})
if(MSVC)
set_property(TARGET mkbtrfs PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
target_link_options(mkbtrfs PUBLIC -static -static-libgcc)
endif()
# --------------------------------------
# test.exe
if(WITH_TEST)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
configure_file(src/tests/test.rc.in test.rc)
set(TEST_SRC_FILES src/tests/test.cpp
${CMAKE_CURRENT_BINARY_DIR}/test.rc
src/tests/create.cpp
src/tests/supersede.cpp
src/tests/overwrite.cpp
src/tests/io.cpp
src/tests/mmap.cpp
src/tests/rename.cpp
src/tests/delete.cpp
src/tests/links.cpp
src/tests/oplock.cpp
src/tests/cs.cpp
src/tests/reparse.cpp
src/tests/streams.cpp
src/tests/ea.cpp
src/tests/fileinfo.cpp
src/tests/security.cpp)
add_executable(test ${TEST_SRC_FILES})
if(MSVC)
set_property(TARGET test PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
target_link_options(test PUBLIC -static -static-libgcc -municode)
target_compile_options(test PUBLIC -Wall -Wno-expansion-to-defined -Wunused-parameter -Wtype-limits -Wextra)
endif()
target_link_libraries(test ntdll version advapi32)
endif()
# --------------------------------------
# install
install(TARGETS btrfs DESTINATION bin)
install(TARGETS shellbtrfs DESTINATION bin)
install(TARGETS ubtrfs DESTINATION bin)
install(TARGETS mkbtrfs DESTINATION bin)