if(PROJECT_ENABLE_ROCKSDB)
  if(PROJECT_BUILD)
    add_definitions(-DPROJECT_ENABLE_ROCKSDB)
    find_library(ROCKSDB_LIBRARY NAMES librocksdb.a REQUIRED)
    link_libraries(${ROCKSDB_LIBRARY})
  elseif(NOT PROJECT_IS_MINGW OR CMAKE_HOST_WIN32)
    ExternalProject_Add(rocksdb_project
      PREFIX external
      URL ${PROJECT_3RD_PARTY_DIR}/rocksdb-${ROCKSDB_VERSION}.tar.gz
      URL_HASH SHA256=${ROCKSDB_HASH}
      LIST_SEPARATOR |
      BUILD_COMMAND 
        ${CMAKE_COMMAND} --build . -- -j$ENV{CMAKE_BUILD_PARALLEL_LEVEL}
      CMAKE_ARGS ${PROJECT_EXTERNAL_CMAKE_FLAGS}
        -DBUILD_SHARED_LIBS=OFF
        -DBUILD_STATIC_LIBS=ON
        -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
        -DFAIL_ON_WARNINGS=OFF
        -DPORTABLE=1
        -DROCKSDB_BUILD_SHARED=OFF
        -DROCKSDB_INSTALL_ON_WINDOWS=ON
        -DWITH_BENCHMARK=OFF
        -DWITH_BENCHMARK_TOOLS=OFF
        -DWITH_BZ2=OFF
        -DWITH_CORE_TOOLS=OFF
        -DWITH_EXAMPLES=OFF
        -DWITH_GFLAGS=OFF
        -DWITH_IOSTATS_CONTEXT=OFF
        -DWITH_PERF_CONTEXT=OFF
        -DWITH_TESTS=OFF
        -DWITH_TOOLS=OFF
        -DWITH_TRACE_TOOLS=OFF
        -DWITH_ZLIB=ON
    )

    list(APPEND PROJECT_DEPENDENCIES rocksdb_project)
  endif()
endif()
