Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# Copyright 2017 The LevelDB Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file. See the AUTHORS file for names of contributors.5cmake_minimum_required(VERSION 3.22)6# Keep the version below in sync with the one in db.h7project(leveldb VERSION 1.22.0 LANGUAGES C CXX)9# C standard can be overridden when this is used as a sub-project.10if(NOT CMAKE_C_STANDARD)11# This project can use C11, but will gracefully decay down to C89.12set(CMAKE_C_STANDARD 11)13set(CMAKE_C_STANDARD_REQUIRED OFF)14set(CMAKE_C_EXTENSIONS OFF)15endif(NOT CMAKE_C_STANDARD)17# C++ standard can be overridden when this is used as a sub-project.18if(NOT CMAKE_CXX_STANDARD)19# This project requires C++17.20set(CMAKE_CXX_STANDARD 17)21set(CMAKE_CXX_STANDARD_REQUIRED ON)22set(CMAKE_CXX_EXTENSIONS OFF)23endif(NOT CMAKE_CXX_STANDARD)25if (WIN32)26set(LEVELDB_PLATFORM_NAME LEVELDB_PLATFORM_WINDOWS)27# TODO(cmumford): Make UNICODE configurable for Windows.28add_definitions(-D_UNICODE -DUNICODE)29else (WIN32)30set(LEVELDB_PLATFORM_NAME LEVELDB_PLATFORM_POSIX)31endif (WIN32)33option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON)34option(LEVELDB_BUILD_BENCHMARKS "Build LevelDB's benchmarks" ON)35option(LEVELDB_INSTALL "Install LevelDB's header and library" ON)37include(CheckIncludeFile)38check_include_file("unistd.h" HAVE_UNISTD_H)40include(CheckLibraryExists)41check_library_exists(crc32c crc32c_value "" HAVE_CRC32C)42check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)43check_library_exists(tcmalloc malloc "" HAVE_TCMALLOC)45include(CheckCXXSymbolExists)46# Using check_cxx_symbol_exists() instead of check_c_symbol_exists() because47# we're including the header from C++, and feature detection should use the same48# compiler language that the project will use later. Principles aside, some49# versions of do not expose fdatasync() in <unistd.h> in standard C mode50# (-std=c11), but do expose the function in standard C++ mode (-std=c++11).51check_cxx_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)52check_cxx_symbol_exists(F_FULLFSYNC "fcntl.h" HAVE_FULLFSYNC)53check_cxx_symbol_exists(O_CLOEXEC "fcntl.h" HAVE_O_CLOEXEC)55if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")56# Disable C++ exceptions.57string(REGEX REPLACE "/EH[a-z]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")58set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")59add_definitions(-D_HAS_EXCEPTIONS=0)61# Disable RTTI.62string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")63set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")64else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")65# Enable strict prototype warnings for C code in clang and gcc.66if(NOT CMAKE_C_FLAGS MATCHES "-Wstrict-prototypes")67set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes")68endif(NOT CMAKE_C_FLAGS MATCHES "-Wstrict-prototypes")70# Disable C++ exceptions.71string(REGEX REPLACE "-fexceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")72set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")74# Disable RTTI.75string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")76set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")77endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")79# Test whether -Wthread-safety is available. See80# https://clang.llvm.org/docs/ThreadSafetyAnalysis.html81include(CheckCXXCompilerFlag)82check_cxx_compiler_flag(-Wthread-safety HAVE_CLANG_THREAD_SAFETY)84include(CheckCXXSourceCompiles)86# Test whether C++17 __has_include is available.87check_cxx_source_compiles("88#if defined(__has_include) && __has_include(<string>)89#include <string>90#endif91int main() { std::string str; return 0; }92" HAVE_CXX17_HAS_INCLUDE)94set(LEVELDB_PUBLIC_INCLUDE_DIR "include/leveldb")95set(LEVELDB_PORT_CONFIG_DIR "include/port")97configure_file(98"port/port_config.h.in"99"${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h"100)102include_directories(103"${PROJECT_BINARY_DIR}/include"104"."105)107if(BUILD_SHARED_LIBS)108# Only export LEVELDB_EXPORT symbols from the shared library.109add_compile_options(-fvisibility=hidden)110endif(BUILD_SHARED_LIBS)112# Must be included before CMAKE_INSTALL_INCLUDEDIR is used.113include(GNUInstallDirs)115add_library(leveldb "")116target_sources(leveldb117PRIVATE118"${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h"119"db/builder.cc"120"db/builder.h"121"db/c.cc"122"db/db_impl.cc"123"db/db_impl.h"124"db/db_iter.cc"125"db/db_iter.h"126"db/dbformat.cc"127"db/dbformat.h"128"db/dumpfile.cc"129"db/filename.cc"130"db/filename.h"131"db/log_format.h"132"db/log_reader.cc"133"db/log_reader.h"134"db/log_writer.cc"135"db/log_writer.h"136"db/memtable.cc"137"db/memtable.h"138"db/repair.cc"139"db/skiplist.h"140"db/snapshot.h"141"db/table_cache.cc"142"db/table_cache.h"143"db/version_edit.cc"144"db/version_edit.h"145"db/version_set.cc"146"db/version_set.h"147"db/write_batch_internal.h"148"db/write_batch.cc"149"port/port_stdcxx.h"150"port/port.h"151"port/thread_annotations.h"152"table/block_builder.cc"153"table/block_builder.h"154"table/block.cc"155"table/block.h"156"table/filter_block.cc"157"table/filter_block.h"158"table/format.cc"159"table/format.h"160"table/iterator_wrapper.h"161"table/iterator.cc"162"table/merger.cc"163"table/merger.h"164"table/table_builder.cc"165"table/table.cc"166"table/two_level_iterator.cc"167"table/two_level_iterator.h"168"util/arena.cc"169"util/arena.h"170"util/bloom.cc"171"util/cache.cc"172"util/coding.cc"173"util/coding.h"174"util/comparator.cc"175"util/crc32c.cc"176"util/crc32c.h"177"util/env.cc"178"util/filter_policy.cc"179"util/hash.cc"180"util/hash.h"181"util/logging.cc"182"util/logging.h"183"util/mutexlock.h"184"util/no_destructor.h"185"util/options.cc"186"util/random.h"187"util/status.cc"189# Only CMake 3.3+ supports PUBLIC sources in targets exported by "install".190$<$<VERSION_GREATER:CMAKE_VERSION,3.2>:PUBLIC>191"${LEVELDB_PUBLIC_INCLUDE_DIR}/c.h"192"${LEVELDB_PUBLIC_INCLUDE_DIR}/cache.h"193"${LEVELDB_PUBLIC_INCLUDE_DIR}/comparator.h"194"${LEVELDB_PUBLIC_INCLUDE_DIR}/db.h"195"${LEVELDB_PUBLIC_INCLUDE_DIR}/dumpfile.h"196"${LEVELDB_PUBLIC_INCLUDE_DIR}/env.h"197"${LEVELDB_PUBLIC_INCLUDE_DIR}/export.h"198"${LEVELDB_PUBLIC_INCLUDE_DIR}/filter_policy.h"199"${LEVELDB_PUBLIC_INCLUDE_DIR}/iterator.h"200"${LEVELDB_PUBLIC_INCLUDE_DIR}/options.h"201"${LEVELDB_PUBLIC_INCLUDE_DIR}/slice.h"202"${LEVELDB_PUBLIC_INCLUDE_DIR}/status.h"203"${LEVELDB_PUBLIC_INCLUDE_DIR}/table_builder.h"204"${LEVELDB_PUBLIC_INCLUDE_DIR}/table.h"205"${LEVELDB_PUBLIC_INCLUDE_DIR}/write_batch.h"206)208if (WIN32)209target_sources(leveldb210PRIVATE211"util/env_windows.cc"212"util/windows_logger.h"213)214else (WIN32)215target_sources(leveldb216PRIVATE217"util/env_posix.cc"218"util/posix_logger.h"219)220endif (WIN32)222# MemEnv is not part of the interface and could be pulled to a separate library.223target_sources(leveldb224PRIVATE225"helpers/memenv/memenv.cc"226"helpers/memenv/memenv.h"227)229target_include_directories(leveldb230PUBLIC231$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>232$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>233)235set_target_properties(leveldb236PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})238target_compile_definitions(leveldb239PRIVATE240# Used by include/export.h when building shared libraries.241LEVELDB_COMPILE_LIBRARY242# Used by port/port.h.243${LEVELDB_PLATFORM_NAME}=1244)245if (NOT HAVE_CXX17_HAS_INCLUDE)246target_compile_definitions(leveldb247PRIVATE248LEVELDB_HAS_PORT_CONFIG_H=1249)250endif(NOT HAVE_CXX17_HAS_INCLUDE)
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.