2024-11-13 15:03:16 +03:00
|
|
|
# Copyright (c) 2020-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru>
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
#
|
|
|
|
# libmdbx = { Revised and extended descendant of Symas LMDB. } Please see
|
|
|
|
# README.md at https://gitflic.ru/project/erthink/libmdbx
|
|
|
|
#
|
|
|
|
# Libmdbx is superior to LMDB in terms of features and reliability, not inferior
|
|
|
|
# in performance. libmdbx works on Linux, FreeBSD, MacOS X and other systems
|
|
|
|
# compliant with POSIX.1-2008, but also support Windows as a complementary
|
|
|
|
# platform.
|
|
|
|
#
|
|
|
|
# The next version is under active non-public development and will be released
|
|
|
|
# as MithrilDB and libmithrildb for libraries & packages. Admittedly mythical
|
|
|
|
# Mithril is resembling silver but being stronger and lighter than steel.
|
|
|
|
# Therefore MithrilDB is rightly relevant name.
|
|
|
|
#
|
|
|
|
# MithrilDB will be radically different from libmdbx by the new database format
|
|
|
|
# and API based on C++17, as well as the Apache 2.0 License. The goal of this
|
|
|
|
# revolution is to provide a clearer and robust API, add more features and new
|
|
|
|
# valuable properties of database.
|
|
|
|
#
|
|
|
|
# The Future will (be) Positive. Всё будет хорошо.
|
|
|
|
#
|
2019-08-31 17:13:02 +03:00
|
|
|
|
2022-11-07 23:37:27 +03:00
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.8.2)
|
|
|
|
cmake_minimum_required(VERSION 3.0.2)
|
|
|
|
elseif(CMAKE_VERSION VERSION_LESS 3.12)
|
2021-08-03 17:17:22 +03:00
|
|
|
cmake_minimum_required(VERSION 3.8.2)
|
|
|
|
else()
|
|
|
|
cmake_minimum_required(VERSION 3.12)
|
|
|
|
endif()
|
2020-04-07 23:06:18 +03:00
|
|
|
|
2019-08-31 17:13:02 +03:00
|
|
|
cmake_policy(PUSH)
|
2021-08-03 17:17:22 +03:00
|
|
|
cmake_policy(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})
|
2022-06-01 15:13:03 +03:00
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 3.21)
|
|
|
|
cmake_policy(SET CMP0126 NEW)
|
|
|
|
endif()
|
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 3.17)
|
|
|
|
cmake_policy(SET CMP0102 NEW)
|
|
|
|
endif()
|
2020-05-10 03:41:28 +03:00
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 3.15)
|
|
|
|
cmake_policy(SET CMP0091 NEW)
|
|
|
|
endif()
|
2019-10-24 16:40:40 +03:00
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 3.13)
|
|
|
|
cmake_policy(SET CMP0077 NEW)
|
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 3.12)
|
|
|
|
cmake_policy(SET CMP0075 NEW)
|
|
|
|
endif()
|
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 3.9)
|
2022-06-01 15:13:03 +03:00
|
|
|
cmake_policy(SET CMP0068 NEW)
|
2019-08-31 17:13:02 +03:00
|
|
|
cmake_policy(SET CMP0069 NEW)
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
check_ipo_supported(RESULT CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE)
|
|
|
|
else()
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE FALSE)
|
|
|
|
endif()
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/COPYRIGHT"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/NOTICE"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/README.md"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h++"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/alloy.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-cursor.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-env.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-extra.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-key-transform.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-txn.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/atomics-ops.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/atomics-types.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/audit.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/chk.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cogs.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cogs.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/coherency.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cold.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/copy.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cursor.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cursor.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dbi.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dbi.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/debug_begin.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/debug_end.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dpl.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dpl.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dxb.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/env-opts.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/env.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/essentials.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/gc-get.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/gc-put.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/gc.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/global.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/internals.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/layout-dxb.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/layout-lck.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck-posix.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck-windows.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/logging_and_debug.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/logging_and_debug.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_chk.1"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_copy.1"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_drop.1"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_dump.1"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_load.1"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_stat.1"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/mdbx.c++"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/meta.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/meta.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/misc.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/mvcc-readers.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/node.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/node.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/ntdll.def"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/options.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/osal.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/osal.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-get.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-iov.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-iov.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-ops.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-ops.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-search.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/pnl.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/pnl.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/preface.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/proto.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/range-estimate.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/refund.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/sort.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/spill.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/spill.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/table.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tls.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tls.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/chk.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/copy.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/drop.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/dump.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/load.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/stat.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/wingetopt.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/wingetopt.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tree.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/txl.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/txl.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/txn.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/unaligned.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/utils.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/utils.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/version.c.in"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/walk.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/walk.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/windows-import.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/windows-import.h")
|
2020-04-15 17:09:37 +03:00
|
|
|
set(MDBX_AMALGAMATED_SOURCE FALSE)
|
|
|
|
find_program(GIT git)
|
|
|
|
if(NOT GIT)
|
|
|
|
message(SEND_ERROR "Git command-line tool not found")
|
|
|
|
endif()
|
|
|
|
set(MDBX_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
2024-11-13 15:03:16 +03:00
|
|
|
elseif(
|
|
|
|
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.json"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/NOTICE"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.c++"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h++"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_chk.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_copy.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_dump.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_load.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_stat.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_drop.c"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ntdll.def"
|
|
|
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in")
|
2020-04-15 17:09:37 +03:00
|
|
|
set(MDBX_AMALGAMATED_SOURCE TRUE)
|
|
|
|
set(MDBX_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"\nThe set of libmdbx source code files is incomplete! "
|
|
|
|
"Instead just follow the https://libmdbx.dqdkfa.ru/usage.html "
|
|
|
|
"PLEASE, AVOID USING ANY OTHER TECHNIQUES.")
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
|
2019-08-31 17:13:02 +03:00
|
|
|
if(DEFINED PROJECT_NAME)
|
2024-11-13 15:03:16 +03:00
|
|
|
option(
|
|
|
|
MDBX_FORCE_BUILD_AS_MAIN_PROJECT
|
|
|
|
"Force libmdbx to full control build options even it added as a subdirectory to your project."
|
|
|
|
OFF)
|
2021-11-16 17:57:54 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(DEFINED PROJECT_NAME AND NOT MDBX_FORCE_BUILD_AS_MAIN_PROJECT)
|
2019-08-31 17:13:02 +03:00
|
|
|
set(SUBPROJECT ON)
|
2019-09-05 11:57:52 +03:00
|
|
|
set(NOT_SUBPROJECT OFF)
|
2020-04-15 17:09:37 +03:00
|
|
|
if(NOT MDBX_AMALGAMATED_SOURCE AND NOT DEFINED BUILD_TESTING)
|
2019-08-31 17:13:02 +03:00
|
|
|
set(BUILD_TESTING OFF)
|
|
|
|
endif()
|
2020-09-27 16:49:55 +03:00
|
|
|
enable_language(C)
|
2019-08-31 17:13:02 +03:00
|
|
|
else()
|
|
|
|
set(SUBPROJECT OFF)
|
2019-09-05 11:57:52 +03:00
|
|
|
set(NOT_SUBPROJECT ON)
|
2020-09-27 16:49:55 +03:00
|
|
|
project(libmdbx C)
|
2020-04-15 17:09:37 +03:00
|
|
|
if(NOT MDBX_AMALGAMATED_SOURCE AND NOT DEFINED BUILD_TESTING)
|
2019-08-31 17:13:02 +03:00
|
|
|
set(BUILD_TESTING ON)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2022-04-21 19:49:57 +03:00
|
|
|
if(NOT MDBX_AMALGAMATED_SOURCE)
|
|
|
|
include(CTest)
|
|
|
|
option(MDBX_ENABLE_TESTS "Build libmdbx tests." ${BUILD_TESTING})
|
|
|
|
elseif(DEFINED MDBX_ENABLE_TESTS AND MDBX_ENABLE_TESTS)
|
2024-11-13 15:03:16 +03:00
|
|
|
message(
|
|
|
|
WARNING
|
|
|
|
"MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: But amalgamated source code don't includes tests."
|
|
|
|
)
|
2020-09-27 16:45:00 +03:00
|
|
|
set(MDBX_ENABLE_TESTS OFF)
|
|
|
|
endif()
|
|
|
|
|
2020-09-27 16:49:55 +03:00
|
|
|
# Try to find a C++ compiler unless sure that this is unnecessary.
|
2024-11-13 15:03:16 +03:00
|
|
|
if(NOT CMAKE_CXX_COMPILER_LOADED)
|
2020-09-27 16:49:55 +03:00
|
|
|
include(CheckLanguage)
|
2024-11-13 15:03:16 +03:00
|
|
|
if(NOT DEFINED MDBX_BUILD_CXX
|
|
|
|
OR MDBX_BUILD_CXX
|
|
|
|
OR (NOT MDBX_AMALGAMATED_SOURCE AND (NOT DEFINED MDBX_ENABLE_TESTS
|
|
|
|
OR MDBX_ENABLE_TESTS)))
|
2020-09-27 16:49:55 +03:00
|
|
|
check_language(CXX)
|
|
|
|
if(CMAKE_CXX_COMPILER)
|
|
|
|
enable_language(CXX)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
enable_language(CXX)
|
|
|
|
endif()
|
|
|
|
|
2021-04-19 17:43:25 +03:00
|
|
|
# Set default build type to Release. This is to ease a User's life.
|
2019-09-10 22:41:53 +03:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
2024-11-13 15:03:16 +03:00
|
|
|
set(CMAKE_BUILD_TYPE
|
|
|
|
Release
|
|
|
|
CACHE
|
|
|
|
STRING
|
|
|
|
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
|
|
|
|
FORCE)
|
2019-09-10 22:41:53 +03:00
|
|
|
endif()
|
2021-04-19 17:43:25 +03:00
|
|
|
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE)
|
2019-09-10 22:41:53 +03:00
|
|
|
|
2020-04-07 23:07:32 +03:00
|
|
|
if(NOT_SUBPROJECT AND (CMAKE_CROSSCOMPILING OR IOS))
|
|
|
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
|
|
|
endif()
|
|
|
|
|
2019-08-31 17:13:02 +03:00
|
|
|
if(NOT "$ENV{TEAMCITY_PROCESS_FLOW_ID}" STREQUAL "")
|
|
|
|
set(CI TEAMCITY)
|
|
|
|
message(STATUS "TeamCity CI")
|
|
|
|
elseif(NOT "$ENV{TRAVIS}" STREQUAL "")
|
|
|
|
set(CI TRAVIS)
|
|
|
|
message(STATUS "Travis CI")
|
|
|
|
elseif(NOT "$ENV{CIRCLECI}" STREQUAL "")
|
|
|
|
set(CI CIRCLE)
|
|
|
|
message(STATUS "Circle CI")
|
|
|
|
elseif(NOT "$ENV{APPVEYOR}" STREQUAL "")
|
|
|
|
set(CI APPVEYOR)
|
|
|
|
message(STATUS "AppVeyor CI")
|
|
|
|
elseif(NOT "$ENV{CI}" STREQUAL "")
|
|
|
|
set(CI "$ENV{CI}")
|
|
|
|
message(STATUS "Other CI (${CI})")
|
|
|
|
else()
|
|
|
|
message(STATUS "Assume No any CI environment")
|
|
|
|
unset(CI)
|
|
|
|
endif()
|
|
|
|
|
2019-09-01 16:35:30 +03:00
|
|
|
# output all mdbx-related targets in single directory
|
|
|
|
if(NOT DEFINED MDBX_OUTPUT_DIR)
|
|
|
|
set(MDBX_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
endif()
|
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${MDBX_OUTPUT_DIR})
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${MDBX_OUTPUT_DIR})
|
|
|
|
set(CMAKE_PDB_OUTPUT_DIRECTORY ${MDBX_OUTPUT_DIR})
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MDBX_OUTPUT_DIR})
|
|
|
|
|
2019-08-31 17:13:02 +03:00
|
|
|
include(CheckFunctionExists)
|
|
|
|
include(FindPackageMessage)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
|
|
|
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION LESS 1900)
|
2024-11-13 15:03:16 +03:00
|
|
|
message(
|
|
|
|
SEND_ERROR "MSVC compiler ${MSVC_VERSION} is too old for building MDBX."
|
|
|
|
" At least 'Microsoft Visual Studio 2015' is required.")
|
2019-08-31 17:13:02 +03:00
|
|
|
endif()
|
|
|
|
|
2022-06-01 15:13:03 +03:00
|
|
|
if(NOT DEFINED THREADS_PREFER_PTHREAD_FLAG)
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
|
|
|
endif()
|
2020-10-05 19:12:20 +03:00
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
2019-08-31 17:13:02 +03:00
|
|
|
include(cmake/utils.cmake)
|
|
|
|
include(cmake/compiler.cmake)
|
|
|
|
include(cmake/profile.cmake)
|
|
|
|
|
2020-10-05 19:12:20 +03:00
|
|
|
# Workaround for `-pthread` toolchain/cmake bug
|
2024-11-13 15:03:16 +03:00
|
|
|
if(NOT APPLE
|
|
|
|
AND NOT MSVC
|
|
|
|
AND CMAKE_USE_PTHREADS_INIT
|
|
|
|
AND NOT CMAKE_THREAD_LIBS_INIT
|
|
|
|
AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
|
2020-10-05 19:12:20 +03:00
|
|
|
check_compiler_flag("-pthread" CC_HAS_PTHREAD)
|
|
|
|
if(CC_HAS_PTHREAD AND NOT CMAKE_EXE_LINKER_FLAGS MATCHES "-pthread")
|
|
|
|
message(STATUS "Force add -pthread for linker flags to avoid troubles")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread")
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pthread")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
check_function_exists(pow NOT_NEED_LIBM)
|
2019-08-31 17:13:02 +03:00
|
|
|
if(NOT_NEED_LIBM)
|
|
|
|
set(LIB_MATH "")
|
|
|
|
else()
|
|
|
|
set(CMAKE_REQUIRED_LIBRARIES m)
|
2024-11-13 15:03:16 +03:00
|
|
|
check_function_exists(pow HAVE_LIBM)
|
2019-08-31 17:13:02 +03:00
|
|
|
if(HAVE_LIBM)
|
|
|
|
set(LIB_MATH m)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "No libm found for math support")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-09-03 02:24:19 +03:00
|
|
|
if(SUBPROJECT)
|
|
|
|
if(NOT DEFINED BUILD_SHARED_LIBS)
|
2019-09-05 11:57:52 +03:00
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" OFF)
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
|
2024-11-13 15:03:16 +03:00
|
|
|
option(CMAKE_POSITION_INDEPENDENT_CODE
|
|
|
|
"Generate position independent (PIC)" ON)
|
2019-09-03 02:24:19 +03:00
|
|
|
endif()
|
2022-07-28 18:48:21 +03:00
|
|
|
set(MDBX_MANAGE_BUILD_FLAGS_DEFAULT OFF)
|
2019-09-03 02:24:19 +03:00
|
|
|
else()
|
2019-09-05 11:57:52 +03:00
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" ON)
|
2024-11-13 15:03:16 +03:00
|
|
|
option(CMAKE_POSITION_INDEPENDENT_CODE "Generate position independent (PIC)"
|
|
|
|
ON)
|
|
|
|
if(CC_HAS_ARCH_NATIVE)
|
|
|
|
option(BUILD_FOR_NATIVE_CPU "Generate code for the compiling machine CPU"
|
|
|
|
OFF)
|
2019-08-31 17:13:02 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE
|
2024-11-13 15:03:16 +03:00
|
|
|
OR GCC_LTO_AVAILABLE
|
|
|
|
OR MSVC_LTO_AVAILABLE
|
|
|
|
OR CLANG_LTO_AVAILABLE)
|
|
|
|
if((CMAKE_CONFIGURATION_TYPES OR NOT CMAKE_BUILD_TYPE_UPPERCASE STREQUAL
|
|
|
|
"DEBUG")
|
|
|
|
AND ((MSVC_LTO_AVAILABLE AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19
|
|
|
|
)
|
|
|
|
OR (GCC_LTO_AVAILABLE AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS
|
|
|
|
7)
|
|
|
|
OR (CLANG_LTO_AVAILABLE AND NOT CMAKE_C_COMPILER_VERSION
|
|
|
|
VERSION_LESS 5)
|
|
|
|
))
|
2022-11-09 23:37:50 +03:00
|
|
|
set(INTERPROCEDURAL_OPTIMIZATION_DEFAULT ON)
|
|
|
|
else()
|
|
|
|
set(INTERPROCEDURAL_OPTIMIZATION_DEFAULT OFF)
|
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
option(INTERPROCEDURAL_OPTIMIZATION
|
|
|
|
"Enable interprocedural/LTO optimization."
|
|
|
|
${INTERPROCEDURAL_OPTIMIZATION_DEFAULT})
|
2019-08-31 17:13:02 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(INTERPROCEDURAL_OPTIMIZATION)
|
2022-11-09 23:37:50 +03:00
|
|
|
if(GCC_LTO_AVAILABLE)
|
2019-08-31 17:13:02 +03:00
|
|
|
set(LTO_ENABLED TRUE)
|
2024-11-13 15:03:16 +03:00
|
|
|
set(CMAKE_AR
|
|
|
|
${CMAKE_GCC_AR}
|
|
|
|
CACHE PATH "Path to ar program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_C_COMPILER_AR
|
|
|
|
${CMAKE_AR}
|
|
|
|
CACHE PATH "Path to ar program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_CXX_COMPILER_AR
|
|
|
|
${CMAKE_AR}
|
|
|
|
CACHE PATH "Path to ar program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_NM
|
|
|
|
${CMAKE_GCC_NM}
|
|
|
|
CACHE PATH "Path to nm program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_RANLIB
|
|
|
|
${CMAKE_GCC_RANLIB}
|
|
|
|
CACHE PATH "Path to ranlib program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_C_COMPILER_RANLIB
|
|
|
|
${CMAKE_RANLIB}
|
|
|
|
CACHE PATH "Path to ranlib program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_CXX_COMPILER_RANLIB
|
|
|
|
${CMAKE_RANLIB}
|
|
|
|
CACHE PATH "Path to ranlib program with LTO-plugin" FORCE)
|
2019-08-31 17:13:02 +03:00
|
|
|
message(STATUS "MDBX indulge Link-Time Optimization by GCC")
|
|
|
|
elseif(CLANG_LTO_AVAILABLE)
|
|
|
|
set(LTO_ENABLED TRUE)
|
2022-10-16 18:10:44 +03:00
|
|
|
if(CMAKE_CLANG_LD)
|
2024-11-13 15:03:16 +03:00
|
|
|
set(CMAKE_LINKER
|
|
|
|
${CMAKE_CLANG_LD}
|
|
|
|
CACHE PATH "Path to lld or ld program with LTO-plugin" FORCE)
|
2022-10-16 18:10:44 +03:00
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
set(CMAKE_AR
|
|
|
|
${CMAKE_CLANG_AR}
|
|
|
|
CACHE PATH "Path to ar program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_C_COMPILER_AR
|
|
|
|
${CMAKE_AR}
|
|
|
|
CACHE PATH "Path to ar program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_CXX_COMPILER_AR
|
|
|
|
${CMAKE_AR}
|
|
|
|
CACHE PATH "Path to ar program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_NM
|
|
|
|
${CMAKE_CLANG_NM}
|
|
|
|
CACHE PATH "Path to nm program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_RANLIB
|
|
|
|
${CMAKE_CLANG_RANLIB}
|
|
|
|
CACHE PATH "Path to ranlib program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_C_COMPILER_RANLIB
|
|
|
|
${CMAKE_RANLIB}
|
|
|
|
CACHE PATH "Path to ranlib program with LTO-plugin" FORCE)
|
|
|
|
set(CMAKE_CXX_COMPILER_RANLIB
|
|
|
|
${CMAKE_RANLIB}
|
|
|
|
CACHE PATH "Path to ranlib program with LTO-plugin" FORCE)
|
2019-08-31 17:13:02 +03:00
|
|
|
message(STATUS "MDBX indulge Link-Time Optimization by CLANG")
|
|
|
|
elseif(MSVC_LTO_AVAILABLE)
|
|
|
|
set(LTO_ENABLED TRUE)
|
|
|
|
message(STATUS "MDBX indulge Link-Time Optimization by MSVC")
|
|
|
|
elseif(CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE)
|
|
|
|
message(STATUS "MDBX indulge Interprocedural Optimization by CMake")
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
set(LTO_ENABLED TRUE)
|
|
|
|
else()
|
|
|
|
message(WARNING "Unable to engage interprocedural/LTO optimization.")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
|
|
|
|
set(LTO_ENABLED FALSE)
|
|
|
|
endif()
|
|
|
|
|
2020-04-15 17:09:37 +03:00
|
|
|
if(NOT MDBX_AMALGAMATED_SOURCE)
|
|
|
|
find_program(VALGRIND valgrind)
|
|
|
|
if(VALGRIND)
|
2024-11-13 15:03:16 +03:00
|
|
|
# (LY) cmake is ugly and nasty. Therefore memcheck-options should be
|
|
|
|
# defined before including ctest. Otherwise ctest may ignore it.
|
2020-04-15 17:09:37 +03:00
|
|
|
set(MEMORYCHECK_SUPPRESSIONS_FILE
|
2024-11-13 15:03:16 +03:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/test/valgrind_suppress.txt"
|
|
|
|
CACHE FILEPATH "Suppressions file for Valgrind" FORCE)
|
2020-04-15 17:09:37 +03:00
|
|
|
set(MEMORYCHECK_COMMAND_OPTIONS
|
2024-11-13 15:03:16 +03:00
|
|
|
"--trace-children=yes --leak-check=full --track-origins=yes --track-origins=yes --error-exitcode=42 --error-markers=@ --errors-for-leak-kinds=definite --fair-sched=yes --suppressions=${MEMORYCHECK_SUPPRESSIONS_FILE}"
|
|
|
|
CACHE STRING "Valgrind options" FORCE)
|
|
|
|
set(VALGRIND_COMMAND_OPTIONS
|
|
|
|
"${MEMORYCHECK_COMMAND_OPTIONS}"
|
|
|
|
CACHE STRING "Valgrind options" FORCE)
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
|
2020-04-15 17:09:37 +03:00
|
|
|
# Enable 'make tags' target.
|
|
|
|
find_program(CTAGS ctags)
|
|
|
|
if(CTAGS)
|
2024-11-13 15:03:16 +03:00
|
|
|
add_custom_target(
|
|
|
|
tags
|
|
|
|
COMMAND ${CTAGS} -R -f tags
|
2020-04-15 17:09:37 +03:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
add_custom_target(ctags DEPENDS tags)
|
|
|
|
endif(CTAGS)
|
|
|
|
|
2020-05-05 18:52:32 +03:00
|
|
|
if(UNIX)
|
2024-11-13 15:03:16 +03:00
|
|
|
find_program(CLANG_FORMAT NAMES clang-format-13 clang-format)
|
2020-05-05 18:52:32 +03:00
|
|
|
if(CLANG_FORMAT)
|
2024-11-13 15:03:16 +03:00
|
|
|
execute_process(COMMAND ${CLANG_FORMAT} "--version"
|
|
|
|
OUTPUT_VARIABLE clang_format_version_info)
|
|
|
|
string(REGEX MATCH "version ([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?"
|
|
|
|
clang_format_version_info CLANG_FORMAT_VERSION)
|
|
|
|
if(clang_format_version_info AND NOT CLANG_FORMAT_VERSION VERSION_LESS
|
|
|
|
13.0)
|
2020-05-05 18:52:32 +03:00
|
|
|
# Enable 'make reformat' target.
|
2024-11-13 15:03:16 +03:00
|
|
|
add_custom_target(
|
|
|
|
reformat
|
2020-05-05 18:52:32 +03:00
|
|
|
VERBATIM
|
|
|
|
COMMAND
|
2024-11-13 15:03:16 +03:00
|
|
|
git ls-files | grep -E \\.\(c|cxx|cc|cpp|h|hxx|hpp\)\(\\.in\)?\$ |
|
|
|
|
xargs ${CLANG_FORMAT} -i --style=file
|
2020-05-05 18:52:32 +03:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
|
|
|
endif()
|
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
|
2020-04-15 17:09:37 +03:00
|
|
|
if(NOT "${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
|
|
|
|
add_custom_target(distclean)
|
2024-11-13 15:03:16 +03:00
|
|
|
add_custom_command(
|
|
|
|
TARGET distclean
|
|
|
|
POST_BUILD
|
2020-04-15 17:09:37 +03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_BINARY_DIR}"
|
|
|
|
COMMENT "Removing the build directory and its content")
|
|
|
|
elseif(IS_DIRECTORY .git AND GIT)
|
|
|
|
add_custom_target(distclean)
|
2024-11-13 15:03:16 +03:00
|
|
|
add_custom_command(
|
|
|
|
TARGET distclean
|
|
|
|
POST_BUILD
|
2020-04-15 17:09:37 +03:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
COMMAND ${GIT} submodule foreach --recursive git clean -f -X -d
|
|
|
|
COMMAND ${GIT} clean -f -X -d
|
|
|
|
COMMENT "Removing all build files from the source directory")
|
|
|
|
endif()
|
|
|
|
endif(NOT MDBX_AMALGAMATED_SOURCE)
|
2019-08-31 17:13:02 +03:00
|
|
|
|
2022-07-28 18:48:21 +03:00
|
|
|
set(MDBX_MANAGE_BUILD_FLAGS_DEFAULT ON)
|
2019-09-03 02:24:19 +03:00
|
|
|
endif(SUBPROJECT)
|
2019-08-31 17:13:02 +03:00
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
option(MDBX_MANAGE_BUILD_FLAGS
|
|
|
|
"Allow libmdbx to configure/manage/override its own build flags"
|
|
|
|
${MDBX_MANAGE_BUILD_FLAGS_DEFAULT})
|
2022-07-28 18:48:21 +03:00
|
|
|
if(MDBX_MANAGE_BUILD_FLAGS)
|
|
|
|
setup_compile_flags()
|
|
|
|
endif()
|
|
|
|
|
2020-08-22 20:19:46 +03:00
|
|
|
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 HAS_CXX11)
|
|
|
|
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_14 HAS_CXX14)
|
|
|
|
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_17 HAS_CXX17)
|
|
|
|
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_20 HAS_CXX20)
|
2021-11-07 02:17:26 +03:00
|
|
|
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_23 HAS_CXX23)
|
2020-08-22 20:19:46 +03:00
|
|
|
if(NOT DEFINED MDBX_CXX_STANDARD)
|
2021-11-07 02:15:03 +03:00
|
|
|
if(DEFINED ENV{CMAKE_CXX_STANDARD})
|
|
|
|
set(CMAKE_CXX_STANDARD $ENV{CMAKE_CXX_STANDARD})
|
|
|
|
endif()
|
2020-08-22 20:19:46 +03:00
|
|
|
if(DEFINED CMAKE_CXX_STANDARD)
|
|
|
|
set(MDBX_CXX_STANDARD ${CMAKE_CXX_STANDARD})
|
2021-11-07 02:17:26 +03:00
|
|
|
elseif(NOT HAS_CXX23 LESS 0
|
2024-11-13 15:03:16 +03:00
|
|
|
AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION
|
|
|
|
VERSION_LESS 12))
|
2021-11-07 02:17:26 +03:00
|
|
|
set(MDBX_CXX_STANDARD 23)
|
2021-08-04 14:09:50 +03:00
|
|
|
elseif(NOT HAS_CXX20 LESS 0
|
2024-11-13 15:03:16 +03:00
|
|
|
AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION
|
|
|
|
VERSION_LESS 10))
|
2020-08-22 20:19:46 +03:00
|
|
|
set(MDBX_CXX_STANDARD 20)
|
2021-08-04 14:09:50 +03:00
|
|
|
elseif(NOT HAS_CXX17 LESS 0
|
2024-11-13 15:03:16 +03:00
|
|
|
AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION
|
|
|
|
VERSION_LESS 5))
|
2020-08-22 20:19:46 +03:00
|
|
|
set(MDBX_CXX_STANDARD 17)
|
|
|
|
elseif(NOT HAS_CXX14 LESS 0)
|
|
|
|
set(MDBX_CXX_STANDARD 14)
|
|
|
|
elseif(NOT HAS_CXX11 LESS 0)
|
|
|
|
set(MDBX_CXX_STANDARD 11)
|
2022-11-07 23:37:27 +03:00
|
|
|
elseif(CXX_FALLBACK_GNU11 OR CXX_FALLBACK_11)
|
|
|
|
set(MDBX_CXX_STANDARD 11)
|
2020-08-22 20:19:46 +03:00
|
|
|
else()
|
|
|
|
set(MDBX_CXX_STANDARD 98)
|
|
|
|
endif()
|
|
|
|
endif()
|
2024-10-08 23:08:52 +03:00
|
|
|
|
|
|
|
list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11)
|
|
|
|
list(FIND CMAKE_C_COMPILE_FEATURES c_std_23 HAS_C23)
|
2020-11-28 13:07:58 +03:00
|
|
|
if(NOT DEFINED MDBX_C_STANDARD)
|
2024-11-13 15:03:16 +03:00
|
|
|
# MSVC >= 19.28 (Microsoft Visual Studio 16.8) is mad! It unable process
|
|
|
|
# Windows SDK headers in the C11 mode!
|
|
|
|
if(MSVC
|
|
|
|
AND MSVC_VERSION GREATER 1927
|
|
|
|
AND NOT MSVC_VERSION GREATER 1929)
|
2022-01-31 23:29:03 +03:00
|
|
|
set(MDBX_C_STANDARD 99)
|
|
|
|
set(C_FALLBACK_11 OFF)
|
|
|
|
set(C_FALLBACK_GNU11 OFF)
|
2024-10-08 23:08:52 +03:00
|
|
|
elseif(NOT HAS_C23 LESS 0)
|
|
|
|
set(MDBX_C_STANDARD 23)
|
2024-11-13 15:03:16 +03:00
|
|
|
elseif(
|
|
|
|
HAS_C11 LESS 0
|
|
|
|
AND NOT C_FALLBACK_GNU11
|
|
|
|
AND NOT C_FALLBACK_11)
|
2020-11-28 13:07:58 +03:00
|
|
|
set(MDBX_C_STANDARD 99)
|
|
|
|
else()
|
|
|
|
set(MDBX_C_STANDARD 11)
|
|
|
|
endif()
|
2019-10-22 12:14:26 +03:00
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
|
2024-09-18 07:59:24 +03:00
|
|
|
if(WIN32 AND EXISTS "${MDBX_SOURCE_DIR}/ntdll.def")
|
2020-04-15 17:09:37 +03:00
|
|
|
if(MSVC)
|
|
|
|
if(NOT MSVC_LIB_EXE)
|
|
|
|
# Find lib.exe
|
|
|
|
get_filename_component(CL_NAME ${CMAKE_C_COMPILER} NAME)
|
|
|
|
string(REPLACE cl.exe lib.exe MSVC_LIB_EXE ${CL_NAME})
|
|
|
|
find_program(MSVC_LIB_EXE ${MSVC_LIB_EXE})
|
|
|
|
endif()
|
|
|
|
if(MSVC_LIB_EXE)
|
|
|
|
message(STATUS "Found MSVC's lib tool: ${MSVC_LIB_EXE}")
|
2024-11-13 15:03:16 +03:00
|
|
|
set(MDBX_NTDLL_EXTRA_IMPLIB
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.lib")
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${MDBX_NTDLL_EXTRA_IMPLIB}"
|
2020-04-15 17:09:37 +03:00
|
|
|
COMMENT "Create extra-import-library for ntdll.dll"
|
|
|
|
MAIN_DEPENDENCY "${MDBX_SOURCE_DIR}/ntdll.def"
|
2024-11-13 15:03:16 +03:00
|
|
|
COMMAND
|
|
|
|
${MSVC_LIB_EXE} /def:"${MDBX_SOURCE_DIR}/ntdll.def"
|
|
|
|
/out:"${MDBX_NTDLL_EXTRA_IMPLIB}"
|
|
|
|
${INITIAL_CMAKE_STATIC_LINKER_FLAGS})
|
2020-04-15 17:09:37 +03:00
|
|
|
else()
|
|
|
|
message(WARNING "MSVC's lib tool not found")
|
|
|
|
endif()
|
|
|
|
elseif(MINGW OR MINGW64)
|
|
|
|
if(NOT DLLTOOL)
|
|
|
|
# Find dlltool
|
|
|
|
get_filename_component(GCC_NAME ${CMAKE_C_COMPILER} NAME)
|
|
|
|
string(REPLACE gcc dlltool DLLTOOL_NAME ${GCC_NAME})
|
|
|
|
find_program(DLLTOOL NAMES ${DLLTOOL_NAME})
|
|
|
|
endif()
|
|
|
|
if(DLLTOOL)
|
|
|
|
message(STATUS "Found dlltool: ${DLLTOOL}")
|
2024-11-13 15:03:16 +03:00
|
|
|
set(MDBX_NTDLL_EXTRA_IMPLIB
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.a")
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${MDBX_NTDLL_EXTRA_IMPLIB}"
|
2020-04-15 17:09:37 +03:00
|
|
|
COMMENT "Create extra-import-library for ntdll.dll"
|
|
|
|
MAIN_DEPENDENCY "${MDBX_SOURCE_DIR}/ntdll.def"
|
2024-11-13 15:03:16 +03:00
|
|
|
COMMAND ${DLLTOOL} -d "${MDBX_SOURCE_DIR}/ntdll.def" -l
|
|
|
|
"${MDBX_NTDLL_EXTRA_IMPLIB}")
|
2020-04-15 17:09:37 +03:00
|
|
|
else()
|
|
|
|
message(WARNING "dlltool not found")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MDBX_NTDLL_EXTRA_IMPLIB)
|
2024-11-13 15:03:16 +03:00
|
|
|
# Sometimes CMake requires a nightmarish magic for simple things.
|
|
|
|
#
|
|
|
|
# (1) create a target out of the library compilation result
|
2020-04-15 17:09:37 +03:00
|
|
|
add_custom_target(ntdll_extra_target DEPENDS "${MDBX_NTDLL_EXTRA_IMPLIB}")
|
2024-11-13 15:03:16 +03:00
|
|
|
# (2) create an library target out of the library compilation result
|
2020-04-15 17:09:37 +03:00
|
|
|
add_library(ntdll_extra STATIC IMPORTED GLOBAL)
|
|
|
|
add_dependencies(ntdll_extra ntdll_extra_target)
|
2024-11-13 15:03:16 +03:00
|
|
|
# (3) specify where the library is (and where to find the headers)
|
|
|
|
set_target_properties(ntdll_extra PROPERTIES IMPORTED_LOCATION
|
|
|
|
"${MDBX_NTDLL_EXTRA_IMPLIB}")
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
# ##############################################################################
|
|
|
|
# ~~~
|
2019-09-03 02:24:19 +03:00
|
|
|
#
|
2019-12-04 23:05:49 +03:00
|
|
|
# #### ##### ##### # #### # # ####
|
|
|
|
# # # # # # # # # ## # #
|
|
|
|
# # # # # # # # # # # # ####
|
|
|
|
# # # ##### # # # # # # # #
|
|
|
|
# # # # # # # # # ## # #
|
|
|
|
# #### # # # #### # # ####
|
2019-09-03 02:24:19 +03:00
|
|
|
#
|
2024-11-13 15:03:16 +03:00
|
|
|
# ~~~
|
|
|
|
# ##############################################################################
|
2019-09-03 02:24:19 +03:00
|
|
|
|
2024-11-19 22:42:08 +03:00
|
|
|
set(MDBX_BUILD_METADATA
|
|
|
|
""
|
|
|
|
CACHE STRING "An extra/custom information provided during libmdbx build")
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
set(MDBX_BUILD_OPTIONS ENABLE_UBSAN ENABLE_ASAN ENABLE_MEMCHECK ENABLE_GPROF
|
|
|
|
ENABLE_GCOV)
|
2020-09-27 16:45:00 +03:00
|
|
|
macro(add_mdbx_option NAME DESCRIPTION DEFAULT)
|
|
|
|
list(APPEND MDBX_BUILD_OPTIONS ${NAME})
|
|
|
|
if(NOT ${DEFAULT} STREQUAL "AUTO")
|
|
|
|
option(${NAME} "${DESCRIPTION}" ${DEFAULT})
|
|
|
|
elseif(NOT DEFINED ${NAME})
|
|
|
|
set(${NAME}_AUTO ON)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
if(IOS)
|
|
|
|
set(MDBX_BUILD_TOOLS_DEFAULT OFF)
|
|
|
|
if(NOT_SUBPROJECT)
|
|
|
|
cmake_policy(SET CMP0006 OLD)
|
2024-11-19 22:42:08 +03:00
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
|
2020-09-27 16:45:00 +03:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(MDBX_BUILD_TOOLS_DEFAULT ON)
|
|
|
|
endif()
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(MDBX_INSTALL_STATIC
|
|
|
|
"Build and install libmdbx for static linking" OFF)
|
|
|
|
add_mdbx_option(MDBX_BUILD_SHARED_LIBRARY
|
|
|
|
"Build libmdbx as shared library (DLL)" ${BUILD_SHARED_LIBS})
|
|
|
|
add_mdbx_option(
|
|
|
|
MDBX_BUILD_TOOLS "Build MDBX tools (mdbx_chk/stat/dump/load/copy)"
|
|
|
|
${MDBX_BUILD_TOOLS_DEFAULT})
|
|
|
|
cmake_dependent_option(
|
|
|
|
MDBX_INSTALL_MANPAGES
|
|
|
|
"Install man-pages for MDBX tools (mdbx_chk/stat/dump/load/copy)" ON
|
|
|
|
MDBX_BUILD_TOOLS OFF)
|
|
|
|
add_mdbx_option(
|
|
|
|
MDBX_TXN_CHECKOWNER
|
|
|
|
"Checking transaction matches the calling thread inside libmdbx's API" ON)
|
|
|
|
add_mdbx_option(MDBX_ENV_CHECKPID "Paranoid checking PID inside libmdbx's API"
|
|
|
|
AUTO)
|
2020-07-22 14:53:15 +03:00
|
|
|
mark_as_advanced(MDBX_ENV_CHECKPID)
|
2019-10-06 14:59:53 +03:00
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use GNU/Linux libc extensions"
|
|
|
|
OFF)
|
2019-10-06 14:59:53 +03:00
|
|
|
mark_as_advanced(MDBX_DISABLE_GNU_SOURCE)
|
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR IOS)
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(MDBX_OSX_SPEED_INSTEADOF_DURABILITY
|
|
|
|
"Disable use fcntl(F_FULLFSYNC) in favor of speed" OFF)
|
2019-09-03 02:24:19 +03:00
|
|
|
mark_as_advanced(MDBX_OSX_SPEED_INSTEADOF_DURABILITY)
|
|
|
|
endif()
|
2024-09-18 07:59:24 +03:00
|
|
|
if(WIN32)
|
2020-04-15 17:09:37 +03:00
|
|
|
if(MDBX_NTDLL_EXTRA_IMPLIB)
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(
|
|
|
|
MDBX_WITHOUT_MSVC_CRT
|
|
|
|
"Avoid dependence from MSVC CRT and use ntdll.dll instead" OFF)
|
2019-09-03 02:24:19 +03:00
|
|
|
endif()
|
2022-10-10 15:52:58 +03:00
|
|
|
set(MDBX_AVOID_MSYNC_DEFAULT ON)
|
2019-09-03 02:24:19 +03:00
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(
|
|
|
|
MDBX_USE_OFDLOCKS
|
|
|
|
"Use Open file description locks (aka OFD locks, non-POSIX)" AUTO)
|
2019-09-03 02:24:19 +03:00
|
|
|
mark_as_advanced(MDBX_USE_OFDLOCKS)
|
2022-10-10 15:52:58 +03:00
|
|
|
set(MDBX_AVOID_MSYNC_DEFAULT OFF)
|
2019-09-03 02:24:19 +03:00
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(
|
|
|
|
MDBX_AVOID_MSYNC
|
|
|
|
"Controls dirty pages tracking, spilling and persisting in MDBX_WRITEMAP mode"
|
|
|
|
${MDBX_AVOID_MSYNC_DEFAULT})
|
|
|
|
add_mdbx_option(
|
|
|
|
MDBX_LOCKING
|
|
|
|
"Locking method (Windows=-1, SysV=5, POSIX=1988, POSIX=2001, POSIX=2008, Futexes=1995)"
|
|
|
|
AUTO)
|
2019-12-04 23:05:49 +03:00
|
|
|
mark_as_advanced(MDBX_LOCKING)
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(
|
|
|
|
MDBX_TRUST_RTC
|
|
|
|
"Does a system have battery-backed Real-Time Clock or just a fake" AUTO)
|
2019-12-04 23:05:49 +03:00
|
|
|
mark_as_advanced(MDBX_TRUST_RTC)
|
2023-10-09 21:49:58 +03:00
|
|
|
add_mdbx_option(MDBX_FORCE_ASSERTIONS "Force enable assertion checking" OFF)
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(
|
|
|
|
MDBX_DISABLE_VALIDATION
|
|
|
|
"Disable some checks to reduce an overhead and detection probability of database corruption to a values closer to the LMDB"
|
|
|
|
OFF)
|
2023-10-09 21:49:58 +03:00
|
|
|
mark_as_advanced(MDBX_DISABLE_VALIDATION)
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(MDBX_ENABLE_REFUND
|
|
|
|
"Zerocost auto-compactification during write-transactions" ON)
|
|
|
|
add_mdbx_option(MDBX_ENABLE_MADVISE
|
|
|
|
"Using POSIX' madvise() and/or similar hints" ON)
|
|
|
|
if(CMAKE_TARGET_BITNESS GREATER 32)
|
2022-11-10 15:09:42 +03:00
|
|
|
set(MDBX_BIGFOOT_DEFAULT ON)
|
|
|
|
else()
|
|
|
|
set(MDBX_BIGFOOT_DEFAULT OFF)
|
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(
|
|
|
|
MDBX_ENABLE_BIGFOOT
|
|
|
|
"Chunking long list of retired pages during huge transactions commit to avoid use sequences of pages"
|
|
|
|
${MDBX_BIGFOOT_DEFAULT})
|
|
|
|
add_mdbx_option(MDBX_ENABLE_PGOP_STAT
|
|
|
|
"Gathering statistics for page operations" ON)
|
2023-10-09 21:49:58 +03:00
|
|
|
add_mdbx_option(MDBX_ENABLE_PROFGC "Profiling of GC search and updates" OFF)
|
|
|
|
mark_as_advanced(MDBX_ENABLE_PROFGC)
|
mdbx: переработка инициализации, проверки и импорта dbi-хендлов в транзакциях.
Ранее инициализация в транзакциях структур данных, связанных с
dbi-хендлами и subDb, выполнялась непосредственно при запуске
транзакций. Что в сценариях с большим кол-вом dbi-дексприторов (например
libfpta) порождало заметные накладные расходы, которые расли линейно от
общего кол-ва открытых subDb, а не от реально используемых в транзакции.
При использовании одной-двух сотен хендлов, при старте каждой транзакции
могли копироваться и/или обнуляться десятки килобайт. Теперь этот
недостаток устранен.
Изменена схема инициализации, валидации и импорта хендлов открытых после
старта транзакции:
1) Инициализация теперь выполняется отложенна, а при старте транзации
обнуляется только массив с однобайтовыми статустами dbi-хендлов.
При этом доступнва опция сборки `MDBX_ENABLE_DBI_SPARSE`, при активации
которой используется битовая карты, что снижает объем инициализации
при старте транзакции в 8 раз (CHAR_BIT).
2) Переработана валидация dbi-хендлов на входах API, с уменьшением кол-ва
проверок и ветвлений до теоретического минимума.
3) Переработ импорт dbi-хендов открытых после старта транзакци, теперь
при этом не захватывается мьютекс.
2023-11-05 22:10:29 +03:00
|
|
|
add_mdbx_option(MDBX_ENABLE_DBI_SPARSE "FIXME" ON)
|
2023-11-04 23:45:29 +03:00
|
|
|
add_mdbx_option(MDBX_ENABLE_DBI_LOCKFREE "FIXME" ON)
|
2020-04-15 17:09:37 +03:00
|
|
|
|
|
|
|
if(NOT MDBX_AMALGAMATED_SOURCE)
|
2021-04-19 17:43:25 +03:00
|
|
|
if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG")
|
|
|
|
set(MDBX_ALLOY_BUILD_DEFAULT OFF)
|
|
|
|
else()
|
|
|
|
set(MDBX_ALLOY_BUILD_DEFAULT ON)
|
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(
|
|
|
|
MDBX_ALLOY_BUILD "Build MDBX library through single/alloyed object file"
|
|
|
|
${MDBX_ALLOY_BUILD_DEFAULT})
|
2020-08-22 20:19:46 +03:00
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
|
|
|
|
if((MDBX_BUILD_TOOLS OR MDBX_ENABLE_TESTS) AND MDBX_BUILD_SHARED_LIBRARY)
|
2024-11-13 15:03:16 +03:00
|
|
|
add_mdbx_option(MDBX_LINK_TOOLS_NONSTATIC
|
|
|
|
"Link MDBX tools with non-static libmdbx" OFF)
|
2020-04-15 17:09:37 +03:00
|
|
|
else()
|
|
|
|
unset(MDBX_LINK_TOOLS_NONSTATIC CACHE)
|
|
|
|
endif()
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
if(CMAKE_CXX_COMPILER_LOADED
|
|
|
|
AND MDBX_CXX_STANDARD LESS 83
|
|
|
|
AND NOT MDBX_CXX_STANDARD LESS 11)
|
2020-08-22 20:19:46 +03:00
|
|
|
if(NOT MDBX_AMALGAMATED_SOURCE)
|
|
|
|
option(MDBX_ENABLE_TESTS "Build MDBX tests" ${BUILD_TESTING})
|
|
|
|
endif()
|
2021-04-29 20:09:16 +03:00
|
|
|
if(NOT MDBX_WITHOUT_MSVC_CRT
|
2024-11-13 15:03:16 +03:00
|
|
|
AND NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION
|
|
|
|
VERSION_LESS 4.8)
|
|
|
|
AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION
|
|
|
|
VERSION_LESS 3.9)
|
|
|
|
AND NOT (MSVC AND MSVC_VERSION LESS 1900))
|
2020-08-22 20:19:46 +03:00
|
|
|
option(MDBX_BUILD_CXX "Build C++ portion" ON)
|
|
|
|
else()
|
|
|
|
set(MDBX_BUILD_CXX FALSE)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(MDBX_BUILD_CXX FALSE)
|
2020-09-27 16:45:00 +03:00
|
|
|
set(MDBX_ENABLE_TESTS FALSE)
|
2020-08-22 20:19:46 +03:00
|
|
|
endif()
|
|
|
|
|
2024-10-08 12:24:30 +03:00
|
|
|
if(CI)
|
|
|
|
add_definitions(-DMDBX_CI="${CI}")
|
|
|
|
endif()
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
# ##############################################################################
|
2020-04-15 17:09:37 +03:00
|
|
|
|
2020-09-28 23:47:37 +03:00
|
|
|
if(MDBX_BUILD_CXX AND NOT CMAKE_CXX_COMPILER_LOADED)
|
2024-11-13 15:03:16 +03:00
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"MDBX_BUILD_CXX=${MDBX_BUILD_CXX}: The C++ compiler is required to build the C++API."
|
|
|
|
)
|
2020-09-27 16:49:55 +03:00
|
|
|
endif()
|
|
|
|
|
2022-04-07 21:57:49 +03:00
|
|
|
if(MDBX_BUILD_CXX)
|
|
|
|
# determine library for C++ std::filesystem
|
|
|
|
probe_libcxx_filesystem()
|
|
|
|
endif()
|
|
|
|
|
2020-04-15 17:09:37 +03:00
|
|
|
# Get version
|
2024-11-13 15:03:16 +03:00
|
|
|
fetch_version(MDBX "${CMAKE_CURRENT_SOURCE_DIR}" FALSE
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
2020-04-15 17:09:37 +03:00
|
|
|
message(STATUS "libmdbx version is ${MDBX_VERSION}")
|
|
|
|
|
|
|
|
# sources list
|
2020-10-02 00:05:02 +03:00
|
|
|
set(LIBMDBX_PUBLIC_HEADERS mdbx.h)
|
|
|
|
set(LIBMDBX_SOURCES mdbx.h "${CMAKE_CURRENT_BINARY_DIR}/config.h")
|
2020-04-15 17:09:37 +03:00
|
|
|
if(MDBX_AMALGAMATED_SOURCE)
|
|
|
|
list(APPEND LIBMDBX_SOURCES mdbx.c)
|
|
|
|
else()
|
|
|
|
# generate version file
|
|
|
|
configure_file("${MDBX_SOURCE_DIR}/version.c.in"
|
2024-11-13 15:03:16 +03:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/version.c" ESCAPE_QUOTES)
|
2020-04-15 17:09:37 +03:00
|
|
|
file(SHA256 "${CMAKE_CURRENT_BINARY_DIR}/version.c" MDBX_SOURCERY_DIGEST)
|
|
|
|
string(MAKE_C_IDENTIFIER "${MDBX_GIT_DESCRIBE}" MDBX_SOURCERY_SUFFIX)
|
|
|
|
set(MDBX_BUILD_SOURCERY "${MDBX_SOURCERY_DIGEST}_${MDBX_SOURCERY_SUFFIX}")
|
|
|
|
|
|
|
|
if(MDBX_ALLOY_BUILD)
|
2020-08-22 20:19:46 +03:00
|
|
|
list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/alloy.c")
|
2020-04-15 17:09:37 +03:00
|
|
|
include_directories("${MDBX_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
list(
|
|
|
|
APPEND
|
|
|
|
LIBMDBX_SOURCES
|
2024-05-19 22:07:58 +03:00
|
|
|
"${MDBX_SOURCE_DIR}/api-cursor.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/api-env.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/api-extra.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/api-key-transform.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/api-txn.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/atomics-ops.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/atomics-types.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/audit.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/chk.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/cogs.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/cogs.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/coherency.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/cold.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/copy.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/cursor.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/cursor.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/dbi.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/dbi.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/dpl.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/dpl.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/dxb.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/env-opts.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/env.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/essentials.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/gc-get.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/gc-put.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/gc.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/global.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/internals.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/layout-dxb.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/layout-lck.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/lck.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/lck.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/logging_and_debug.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/logging_and_debug.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/meta.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/meta.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/misc.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/mvcc-readers.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/node.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/node.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/options.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/osal.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/osal.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/page-get.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/page-iov.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/page-iov.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/page-ops.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/page-ops.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/page-search.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/pnl.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/pnl.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/preface.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/proto.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/range-estimate.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/refund.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/sort.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/spill.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/spill.h"
|
2024-08-03 13:25:44 +03:00
|
|
|
"${MDBX_SOURCE_DIR}/table.c"
|
2024-05-19 22:07:58 +03:00
|
|
|
"${MDBX_SOURCE_DIR}/tls.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/tls.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/tree.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/txl.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/txl.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/txn.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/unaligned.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/utils.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/utils.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/walk.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/walk.h"
|
2024-11-13 15:03:16 +03:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/version.c")
|
2024-05-19 22:07:58 +03:00
|
|
|
if(NOT MSVC)
|
|
|
|
list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/lck-posix.c")
|
|
|
|
endif()
|
2022-07-13 22:11:28 +03:00
|
|
|
if(NOT APPLE)
|
2024-11-13 15:03:16 +03:00
|
|
|
list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/windows-import.h"
|
|
|
|
"${MDBX_SOURCE_DIR}/windows-import.c"
|
|
|
|
"${MDBX_SOURCE_DIR}/lck-windows.c")
|
2022-07-13 22:11:28 +03:00
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
include_directories("${MDBX_SOURCE_DIR}")
|
|
|
|
endif()
|
|
|
|
endif(MDBX_AMALGAMATED_SOURCE)
|
2020-08-22 20:19:46 +03:00
|
|
|
if(MDBX_BUILD_CXX)
|
2024-11-13 15:03:16 +03:00
|
|
|
message(
|
|
|
|
STATUS "Use C${MDBX_C_STANDARD} and C++${MDBX_CXX_STANDARD} for libmdbx")
|
2020-10-02 00:05:02 +03:00
|
|
|
list(APPEND LIBMDBX_PUBLIC_HEADERS mdbx.h++)
|
2020-08-22 20:19:46 +03:00
|
|
|
list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/mdbx.c++" mdbx.h++)
|
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
message(
|
|
|
|
STATUS "Use C${MDBX_C_STANDARD} for libmdbx but C++ portion is disabled")
|
2020-08-22 20:19:46 +03:00
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
|
2021-06-24 15:41:54 +03:00
|
|
|
if(SUBPROJECT AND MSVC)
|
|
|
|
if(MSVC_VERSION LESS 1900)
|
2024-11-13 15:03:16 +03:00
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required."
|
|
|
|
)
|
2021-06-24 15:41:54 +03:00
|
|
|
endif()
|
|
|
|
add_compile_options("/utf-8")
|
|
|
|
endif()
|
|
|
|
|
2020-04-15 17:09:37 +03:00
|
|
|
macro(target_setup_options TARGET)
|
|
|
|
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
2024-11-13 15:03:16 +03:00
|
|
|
set_target_properties(
|
|
|
|
${TARGET} PROPERTIES INTERPROCEDURAL_OPTIMIZATION
|
|
|
|
$<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
2024-11-09 23:02:56 +03:00
|
|
|
if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11)
|
2024-11-13 15:03:16 +03:00
|
|
|
set_target_properties(${TARGET} PROPERTIES C_STANDARD ${MDBX_C_STANDARD}
|
|
|
|
C_STANDARD_REQUIRED ON)
|
2022-01-31 23:29:03 +03:00
|
|
|
endif()
|
2020-08-22 20:19:46 +03:00
|
|
|
if(MDBX_BUILD_CXX)
|
2024-11-09 23:02:56 +03:00
|
|
|
if(NOT CXX_FALLBACK_GNU11 AND NOT CXX_FALLBACK_11)
|
2024-11-13 15:03:16 +03:00
|
|
|
set_target_properties(
|
|
|
|
${TARGET} PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD}
|
|
|
|
CXX_STANDARD_REQUIRED ON)
|
2024-11-09 23:02:56 +03:00
|
|
|
endif()
|
2021-06-24 15:41:54 +03:00
|
|
|
if(MSVC AND NOT MSVC_VERSION LESS 1910)
|
|
|
|
target_compile_options(${TARGET} INTERFACE "/Zc:__cplusplus")
|
|
|
|
endif()
|
2020-08-22 20:19:46 +03:00
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
if(CC_HAS_FASTMATH AND NOT (CMAKE_COMPILER_IS_CLANG
|
|
|
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10))
|
2020-04-15 17:09:37 +03:00
|
|
|
target_compile_options(${TARGET} PRIVATE "-ffast-math")
|
|
|
|
endif()
|
|
|
|
if(CC_HAS_VISIBILITY)
|
|
|
|
target_compile_options(${TARGET} PRIVATE "-fvisibility=hidden")
|
|
|
|
endif()
|
|
|
|
if(BUILD_FOR_NATIVE_CPU AND CC_HAS_ARCH_NATIVE)
|
2021-06-24 15:41:54 +03:00
|
|
|
target_compile_options(${TARGET} PRIVATE "-march=native")
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(libmdbx_setup_libs TARGET MODE)
|
2022-11-07 23:37:27 +03:00
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.1)
|
|
|
|
target_link_libraries(${TARGET} ${MODE} ${CMAKE_THREAD_LIBS_INIT})
|
|
|
|
else()
|
|
|
|
target_link_libraries(${TARGET} ${MODE} Threads::Threads)
|
|
|
|
endif()
|
2024-09-18 07:59:24 +03:00
|
|
|
if(WIN32)
|
2024-11-13 15:03:16 +03:00
|
|
|
target_link_libraries(
|
|
|
|
${TARGET}
|
|
|
|
${MODE}
|
|
|
|
ntdll
|
|
|
|
user32
|
|
|
|
kernel32
|
|
|
|
advapi32
|
|
|
|
ole32)
|
2021-04-29 20:09:16 +03:00
|
|
|
if(MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_WITHOUT_MSVC_CRT)
|
2020-04-15 17:09:37 +03:00
|
|
|
target_link_libraries(${TARGET} ${MODE} ntdll_extra)
|
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL
|
|
|
|
"Solaris")
|
2020-04-15 17:09:37 +03:00
|
|
|
target_link_libraries(${TARGET} ${MODE} kstat)
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
|
|
|
|
target_link_libraries(${TARGET} ${MODE} log)
|
|
|
|
endif()
|
2022-04-05 17:02:39 +03:00
|
|
|
if(LIBCXX_FILESYSTEM AND MDBX_BUILD_CXX)
|
2024-11-13 15:03:16 +03:00
|
|
|
if(CMAKE_COMPILER_IS_ELBRUSCXX
|
|
|
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.25.23
|
|
|
|
AND NOT CMAKE_VERSION VERSION_LESS 3.13)
|
2022-04-05 18:34:37 +03:00
|
|
|
target_link_options(${TARGET} PUBLIC "-Wl,--allow-multiple-definition")
|
|
|
|
endif()
|
2022-04-05 17:02:39 +03:00
|
|
|
target_link_libraries(${TARGET} PUBLIC ${LIBCXX_FILESYSTEM})
|
2020-08-22 20:19:46 +03:00
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
# build static library
|
|
|
|
if(MDBX_INSTALL_STATIC)
|
|
|
|
add_library(mdbx-static STATIC ${LIBMDBX_SOURCES})
|
|
|
|
else()
|
|
|
|
add_library(mdbx-static STATIC EXCLUDE_FROM_ALL ${LIBMDBX_SOURCES})
|
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
set_target_properties(mdbx-static PROPERTIES PUBLIC_HEADER
|
|
|
|
"${LIBMDBX_PUBLIC_HEADERS}")
|
2020-04-17 00:37:29 +03:00
|
|
|
target_compile_definitions(mdbx-static PRIVATE MDBX_BUILD_SHARED_LIBRARY=0)
|
2020-04-15 17:09:37 +03:00
|
|
|
target_setup_options(mdbx-static)
|
|
|
|
libmdbx_setup_libs(mdbx-static INTERFACE)
|
|
|
|
if(MDBX_BUILD_SHARED_LIBRARY)
|
|
|
|
set_target_properties(mdbx-static PROPERTIES OUTPUT_NAME mdbx-static)
|
|
|
|
else()
|
|
|
|
set_target_properties(mdbx-static PROPERTIES OUTPUT_NAME mdbx)
|
|
|
|
endif()
|
2022-04-13 11:05:50 +03:00
|
|
|
target_include_directories(mdbx-static INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
|
2019-09-03 02:24:19 +03:00
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
# ##############################################################################
|
2020-04-15 17:09:37 +03:00
|
|
|
|
|
|
|
# build shared library
|
|
|
|
if(MDBX_BUILD_SHARED_LIBRARY)
|
|
|
|
add_library(mdbx SHARED ${LIBMDBX_SOURCES})
|
2024-11-13 15:03:16 +03:00
|
|
|
set_target_properties(mdbx PROPERTIES PUBLIC_HEADER
|
|
|
|
"${LIBMDBX_PUBLIC_HEADERS}")
|
|
|
|
target_compile_definitions(
|
|
|
|
mdbx
|
|
|
|
PRIVATE LIBMDBX_EXPORTS MDBX_BUILD_SHARED_LIBRARY=1
|
|
|
|
INTERFACE LIBMDBX_IMPORTS)
|
2020-04-15 17:09:37 +03:00
|
|
|
target_setup_options(mdbx)
|
|
|
|
libmdbx_setup_libs(mdbx PRIVATE)
|
2020-05-10 03:41:28 +03:00
|
|
|
if(MSVC)
|
2021-04-29 20:09:16 +03:00
|
|
|
if(MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_WITHOUT_MSVC_CRT)
|
2020-05-10 03:41:28 +03:00
|
|
|
set_property(TARGET mdbx PROPERTY LINKER_FLAGS "/NODEFAULTLIB")
|
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
set_property(
|
|
|
|
TARGET mdbx PROPERTY MSVC_RUNTIME_LIBRARY
|
|
|
|
"MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
2020-05-10 03:41:28 +03:00
|
|
|
endif()
|
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
if(CC_HAS_VISIBILITY AND (LTO_ENABLED OR INTERPROCEDURAL_OPTIMIZATION))
|
|
|
|
set_target_properties(mdbx PROPERTIES LINK_FLAGS "-fvisibility=hidden")
|
|
|
|
endif()
|
|
|
|
list(APPEND MDBX_BUILD_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
|
2022-04-13 11:05:50 +03:00
|
|
|
target_include_directories(mdbx INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MDBX_BUILD_SHARED_LIBRARY AND MDBX_LINK_TOOLS_NONSTATIC)
|
|
|
|
set(TOOL_MDBX_LIB mdbx)
|
|
|
|
|
|
|
|
# use, i.e. don't skip the full RPATH for the build tree
|
|
|
|
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
# when building, don't use the install RPATH already (but later on when
|
|
|
|
# installing)
|
2020-04-15 17:09:37 +03:00
|
|
|
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
# add the automatically determined parts of the RPATH which point to
|
|
|
|
# directories outside the build tree to the install RPATH
|
2020-04-15 17:09:37 +03:00
|
|
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
# the RPATH to be used when installing, but only if it's not a system
|
|
|
|
# directory
|
|
|
|
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
|
|
|
|
"${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
|
2020-04-15 17:09:37 +03:00
|
|
|
if(isSystemDir EQUAL -1)
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
|
|
|
|
set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
|
|
|
|
else()
|
|
|
|
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib")
|
|
|
|
endif()
|
|
|
|
endif()
|
2024-10-07 09:09:35 +03:00
|
|
|
|
|
|
|
if(WIN32)
|
2024-11-13 15:03:16 +03:00
|
|
|
# Windows don't have RPATH feature, therefore we should prepare PATH or copy
|
|
|
|
# DLL(s)
|
2024-10-07 09:09:35 +03:00
|
|
|
set(TOOL_MDBX_DLLCRUTCH "Crutch for ${CMAKE_SYSTEM_NAME}")
|
|
|
|
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_VERSION VERSION_LESS 3.0)
|
|
|
|
# will use LOCATION property to compose DLLPATH
|
|
|
|
cmake_policy(SET CMP0026 OLD)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(TOOL_MDBX_DLLCRUTCH FALSE)
|
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
else()
|
|
|
|
set(TOOL_MDBX_LIB mdbx-static)
|
2024-10-07 09:09:35 +03:00
|
|
|
set(TOOL_MDBX_DLLCRUTCH FALSE)
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# build mdbx-tools
|
|
|
|
if(MDBX_BUILD_TOOLS)
|
2024-05-19 22:07:58 +03:00
|
|
|
set(WINGETOPT_SRC "")
|
2024-09-18 07:59:24 +03:00
|
|
|
if(WIN32)
|
2024-11-13 15:03:16 +03:00
|
|
|
set(WINGETOPT_SRC ${MDBX_SOURCE_DIR}/tools/wingetopt.c
|
|
|
|
${MDBX_SOURCE_DIR}/tools/wingetopt.h)
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
|
2024-05-19 22:07:58 +03:00
|
|
|
foreach(TOOL chk copy stat dump load drop)
|
|
|
|
if(MDBX_AMALGAMATED_SOURCE)
|
|
|
|
add_executable(mdbx_${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/mdbx_${TOOL}.c)
|
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
add_executable(mdbx_${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/tools/${TOOL}.c
|
|
|
|
${WINGETOPT_SRC})
|
2024-05-19 22:07:58 +03:00
|
|
|
endif()
|
2022-01-31 23:29:03 +03:00
|
|
|
if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11)
|
2024-11-13 15:03:16 +03:00
|
|
|
set_target_properties(
|
|
|
|
mdbx_${TOOL} PROPERTIES C_STANDARD ${MDBX_C_STANDARD}
|
|
|
|
C_STANDARD_REQUIRED ON)
|
2020-06-26 02:57:46 +03:00
|
|
|
endif()
|
2024-05-19 22:07:58 +03:00
|
|
|
target_setup_options(mdbx_${TOOL})
|
|
|
|
target_link_libraries(mdbx_${TOOL} ${TOOL_MDBX_LIB})
|
2020-04-15 17:09:37 +03:00
|
|
|
endforeach()
|
|
|
|
if(LIB_MATH)
|
|
|
|
target_link_libraries(mdbx_chk ${LIB_MATH})
|
|
|
|
target_link_libraries(mdbx_stat ${LIB_MATH})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
# ##############################################################################
|
2020-04-15 17:09:37 +03:00
|
|
|
|
|
|
|
# mdbx-shared-lib installation
|
2020-09-27 14:16:26 +03:00
|
|
|
if(NOT DEFINED MDBX_DLL_INSTALL_DESTINATION)
|
|
|
|
if(WIN32)
|
2021-06-17 16:59:40 +03:00
|
|
|
set(MDBX_DLL_INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR})
|
2020-09-27 14:16:26 +03:00
|
|
|
else()
|
2021-06-17 16:59:40 +03:00
|
|
|
set(MDBX_DLL_INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
2020-09-27 14:16:26 +03:00
|
|
|
endif()
|
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
if(MDBX_BUILD_SHARED_LIBRARY)
|
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.12)
|
2024-11-13 15:03:16 +03:00
|
|
|
install(
|
|
|
|
TARGETS mdbx
|
|
|
|
EXPORT libmdbx
|
2020-09-27 14:16:26 +03:00
|
|
|
LIBRARY DESTINATION ${MDBX_DLL_INSTALL_DESTINATION} COMPONENT runtime
|
2021-06-17 16:59:40 +03:00
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
|
|
|
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel
|
2024-11-13 15:03:16 +03:00
|
|
|
INCLUDES
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
COMPONENT devel)
|
2020-04-15 17:09:37 +03:00
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
install(
|
|
|
|
TARGETS mdbx
|
|
|
|
EXPORT libmdbx
|
|
|
|
LIBRARY DESTINATION ${MDBX_DLL_INSTALL_DESTINATION}
|
|
|
|
COMPONENT runtime
|
|
|
|
NAMELINK_COMPONENT devel
|
2021-06-17 16:59:40 +03:00
|
|
|
OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
|
|
|
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel
|
2024-11-13 15:03:16 +03:00
|
|
|
INCLUDES
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
COMPONENT devel)
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
endif(MDBX_BUILD_SHARED_LIBRARY)
|
|
|
|
|
|
|
|
# mdbx-tools installation
|
|
|
|
if(MDBX_BUILD_TOOLS)
|
2020-09-27 14:16:26 +03:00
|
|
|
if(NOT DEFINED MDBX_TOOLS_INSTALL_DESTINATION)
|
2021-06-17 16:59:40 +03:00
|
|
|
set(MDBX_TOOLS_INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR})
|
2020-09-27 14:16:26 +03:00
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
install(TARGETS mdbx_chk mdbx_stat mdbx_copy mdbx_dump mdbx_load mdbx_drop
|
|
|
|
RUNTIME DESTINATION ${MDBX_TOOLS_INSTALL_DESTINATION}
|
|
|
|
COMPONENT runtime)
|
2020-09-27 14:16:26 +03:00
|
|
|
if(MDBX_INSTALL_MANPAGES)
|
|
|
|
if(NOT DEFINED MDBX_MAN_INSTALL_DESTINATION)
|
2021-06-17 16:59:40 +03:00
|
|
|
set(MDBX_MAN_INSTALL_DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
|
2020-09-27 14:16:26 +03:00
|
|
|
endif()
|
|
|
|
install(
|
2024-11-13 15:03:16 +03:00
|
|
|
FILES "${MDBX_SOURCE_DIR}/man1/mdbx_chk.1"
|
|
|
|
"${MDBX_SOURCE_DIR}/man1/mdbx_stat.1"
|
|
|
|
"${MDBX_SOURCE_DIR}/man1/mdbx_copy.1"
|
|
|
|
"${MDBX_SOURCE_DIR}/man1/mdbx_dump.1"
|
|
|
|
"${MDBX_SOURCE_DIR}/man1/mdbx_load.1"
|
|
|
|
"${MDBX_SOURCE_DIR}/man1/mdbx_drop.1"
|
2020-09-27 14:16:26 +03:00
|
|
|
DESTINATION ${MDBX_MAN_INSTALL_DESTINATION}
|
|
|
|
COMPONENT doc)
|
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
endif(MDBX_BUILD_TOOLS)
|
|
|
|
|
|
|
|
# mdbx-static-lib installation
|
|
|
|
if(MDBX_INSTALL_STATIC)
|
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.12)
|
2024-11-13 15:03:16 +03:00
|
|
|
install(
|
|
|
|
TARGETS mdbx-static
|
|
|
|
EXPORT libmdbx
|
2021-06-17 16:59:40 +03:00
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
|
|
|
|
OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
|
|
|
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel
|
2024-11-13 15:03:16 +03:00
|
|
|
INCLUDES
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
COMPONENT devel)
|
2020-04-15 17:09:37 +03:00
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
install(
|
|
|
|
TARGETS mdbx-static
|
|
|
|
EXPORT libmdbx
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
COMPONENT devel
|
|
|
|
NAMELINK_COMPONENT devel
|
2021-06-17 16:59:40 +03:00
|
|
|
OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
|
|
|
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel
|
2024-11-13 15:03:16 +03:00
|
|
|
INCLUDES
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
COMPONENT devel)
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
endif(MDBX_INSTALL_STATIC)
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
# ##############################################################################
|
2020-04-15 17:09:37 +03:00
|
|
|
|
|
|
|
# collect options & build info
|
2021-06-02 14:44:58 +03:00
|
|
|
if(NOT DEFINED MDBX_BUILD_TIMESTAMP)
|
2024-11-19 23:37:37 +03:00
|
|
|
if(NOT "$ENV{SOURCE_DATE_EPOCH}" STREQUAL "")
|
|
|
|
set(FPTA_BUILD_TIMESTAMP "$ENV{SOURCE_DATE_EPOCH}")
|
|
|
|
else()
|
|
|
|
string(TIMESTAMP FPTA_BUILD_TIMESTAMP UTC)
|
|
|
|
endif()
|
2021-06-02 14:44:58 +03:00
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
set(MDBX_BUILD_FLAGS ${CMAKE_C_FLAGS})
|
2020-08-22 20:19:46 +03:00
|
|
|
if(MDBX_BUILD_CXX)
|
|
|
|
set(MDBX_BUILD_FLAGS ${CMAKE_CXX_FLAGS})
|
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
|
|
|
|
# append cmake's build-type flags and defines
|
|
|
|
if(NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
list(APPEND MDBX_BUILD_FLAGS ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}})
|
2020-08-22 20:19:46 +03:00
|
|
|
if(MDBX_BUILD_CXX)
|
2024-11-13 15:03:16 +03:00
|
|
|
list(APPEND MDBX_BUILD_FLAGS
|
|
|
|
${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}})
|
2020-08-22 20:19:46 +03:00
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
|
2020-11-17 13:51:10 +03:00
|
|
|
# choice target to fetch definitions and options
|
|
|
|
if(MDBX_BUILD_SHARED_LIBRARY)
|
|
|
|
set(target4fetch mdbx)
|
|
|
|
else()
|
|
|
|
set(target4fetch mdbx-static)
|
|
|
|
endif()
|
|
|
|
|
2020-04-15 17:09:37 +03:00
|
|
|
# get definitions
|
2020-11-17 13:51:10 +03:00
|
|
|
get_target_property(defs_list ${target4fetch} COMPILE_DEFINITIONS)
|
2020-04-15 17:09:37 +03:00
|
|
|
if(defs_list)
|
|
|
|
list(APPEND MDBX_BUILD_FLAGS ${defs_list})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# get target compile options
|
2020-11-17 13:51:10 +03:00
|
|
|
get_target_property(options_list ${target4fetch} COMPILE_OPTIONS)
|
2020-04-15 17:09:37 +03:00
|
|
|
if(options_list)
|
|
|
|
list(APPEND MDBX_BUILD_FLAGS ${options_list})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(REMOVE_DUPLICATES MDBX_BUILD_FLAGS)
|
|
|
|
string(REPLACE ";" " " MDBX_BUILD_FLAGS "${MDBX_BUILD_FLAGS}")
|
|
|
|
if(CMAKE_CONFIGURATION_TYPES)
|
|
|
|
# add dynamic part via per-configuration define
|
2024-11-13 15:03:16 +03:00
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"MDBX Compile Flags: ${MDBX_BUILD_FLAGS} <AND CONFIGURATION DEPENDENT>")
|
|
|
|
add_definitions(
|
|
|
|
-DMDBX_BUILD_FLAGS_CONFIG="$<$<CONFIG:Debug>:${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_DEFINES_DEBUG}>$<$<CONFIG:Release>:${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_DEFINES_RELEASE}>$<$<CONFIG:RelWithDebInfo>:${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CMAKE_C_DEFINES_RELWITHDEBINFO}>$<$<CONFIG:MinSizeRel>:${CMAKE_C_FLAGS_MINSIZEREL} ${CMAKE_C_DEFINES_MINSIZEREL}>"
|
|
|
|
)
|
2020-04-15 17:09:37 +03:00
|
|
|
else()
|
|
|
|
message(STATUS "MDBX Compile Flags: ${MDBX_BUILD_FLAGS}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# get compiler info
|
2024-11-13 15:03:16 +03:00
|
|
|
execute_process(
|
|
|
|
COMMAND sh -c "${CMAKE_C_COMPILER} --version | head -1"
|
2020-04-15 17:09:37 +03:00
|
|
|
OUTPUT_VARIABLE MDBX_BUILD_COMPILER
|
2024-11-13 15:03:16 +03:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
|
2020-04-15 17:09:37 +03:00
|
|
|
RESULT_VARIABLE rc)
|
|
|
|
if(rc OR NOT MDBX_BUILD_COMPILER)
|
2024-11-13 15:03:16 +03:00
|
|
|
string(STRIP "${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}"
|
|
|
|
MDBX_BUILD_COMPILER)
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# make a build-target triplet
|
|
|
|
if(CMAKE_C_COMPILER_TARGET)
|
|
|
|
set(MDBX_BUILD_TARGET "${CMAKE_C_COMPILER_TARGET}")
|
|
|
|
else()
|
2022-04-22 12:55:00 +03:00
|
|
|
if(CMAKE_C_COMPILER_ARCHITECTURE_ID)
|
|
|
|
string(STRIP "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MDBX_BUILD_TARGET)
|
2024-11-13 15:03:16 +03:00
|
|
|
elseif(CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL
|
|
|
|
CMAKE_SYSTEM_NAME)
|
2022-04-22 12:55:00 +03:00
|
|
|
string(STRIP "${CMAKE_GENERATOR_PLATFORM}" MDBX_BUILD_TARGET)
|
|
|
|
elseif(CMAKE_SYSTEM_ARCH)
|
|
|
|
string(STRIP "${CMAKE_SYSTEM_ARCH}" MDBX_BUILD_TARGET)
|
|
|
|
elseif(CMAKE_LIBRARY_ARCHITECTURE)
|
|
|
|
string(STRIP "${CMAKE_LIBRARY_ARCHITECTURE}" MDBX_BUILD_TARGET)
|
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR)
|
|
|
|
string(STRIP "${CMAKE_SYSTEM_PROCESSOR}" MDBX_BUILD_TARGET)
|
|
|
|
else()
|
|
|
|
set(MDBX_BUILD_TARGET "unknown")
|
|
|
|
endif()
|
|
|
|
if(CMAKE_C_COMPILER_ABI
|
2024-11-13 15:03:16 +03:00
|
|
|
AND NOT (CMAKE_C_COMPILER_ABI MATCHES ".*${MDBX_BUILD_TARGET}.*"
|
|
|
|
OR MDBX_BUILD_TARGET MATCHES ".*${CMAKE_C_COMPILER_ABI}.*"))
|
|
|
|
string(CONCAT MDBX_BUILD_TARGET
|
|
|
|
"${MDBX_BUILD_TARGET}-${CMAKE_C_COMPILER_ABI}")
|
2022-04-22 12:55:00 +03:00
|
|
|
endif()
|
|
|
|
if(CMAKE_C_PLATFORM_ID
|
2024-11-13 15:03:16 +03:00
|
|
|
AND NOT (CMAKE_SYSTEM_NAME
|
|
|
|
AND (CMAKE_C_PLATFORM_ID MATCHES ".*${CMAKE_SYSTEM_NAME}.*"
|
|
|
|
OR CMAKE_SYSTEM_NAME MATCHES ".*${CMAKE_C_PLATFORM_ID}.*"))
|
|
|
|
AND NOT (CMAKE_C_PLATFORM_ID MATCHES ".*${CMAKE_C_PLATFORM_ID}.*"
|
|
|
|
OR MDBX_BUILD_TARGET MATCHES ".*${CMAKE_C_PLATFORM_ID}.*"))
|
|
|
|
string(CONCAT MDBX_BUILD_TARGET
|
|
|
|
"${MDBX_BUILD_TARGET}-${CMAKE_C_COMPILER_ABI}")
|
2022-04-22 12:55:00 +03:00
|
|
|
endif()
|
|
|
|
if(CMAKE_SYSTEM_NAME)
|
2022-11-07 23:37:27 +03:00
|
|
|
string(CONCAT MDBX_BUILD_TARGET "${MDBX_BUILD_TARGET}-${CMAKE_SYSTEM_NAME}")
|
2022-04-22 12:55:00 +03:00
|
|
|
endif()
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# provide build-type
|
|
|
|
if(CMAKE_CONFIGURATION_TYPES)
|
2020-09-28 23:47:37 +03:00
|
|
|
# via per-configuration define
|
2020-04-15 17:09:37 +03:00
|
|
|
add_definitions(-DMDBX_BUILD_TYPE="$<CONFIG>")
|
2020-09-30 04:01:48 +03:00
|
|
|
set(MDBX_BUILD_TYPE "<CONFIGURATION DEPENDENT>")
|
2020-04-15 17:09:37 +03:00
|
|
|
else()
|
|
|
|
set(MDBX_BUILD_TYPE ${CMAKE_BUILD_TYPE})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# options
|
2024-11-13 15:03:16 +03:00
|
|
|
set(options VERSION C_COMPILER CXX_COMPILER MDBX_BUILD_TARGET MDBX_BUILD_TYPE
|
|
|
|
${MDBX_BUILD_OPTIONS})
|
2020-04-15 17:09:37 +03:00
|
|
|
foreach(item IN LISTS options)
|
|
|
|
if(DEFINED ${item})
|
|
|
|
set(value "${${item}}")
|
|
|
|
elseif(DEFINED MDBX_${item})
|
|
|
|
set(item MDBX_${item})
|
|
|
|
set(value "${${item}}")
|
|
|
|
elseif(DEFINED CMAKE_${item})
|
|
|
|
set(item CMAKE_${item})
|
|
|
|
set(value "${${item}}")
|
|
|
|
else()
|
2021-12-10 17:15:53 +03:00
|
|
|
set(value "AUTO (not pre-defined explicitly)")
|
2020-04-15 17:09:37 +03:00
|
|
|
endif()
|
|
|
|
message(STATUS "${item}: ${value}")
|
|
|
|
endforeach(item)
|
|
|
|
|
|
|
|
# provide config.h for library build info
|
|
|
|
configure_file("${MDBX_SOURCE_DIR}/config.h.in"
|
2024-11-13 15:03:16 +03:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/config.h" ESCAPE_QUOTES)
|
2020-04-15 17:09:37 +03:00
|
|
|
add_definitions(-DMDBX_CONFIG_H="${CMAKE_CURRENT_BINARY_DIR}/config.h")
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
# ##############################################################################
|
2019-09-03 02:24:19 +03:00
|
|
|
|
2020-04-15 17:09:37 +03:00
|
|
|
if(NOT MDBX_AMALGAMATED_SOURCE AND MDBX_ENABLE_TESTS)
|
2020-09-28 23:47:37 +03:00
|
|
|
if(NOT CMAKE_CXX_COMPILER_LOADED)
|
2024-11-13 15:03:16 +03:00
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: The C++ compiler is required to build the tests."
|
|
|
|
)
|
2020-09-27 16:49:55 +03:00
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
add_subdirectory(test)
|
|
|
|
endif()
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
# ##############################################################################
|
2020-09-27 16:45:00 +03:00
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
if(NOT SUBPROJECT)
|
2022-06-12 23:13:14 +03:00
|
|
|
set(PACKAGE "libmdbx")
|
|
|
|
set(CPACK_PACKAGE_VERSION_MAJOR ${MDBX_VERSION_MAJOR})
|
|
|
|
set(CPACK_PACKAGE_VERSION_MINOR ${MDBX_VERSION_MINOR})
|
|
|
|
set(CPACK_PACKAGE_VERSION_PATCH ${MDBX_VERSION_RELEASE})
|
|
|
|
set(CPACK_PACKAGE_VERSION_COMMIT ${MDBX_VERSION_REVISION})
|
2024-11-13 15:03:16 +03:00
|
|
|
set(PACKAGE_VERSION
|
|
|
|
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.${CPACK_PACKAGE_VERSION_COMMIT}"
|
|
|
|
)
|
2022-06-12 23:13:14 +03:00
|
|
|
message(STATUS "libmdbx package version is ${PACKAGE_VERSION}")
|
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
|
|
cmake_policy(POP)
|