forked from google/leveldb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
264 lines (232 loc) · 5.87 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
cmake_minimum_required(VERSION 2.8)
PROJECT(leveldb)
ENABLE_TESTING()
set(VERSION_MAJOR 1)
set(VERSION_MINOR 20)
set(VERRION_PATCH 0)
set(VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR} include)
# Set a default build type for single-configuration
# CMake generators if no build type is set.
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE)
#set(CMAKE_BUILD_TYPE DEBUG)
endif()
message("Configuration: ${CMAKE_BUILD_TYPE}")
## needs define:
## COMPILER_MSVC
## LEVELDB_PLATFORM_POSIX
## LEVELDB_CSTDATOMIC_PRESENT
## SNAPPY
## OS_****
if(WIN32 AND MSVC)
add_definitions(-DOS_WIN)
add_definitions(-DLEVELDB_PLATFORM_WINDOWS)
add_definitions(-DCOMPILER_MSVC)
add_definitions(-DWINVER=0x0501 -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
add_definitions(-Dssize_t=ptrdiff_t) #workaround for ssize_t
add_definitions(-D_X86_)
set(PORT_SRCS port/port_win.cc util/env_win.cc util/win_logger.cc)
set(PORT_HDRS port/port_win.h util/win_logger.h)
include_directories(port/win) #workaround for stdint.h
# set(CAPI_SRC db/c.cc)
# set(CAPI_HDRS include/leveldb/c.h)
set(CAPI_SRC)
set(CAPI_HDRS)
set(CAPI_TEST)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /Oi /EHsc")
#set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /DNDEBUG /MD")
set(CMAKE_CXX_FLAGS_RELEASE "/Ox /Ob2 /Ot /DNDEBUG /MD")
set(CMAKE_CXX_FLAGS_DEBUG "/Od /Zi /Ob0 /RTC1 /D_DEBUG /MDd")
set(LIBS "${LIBS}" shlwapi)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-DOS_LINUX)
add_definitions(-DLEVELDB_PLATFORM_POSIX)
add_definitions(-fno-builtin-memcmp)
set(PORT_SRCS port/port_posix.cc util/env_posix.cc)
set(PORT_HDRS port/port_posix.h util/posix_logger.h)
set(CAPI_SRC db/c.cc)
set(CAPI_HDRS include/leveldb/c.h)
set(CAPI_TEST db/c_test.c)
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
else()
error("Unknown platform")
endif()
###
# embedded snappy
###
add_definitions(-DSNAPPY)
include_directories(dep/snappy)
set(SNAPPY_SRCS
dep/snappy/snappy.cc
dep/snappy/snappy-sinksource.cc
dep/snappy/snappy-stubs-internal.cc
)
set(SNAPPY_HDRS
dep/snappy/snappy.h
dep/snappy/snappy-internal.h
dep/snappy/snappy-sinksource.h
dep/snappy/snappy-stubs-internal.h
dep/snappy/snappy-stubs-public.h
)
###
# crc32c-hw
###
add_definitions(-DCRC32C)
add_definitions(-DCRC32C_STATIC)
include_directories(dep/crc32c-hw/include dep/crc32c-hw/src)
set(CRC32C_SRC dep/crc32c-hw/src/crc32c.cpp)
set(CRC32C_HDRS dep/crc32c-hw/include/crc32c.h)
set(SRCS
db/builder.cc
db/db_impl.cc
db/db_iter.cc
db/dbformat.cc
db/filename.cc
db/log_reader.cc
db/log_writer.cc
db/memtable.cc
db/repair.cc
db/table_cache.cc
db/version_edit.cc
db/version_set.cc
db/write_batch.cc
helpers/memenv/memenv.cc
table/block_builder.cc
table/block.cc
table/filter_block.cc
table/format.cc
table/iterator.cc
table/merger.cc
table/table_builder.cc
table/table.cc
table/two_level_iterator.cc
util/arena.cc
util/bloom.cc
util/cache.cc
util/coding.cc
util/comparator.cc
util/crc32c.cc
util/env.cc
util/filter_policy.cc
util/hash.cc
util/histogram.cc
util/logging.cc
util/options.cc
util/status.cc
${PORT_SRCS}
${CAPI_SRC}
)
set(HDRS
db/builder.h
db/db_impl.h
db/db_iter.h
db/dbformat.h
db/filename.h
db/log_format.h
db/log_reader.h
db/log_writer.h
db/memtable.h
db/skiplist.h
db/snapshot.h
db/table_cache.h
db/version_edit.h
db/version_set.h
db/write_batch_internal.h
helpers/memenv/memenv.h
include/leveldb/cache.h
include/leveldb/comparator.h
include/leveldb/db.h
include/leveldb/env.h
include/leveldb/filter_policy.h
include/leveldb/iterator.h
include/leveldb/options.h
include/leveldb/slice.h
include/leveldb/status.h
include/leveldb/table.h
include/leveldb/table_builder.h
include/leveldb/write_batch.h
port/atomic_pointer.h
port/port.h
port/thread_annotations.h
table/block.h
table/block_builder.h
table/filter_block.h
table/format.h
table/iterator_wrapper.h
table/merger.h
table/two_level_iterator.h
util/arena.h
util/coding.h
util/crc32c.h
util/hash.h
util/histogram.h
util/logging.h
util/mutexlock.h
util/random.h
${PORT_HDRS}
${CAPI_HDRS}
)
add_library(leveldb SHARED ${SRCS} ${HDRS} ${SNAPPY_SRCS} ${SNAPPY_HDRS} ${CRC32C_SRC})
set_target_properties(leveldb PROPERTIES
VERSION ${VERSION_STRING}
SOVERSION ${VERSION_MAJOR}
)
add_library(leveldb_static STATIC ${SRCS} ${HDRS} ${SNAPPY_SRCS} ${SNAPPY_HDRS} ${CRC32C_SRC})
find_package(Threads)
target_link_libraries(leveldb ${CMAKE_THREAD_LIBS_INIT} ${LIBS})
target_link_libraries(leveldb_static ${CMAKE_THREAD_LIBS_INIT} ${LIBS})
###
# TESTS
###
set(TESTHARNESS_SRCS
util/testutil.cc
util/testharness.cc
)
set(TESTHARNESS_HDRS
util/testutil.h
util/testharness.h
)
add_library(leveldb-testharness STATIC ${TESTHARNESS_SRCS})
macro(leveldb_tests)
foreach(t ${ARGN})
get_filename_component(_tname ${t} NAME_WE)
add_executable(${_tname} ${t})
target_link_libraries(${_tname}
leveldb-testharness
leveldb_static
)
add_test(NAME ${_tname}
COMMAND $<TARGET_FILE:${_tname}>)
endforeach()
endmacro()
leveldb_tests(
util/arena_test.cc
db/autocompact_test.cc
util/bloom_test.cc
${CAPI_TEST}
util/cache_test.cc
util/coding_test.cc
db/corruption_test.cc
util/crc32c_test.cc
db/db_test.cc
db/dbformat_test.cc
util/env_test.cc
db/filename_test.cc
table/filter_block_test.cc
issues/issue178_test.cc
issues/issue200_test.cc
db/log_test.cc
db/recovery_test.cc
db/skiplist_test.cc
table/table_test.cc
db/version_edit_test.cc
db/version_set_test.cc
db/write_batch_test.cc
db/db_bench.cc
db/fault_injection_test.cc
helpers/memenv/memenv_test.cc
util/hash_test.cc
)
# TODO: memenv_test