CMakeLists.txt 47.3 KB
Newer Older
1 2
# Prerequisites for Windows:
#     This cmake build is for Windows 64-bit only.
D
Dmitri Smirnov 已提交
3 4
#
# Prerequisites:
5
#     You must have at least Visual Studio 2015 Update 3. Start the Developer Command Prompt window that is a part of Visual Studio installation.
D
Dmitri Smirnov 已提交
6
#     Run the build commands from within the Developer Command Prompt window to have paths to the compiler and runtime libraries set.
7
#     You must have git.exe in your %PATH% environment variable.
D
Dmitri Smirnov 已提交
8 9
#
# To build Rocksdb for Windows is as easy as 1-2-3-4-5:
A
agiardullo 已提交
10
#
11
# 1. Update paths to third-party libraries in thirdparty.inc file
D
Dmitri Smirnov 已提交
12 13 14
# 2. Create a new directory for build artifacts
#        mkdir build
#        cd build
15 16
# 3. Run cmake to generate project files for Windows, add more options to enable required third-party libraries.
#    See thirdparty.inc for more information.
17
#        sample command: cmake -G "Visual Studio 15 Win64" -DCMAKE_BUILD_TYPE=Release -DWITH_GFLAGS=1 -DWITH_SNAPPY=1 -DWITH_JEMALLOC=1 -DWITH_JNI=1 ..
18
# 4. Then build the project in debug mode (you may want to add /m[:<N>] flag to run msbuild in <N> parallel threads
19
#                                          or simply /m to use all avail cores)
20 21 22 23 24
#        msbuild rocksdb.sln
#
#        rocksdb.sln build features exclusions of test only code in Release. If you build ALL_BUILD then everything
#        will be attempted but test only code does not build in Release mode.
#
25
# 5. And release mode (/m[:<N>] is also supported)
26
#        msbuild rocksdb.sln /p:Configuration=Release
D
Dmitri Smirnov 已提交
27
#
28 29 30 31 32 33
# Linux:
#
# 1. Install a recent toolchain such as devtoolset-3 if you're on a older distro. C++11 required.
# 2. mkdir build; cd build
# 3. cmake ..
# 4. make -j
D
Dmitri Smirnov 已提交
34

35 36 37 38 39 40 41 42
cmake_minimum_required(VERSION 3.5.1)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/")
include(ReadVersion)
get_rocksdb_version(rocksdb_VERSION)
project(rocksdb
  VERSION ${rocksdb_VERSION}
  LANGUAGES CXX C ASM)
D
Dmitri Smirnov 已提交
43

44 45 46 47
if(POLICY CMP0042)
  cmake_policy(SET CMP0042 NEW)
endif()

48 49 50 51 52 53 54 55 56 57
if(NOT CMAKE_BUILD_TYPE)
  if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
    set(default_build_type "Debug")
  else()
    set(default_build_type "RelWithDebInfo")
  endif()
  set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING
    "Default BUILD_TYPE is ${default_build_type}" FORCE)
endif()

58 59 60 61 62 63
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
  set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)

64
option(WITH_JEMALLOC "build with JeMalloc" OFF)
65 66 67
option(WITH_SNAPPY "build with SNAPPY" OFF)
option(WITH_LZ4 "build with lz4" OFF)
option(WITH_ZLIB "build with zlib" OFF)
68
option(WITH_ZSTD "build with zstd" OFF)
69 70 71 72
option(WITH_WINDOWS_UTF8_FILENAMES "use UTF8 as characterset for opening files, regardles of the system code page" OFF)
if (WITH_WINDOWS_UTF8_FILENAMES)
  add_definitions(-DROCKSDB_WINDOWS_UTF8_FILENAMES)
endif()
73 74
# third-party/folly is only validated to work on Linux and Windows for now.
# So only turn it on there by default.
75
if(CMAKE_SYSTEM_NAME MATCHES "Linux|Windows")
76 77 78 79 80 81
  if(MSVC AND MSVC_VERSION LESS 1910)
    # Folly does not compile with MSVC older than VS2017
    option(WITH_FOLLY_DISTRIBUTED_MUTEX "build with folly::DistributedMutex" OFF)
  else()
    option(WITH_FOLLY_DISTRIBUTED_MUTEX "build with folly::DistributedMutex" ON)
  endif()
82 83 84
else()
  option(WITH_FOLLY_DISTRIBUTED_MUTEX "build with folly::DistributedMutex" OFF)
endif()
85

P
Peter Dillinger 已提交
86 87 88 89
if( NOT DEFINED CMAKE_CXX_STANDARD )
  set(CMAKE_CXX_STANDARD 11)
endif()

90 91
include(CMakeDependentOption)

T
Tamir Duberstein 已提交
92
if(MSVC)
93
  option(WITH_GFLAGS "build with GFlags" OFF)
94
  option(WITH_XPRESS "build with windows built in compression" OFF)
95 96
  include(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty.inc)
else()
97
  if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" AND NOT CMAKE_SYSTEM_NAME MATCHES "kFreeBSD")
98
    # FreeBSD has jemalloc as default malloc
99
    # but it does not have all the jemalloc files in include/...
T
Tamir Duberstein 已提交
100
    set(WITH_JEMALLOC ON)
101 102 103 104
  else()
    if(WITH_JEMALLOC)
      find_package(JeMalloc REQUIRED)
      add_definitions(-DROCKSDB_JEMALLOC -DJEMALLOC_NO_DEMANGLE)
105
      list(APPEND THIRDPARTY_LIBS JeMalloc::JeMalloc)
106
    endif()
T
Tamir Duberstein 已提交
107
  endif()
108

109 110 111 112 113
  if(MINGW)
    option(WITH_GFLAGS "build with GFlags" OFF)
  else()
    option(WITH_GFLAGS "build with GFlags" ON)
  endif()
114
  set(GFLAGS_LIB)
115
  if(WITH_GFLAGS)
116 117 118 119 120 121
    # Config with namespace available since gflags 2.2.2
    option(GFLAGS_USE_TARGET_NAMESPACE "Use gflags import target with namespace." ON)
    find_package(gflags CONFIG)
    if(gflags_FOUND)
      if(TARGET ${GFLAGS_TARGET})
        # Config with GFLAGS_TARGET available since gflags 2.2.0
122
        set(GFLAGS_LIB ${GFLAGS_TARGET})
123 124
      else()
        # Config with GFLAGS_LIBRARIES available since gflags 2.1.0
125
        set(GFLAGS_LIB ${GFLAGS_LIBRARIES})
126 127 128
      endif()
    else()
      find_package(gflags REQUIRED)
129
        set(GFLAGS_LIB gflags::gflags)
130
    endif()
131 132
    include_directories(${GFLAGS_INCLUDE_DIR})
    list(APPEND THIRDPARTY_LIBS ${GFLAGS_LIB})
133
    add_definitions(-DGFLAGS=1)
134
  endif()
J
Jay 已提交
135

136
  if(WITH_SNAPPY)
137 138 139 140
    find_package(Snappy CONFIG)
    if(NOT Snappy_FOUND)
      find_package(Snappy REQUIRED)
    endif()
141
    add_definitions(-DSNAPPY)
142
    list(APPEND THIRDPARTY_LIBS Snappy::snappy)
143
  endif()
J
Jay 已提交
144 145

  if(WITH_ZLIB)
146
    find_package(ZLIB REQUIRED)
J
Jay 已提交
147
    add_definitions(-DZLIB)
148
    list(APPEND THIRDPARTY_LIBS ZLIB::ZLIB)
J
Jay 已提交
149 150 151 152
  endif()

  option(WITH_BZ2 "build with bzip2" OFF)
  if(WITH_BZ2)
153
    find_package(BZip2 REQUIRED)
J
Jay 已提交
154
    add_definitions(-DBZIP2)
155 156 157 158 159
    if(BZIP2_INCLUDE_DIRS)
      include_directories(${BZIP2_INCLUDE_DIRS})
    else()
      include_directories(${BZIP2_INCLUDE_DIR})
    endif()
J
Jay 已提交
160 161 162 163 164 165
    list(APPEND THIRDPARTY_LIBS ${BZIP2_LIBRARIES})
  endif()

  if(WITH_LZ4)
    find_package(lz4 REQUIRED)
    add_definitions(-DLZ4)
166
    list(APPEND THIRDPARTY_LIBS lz4::lz4)
J
Jay 已提交
167 168 169 170 171 172
  endif()

  if(WITH_ZSTD)
    find_package(zstd REQUIRED)
    add_definitions(-DZSTD)
    include_directories(${ZSTD_INCLUDE_DIR})
173
    list(APPEND THIRDPARTY_LIBS zstd::zstd)
J
Jay 已提交
174
  endif()
175 176
endif()

M
mrambacher 已提交
177 178
string(TIMESTAMP TS "%Y-%m-%d %H:%M:%S" UTC)
set(BUILD_DATE "${TS}" CACHE STRING "the time we first built rocksdb")
D
Dmitri Smirnov 已提交
179

180 181
find_package(Git)

T
Tamir Duberstein 已提交
182
if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
M
mrambacher 已提交
183 184 185 186 187 188
  execute_process(WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE GIT_SHA COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD )
  execute_process(WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" RESULT_VARIABLE GIT_MOD COMMAND "${GIT_EXECUTABLE}" diff-index HEAD --quiet)
  execute_process(WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE GIT_DATE COMMAND "${GIT_EXECUTABLE}" log -1 --date=format:"%Y-%m-%d %T" --format="%ad")
  execute_process(WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE GIT_TAG RESULT_VARIABLE rv COMMAND "${GIT_EXECUTABLE}" symbolic-ref -q --short HEAD OUTPUT_STRIP_TRAILING_WHITESPACE)
  if (rv AND NOT rv EQUAL 0)
    execute_process(WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE GIT_TAG COMMAND "${GIT_EXECUTABLE}" describe --tags --exact-match OUTPUT_STRIP_TRAILING_WHITESPACE)
189
  endif()
190
else()
191
  set(GIT_SHA 0)
192
  set(GIT_MOD 1)
193
endif()
M
mrambacher 已提交
194 195
string(REGEX REPLACE "[^0-9a-fA-F]+" "" GIT_SHA "${GIT_SHA}")
string(REGEX REPLACE "[^0-9: /-]+" "" GIT_DATE "${GIT_DATE}")
196

197 198 199 200 201 202
option(WITH_MD_LIBRARY "build with MD" ON)
if(WIN32 AND MSVC)
  if(WITH_MD_LIBRARY)
    set(RUNTIME_LIBRARY "MD")
  else()
    set(RUNTIME_LIBRARY "MT")
T
Tamir Duberstein 已提交
203
  endif()
204
endif()
T
Tomas Kolda 已提交
205

206 207
set(BUILD_VERSION_CC ${CMAKE_BINARY_DIR}/build_version.cc)
configure_file(util/build_version.cc.in ${BUILD_VERSION_CC} @ONLY)
M
mrambacher 已提交
208

209 210
if(MSVC)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue")
211
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W4 /wd4127 /wd4800 /wd4996 /wd4351 /wd4100 /wd4204 /wd4324")
212 213
else()
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wextra -Wall")
O
Orgad Shaneh 已提交
214
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -Wno-strict-aliasing")
215 216 217
  if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes")
  endif()
218
  if(MINGW)
219
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format -fno-asynchronous-unwind-tables")
220
    add_definitions(-D_POSIX_C_SOURCE=1)
221 222
  endif()
  if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
T
Tamir Duberstein 已提交
223
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
224 225 226 227 228 229 230 231
    include(CheckCXXCompilerFlag)
    CHECK_CXX_COMPILER_FLAG("-momit-leaf-frame-pointer" HAVE_OMIT_LEAF_FRAME_POINTER)
    if(HAVE_OMIT_LEAF_FRAME_POINTER)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -momit-leaf-frame-pointer")
    endif()
  endif()
endif()

232
include(CheckCCompilerFlag)
233 234 235 236 237 238 239 240 241 242 243 244
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
  CHECK_C_COMPILER_FLAG("-mcpu=power9" HAS_POWER9)
  if(HAS_POWER9)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=power9 -mtune=power9")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=power9 -mtune=power9")
  else()
    CHECK_C_COMPILER_FLAG("-mcpu=power8" HAS_POWER8)
    if(HAS_POWER8)
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=power8 -mtune=power8")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=power8 -mtune=power8")
    endif(HAS_POWER8)
  endif(HAS_POWER9)
245 246 247 248 249 250
  CHECK_C_COMPILER_FLAG("-maltivec" HAS_ALTIVEC)
  if(HAS_ALTIVEC)
    message(STATUS " HAS_ALTIVEC yes")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maltivec")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec")
  endif(HAS_ALTIVEC)
251
endif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
252

253
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|AARCH64")
254
        CHECK_C_COMPILER_FLAG("-march=armv8-a+crc+crypto" HAS_ARMV8_CRC)
255 256
  if(HAS_ARMV8_CRC)
    message(STATUS " HAS_ARMV8_CRC yes")
257 258
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crc+crypto -Wno-unused-function")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crc+crypto -Wno-unused-function")
259
  endif(HAS_ARMV8_CRC)
260
endif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|AARCH64")
261

262 263
option(PORTABLE "build a portable binary" OFF)
option(FORCE_SSE42 "force building with SSE4.2, even when PORTABLE=ON" OFF)
264 265
option(FORCE_AVX "force building with AVX, even when PORTABLE=ON" OFF)
option(FORCE_AVX2 "force building with AVX2, even when PORTABLE=ON" OFF)
266 267 268 269
if(PORTABLE)
  # MSVC does not need a separate compiler flag to enable SSE4.2; if nmmintrin.h
  # is available, it is available by default.
  if(FORCE_SSE42 AND NOT MSVC)
270
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2 -mpclmul")
T
Tomas Kolda 已提交
271
  endif()
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
  if(MSVC)
    if(FORCE_AVX)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX")
    endif()
    # MSVC automatically enables BMI / lzcnt with AVX2.
    if(FORCE_AVX2)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
    endif()
  else()
    if(FORCE_AVX)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
    endif()
    if(FORCE_AVX2)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2 -mbmi -mlzcnt")
    endif()
  endif()
T
Tamir Duberstein 已提交
288
else()
289 290 291
  if(MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
  else()
292
    if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64" AND NOT HAS_ARMV8_CRC)
293 294
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
    endif()
T
Tamir Duberstein 已提交
295
  endif()
T
Tamir Duberstein 已提交
296 297
endif()

298
include(CheckCXXSourceCompiles)
299
if(NOT MSVC)
300
  set(CMAKE_REQUIRED_FLAGS "-msse4.2 -mpclmul")
301
endif()
P
Peter Dillinger 已提交
302

303 304 305
CHECK_CXX_SOURCE_COMPILES("
#include <cstdint>
#include <nmmintrin.h>
306
#include <wmmintrin.h>
307 308
int main() {
  volatile uint32_t x = _mm_crc32_u32(0, 0);
309 310 311 312
  const auto a = _mm_set_epi64x(0, 0);
  const auto b = _mm_set_epi64x(0, 0);
  const auto c = _mm_clmulepi64_si128(a, b, 0x00);
  auto d = _mm_cvtsi128_si64(c);
313 314
}
" HAVE_SSE42)
315
unset(CMAKE_REQUIRED_FLAGS)
316 317
if(HAVE_SSE42)
  add_definitions(-DHAVE_SSE42)
318
  add_definitions(-DHAVE_PCLMUL)
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
elseif(FORCE_SSE42)
  message(FATAL_ERROR "FORCE_SSE42=ON but unable to compile with SSE4.2 enabled")
endif()

CHECK_CXX_SOURCE_COMPILES("
#if defined(_MSC_VER) && !defined(__thread)
#define __thread __declspec(thread)
#endif
int main() {
  static __thread int tls;
}
" HAVE_THREAD_LOCAL)
if(HAVE_THREAD_LOCAL)
  add_definitions(-DROCKSDB_SUPPORT_THREAD_LOCAL)
endif()

335 336 337 338 339 340 341 342 343
option(FAIL_ON_WARNINGS "Treat compile warnings as errors" ON)
if(FAIL_ON_WARNINGS)
  if(MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
  else() # assume GCC
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
  endif()
endif()

344 345 346 347 348 349 350 351 352
option(WITH_ASAN "build with ASAN" OFF)
if(WITH_ASAN)
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
  if(WITH_JEMALLOC)
    message(FATAL "ASAN does not work well with JeMalloc")
  endif()
endif()
D
Dmitri Smirnov 已提交
353

354 355 356 357 358 359 360 361 362
option(WITH_TSAN "build with TSAN" OFF)
if(WITH_TSAN)
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -pie")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fPIC")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fPIC")
  if(WITH_JEMALLOC)
    message(FATAL "TSAN does not work well with JeMalloc")
  endif()
endif()
363

364 365
option(WITH_UBSAN "build with UBSAN" OFF)
if(WITH_UBSAN)
366
  add_definitions(-DROCKSDB_UBSAN_RUN)
367 368 369 370 371 372 373
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
  if(WITH_JEMALLOC)
    message(FATAL "UBSAN does not work well with JeMalloc")
  endif()
endif()
D
Dmitri Smirnov 已提交
374

375 376 377
option(WITH_NUMA "build with NUMA policy support" OFF)
if(WITH_NUMA)
  find_package(NUMA REQUIRED)
378 379
  add_definitions(-DNUMA)
  include_directories(${NUMA_INCLUDE_DIR})
380
  list(APPEND THIRDPARTY_LIBS NUMA::NUMA)
381 382
endif()

383 384 385
option(WITH_TBB "build with Threading Building Blocks (TBB)" OFF)
if(WITH_TBB)
  find_package(TBB REQUIRED)
386
  add_definitions(-DTBB)
387
  list(APPEND THIRDPARTY_LIBS TBB::TBB)
388 389
endif()

390 391 392 393 394 395
# Stall notifications eat some performance from inserts
option(DISABLE_STALL_NOTIF "Build with stall notifications" OFF)
if(DISABLE_STALL_NOTIF)
  add_definitions(-DROCKSDB_DISABLE_STALL_NOTIFICATION)
endif()

396 397 398 399
option(WITH_DYNAMIC_EXTENSION "build with dynamic extension support" OFF)
if(NOT WITH_DYNAMIC_EXTENSION)
  add_definitions(-DROCKSDB_NO_DYNAMIC_EXTENSION)
endif()
400

401 402 403 404 405 406
option(ASSERT_STATUS_CHECKED "build with assert status checked" OFF)
if (ASSERT_STATUS_CHECKED)
  message(STATUS "Build with assert status checked")
  add_definitions(-DROCKSDB_ASSERT_STATUS_CHECKED)
endif()

407 408 409 410 411 412
if(DEFINED USE_RTTI)
  if(USE_RTTI)
    message(STATUS "Enabling RTTI")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DROCKSDB_USE_RTTI")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DROCKSDB_USE_RTTI")
  else()
413 414 415 416 417 418 419 420 421
    if(MSVC)
      message(STATUS "Disabling RTTI in Release builds. Always on in Debug.")
      set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DROCKSDB_USE_RTTI")
      set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GR-")
    else()
      message(STATUS "Disabling RTTI in Release builds")
      set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-rtti")
      set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-rtti")
    endif()
422
  endif()
423 424 425
else()
  message(STATUS "Enabling RTTI in Debug builds only (default)")
  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DROCKSDB_USE_RTTI")
426 427 428 429 430
  if(MSVC)
     set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GR-")
  else()
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-rtti")
  endif()
431 432
endif()

433 434
# Used to run CI build and tests so we can run faster
option(OPTDBG "Build optimized debug build with MSVC" OFF)
435
option(WITH_RUNTIME_DEBUG "build with debug version of runtime library" ON)
O
Orgad Shaneh 已提交
436
if(MSVC)
437
  if(OPTDBG)
438
    message(STATUS "Debug optimization is enabled")
439
    set(CMAKE_CXX_FLAGS_DEBUG "/Oxt")
440
  else()
P
Peter Dillinger 已提交
441 442 443 444 445 446 447 448 449
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /RTC1")

    # Minimal Build is deprecated after MSVC 2015
    if( MSVC_VERSION GREATER 1900 )
      set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Gm-")
    else()
      set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Gm")
    endif()

450 451 452 453 454
  endif()
  if(WITH_RUNTIME_DEBUG)
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /${RUNTIME_LIBRARY}d")
  else()
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /${RUNTIME_LIBRARY}")
455
  endif()
T
Tomas Kolda 已提交
456
  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oxt /Zp8 /Gm- /Gy /${RUNTIME_LIBRARY}")
457 458 459

  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
460 461
endif()

462 463 464
if(CMAKE_COMPILER_IS_GNUCXX)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp")
endif()
D
Dmitri Smirnov 已提交
465

466 467 468
option(ROCKSDB_LITE "Build RocksDBLite version" OFF)
if(ROCKSDB_LITE)
  add_definitions(-DROCKSDB_LITE)
Y
Yi Wu 已提交
469
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -Os")
470
endif()
D
Dmitri Smirnov 已提交
471

472 473 474 475 476 477 478 479
if(CMAKE_SYSTEM_NAME MATCHES "Cygwin")
  add_definitions(-fno-builtin-memcmp -DCYGWIN)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
  add_definitions(-DOS_MACOSX)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
  add_definitions(-DOS_LINUX)
elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
  add_definitions(-DOS_SOLARIS)
480 481
elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD")
  add_definitions(-DOS_GNU_KFREEBSD)
482 483 484 485 486 487 488 489 490 491 492 493
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  add_definitions(-DOS_FREEBSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
  add_definitions(-DOS_NETBSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
  add_definitions(-DOS_OPENBSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
  add_definitions(-DOS_DRAGONFLYBSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "Android")
  add_definitions(-DOS_ANDROID)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
  add_definitions(-DWIN32 -DOS_WIN -D_MBCS -DWIN64 -DNOMINMAX)
O
Orgad Shaneh 已提交
494 495 496
  if(MINGW)
    add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_VISTA)
  endif()
497 498 499 500 501 502 503 504
endif()

if(NOT WIN32)
  add_definitions(-DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX)
endif()

option(WITH_FALLOCATE "build with fallocate" ON)
if(WITH_FALLOCATE)
505
  CHECK_CXX_SOURCE_COMPILES("
506 507 508 509
#include <fcntl.h>
#include <linux/falloc.h>
int main() {
 int fd = open(\"/dev/null\", 0);
510
 fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, 1024);
511 512 513 514 515 516 517
}
" HAVE_FALLOCATE)
  if(HAVE_FALLOCATE)
    add_definitions(-DROCKSDB_FALLOCATE_PRESENT)
  endif()
endif()

518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
CHECK_CXX_SOURCE_COMPILES("
#include <fcntl.h>
int main() {
  int fd = open(\"/dev/null\", 0);
  sync_file_range(fd, 0, 1024, SYNC_FILE_RANGE_WRITE);
}
" HAVE_SYNC_FILE_RANGE_WRITE)
if(HAVE_SYNC_FILE_RANGE_WRITE)
  add_definitions(-DROCKSDB_RANGESYNC_PRESENT)
endif()

CHECK_CXX_SOURCE_COMPILES("
#include <pthread.h>
int main() {
  (void) PTHREAD_MUTEX_ADAPTIVE_NP;
}
" HAVE_PTHREAD_MUTEX_ADAPTIVE_NP)
if(HAVE_PTHREAD_MUTEX_ADAPTIVE_NP)
  add_definitions(-DROCKSDB_PTHREAD_ADAPTIVE_MUTEX)
endif()

include(CheckCXXSymbolExists)
540 541 542 543 544
if(CMAKE_SYSTEM_NAME MATCHES "^FreeBSD")
  check_cxx_symbol_exists(malloc_usable_size malloc_np.h HAVE_MALLOC_USABLE_SIZE)
else()
  check_cxx_symbol_exists(malloc_usable_size malloc.h HAVE_MALLOC_USABLE_SIZE)
endif()
545 546 547
if(HAVE_MALLOC_USABLE_SIZE)
  add_definitions(-DROCKSDB_MALLOC_USABLE_SIZE)
endif()
D
Dmitri Smirnov 已提交
548

549 550 551 552 553
check_cxx_symbol_exists(sched_getcpu sched.h HAVE_SCHED_GETCPU)
if(HAVE_SCHED_GETCPU)
  add_definitions(-DROCKSDB_SCHED_GETCPU_PRESENT)
endif()

F
Fabrice Fontaine 已提交
554 555 556 557 558
check_cxx_symbol_exists(getauxval auvx.h HAVE_AUXV_GETAUXVAL)
if(HAVE_AUXV_GETAUXVAL)
  add_definitions(-DROCKSDB_AUXV_GETAUXVAL_PRESENT)
endif()

D
Dmitri Smirnov 已提交
559 560
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/include)
561
if(WITH_FOLLY_DISTRIBUTED_MUTEX)
562 563
  include_directories(${PROJECT_SOURCE_DIR}/third-party/folly)
endif()
564
find_package(Threads REQUIRED)
D
Dmitri Smirnov 已提交
565

566
# Main library source code
567

D
Dmitri Smirnov 已提交
568
set(SOURCES
569
        cache/cache.cc
570 571 572
        cache/clock_cache.cc
        cache/lru_cache.cc
        cache/sharded_cache.cc
573
        db/arena_wrapped_db_iter.cc
574
        db/blob/blob_file_addition.cc
575
        db/blob/blob_file_builder.cc
576
        db/blob/blob_file_cache.cc
577
        db/blob/blob_file_garbage.cc
578
        db/blob/blob_file_meta.cc
579
        db/blob/blob_file_reader.cc
580
        db/blob/blob_log_format.cc
581
        db/blob/blob_log_sequential_reader.cc
582
        db/blob/blob_log_writer.cc
D
Dmitri Smirnov 已提交
583 584 585
        db/builder.cc
        db/c.cc
        db/column_family.cc
586 587
        db/compaction/compaction.cc
        db/compaction/compaction_iterator.cc
588
        db/compaction/compaction_picker.cc
589 590 591 592
        db/compaction/compaction_job.cc
        db/compaction/compaction_picker_fifo.cc
        db/compaction/compaction_picker_level.cc
        db/compaction/compaction_picker_universal.cc
593
        db/compaction/sst_partitioner.cc
A
agiardullo 已提交
594
        db/convenience.cc
D
Dmitri Smirnov 已提交
595
        db/db_filesnapshot.cc
596
        db/db_impl/compacted_db_impl.cc
597 598 599 600 601 602 603 604 605
        db/db_impl/db_impl.cc
        db/db_impl/db_impl_write.cc
        db/db_impl/db_impl_compaction_flush.cc
        db/db_impl/db_impl_files.cc
        db/db_impl/db_impl_open.cc
        db/db_impl/db_impl_debug.cc
        db/db_impl/db_impl_experimental.cc
        db/db_impl/db_impl_readonly.cc
        db/db_impl/db_impl_secondary.cc
606
        db/db_info_dumper.cc
D
Dmitri Smirnov 已提交
607
        db/db_iter.cc
608
        db/dbformat.cc
609
        db/error_handler.cc
D
Dmitri Smirnov 已提交
610 611
        db/event_helpers.cc
        db/experimental.cc
612
        db/external_sst_file_ingestion_job.cc
D
Dmitri Smirnov 已提交
613 614 615 616
        db/file_indexer.cc
        db/flush_job.cc
        db/flush_scheduler.cc
        db/forward_iterator.cc
617
        db/import_column_family_job.cc
D
Dmitri Smirnov 已提交
618
        db/internal_stats.cc
S
Siying Dong 已提交
619
        db/logs_with_prep_tracker.cc
D
Dmitri Smirnov 已提交
620 621
        db/log_reader.cc
        db/log_writer.cc
622
        db/malloc_stats.cc
D
Dmitri Smirnov 已提交
623 624 625 626
        db/memtable.cc
        db/memtable_list.cc
        db/merge_helper.cc
        db/merge_operator.cc
627
        db/output_validator.cc
628
        db/periodic_work_scheduler.cc
629
        db/range_del_aggregator.cc
630
        db/range_tombstone_fragmenter.cc
D
Dmitri Smirnov 已提交
631
        db/repair.cc
632
        db/snapshot_impl.cc
D
Dmitri Smirnov 已提交
633 634 635
        db/table_cache.cc
        db/table_properties_collector.cc
        db/transaction_log_impl.cc
636
        db/trim_history_scheduler.cc
D
Dmitri Smirnov 已提交
637 638
        db/version_builder.cc
        db/version_edit.cc
639
        db/version_edit_handler.cc
D
Dmitri Smirnov 已提交
640
        db/version_set.cc
641
        db/wal_edit.cc
D
Dmitri Smirnov 已提交
642 643 644 645 646
        db/wal_manager.cc
        db/write_batch.cc
        db/write_batch_base.cc
        db/write_controller.cc
        db/write_thread.cc
647
        env/composite_env.cc
648 649
        env/env.cc
        env/env_chroot.cc
E
Ewout Prangsma 已提交
650
        env/env_encryption.cc
651
        env/env_hdfs.cc
652
        env/file_system.cc
653
        env/file_system_tracer.cc
654
        env/fs_remap.cc
655
        env/mock_env.cc
656
        file/delete_scheduler.cc
657
        file/file_prefetch_buffer.cc
658 659
        file/file_util.cc
        file/filename.cc
660
        file/line_file_reader.cc
661 662 663 664
        file/random_access_file_reader.cc
        file/read_write_util.cc
        file/readahead_raf.cc
        file/sequence_file_reader.cc
665
        file/sst_file_manager_impl.cc
666
        file/writable_file_writer.cc
667 668 669
        logging/auto_roll_logger.cc
        logging/event_logger.cc
        logging/log_buffer.cc
670 671 672
        memory/arena.cc
        memory/concurrent_arena.cc
        memory/jemalloc_nodump_allocator.cc
673
        memory/memkind_kmem_allocator.cc
674
        memtable/alloc_tracker.cc
675 676
        memtable/hash_linklist_rep.cc
        memtable/hash_skiplist_rep.cc
677 678
        memtable/skiplistrep.cc
        memtable/vectorrep.cc
679
        memtable/write_buffer_manager.cc
680 681
        monitoring/histogram.cc
        monitoring/histogram_windowing.cc
682
        monitoring/in_memory_stats_history.cc
683 684 685 686
        monitoring/instrumented_mutex.cc
        monitoring/iostats_context.cc
        monitoring/perf_context.cc
        monitoring/perf_level.cc
687
        monitoring/persistent_stats_history.cc
688 689 690 691 692 693
        monitoring/statistics.cc
        monitoring/thread_status_impl.cc
        monitoring/thread_status_updater.cc
        monitoring/thread_status_util.cc
        monitoring/thread_status_util_debug.cc
        options/cf_options.cc
694
        options/configurable.cc
695
        options/customizable.cc
696 697 698 699
        options/db_options.cc
        options/options.cc
        options/options_helper.cc
        options/options_parser.cc
D
Dmitri Smirnov 已提交
700
        port/stack_trace.cc
701
        table/adaptive/adaptive_table_factory.cc
702
        table/block_based/binary_search_index_reader.cc
703 704 705 706
        table/block_based/block.cc
        table/block_based/block_based_filter_block.cc
        table/block_based/block_based_table_builder.cc
        table/block_based/block_based_table_factory.cc
707
        table/block_based/block_based_table_iterator.cc
708 709
        table/block_based/block_based_table_reader.cc
        table/block_based/block_builder.cc
710
        table/block_based/block_prefetcher.cc
711 712 713
        table/block_based/block_prefix_index.cc
        table/block_based/data_block_hash_index.cc
        table/block_based/data_block_footer.cc
714
        table/block_based/filter_block_reader_common.cc
715
        table/block_based/filter_policy.cc
716 717
        table/block_based/flush_block_policy.cc
        table/block_based/full_filter_block.cc
718
        table/block_based/hash_index_reader.cc
719
        table/block_based/index_builder.cc
720
        table/block_based/index_reader_common.cc
721
        table/block_based/parsed_full_filter_block.cc
722
        table/block_based/partitioned_filter_block.cc
723
        table/block_based/partitioned_index_iterator.cc
724 725
        table/block_based/partitioned_index_reader.cc
        table/block_based/reader_common.cc
726
        table/block_based/uncompression_dict_reader.cc
S
Siying Dong 已提交
727
        table/block_fetcher.cc
728 729 730
        table/cuckoo/cuckoo_table_builder.cc
        table/cuckoo/cuckoo_table_factory.cc
        table/cuckoo/cuckoo_table_reader.cc
D
Dmitri Smirnov 已提交
731 732 733
        table/format.cc
        table/get_context.cc
        table/iterator.cc
734
        table/merging_iterator.cc
D
Dmitri Smirnov 已提交
735
        table/meta_blocks.cc
736
        table/persistent_cache_helper.cc
737
        table/plain/plain_table_bloom.cc
738 739 740 741 742
        table/plain/plain_table_builder.cc
        table/plain/plain_table_factory.cc
        table/plain/plain_table_index.cc
        table/plain/plain_table_key_coding.cc
        table/plain/plain_table_reader.cc
743
        table/sst_file_dumper.cc
744
        table/sst_file_reader.cc
745
        table/sst_file_writer.cc
746
        table/table_factory.cc
D
Dmitri Smirnov 已提交
747 748
        table/table_properties.cc
        table/two_level_iterator.cc
749 750 751 752
        test_util/sync_point.cc
        test_util/sync_point_impl.cc
        test_util/testutil.cc
        test_util/transaction_test_util.cc
753
        tools/block_cache_analyzer/block_cache_trace_analyzer.cc
754
        tools/dump/db_dump_tool.cc
A
Akanksha Mahajan 已提交
755
        tools/io_tracer_parser_tool.cc
756 757 758
        tools/ldb_cmd.cc
        tools/ldb_tool.cc
        tools/sst_dump_tool.cc
Z
Zhichao Cao 已提交
759
        tools/trace_analyzer_tool.cc
760
        trace_replay/trace_replay.cc
H
haoyuhuang 已提交
761
        trace_replay/block_cache_tracer.cc
762
        trace_replay/io_tracer.cc
D
Dmitri Smirnov 已提交
763 764 765
        util/coding.cc
        util/compaction_job_stats_impl.cc
        util/comparator.cc
766
        util/compression_context_cache.cc
767
        util/concurrent_task_limiter_impl.cc
D
Dmitri Smirnov 已提交
768 769 770 771
        util/crc32c.cc
        util/dynamic_bloom.cc
        util/hash.cc
        util/murmurhash.cc
772
        util/random.cc
D
Dmitri Smirnov 已提交
773
        util/rate_limiter.cc
774
        util/ribbon_config.cc
D
Dmitri Smirnov 已提交
775
        util/slice.cc
776
        util/file_checksum_helper.cc
D
Dmitri Smirnov 已提交
777 778 779
        util/status.cc
        util/string_util.cc
        util/thread_local.cc
780
        util/threadpool_imp.cc
D
Dmitri Smirnov 已提交
781 782
        util/xxhash.cc
        utilities/backupable/backupable_db.cc
Y
Yi Wu 已提交
783
        utilities/blob_db/blob_compaction_filter.cc
784
        utilities/blob_db/blob_db.cc
A
Anirban Rahut 已提交
785
        utilities/blob_db/blob_db_impl.cc
786
        utilities/blob_db/blob_db_impl_filesnapshot.cc
Y
Yi Wu 已提交
787
        utilities/blob_db/blob_dump_tool.cc
788
        utilities/blob_db/blob_file.cc
789 790 791
        utilities/cassandra/cassandra_compaction_filter.cc
        utilities/cassandra/format.cc
        utilities/cassandra/merge_operator.cc
792
        utilities/checkpoint/checkpoint_impl.cc
793
        utilities/compaction_filters/remove_emptyvalue_compactionfilter.cc
A
Andrew Kryczka 已提交
794
        utilities/debug.cc
D
Dmitri Smirnov 已提交
795
        utilities/env_mirror.cc
A
Andrew Kryczka 已提交
796
        utilities/env_timed.cc
M
mrambacher 已提交
797 798
        utilities/fault_injection_env.cc
        utilities/fault_injection_fs.cc
D
Dmitri Smirnov 已提交
799
        utilities/leveldb_options/leveldb_options.cc
800
        utilities/memory/memory_util.cc
P
Pooya Shareghi 已提交
801
        utilities/merge_operators/bytesxor.cc
802 803
        utilities/merge_operators/max.cc
        utilities/merge_operators/put.cc
804
        utilities/merge_operators/sortlist.cc
D
Dmitri Smirnov 已提交
805 806 807
        utilities/merge_operators/string_append/stringappend.cc
        utilities/merge_operators/string_append/stringappend2.cc
        utilities/merge_operators/uint64add.cc
808
        utilities/object_registry.cc
809
        utilities/option_change_migration/option_change_migration.cc
810
        utilities/options/options_util.cc
811 812 813
        utilities/persistent_cache/block_cache_tier.cc
        utilities/persistent_cache/block_cache_tier_file.cc
        utilities/persistent_cache/block_cache_tier_metadata.cc
814
        utilities/persistent_cache/persistent_cache_tier.cc
815
        utilities/persistent_cache/volatile_tier_impl.cc
816
        utilities/simulator_cache/cache_simulator.cc
817
        utilities/simulator_cache/sim_cache.cc
818
        utilities/table_properties_collectors/compact_on_deletion_collector.cc
819
        utilities/trace/file_trace_reader_writer.cc
820 821 822
        utilities/transactions/lock/lock_manager.cc
        utilities/transactions/lock/point/point_lock_tracker.cc
        utilities/transactions/lock/point/point_lock_manager.cc
823 824
        utilities/transactions/lock/range/range_tree/range_tree_lock_manager.cc
        utilities/transactions/lock/range/range_tree/range_tree_lock_tracker.cc
D
Dmitri Smirnov 已提交
825
        utilities/transactions/optimistic_transaction_db_impl.cc
826
        utilities/transactions/optimistic_transaction.cc
Y
Yi Wu 已提交
827
        utilities/transactions/pessimistic_transaction.cc
M
Maysam Yabandeh 已提交
828
        utilities/transactions/pessimistic_transaction_db.cc
Y
Yi Wu 已提交
829 830
        utilities/transactions/snapshot_checker.cc
        utilities/transactions/transaction_base.cc
A
agiardullo 已提交
831
        utilities/transactions/transaction_db_mutex_impl.cc
A
agiardullo 已提交
832
        utilities/transactions/transaction_util.cc
833
        utilities/transactions/write_prepared_txn.cc
834
        utilities/transactions/write_prepared_txn_db.cc
835 836
        utilities/transactions/write_unprepared_txn.cc
        utilities/transactions/write_unprepared_txn_db.cc
D
Dmitri Smirnov 已提交
837 838
        utilities/ttl/db_ttl_impl.cc
        utilities/write_batch_with_index/write_batch_with_index.cc
M
mrambacher 已提交
839
        utilities/write_batch_with_index/write_batch_with_index_internal.cc)
840

841
list(APPEND SOURCES
842 843 844 845 846 847 848 849 850 851 852 853 854
  utilities/transactions/lock/range/range_tree/lib/locktree/concurrent_tree.cc
  utilities/transactions/lock/range/range_tree/lib/locktree/keyrange.cc
  utilities/transactions/lock/range/range_tree/lib/locktree/lock_request.cc
  utilities/transactions/lock/range/range_tree/lib/locktree/locktree.cc
  utilities/transactions/lock/range/range_tree/lib/locktree/manager.cc
  utilities/transactions/lock/range/range_tree/lib/locktree/range_buffer.cc
  utilities/transactions/lock/range/range_tree/lib/locktree/treenode.cc
  utilities/transactions/lock/range/range_tree/lib/locktree/txnid_set.cc
  utilities/transactions/lock/range/range_tree/lib/locktree/wfg.cc
  utilities/transactions/lock/range/range_tree/lib/standalone_port.cc
  utilities/transactions/lock/range/range_tree/lib/util/dbt.cc
  utilities/transactions/lock/range/range_tree/lib/util/memarena.cc)

H
Huachao Huang 已提交
855 856 857 858
if(HAVE_SSE42 AND NOT MSVC)
  set_source_files_properties(
    util/crc32c.cc
    PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul")
859 860
endif()

861
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
862 863 864
  list(APPEND SOURCES
    util/crc32c_ppc.c
    util/crc32c_ppc_asm.S)
865
endif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
866

867 868 869 870 871
if(HAS_ARMV8_CRC)
  list(APPEND SOURCES
    util/crc32c_arm64.cc)
endif(HAS_ARMV8_CRC)

872 873 874 875 876 877
if(WIN32)
  list(APPEND SOURCES
    port/win/io_win.cc
    port/win/env_win.cc
    port/win/env_default.cc
    port/win/port_win.cc
L
Lucian Petrut 已提交
878 879 880 881 882 883 884
    port/win/win_logger.cc)
  if(NOT MINGW)
    # Mingw only supports std::thread when using
    # posix threads.
    list(APPEND SOURCES
      port/win/win_thread.cc)
  endif()
885 886
if(WITH_XPRESS)
  list(APPEND SOURCES
887
    port/win/xpress_win.cc)
888
endif()
889

890 891 892 893
if(WITH_JEMALLOC)
  list(APPEND SOURCES
    port/win/win_jemalloc.cc)
endif()
894

895 896 897
else()
  list(APPEND SOURCES
    port/port_posix.cc
898
    env/env_posix.cc
899
    env/fs_posix.cc
900
    env/io_posix.cc)
901
endif()
D
Dmitri Smirnov 已提交
902

903 904 905 906 907 908 909 910 911
if(WITH_FOLLY_DISTRIBUTED_MUTEX)
  list(APPEND SOURCES
    third-party/folly/folly/detail/Futex.cpp
    third-party/folly/folly/synchronization/AtomicNotification.cpp
    third-party/folly/folly/synchronization/DistributedMutex.cpp
    third-party/folly/folly/synchronization/ParkingLot.cpp
    third-party/folly/folly/synchronization/WaitOptions.cpp)
endif()

912 913
set(ROCKSDB_STATIC_LIB rocksdb${ARTIFACT_SUFFIX})
set(ROCKSDB_SHARED_LIB rocksdb-shared${ARTIFACT_SUFFIX})
914 915

option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" ON)
916 917 918 919 920 921 922 923

option(WITH_LIBRADOS "Build with librados" OFF)
if(WITH_LIBRADOS)
  list(APPEND SOURCES
    utilities/env_librados.cc)
  list(APPEND THIRDPARTY_LIBS rados)
endif()

924
if(WIN32)
925
  set(SYSTEM_LIBS ${SYSTEM_LIBS} shlwapi.lib rpcrt4.lib)
926
else()
927
  set(SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
928 929
endif()

M
mrambacher 已提交
930
add_library(${ROCKSDB_STATIC_LIB} STATIC ${SOURCES} ${BUILD_VERSION_CC})
931
target_link_libraries(${ROCKSDB_STATIC_LIB} PRIVATE
932 933
  ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})

934
if(ROCKSDB_BUILD_SHARED)
M
mrambacher 已提交
935
  add_library(${ROCKSDB_SHARED_LIB} SHARED ${SOURCES} ${BUILD_VERSION_CC})
936
  target_link_libraries(${ROCKSDB_SHARED_LIB} PRIVATE
937
    ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952

  if(WIN32)
    set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES
      COMPILE_DEFINITIONS "ROCKSDB_DLL;ROCKSDB_LIBRARY_EXPORTS")
    if(MSVC)
      set_target_properties(${ROCKSDB_STATIC_LIB} PROPERTIES
        COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_STATIC_LIB}.pdb")
      set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES
        COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_SHARED_LIB}.pdb")
    endif()
  else()
    set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES
                          LINKER_LANGUAGE CXX
                          VERSION ${rocksdb_VERSION}
                          SOVERSION ${rocksdb_VERSION_MAJOR}
953
                          OUTPUT_NAME "rocksdb${ARTIFACT_SUFFIX}")
O
Orgad Shaneh 已提交
954
  endif()
955 956
endif()

957 958 959 960 961 962
if(ROCKSDB_BUILD_SHARED AND NOT WIN32)
  set(ROCKSDB_LIB ${ROCKSDB_SHARED_LIB})
else()
  set(ROCKSDB_LIB ${ROCKSDB_STATIC_LIB})
endif()

963
option(WITH_JNI "build with JNI" OFF)
964 965 966 967 968 969 970 971 972 973
# Tests are excluded from Release builds
CMAKE_DEPENDENT_OPTION(WITH_TESTS "build with tests" ON
  "CMAKE_BUILD_TYPE STREQUAL Debug" OFF)
option(WITH_BENCHMARK_TOOLS "build with benchmarks" ON)
option(WITH_CORE_TOOLS "build with ldb and sst_dump" ON)
option(WITH_TOOLS "build with tools" ON)

if(WITH_TESTS OR WITH_BENCHMARK_TOOLS OR WITH_TOOLS OR WITH_JNI OR JNI)
  include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third-party/gtest-1.8.1/fused-src)
endif()
974 975 976
if(WITH_JNI OR JNI)
  message(STATUS "JNI library is enabled")
  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/java)
977 978 979 980
else()
  message(STATUS "JNI library is disabled")
endif()

P
Paweł Bylica 已提交
981 982 983 984 985 986 987 988 989 990 991 992 993
# Installation and packaging
if(WIN32)
  option(ROCKSDB_INSTALL_ON_WINDOWS "Enable install target on Windows" OFF)
endif()
if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
  if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
      # Change default installation prefix on Linux to /usr
      set(CMAKE_INSTALL_PREFIX /usr CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
    endif()
  endif()

  include(GNUInstallDirs)
994 995 996 997 998
  include(CMakePackageConfigHelpers)

  set(package_config_destination ${CMAKE_INSTALL_LIBDIR}/cmake/rocksdb)

  configure_package_config_file(
B
Bartek Wrona 已提交
999
    ${CMAKE_CURRENT_LIST_DIR}/cmake/RocksDBConfig.cmake.in RocksDBConfig.cmake
1000 1001 1002 1003 1004
    INSTALL_DESTINATION ${package_config_destination}
  )

  write_basic_package_version_file(
    RocksDBConfigVersion.cmake
1005
    VERSION ${rocksdb_VERSION}
1006 1007 1008 1009 1010
    COMPATIBILITY SameMajorVersion
  )

  install(DIRECTORY include/rocksdb COMPONENT devel DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

1011 1012
  install(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/modules" COMPONENT devel DESTINATION ${package_config_destination})

1013 1014 1015 1016 1017 1018 1019 1020
  install(
    TARGETS ${ROCKSDB_STATIC_LIB}
    EXPORT RocksDBTargets
    COMPONENT devel
    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
    INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
  )

1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
  if(ROCKSDB_BUILD_SHARED)
    install(
      TARGETS ${ROCKSDB_SHARED_LIB}
      EXPORT RocksDBTargets
      COMPONENT runtime
      ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
      RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
      LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
      INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
    )
  endif()
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046

  install(
    EXPORT RocksDBTargets
    COMPONENT devel
    DESTINATION ${package_config_destination}
    NAMESPACE RocksDB::
  )

  install(
    FILES
    ${CMAKE_CURRENT_BINARY_DIR}/RocksDBConfig.cmake
    ${CMAKE_CURRENT_BINARY_DIR}/RocksDBConfigVersion.cmake
    COMPONENT devel
    DESTINATION ${package_config_destination}
  )
P
Paweł Bylica 已提交
1047 1048
endif()

1049 1050
option(WITH_ALL_TESTS "Build all test, rather than a small subset" ON)

球状闪电 已提交
1051
if(WITH_TESTS OR WITH_BENCHMARK_TOOLS)
1052
  add_subdirectory(third-party/gtest-1.8.1/fused-src/gtest)
1053
  add_library(testharness STATIC
1054
  test_util/mock_time_env.cc
1055 1056
  test_util/testharness.cc)
  target_link_libraries(testharness gtest)
球状闪电 已提交
1057
endif()
1058

球状闪电 已提交
1059
if(WITH_TESTS)
P
Paweł Bylica 已提交
1060
  set(TESTS
1061 1062 1063 1064 1065
        db/db_basic_test.cc
        env/env_basic_test.cc
  )
  if(WITH_ALL_TESTS)
    list(APPEND TESTS
1066 1067
        cache/cache_test.cc
        cache/lru_cache_test.cc
1068
        db/blob/blob_file_addition_test.cc
1069
        db/blob/blob_file_builder_test.cc
1070
        db/blob/blob_file_cache_test.cc
1071
        db/blob/blob_file_garbage_test.cc
1072
        db/blob/blob_file_reader_test.cc
1073
        db/blob/db_blob_basic_test.cc
1074
        db/blob/db_blob_compaction_test.cc
1075
        db/blob/db_blob_corruption_test.cc
1076
        db/blob/db_blob_index_test.cc
D
Dmitri Smirnov 已提交
1077 1078
        db/column_family_test.cc
        db/compact_files_test.cc
1079 1080 1081 1082
        db/compaction/compaction_job_stats_test.cc
        db/compaction/compaction_job_test.cc
        db/compaction/compaction_iterator_test.cc
        db/compaction/compaction_picker_test.cc
D
Dmitri Smirnov 已提交
1083 1084 1085
        db/comparator_db_test.cc
        db/corruption_test.cc
        db/cuckoo_table_db_test.cc
1086
        db/db_with_timestamp_basic_test.cc
1087 1088
        db/db_block_cache_test.cc
        db/db_bloom_filter_test.cc
1089
        db/db_compaction_filter_test.cc
1090
        db/db_compaction_test.cc
1091
        db/db_dynamic_level_test.cc
1092
        db/db_flush_test.cc
1093
        db/db_inplace_update_test.cc
1094
        db/db_io_failure_test.cc
1095
        db/db_iter_test.cc
1096
        db/db_iter_stress_test.cc
1097
        db/db_iterator_test.cc
1098
        db/db_kv_checksum_test.cc
1099
        db/db_log_iter_test.cc
1100
        db/db_memtable_test.cc
1101
        db/db_merge_operator_test.cc
1102
        db/db_merge_operand_test.cc
1103
        db/db_options_test.cc
1104
        db/db_properties_test.cc
1105
        db/db_range_del_test.cc
1106
        db/db_secondary_test.cc
1107
        db/db_sst_test.cc
1108
        db/db_statistics_test.cc
1109 1110 1111
        db/db_table_properties_test.cc
        db/db_tailing_iter_test.cc
        db/db_test.cc
1112
        db/db_test2.cc
1113
        db/db_logical_block_size_cache_test.cc
1114
        db/db_universal_compaction_test.cc
S
sdong 已提交
1115
        db/db_wal_test.cc
1116
        db/db_with_timestamp_compaction_test.cc
Y
Yi Wu 已提交
1117
        db/db_write_test.cc
D
Dmitri Smirnov 已提交
1118 1119
        db/dbformat_test.cc
        db/deletefile_test.cc
1120
        db/error_handler_fs_test.cc
1121
        db/obsolete_files_test.cc
1122 1123
        db/external_sst_file_basic_test.cc
        db/external_sst_file_test.cc
D
Dmitri Smirnov 已提交
1124 1125 1126 1127 1128 1129
        db/fault_injection_test.cc
        db/file_indexer_test.cc
        db/filename_test.cc
        db/flush_job_test.cc
        db/listener_test.cc
        db/log_test.cc
1130
        db/manual_compaction_test.cc
D
Dmitri Smirnov 已提交
1131
        db/memtable_list_test.cc
1132
        db/merge_helper_test.cc
1133
        db/merge_test.cc
1134
        db/options_file_test.cc
D
Dmitri Smirnov 已提交
1135
        db/perf_context_test.cc
1136
        db/periodic_work_scheduler_test.cc
D
Dmitri Smirnov 已提交
1137 1138
        db/plain_table_db_test.cc
        db/prefix_test.cc
1139 1140
        db/range_del_aggregator_test.cc
        db/range_tombstone_fragmenter_test.cc
A
Andrew Kryczka 已提交
1141
        db/repair_test.cc
D
Dmitri Smirnov 已提交
1142 1143 1144 1145 1146
        db/table_properties_collector_test.cc
        db/version_builder_test.cc
        db/version_edit_test.cc
        db/version_set_test.cc
        db/wal_manager_test.cc
1147
        db/wal_edit_test.cc
D
Dmitri Smirnov 已提交
1148 1149 1150
        db/write_batch_test.cc
        db/write_callback_test.cc
        db/write_controller_test.cc
1151
        env/env_test.cc
1152
        env/io_posix_test.cc
1153
        env/mock_env_test.cc
1154
        file/delete_scheduler_test.cc
1155
        file/prefetch_test.cc
1156
        file/random_access_file_reader_test.cc
1157
        logging/auto_roll_logger_test.cc
1158
        logging/env_logger_test.cc
1159
        logging/event_logger_test.cc
1160
        memory/arena_test.cc
1161
        memory/memkind_kmem_allocator_test.cc
1162 1163
        memtable/inlineskiplist_test.cc
        memtable/skiplist_test.cc
1164
        memtable/write_buffer_manager_test.cc
1165 1166 1167
        monitoring/histogram_test.cc
        monitoring/iostats_context_test.cc
        monitoring/statistics_test.cc
1168
        monitoring/stats_history_test.cc
1169
        options/configurable_test.cc
1170
        options/customizable_test.cc
1171 1172
        options/options_settable_test.cc
        options/options_test.cc
1173
        table/block_based/block_based_filter_block_test.cc
1174
        table/block_based/block_based_table_reader_test.cc
1175 1176 1177
        table/block_based/block_test.cc
        table/block_based/data_block_hash_index_test.cc
        table/block_based/full_filter_block_test.cc
1178
        table/block_based/partitioned_filter_block_test.cc
Y
Yi Wu 已提交
1179
        table/cleanable_test.cc
1180 1181
        table/cuckoo/cuckoo_table_builder_test.cc
        table/cuckoo/cuckoo_table_reader_test.cc
D
Dmitri Smirnov 已提交
1182
        table/merger_test.cc
1183
        table/sst_file_reader_test.cc
D
Dmitri Smirnov 已提交
1184
        table/table_test.cc
1185
        table/block_fetcher_test.cc
1186
        test_util/testutil_test.cc
J
Jay Zhuang 已提交
1187
        trace_replay/block_cache_tracer_test.cc
1188
        trace_replay/io_tracer_test.cc
1189
        tools/block_cache_analyzer/block_cache_trace_analyzer_test.cc
A
Akanksha Mahajan 已提交
1190
        tools/io_tracer_parser_test.cc
1191
        tools/ldb_cmd_test.cc
D
Dmitri Smirnov 已提交
1192
        tools/reduce_levels_test.cc
1193
        tools/sst_dump_test.cc
Z
Zhichao Cao 已提交
1194
        tools/trace_analyzer_test.cc
D
Dmitri Smirnov 已提交
1195 1196 1197 1198
        util/autovector_test.cc
        util/bloom_test.cc
        util/coding_test.cc
        util/crc32c_test.cc
C
Cheng Chang 已提交
1199
        util/defer_test.cc
D
Dmitri Smirnov 已提交
1200
        util/dynamic_bloom_test.cc
1201
        util/file_reader_writer_test.cc
1202
        util/filelock_test.cc
1203
        util/hash_test.cc
1204
        util/heap_test.cc
1205
        util/random_test.cc
D
Dmitri Smirnov 已提交
1206
        util/rate_limiter_test.cc
1207
        util/repeatable_thread_test.cc
1208
        util/ribbon_test.cc
1209
        util/slice_test.cc
D
Dmitri Smirnov 已提交
1210
        util/slice_transform_test.cc
A
Anirban Rahut 已提交
1211
        util/timer_queue_test.cc
1212
        util/timer_test.cc
D
Dmitri Smirnov 已提交
1213 1214
        util/thread_list_test.cc
        util/thread_local_test.cc
1215
        util/work_queue_test.cc
D
Dmitri Smirnov 已提交
1216
        utilities/backupable/backupable_db_test.cc
Y
Yi Wu 已提交
1217
        utilities/blob_db/blob_db_test.cc
1218 1219 1220 1221
        utilities/cassandra/cassandra_functional_test.cc
        utilities/cassandra/cassandra_format_test.cc
        utilities/cassandra/cassandra_row_merge_test.cc
        utilities/cassandra/cassandra_serialize_test.cc
D
Dmitri Smirnov 已提交
1222
        utilities/checkpoint/checkpoint_test.cc
1223
        utilities/memory/memory_test.cc
D
Dmitri Smirnov 已提交
1224
        utilities/merge_operators/string_append/stringappend_test.cc
1225
        utilities/object_registry_test.cc
1226
        utilities/option_change_migration/option_change_migration_test.cc
Y
yuslepukhin 已提交
1227
        utilities/options/options_util_test.cc
1228
        utilities/persistent_cache/hash_table_test.cc
1229
        utilities/persistent_cache/persistent_cache_test.cc
1230
        utilities/simulator_cache/cache_simulator_test.cc
1231
        utilities/simulator_cache/sim_cache_test.cc
1232
        utilities/table_properties_collectors/compact_on_deletion_collector_test.cc
D
Dmitri Smirnov 已提交
1233
        utilities/transactions/optimistic_transaction_test.cc
A
agiardullo 已提交
1234
        utilities/transactions/transaction_test.cc
1235
        utilities/transactions/lock/point/point_lock_manager_test.cc
1236
        utilities/transactions/write_prepared_transaction_test.cc
1237
        utilities/transactions/write_unprepared_transaction_test.cc
1238
        utilities/transactions/lock/range/range_locking_test.cc
D
Dmitri Smirnov 已提交
1239 1240
        utilities/ttl/ttl_test.cc
        utilities/write_batch_with_index/write_batch_with_index_test.cc
1241 1242
    )
  endif()
P
Paweł Bylica 已提交
1243 1244 1245
  if(WITH_LIBRADOS)
    list(APPEND TESTS utilities/env_librados_test.cc)
  endif()
1246

1247 1248 1249 1250
  if(WITH_FOLLY_DISTRIBUTED_MUTEX)
    list(APPEND TESTS third-party/folly/folly/synchronization/test/DistributedMutexTest.cpp)
  endif()

P
Paweł Bylica 已提交
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
  set(TESTUTIL_SOURCE
      db/db_test_util.cc
      monitoring/thread_status_updater_debug.cc
      table/mock_table.cc
      utilities/cassandra/test_utils.cc
  )
  enable_testing()
  add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
  set(TESTUTILLIB testutillib${ARTIFACT_SUFFIX})
  add_library(${TESTUTILLIB} STATIC ${TESTUTIL_SOURCE})
1261
  target_link_libraries(${TESTUTILLIB} ${ROCKSDB_LIB})
P
Paweł Bylica 已提交
1262 1263 1264 1265 1266 1267 1268
  if(MSVC)
    set_target_properties(${TESTUTILLIB} PROPERTIES COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/testutillib${ARTIFACT_SUFFIX}.pdb")
  endif()
  set_target_properties(${TESTUTILLIB}
        PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_RELEASE 1
        EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
        EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
P
Peter Dillinger 已提交
1269
  )
P
Paweł Bylica 已提交
1270

1271
  foreach(sourcefile ${TESTS})
P
Paweł Bylica 已提交
1272
      get_filename_component(exename ${sourcefile} NAME_WE)
1273
      add_executable(${CMAKE_PROJECT_NAME}_${exename}${ARTIFACT_SUFFIX} ${sourcefile})
B
Bartek Wrona 已提交
1274
      set_target_properties(${CMAKE_PROJECT_NAME}_${exename}${ARTIFACT_SUFFIX}
P
Paweł Bylica 已提交
1275 1276 1277
        PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_RELEASE 1
        EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
        EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
B
Bartek Wrona 已提交
1278
        OUTPUT_NAME ${exename}${ARTIFACT_SUFFIX}
P
Peter Dillinger 已提交
1279
      )
1280
      target_link_libraries(${CMAKE_PROJECT_NAME}_${exename}${ARTIFACT_SUFFIX} testutillib${ARTIFACT_SUFFIX} testharness gtest ${THIRDPARTY_LIBS} ${ROCKSDB_LIB})
P
Paweł Bylica 已提交
1281 1282
      if(NOT "${exename}" MATCHES "db_sanity_test")
        add_test(NAME ${exename} COMMAND ${exename}${ARTIFACT_SUFFIX})
B
Bartek Wrona 已提交
1283
        add_dependencies(check ${CMAKE_PROJECT_NAME}_${exename}${ARTIFACT_SUFFIX})
P
Paweł Bylica 已提交
1284
      endif()
1285 1286 1287 1288
      if("${exename}" MATCHES "env_librados_test")
        # env_librados_test.cc uses librados directly
        target_link_libraries(${CMAKE_PROJECT_NAME}_${exename}${ARTIFACT_SUFFIX} rados)
      endif()
1289
  endforeach(sourcefile ${TESTS})
P
Paweł Bylica 已提交
1290

1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
  if(WIN32)
    # C executables must link to a shared object
    if(ROCKSDB_BUILD_SHARED)
      set(ROCKSDB_LIB_FOR_C ${ROCKSDB_SHARED_LIB})
    else()
      set(ROCKSDB_LIB_FOR_C OFF)
    endif()
  else()
    set(ROCKSDB_LIB_FOR_C ${ROCKSDB_LIB})
  endif()
P
Paweł Bylica 已提交
1301

1302 1303
  if(ROCKSDB_LIB_FOR_C)
    set(C_TESTS db/c_test.c)
1304
    add_executable(c_test db/c_test.c)
Y
Yuhong Guo 已提交
1305
    target_link_libraries(c_test ${ROCKSDB_LIB_FOR_C} testharness)
1306 1307
    add_test(NAME c_test COMMAND c_test${ARTIFACT_SUFFIX})
    add_dependencies(check c_test)
1308
  endif()
P
Paweł Bylica 已提交
1309
endif()
A
Arun Sharma 已提交
1310

1311
if(WITH_BENCHMARK_TOOLS)
1312
  add_executable(db_bench${ARTIFACT_SUFFIX}
1313
    tools/db_bench.cc
1314
    tools/db_bench_tool.cc)
1315
  target_link_libraries(db_bench${ARTIFACT_SUFFIX}
1316
    ${ROCKSDB_LIB} ${THIRDPARTY_LIBS})
1317

1318
  add_executable(cache_bench${ARTIFACT_SUFFIX}
1319
    cache/cache_bench.cc)
1320
  target_link_libraries(cache_bench${ARTIFACT_SUFFIX}
1321
    ${ROCKSDB_LIB} ${GFLAGS_LIB})
1322

1323
  add_executable(memtablerep_bench${ARTIFACT_SUFFIX}
1324
    memtable/memtablerep_bench.cc)
1325
  target_link_libraries(memtablerep_bench${ARTIFACT_SUFFIX}
1326
    ${ROCKSDB_LIB} ${GFLAGS_LIB})
1327

1328
  add_executable(range_del_aggregator_bench${ARTIFACT_SUFFIX}
1329
    db/range_del_aggregator_bench.cc)
1330
  target_link_libraries(range_del_aggregator_bench${ARTIFACT_SUFFIX}
1331
    ${ROCKSDB_LIB} ${GFLAGS_LIB})
1332

1333
  add_executable(table_reader_bench${ARTIFACT_SUFFIX}
1334
    table/table_reader_bench.cc)
1335
  target_link_libraries(table_reader_bench${ARTIFACT_SUFFIX}
1336
    ${ROCKSDB_LIB} testharness ${GFLAGS_LIB})
1337

1338
  add_executable(filter_bench${ARTIFACT_SUFFIX}
1339
    util/filter_bench.cc)
1340
  target_link_libraries(filter_bench${ARTIFACT_SUFFIX}
1341
    ${ROCKSDB_LIB} ${GFLAGS_LIB})
1342

1343
  add_executable(hash_table_bench${ARTIFACT_SUFFIX}
1344
    utilities/persistent_cache/hash_table_bench.cc)
1345
  target_link_libraries(hash_table_bench${ARTIFACT_SUFFIX}
1346
    ${ROCKSDB_LIB} ${GFLAGS_LIB})
1347 1348
endif()

1349
if(WITH_CORE_TOOLS OR WITH_TOOLS)
P
Paweł Bylica 已提交
1350
  add_subdirectory(tools)
1351 1352 1353 1354 1355
  add_custom_target(core_tools
    DEPENDS ${core_tool_deps})
endif()

if(WITH_TOOLS)
1356 1357 1358
  add_subdirectory(db_stress_tool)
  add_custom_target(tools
    DEPENDS ${tool_deps})
A
Arun Sharma 已提交
1359
endif()
1360 1361 1362 1363 1364

option(WITH_EXAMPLES "build with examples" OFF)
if(WITH_EXAMPLES)
  add_subdirectory(examples)
endif()