mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-28 18:48:48 +08:00
mdbx-build: rearrange source files, rework CMakeLists.txt and refine GNUMakefile (squashed).
Change-Id: Id73d346695011dab2f670bb9e6293a1e5a1835ca
This commit is contained in:
parent
f414876e99
commit
971f924c44
@ -1,411 +0,0 @@
|
||||
##
|
||||
## This is the minimal template for CMakeList.txt which could be used
|
||||
## to build libmdbx from the "amalgamated form" of libmdbx's source code.
|
||||
##
|
||||
## The amalgamated form is intended to embedding libmdbx in other projects
|
||||
## in cases when using as git-submodule is not acceptable or inconveniently.
|
||||
##
|
||||
## The amalgamated form could be generated from full git repository
|
||||
## on Linux just by `make dist`.
|
||||
##
|
||||
|
||||
##
|
||||
## Copyright 2020 Leonid Yuriev <leo@yuriev.ru>
|
||||
## and other libmdbx authors: please see AUTHORS file.
|
||||
## All rights reserved.
|
||||
##
|
||||
## Redistribution and use in source and binary forms, with or without
|
||||
## modification, are permitted only as authorized by the OpenLDAP
|
||||
## Public License.
|
||||
##
|
||||
## A copy of this license is available in the file LICENSE in the
|
||||
## top-level directory of the distribution or, alternatively, at
|
||||
## <http://www.OpenLDAP.org/license.html>.
|
||||
##
|
||||
|
||||
##
|
||||
## libmdbx = { Revised and extended descendant of Symas LMDB. }
|
||||
## Please see README.md at https://github.com/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. Всё будет хорошо.
|
||||
##
|
||||
|
||||
cmake_minimum_required(VERSION 3.8.2)
|
||||
|
||||
cmake_policy(PUSH)
|
||||
cmake_policy(VERSION 3.8.2)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.13)
|
||||
cmake_policy(SET CMP0077 NEW)
|
||||
endif()
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.12)
|
||||
cmake_policy(SET CMP0075 NEW)
|
||||
endif()
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.9)
|
||||
cmake_policy(SET CMP0069 NEW)
|
||||
include(CheckIPOSupported)
|
||||
check_ipo_supported(RESULT CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE)
|
||||
else()
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE FALSE)
|
||||
endif()
|
||||
|
||||
if(DEFINED PROJECT_NAME)
|
||||
set(SUBPROJECT ON)
|
||||
set(NOT_SUBPROJECT OFF)
|
||||
else()
|
||||
set(SUBPROJECT OFF)
|
||||
set(NOT_SUBPROJECT ON)
|
||||
project(libmdbx C CXX)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED IOS)
|
||||
if(APPLE AND (CMAKE_SYSTEM_NAME STREQUAL "iOS"
|
||||
OR DEFINED CMAKE_IOS_DEVELOPER_ROOT
|
||||
OR DEFINED IOS_PLATFORM OR DEFINED IOS_ARCH))
|
||||
set(IOS TRUE)
|
||||
else()
|
||||
set(IOS FALSE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING
|
||||
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
|
||||
FORCE)
|
||||
endif()
|
||||
|
||||
if(NOT_SUBPROJECT AND (CMAKE_CROSSCOMPILING OR IOS))
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
endif()
|
||||
|
||||
if(IOS)
|
||||
set(MDBX_BUILD_TOOLS_DEFAULT OFF)
|
||||
if(NOT_SUBPROJECT)
|
||||
cmake_policy(SET CMP0006 OLD)
|
||||
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO")
|
||||
endif()
|
||||
else()
|
||||
set(MDBX_BUILD_TOOLS_DEFAULT ON)
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
if(SUBPROJECT)
|
||||
if(NOT DEFINED BUILD_SHARED_LIBS)
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" OFF)
|
||||
endif()
|
||||
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
|
||||
option(CMAKE_POSITION_INDEPENDENT_CODE "Generate position independed (PIC)" ON)
|
||||
endif()
|
||||
else()
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" ON)
|
||||
option(CMAKE_POSITION_INDEPENDENT_CODE "Generate position independed (PIC)" ON)
|
||||
if(CMAKE_CONFIGURATION_TYPES OR NOT CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG")
|
||||
set(INTERPROCEDURAL_OPTIMIZATION_DEFAULT ON)
|
||||
else()
|
||||
set(INTERPROCEDURAL_OPTIMIZATION_DEFAULT OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11)
|
||||
if(NOT HAS_C11 LESS 0)
|
||||
set(MDBX_C_STANDARD 11)
|
||||
else()
|
||||
set(MDBX_C_STANDARD 99)
|
||||
endif()
|
||||
message(STATUS "Use C${MDBX_C_STANDARD} for libmdbx")
|
||||
|
||||
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()
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
#
|
||||
# #### ##### ##### # #### # # ####
|
||||
# # # # # # # # # ## # #
|
||||
# # # # # # # # # # # # ####
|
||||
# # # ##### # # # # # # # #
|
||||
# # # # # # # # # ## # #
|
||||
# #### # # # #### # # ####
|
||||
#
|
||||
|
||||
set(MDBX_BUILD_OPTIONS "")
|
||||
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})
|
||||
add_mdbx_option(MDBX_ALLOY_BUILD "Build MDBX library as single object file" ON)
|
||||
add_mdbx_option(MDBX_TXN_CHECKOWNER "Checking transaction matches the calling thread inside libmdbx's API" ON)
|
||||
add_mdbx_option(MDBX_TXN_CHECKPID "Paranoid checking PID inside libmdbx's API" AUTO)
|
||||
mark_as_advanced(MDBX_TXN_CHECKPID)
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use nonstandard GNU/Linux extension functions" OFF)
|
||||
mark_as_advanced(MDBX_DISABLE_GNU_SOURCE)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
|
||||
add_mdbx_option(MDBX_OSX_SPEED_INSTEADOF_DURABILITY "Disable use fcntl(F_FULLFSYNC) in favor of speed" OFF)
|
||||
mark_as_advanced(MDBX_OSX_SPEED_INSTEADOF_DURABILITY)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
add_mdbx_option(MDBX_AVOID_CRT "Avoid dependence from MSVC CRT" OFF)
|
||||
if(NOT MDBX_BUILD_SHARED_LIBRARY)
|
||||
add_mdbx_option(MDBX_CONFIG_MANUAL_TLS_CALLBACK
|
||||
"Provide mdbx_dll_handler() for manual initialization" OFF)
|
||||
mark_as_advanced(MDBX_CONFIG_MANUAL_TLS_CALLBACK)
|
||||
endif()
|
||||
else()
|
||||
add_mdbx_option(MDBX_USE_OFDLOCKS "Use Open file description locks (aka OFD locks, non-POSIX)" AUTO)
|
||||
mark_as_advanced(MDBX_USE_OFDLOCKS)
|
||||
endif()
|
||||
add_mdbx_option(MDBX_LOCKING "Locking method (Win32=-1, SysV=5, POSIX=1988, POSIX=2001, POSIX=2008, Futexes=1995)" AUTO)
|
||||
mark_as_advanced(MDBX_LOCKING)
|
||||
add_mdbx_option(MDBX_TRUST_RTC "Does a system have battery-backed Real-Time Clock or just a fake." AUTO)
|
||||
mark_as_advanced(MDBX_TRUST_RTC)
|
||||
option(MDBX_FORCE_ASSERTIONS "Force enable assertion checking." OFF)
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
|
||||
# provide build timestamp
|
||||
string(TIMESTAMP MDBX_BUILD_TIMESTAMP UTC)
|
||||
add_definitions(-DMDBX_BUILD_TIMESTAMP="${MDBX_BUILD_TIMESTAMP}")
|
||||
|
||||
# provide compiler info
|
||||
execute_process(COMMAND sh -c "${CMAKE_C_COMPILER} --version | head -1"
|
||||
OUTPUT_VARIABLE MDBX_BUILD_COMPILER
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE rc)
|
||||
if(rc OR NOT MDBX_BUILD_COMPILER)
|
||||
string(STRIP "${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}" MDBX_BUILD_COMPILER)
|
||||
endif()
|
||||
add_definitions(-DMDBX_BUILD_COMPILER="${MDBX_BUILD_COMPILER}")
|
||||
|
||||
# provide cpu/arch-system pair
|
||||
if(CMAKE_C_COMPILER_TARGET)
|
||||
set(MDBX_BUILD_TARGET "${CMAKE_C_COMPILER_TARGET}")
|
||||
elseif(CMAKE_C_PLATFORM_ID AND NOT CMAKE_C_PLATFORM_ID STREQUAL CMAKE_SYSTEM_NAME)
|
||||
string(STRIP "${CMAKE_C_PLATFORM_ID}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
elseif(CMAKE_LIBRARY_ARCHITECTURE)
|
||||
string(STRIP "${CMAKE_LIBRARY_ARCHITECTURE}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
elseif(CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_C_PLATFORM_ID STREQUAL CMAKE_SYSTEM_NAME)
|
||||
string(STRIP "${CMAKE_GENERATOR_PLATFORM}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
elseif(CMAKE_SYSTEM_ARCH)
|
||||
string(STRIP "${CMAKE_SYSTEM_ARCH}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
else()
|
||||
string(STRIP "${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
endif()
|
||||
add_definitions(-DMDBX_BUILD_TARGET="${MDBX_BUILD_TARGET}")
|
||||
|
||||
# provide build target-config
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
add_definitions(-DMDBX_BUILD_CONFIG="$<CONFIG>")
|
||||
else()
|
||||
add_definitions(-DMDBX_BUILD_CONFIG="${CMAKE_BUILD_TYPE}")
|
||||
endif()
|
||||
|
||||
# provide build cflags
|
||||
set(MDBX_BUILD_FLAGS "")
|
||||
list(APPEND MDBX_BUILD_FLAGS ${CMAKE_C_FLAGS})
|
||||
list(APPEND MDBX_BUILD_FLAGS ${CMAKE_C_DEFINES})
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
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}>")
|
||||
else()
|
||||
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE)
|
||||
list(APPEND MDBX_BUILD_FLAGS ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}})
|
||||
list(APPEND MDBX_BUILD_FLAGS ${CMAKE_C_DEFINES_${CMAKE_BUILD_TYPE_UPPERCASE}})
|
||||
endif()
|
||||
list(REMOVE_DUPLICATES MDBX_BUILD_FLAGS)
|
||||
string(REPLACE ";" " " MDBX_BUILD_FLAGS "${MDBX_BUILD_FLAGS}")
|
||||
add_definitions(-DMDBX_BUILD_FLAGS="${MDBX_BUILD_FLAGS}")
|
||||
|
||||
################################################################################
|
||||
|
||||
# shared library
|
||||
if(MDBX_BUILD_SHARED_LIBRARY)
|
||||
add_library(mdbx SHARED mdbx.c mdbx.h)
|
||||
set_target_properties(mdbx PROPERTIES
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON
|
||||
PUBLIC_HEADER mdbx.h)
|
||||
target_compile_definitions(mdbx PRIVATE LIBMDBX_EXPORTS INTERFACE LIBMDBX_IMPORTS)
|
||||
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
||||
set_target_properties(mdbx PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
||||
endif()
|
||||
target_link_libraries(mdbx PRIVATE ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(WIN32)
|
||||
target_link_libraries(mdbx PRIVATE ntdll.lib)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Solaris")
|
||||
target_link_libraries(mdbx PRIVATE kstat)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
|
||||
target_link_libraries(mdbx PRIVATE log)
|
||||
endif()
|
||||
list(APPEND MDBX_BUILD_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
|
||||
endif()
|
||||
|
||||
# static library used for tools, to avoid rpath/dll-path troubles
|
||||
add_library(mdbx-static STATIC mdbx.c mdbx.h)
|
||||
set_target_properties(mdbx-static PROPERTIES
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON
|
||||
PUBLIC_HEADER mdbx.h)
|
||||
target_link_libraries(mdbx-static INTERFACE ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
||||
set_target_properties(mdbx-static PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
||||
endif()
|
||||
if(WIN32)
|
||||
target_link_libraries(mdbx-static INTERFACE ntdll.lib)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Solaris")
|
||||
target_link_libraries(mdbx-static INTERFACE kstat)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
|
||||
target_link_libraries(mdbx-static INTERFACE log)
|
||||
endif()
|
||||
|
||||
# mdbx-tools
|
||||
if(MDBX_BUILD_TOOLS)
|
||||
foreach(TOOL mdbx_chk mdbx_copy mdbx_stat mdbx_dump mdbx_load)
|
||||
add_executable(${TOOL} ${TOOL}.c)
|
||||
set_target_properties(${TOOL} PROPERTIES
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
|
||||
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
||||
set_target_properties(${TOOL} PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
||||
endif()
|
||||
target_link_libraries(${TOOL} mdbx-static)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# installation
|
||||
if(MDBX_BUILD_SHARED_LIBRARY)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
install(TARGETS mdbx EXPORT libmdbx
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT runtime
|
||||
OBJECTS
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include
|
||||
COMPONENT devel
|
||||
INCLUDES
|
||||
DESTINATION include
|
||||
COMPONENT devel)
|
||||
else()
|
||||
install(TARGETS mdbx EXPORT libmdbx
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT runtime
|
||||
NAMELINK_COMPONENT devel
|
||||
OBJECTS
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include
|
||||
COMPONENT devel
|
||||
INCLUDES
|
||||
DESTINATION include
|
||||
COMPONENT devel)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
install(TARGETS mdbx-static EXPORT libmdbx EXCLUDE_FROM_ALL
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT runtime
|
||||
OBJECTS
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include
|
||||
COMPONENT devel
|
||||
INCLUDES
|
||||
DESTINATION include
|
||||
COMPONENT devel)
|
||||
else()
|
||||
install(TARGETS mdbx-static EXPORT libmdbx EXCLUDE_FROM_ALL
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT runtime
|
||||
NAMELINK_COMPONENT devel
|
||||
OBJECTS
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include
|
||||
COMPONENT devel
|
||||
INCLUDES
|
||||
DESTINATION include
|
||||
COMPONENT devel)
|
||||
endif()
|
||||
|
||||
if(MDBX_BUILD_TOOLS)
|
||||
install(
|
||||
TARGETS
|
||||
mdbx_chk
|
||||
mdbx_stat
|
||||
mdbx_copy
|
||||
mdbx_dump
|
||||
mdbx_load
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime)
|
||||
install(
|
||||
FILES
|
||||
man1/mdbx_chk.1
|
||||
man1/mdbx_stat.1
|
||||
man1/mdbx_copy.1
|
||||
man1/mdbx_dump.1
|
||||
man1/mdbx_load.1
|
||||
DESTINATION man/man1
|
||||
COMPONENT doc)
|
||||
endif()
|
||||
|
||||
cmake_policy(POP)
|
580
CMakeLists.txt
580
CMakeLists.txt
@ -52,17 +52,42 @@ else()
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE FALSE)
|
||||
endif()
|
||||
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/core.c" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/alloy.c" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/version.c.in" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/mdbx_chk.c")
|
||||
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")
|
||||
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.c" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/man1" AND
|
||||
EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_chk.c")
|
||||
set(MDBX_AMALGAMATED_SOURCE TRUE)
|
||||
set(MDBX_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
else()
|
||||
message(FATAL_ERROR "Please use libmdbx as a git-submodule or the amalgamated source code")
|
||||
endif()
|
||||
|
||||
if(DEFINED PROJECT_NAME)
|
||||
set(SUBPROJECT ON)
|
||||
set(NOT_SUBPROJECT OFF)
|
||||
if(NOT DEFINED BUILD_TESTING)
|
||||
if(NOT MDBX_AMALGAMATED_SOURCE AND NOT DEFINED BUILD_TESTING)
|
||||
set(BUILD_TESTING OFF)
|
||||
endif()
|
||||
else()
|
||||
set(SUBPROJECT OFF)
|
||||
set(NOT_SUBPROJECT ON)
|
||||
project(libmdbx C CXX)
|
||||
if(NOT DEFINED BUILD_TESTING)
|
||||
if(NOT MDBX_AMALGAMATED_SOURCE AND NOT DEFINED BUILD_TESTING)
|
||||
set(BUILD_TESTING ON)
|
||||
endif()
|
||||
endif()
|
||||
@ -87,9 +112,6 @@ else()
|
||||
set(MDBX_BUILD_TOOLS_DEFAULT ON)
|
||||
endif()
|
||||
|
||||
# only for compatibility testing
|
||||
# set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
if(NOT "$ENV{TEAMCITY_PROCESS_FLOW_ID}" STREQUAL "")
|
||||
set(CI TEAMCITY)
|
||||
message(STATUS "TeamCity CI")
|
||||
@ -119,19 +141,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${MDBX_OUTPUT_DIR})
|
||||
set(CMAKE_PDB_OUTPUT_DIRECTORY ${MDBX_OUTPUT_DIR})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MDBX_OUTPUT_DIR})
|
||||
|
||||
include(CheckLibraryExists)
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckCCompilerFlag)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckCSourceRuns)
|
||||
include(CheckCXXSourceRuns)
|
||||
include(CheckCSourceCompiles)
|
||||
include(CheckCXXSourceCompiles)
|
||||
include(TestBigEndian)
|
||||
include(CheckFunctionExists)
|
||||
include(FindPackageMessage)
|
||||
include(CheckStructHasMember)
|
||||
include(CMakeDependentOption)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION LESS 1900)
|
||||
@ -151,15 +162,6 @@ include(cmake/utils.cmake)
|
||||
include(cmake/compiler.cmake)
|
||||
include(cmake/profile.cmake)
|
||||
|
||||
find_program(ECHO echo)
|
||||
find_program(CAT cat)
|
||||
find_program(GIT git)
|
||||
find_program(LD ld)
|
||||
|
||||
# CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
|
||||
# CHECK_INCLUDE_FILES(sys/uio.h HAVE_SYS_UIO_H)
|
||||
# CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)
|
||||
|
||||
CHECK_FUNCTION_EXISTS(pow NOT_NEED_LIBM)
|
||||
if(NOT_NEED_LIBM)
|
||||
set(LIB_MATH "")
|
||||
@ -228,57 +230,56 @@ else()
|
||||
set(LTO_ENABLED FALSE)
|
||||
endif()
|
||||
|
||||
find_program(VALGRIND valgrind)
|
||||
if(VALGRIND)
|
||||
# LY: cmake is ugly and nasty.
|
||||
# - therefore memcheck-options should be defined before including ctest;
|
||||
# - otherwise ctest may ignore it.
|
||||
set(MEMORYCHECK_SUPPRESSIONS_FILE
|
||||
"${PROJECT_SOURCE_DIR}/test/valgrind_suppress.txt"
|
||||
CACHE FILEPATH "Suppressions file for Valgrind" FORCE)
|
||||
set(MEMORYCHECK_COMMAND_OPTIONS
|
||||
"--trace-children=yes --leak-check=full --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)
|
||||
endif()
|
||||
if(NOT MDBX_AMALGAMATED_SOURCE)
|
||||
find_program(VALGRIND valgrind)
|
||||
if(VALGRIND)
|
||||
# LY: cmake is ugly and nasty.
|
||||
# - therefore memcheck-options should be defined before including ctest;
|
||||
# - otherwise ctest may ignore it.
|
||||
set(MEMORYCHECK_SUPPRESSIONS_FILE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/test/valgrind_suppress.txt"
|
||||
CACHE FILEPATH "Suppressions file for Valgrind" FORCE)
|
||||
set(MEMORYCHECK_COMMAND_OPTIONS
|
||||
"--trace-children=yes --leak-check=full --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)
|
||||
endif()
|
||||
|
||||
#
|
||||
# Enable 'make tags' target.
|
||||
find_program(CTAGS ctags)
|
||||
if(CTAGS)
|
||||
add_custom_target(tags COMMAND ${CTAGS} -R -f tags
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||
add_custom_target(ctags DEPENDS tags)
|
||||
endif(CTAGS)
|
||||
# Enable 'make tags' target.
|
||||
find_program(CTAGS ctags)
|
||||
if(CTAGS)
|
||||
add_custom_target(tags COMMAND ${CTAGS} -R -f tags
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_custom_target(ctags DEPENDS tags)
|
||||
endif(CTAGS)
|
||||
|
||||
#
|
||||
# Enable 'make reformat' target.
|
||||
find_program(CLANG_FORMAT
|
||||
NAMES clang-format-6.0 clang-format-5.0 clang-format-4.0
|
||||
clang-format-3.9 clang-format-3.8 clang-format-3.7 clang-format)
|
||||
if(CLANG_FORMAT AND UNIX)
|
||||
add_custom_target(reformat
|
||||
VERBATIM
|
||||
COMMAND
|
||||
git ls-files |
|
||||
grep -E \\.\(c|cxx|cc|cpp|h|hxx|hpp\)\(\\.in\)?\$ |
|
||||
xargs ${CLANG_FORMAT} -i --style=file
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||
endif()
|
||||
# Enable 'make reformat' target.
|
||||
find_program(CLANG_FORMAT
|
||||
NAMES clang-format-11.0 clang-format-10.0 clang-format-9.0 clang-format-8.0 clang-format)
|
||||
if(CLANG_FORMAT AND UNIX)
|
||||
add_custom_target(reformat
|
||||
VERBATIM
|
||||
COMMAND
|
||||
git ls-files |
|
||||
grep -E \\.\(c|cxx|cc|cpp|h|hxx|hpp\)\(\\.in\)?\$ |
|
||||
xargs ${CLANG_FORMAT} -i --style=file
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
if(NOT "${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
|
||||
add_custom_target(distclean)
|
||||
add_custom_command(TARGET distclean
|
||||
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)
|
||||
add_custom_command(TARGET distclean
|
||||
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()
|
||||
if(NOT "${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
|
||||
add_custom_target(distclean)
|
||||
add_custom_command(TARGET distclean
|
||||
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)
|
||||
add_custom_command(TARGET distclean
|
||||
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)
|
||||
|
||||
setup_compile_flags()
|
||||
endif(SUBPROJECT)
|
||||
@ -291,6 +292,57 @@ else()
|
||||
endif()
|
||||
message(STATUS "Use C${MDBX_C_STANDARD} for libmdbx")
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND EXISTS "${MDBX_SOURCE_DIR}/ntdll.def")
|
||||
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}")
|
||||
set(MDBX_NTDLL_EXTRA_IMPLIB "${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.lib")
|
||||
add_custom_command(OUTPUT "${MDBX_NTDLL_EXTRA_IMPLIB}"
|
||||
COMMENT "Create extra-import-library for ntdll.dll"
|
||||
MAIN_DEPENDENCY "${MDBX_SOURCE_DIR}/ntdll.def"
|
||||
COMMAND ${MSVC_LIB_EXE} /def:"${MDBX_SOURCE_DIR}/ntdll.def" /out:"${MDBX_NTDLL_EXTRA_IMPLIB}" ${INITIAL_CMAKE_STATIC_LINKER_FLAGS})
|
||||
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}")
|
||||
set(MDBX_NTDLL_EXTRA_IMPLIB "${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.a")
|
||||
add_custom_command(OUTPUT "${MDBX_NTDLL_EXTRA_IMPLIB}"
|
||||
COMMENT "Create extra-import-library for ntdll.dll"
|
||||
MAIN_DEPENDENCY "${MDBX_SOURCE_DIR}/ntdll.def"
|
||||
COMMAND ${DLLTOOL} -d "${MDBX_SOURCE_DIR}/ntdll.def" -l "${MDBX_NTDLL_EXTRA_IMPLIB}")
|
||||
else()
|
||||
message(WARNING "dlltool not found")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MDBX_NTDLL_EXTRA_IMPLIB)
|
||||
# LY: Sometimes CMake requires a nightmarish magic for simple things.
|
||||
# 1) create a target out of the library compilation result
|
||||
add_custom_target(ntdll_extra_target DEPENDS "${MDBX_NTDLL_EXTRA_IMPLIB}")
|
||||
# 2) create an library target out of the library compilation result
|
||||
add_library(ntdll_extra STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(ntdll_extra ntdll_extra_target)
|
||||
# 3) specify where the library is (and where to find the headers)
|
||||
set_target_properties(ntdll_extra
|
||||
PROPERTIES
|
||||
IMPORTED_LOCATION "${MDBX_NTDLL_EXTRA_IMPLIB}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
macro(add_mdbx_option NAME DESCRIPTION DEFAULT)
|
||||
list(APPEND MDBX_BUILD_OPTIONS ${NAME})
|
||||
if(NOT ${DEFAULT} STREQUAL "AUTO")
|
||||
@ -312,43 +364,399 @@ endmacro()
|
||||
#
|
||||
|
||||
set(MDBX_BUILD_OPTIONS ENABLE_ASAN MDBX_USE_VALGRIND ENABLE_GPROF ENABLE_GCOV)
|
||||
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})
|
||||
add_mdbx_option(MDBX_ALLOY_BUILD "Build MDBX library as single object file" ON)
|
||||
add_mdbx_option(MDBX_TXN_CHECKOWNER "Checking transaction matches the calling thread inside libmdbx's API" ON)
|
||||
add_mdbx_option(MDBX_TXN_CHECKPID "Paranoid checking PID inside libmdbx's API" AUTO)
|
||||
mark_as_advanced(MDBX_TXN_CHECKPID)
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use nonstandard GNU/Linux extension functions" OFF)
|
||||
add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use GNU/Linux libc extensions" OFF)
|
||||
mark_as_advanced(MDBX_DISABLE_GNU_SOURCE)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR IOS)
|
||||
add_mdbx_option(MDBX_OSX_SPEED_INSTEADOF_DURABILITY "Disable use fcntl(F_FULLFSYNC) in favor of speed" OFF)
|
||||
mark_as_advanced(MDBX_OSX_SPEED_INSTEADOF_DURABILITY)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
add_mdbx_option(MDBX_AVOID_CRT "Avoid dependence from MSVC CRT" ${NOT_SUBPROJECT})
|
||||
if(NOT MDBX_BUILD_SHARED_LIBRARY)
|
||||
add_mdbx_option(MDBX_CONFIG_MANUAL_TLS_CALLBACK
|
||||
"Provide mdbx_dll_handler() for manual initialization" OFF)
|
||||
mark_as_advanced(MDBX_CONFIG_MANUAL_TLS_CALLBACK)
|
||||
if(MDBX_NTDLL_EXTRA_IMPLIB)
|
||||
add_mdbx_option(MDBX_AVOID_CRT "Avoid dependence from MSVC CRT and use ntdll.dll instead" ${NOT_SUBPROJECT})
|
||||
endif()
|
||||
add_mdbx_option(MDBX_CONFIG_MANUAL_TLS_CALLBACK
|
||||
"Provide mdbx_dll_handler() for manual initialization" OFF)
|
||||
mark_as_advanced(MDBX_CONFIG_MANUAL_TLS_CALLBACK)
|
||||
else()
|
||||
add_mdbx_option(MDBX_USE_OFDLOCKS "Use Open file description locks (aka OFD locks, non-POSIX)" AUTO)
|
||||
mark_as_advanced(MDBX_USE_OFDLOCKS)
|
||||
endif()
|
||||
add_mdbx_option(MDBX_LOCKING "Locking method (Win32=-1, SysV=5, POSIX=1988, POSIX=2001, POSIX=2008, Futexes=1995)" AUTO)
|
||||
mark_as_advanced(MDBX_LOCKING)
|
||||
add_mdbx_option(MDBX_TRUST_RTC "Does a system have battery-backed Real-Time Clock or just a fake." AUTO)
|
||||
add_mdbx_option(MDBX_TRUST_RTC "Does a system have battery-backed Real-Time Clock or just a fake" AUTO)
|
||||
mark_as_advanced(MDBX_TRUST_RTC)
|
||||
option(MDBX_FORCE_ASSERTIONS "Force enable assertion checking." OFF)
|
||||
option(MDBX_ENABLE_TESTS "Build MDBX tests." ${BUILD_TESTING})
|
||||
option(MDBX_FORCE_ASSERTIONS "Force enable assertion checking" OFF)
|
||||
|
||||
if(NOT MDBX_AMALGAMATED_SOURCE)
|
||||
add_mdbx_option(MDBX_ALLOY_BUILD "Build MDBX library through single/alloyed object file" ON)
|
||||
option(MDBX_ENABLE_TESTS "Build MDBX tests" ${BUILD_TESTING})
|
||||
endif(NOT MDBX_AMALGAMATED_SOURCE)
|
||||
|
||||
if((MDBX_BUILD_TOOLS OR MDBX_ENABLE_TESTS) AND MDBX_BUILD_SHARED_LIBRARY)
|
||||
add_mdbx_option(MDBX_LINK_TOOLS_NONSTATIC "Link MDBX tools with non-static libmdbx" OFF)
|
||||
else()
|
||||
unset(MDBX_LINK_TOOLS_NONSTATIC CACHE)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
|
||||
add_subdirectory(src)
|
||||
if(MDBX_ENABLE_TESTS)
|
||||
# Get version
|
||||
fetch_version(MDBX "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" FALSE)
|
||||
message(STATUS "libmdbx version is ${MDBX_VERSION}")
|
||||
|
||||
# sources list
|
||||
set(LIBMDBX_SOURCES mdbx.h "${CMAKE_CURRENT_BINARY_DIR}/config.h")
|
||||
if(MDBX_AMALGAMATED_SOURCE)
|
||||
list(APPEND LIBMDBX_SOURCES mdbx.c)
|
||||
else()
|
||||
# generate version file
|
||||
configure_file("${MDBX_SOURCE_DIR}/version.c.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/version.c" ESCAPE_QUOTES)
|
||||
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)
|
||||
list(APPEND LIBMDBX_SOURCES ${MDBX_SOURCE_DIR}/alloy.c)
|
||||
include_directories("${MDBX_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
else()
|
||||
list(APPEND LIBMDBX_SOURCES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/version.c"
|
||||
"${MDBX_SOURCE_DIR}/options.h" "${MDBX_SOURCE_DIR}/defs.h"
|
||||
"${MDBX_SOURCE_DIR}/internals.h" "${MDBX_SOURCE_DIR}/osal.h"
|
||||
"${MDBX_SOURCE_DIR}/core.c" "${MDBX_SOURCE_DIR}/osal.c"
|
||||
"${MDBX_SOURCE_DIR}/lck-posix.c" "${MDBX_SOURCE_DIR}/lck-windows.c")
|
||||
include_directories("${MDBX_SOURCE_DIR}")
|
||||
endif()
|
||||
endif(MDBX_AMALGAMATED_SOURCE)
|
||||
|
||||
macro(target_setup_options TARGET)
|
||||
if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
||||
endif()
|
||||
if(CC_HAS_FASTMATH)
|
||||
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)
|
||||
target_compile_options(${TARGET} PUBLIC "-march=native")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(libmdbx_setup_libs TARGET MODE)
|
||||
target_link_libraries(${TARGET} ${MODE} ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(${TARGET} ${MODE} ntdll.lib)
|
||||
if(MDBX_NTDLL_EXTRA_IMPLIB)
|
||||
target_link_libraries(${TARGET} ${MODE} ntdll_extra)
|
||||
endif()
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Solaris")
|
||||
target_link_libraries(${TARGET} ${MODE} kstat)
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
|
||||
target_link_libraries(${TARGET} ${MODE} log)
|
||||
endif()
|
||||
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()
|
||||
set_target_properties(mdbx-static PROPERTIES
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON
|
||||
PUBLIC_HEADER mdbx.h)
|
||||
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()
|
||||
|
||||
################################################################################
|
||||
|
||||
# build shared library
|
||||
if(MDBX_BUILD_SHARED_LIBRARY)
|
||||
add_library(mdbx SHARED ${LIBMDBX_SOURCES})
|
||||
set_target_properties(mdbx PROPERTIES
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON
|
||||
PUBLIC_HEADER mdbx.h)
|
||||
target_compile_definitions(mdbx PRIVATE LIBMDBX_EXPORTS INTERFACE LIBMDBX_IMPORTS)
|
||||
target_setup_options(mdbx)
|
||||
libmdbx_setup_libs(mdbx PRIVATE)
|
||||
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})
|
||||
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)
|
||||
|
||||
# when building, don't use the install RPATH already (but later on when installing)
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
|
||||
|
||||
# add the automatically determined parts of the RPATH
|
||||
# which point to directories outside the build tree to the install RPATH
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
|
||||
# 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)
|
||||
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()
|
||||
else()
|
||||
set(TOOL_MDBX_LIB mdbx-static)
|
||||
endif()
|
||||
|
||||
# build mdbx-tools
|
||||
if(MDBX_BUILD_TOOLS)
|
||||
if(NOT MDBX_AMALGAMATED_SOURCE AND ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
set(WINGETOPT_SRC ${MDBX_SOURCE_DIR}/wingetopt.c ${MDBX_SOURCE_DIR}/wingetopt.h)
|
||||
else()
|
||||
set(WINGETOPT_SRC "")
|
||||
endif()
|
||||
|
||||
foreach(TOOL mdbx_chk mdbx_copy mdbx_stat mdbx_dump mdbx_load)
|
||||
add_executable(${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/${TOOL}.c ${WINGETOPT_SRC})
|
||||
set_target_properties(${TOOL} PROPERTIES
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
|
||||
target_setup_options(${TOOL})
|
||||
target_link_libraries(${TOOL} ${TOOL_MDBX_LIB})
|
||||
endforeach()
|
||||
if(LIB_MATH)
|
||||
target_link_libraries(mdbx_chk ${LIB_MATH})
|
||||
target_link_libraries(mdbx_stat ${LIB_MATH})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
|
||||
# mdbx-shared-lib installation
|
||||
if(MDBX_BUILD_SHARED_LIBRARY)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
install(TARGETS mdbx EXPORT libmdbx
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT runtime
|
||||
OBJECTS
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include
|
||||
COMPONENT devel
|
||||
INCLUDES
|
||||
DESTINATION include
|
||||
COMPONENT devel)
|
||||
else()
|
||||
install(TARGETS mdbx EXPORT libmdbx
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT runtime
|
||||
NAMELINK_COMPONENT devel
|
||||
OBJECTS
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include
|
||||
COMPONENT devel
|
||||
INCLUDES
|
||||
DESTINATION include
|
||||
COMPONENT devel)
|
||||
endif()
|
||||
endif(MDBX_BUILD_SHARED_LIBRARY)
|
||||
|
||||
# mdbx-tools installation
|
||||
if(MDBX_BUILD_TOOLS)
|
||||
install(
|
||||
TARGETS
|
||||
mdbx_chk
|
||||
mdbx_stat
|
||||
mdbx_copy
|
||||
mdbx_dump
|
||||
mdbx_load
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime)
|
||||
install(
|
||||
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"
|
||||
DESTINATION man/man1
|
||||
COMPONENT doc)
|
||||
endif(MDBX_BUILD_TOOLS)
|
||||
|
||||
# mdbx-static-lib installation
|
||||
if(MDBX_INSTALL_STATIC)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
install(TARGETS mdbx-static EXPORT libmdbx
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT runtime
|
||||
OBJECTS
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include
|
||||
COMPONENT devel
|
||||
INCLUDES
|
||||
DESTINATION include
|
||||
COMPONENT devel)
|
||||
else()
|
||||
install(TARGETS mdbx-static EXPORT libmdbx
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT runtime
|
||||
NAMELINK_COMPONENT devel
|
||||
OBJECTS
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include
|
||||
COMPONENT devel
|
||||
INCLUDES
|
||||
DESTINATION include
|
||||
COMPONENT devel)
|
||||
endif()
|
||||
endif(MDBX_INSTALL_STATIC)
|
||||
|
||||
################################################################################
|
||||
|
||||
# collect options & build info
|
||||
string(TIMESTAMP MDBX_BUILD_TIMESTAMP UTC)
|
||||
set(MDBX_BUILD_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
# 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}})
|
||||
endif()
|
||||
|
||||
# get definitions
|
||||
get_target_property(defs_list mdbx-static COMPILE_DEFINITIONS)
|
||||
if(defs_list)
|
||||
list(APPEND MDBX_BUILD_FLAGS ${defs_list})
|
||||
endif()
|
||||
|
||||
# get target compile options
|
||||
get_target_property(options_list mdbx-static COMPILE_OPTIONS)
|
||||
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
|
||||
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}>")
|
||||
else()
|
||||
message(STATUS "MDBX Compile Flags: ${MDBX_BUILD_FLAGS}")
|
||||
endif()
|
||||
|
||||
# get compiler info
|
||||
execute_process(COMMAND sh -c "${CMAKE_C_COMPILER} --version | head -1"
|
||||
OUTPUT_VARIABLE MDBX_BUILD_COMPILER
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE rc)
|
||||
if(rc OR NOT MDBX_BUILD_COMPILER)
|
||||
string(STRIP "${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}" MDBX_BUILD_COMPILER)
|
||||
endif()
|
||||
|
||||
# make a build-target triplet
|
||||
if(CMAKE_C_COMPILER_TARGET)
|
||||
set(MDBX_BUILD_TARGET "${CMAKE_C_COMPILER_TARGET}")
|
||||
elseif(CMAKE_C_PLATFORM_ID AND NOT CMAKE_C_PLATFORM_ID STREQUAL CMAKE_SYSTEM_NAME)
|
||||
string(STRIP "${CMAKE_C_PLATFORM_ID}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
elseif(CMAKE_LIBRARY_ARCHITECTURE)
|
||||
string(STRIP "${CMAKE_LIBRARY_ARCHITECTURE}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
elseif(CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_C_PLATFORM_ID STREQUAL CMAKE_SYSTEM_NAME)
|
||||
string(STRIP "${CMAKE_GENERATOR_PLATFORM}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
elseif(CMAKE_SYSTEM_ARCH)
|
||||
string(STRIP "${CMAKE_SYSTEM_ARCH}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
else()
|
||||
string(STRIP "${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
endif()
|
||||
|
||||
# provide build-type
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
add_definitions(-DMDBX_BUILD_TYPE="$<CONFIG>")
|
||||
else()
|
||||
set(MDBX_BUILD_TYPE ${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
|
||||
# options
|
||||
set(options VERSION C_COMPILER CXX_COMPILER)
|
||||
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()
|
||||
set(value "undefined")
|
||||
endif()
|
||||
message(STATUS "${item}: ${value}")
|
||||
endforeach(item)
|
||||
|
||||
# provide config.h for library build info
|
||||
configure_file("${MDBX_SOURCE_DIR}/config.h.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/config.h" ESCAPE_QUOTES)
|
||||
add_definitions(-DMDBX_CONFIG_H="${CMAKE_CURRENT_BINARY_DIR}/config.h")
|
||||
|
||||
################################################################################
|
||||
|
||||
if(NOT MDBX_AMALGAMATED_SOURCE AND MDBX_ENABLE_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
|
74
GNUmakefile
74
GNUmakefile
@ -62,7 +62,7 @@ strip: all
|
||||
clean:
|
||||
rm -rf $(TOOLS) mdbx_test @* *.[ao] *.[ls]o *~ tmp.db/* \
|
||||
*.gcov *.log *.err src/*.o test/*.o mdbx_example dist \
|
||||
config.h src/elements/config.h src/elements/version.c *.tar*
|
||||
config.h src/config.h src/version.c *.tar*
|
||||
|
||||
libmdbx.a: mdbx-static.o
|
||||
$(AR) rs $@ $?
|
||||
@ -113,7 +113,8 @@ define uname2titer
|
||||
esac
|
||||
endef
|
||||
|
||||
DIST_EXTRA := LICENSE README.md CMakeLists.txt GNUmakefile Makefile $(addprefix man1/, $(MANPAGES))
|
||||
DIST_EXTRA := LICENSE README.md CMakeLists.txt GNUmakefile Makefile VERSION config.h.in \
|
||||
$(addprefix man1/, $(MANPAGES)) cmake/compiler.cmake cmake/profile.cmake cmake/utils.cmake
|
||||
DIST_SRC := mdbx.h mdbx.c $(addsuffix .c, $(TOOLS))
|
||||
|
||||
TEST_DB ?= $(shell [ -d /dev/shm ] && echo /dev/shm || echo /tmp)/mdbx-test.db
|
||||
@ -129,12 +130,13 @@ CXXFLAGS := $(CXXSTD) $(filter-out -std=gnu11,$(CFLAGS))
|
||||
TAR ?= $(shell which gnu-tar || echo tar)
|
||||
|
||||
MAN_SRCDIR := src/man1/
|
||||
ALLOY_DEPS := $(wildcard src/elements/*)
|
||||
ALLOY_DEPS := $(wildcard src/*)
|
||||
MDBX_VERSION_GIT = ${shell set -o pipefail; git describe --tags | sed -n 's|^v*\([0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\)\(.*\)|\1|p' || echo 'Please fetch tags and/or install latest git version'}
|
||||
MDBX_REVISION_GIT = $(shell git rev-list --count --no-merges HEAD || echo 'Please fetch tags and/or install latest git version')
|
||||
MDBX_GIT_TIMESTAMP = $(shell git show --no-patch --format=%cI HEAD || echo 'Please install latest get version')
|
||||
MDBX_GIT_DESCRIBE = $(shell git describe --tags --long --dirty=-dirty || echo 'Please fetch tags and/or install latest git version')
|
||||
MDBX_VERSION_SUFFIX = $(shell set -o pipefail; echo -n '$(MDBX_GIT_DESCRIBE)' | tr -c -s '[a-zA-Z0-9]' _)
|
||||
MDBX_BUILD_SOURCERY = $(shell set -o pipefail; $(MAKE) -s src/elements/version.c && (openssl dgst -r -sha256 src/elements/version.c || sha256sum src/elements/version.c || shasum -a 256 src/elements/version.c) 2>/dev/null | cut -d ' ' -f 1 || echo 'Please install openssl or sha256sum or shasum')_$(MDBX_VERSION_SUFFIX)
|
||||
MDBX_BUILD_SOURCERY = $(shell set -o pipefail; $(MAKE) -s src/version.c && (openssl dgst -r -sha256 src/version.c || sha256sum src/version.c || shasum -a 256 src/version.c) 2>/dev/null | cut -d ' ' -f 1 || echo 'Please install openssl or sha256sum or shasum')_$(MDBX_VERSION_SUFFIX)
|
||||
|
||||
check: test mdbx_example dist
|
||||
|
||||
@ -177,7 +179,7 @@ $(patsubst %.cc,%.o,$(1)): $(1) $(TEST_INC) mdbx.h $(lastword $(MAKEFILE_LIST))
|
||||
endef
|
||||
$(foreach file,$(TEST_SRC),$(eval $(call test-rule,$(file))))
|
||||
|
||||
mdbx_%: src/tools/mdbx_%.c libmdbx.a
|
||||
mdbx_%: src/mdbx_%.c libmdbx.a
|
||||
$(CC) $(CFLAGS) $(MDBX_OPTIONS) '-DMDBX_CONFIG_H="config.h"' $^ $(EXE_LDFLAGS) $(LIBS) -o $@
|
||||
|
||||
mdbx_test: $(TEST_OBJ) libmdbx.$(SO_SUFFIX)
|
||||
@ -185,7 +187,7 @@ mdbx_test: $(TEST_OBJ) libmdbx.$(SO_SUFFIX)
|
||||
|
||||
git_DIR := $(shell if [ -d .git ]; then echo .git; elif [ -s .git -a -f .git ]; then grep '^gitdir: ' .git | cut -d ':' -f 2; else echo "Please use libmdbx as a git-submodule or the amalgamated source code" >&2 && echo git_directory; fi)
|
||||
|
||||
src/elements/version.c: src/elements/version.c.in $(lastword $(MAKEFILE_LIST)) $(git_DIR)/HEAD $(git_DIR)/index $(git_DIR)/refs/tags
|
||||
src/version.c: src/version.c.in $(lastword $(MAKEFILE_LIST)) $(git_DIR)/HEAD $(git_DIR)/index $(git_DIR)/refs/tags
|
||||
sed \
|
||||
-e "s|@MDBX_GIT_TIMESTAMP@|$(MDBX_GIT_TIMESTAMP)|" \
|
||||
-e "s|@MDBX_GIT_TREE@|$(shell git show --no-patch --format=%T HEAD || echo 'Please install latest get version')|" \
|
||||
@ -194,10 +196,10 @@ src/elements/version.c: src/elements/version.c.in $(lastword $(MAKEFILE_LIST)) $
|
||||
-e "s|\$${MDBX_VERSION_MAJOR}|$(shell echo '$(MDBX_VERSION_GIT)' | cut -d . -f 1)|" \
|
||||
-e "s|\$${MDBX_VERSION_MINOR}|$(shell echo '$(MDBX_VERSION_GIT)' | cut -d . -f 2)|" \
|
||||
-e "s|\$${MDBX_VERSION_RELEASE}|$(shell echo '$(MDBX_VERSION_GIT)' | cut -d . -f 3)|" \
|
||||
-e "s|\$${MDBX_VERSION_REVISION}|$(shell git rev-list --count --no-merges HEAD || echo 'Please fetch tags and/or install latest git version')|" \
|
||||
src/elements/version.c.in > $@
|
||||
-e "s|\$${MDBX_VERSION_REVISION}|$(MDBX_REVISION_GIT)|" \
|
||||
src/version.c.in > $@
|
||||
|
||||
src/elements/config.h: src/elements/version.c $(lastword $(MAKEFILE_LIST))
|
||||
src/config.h: src/version.c $(lastword $(MAKEFILE_LIST))
|
||||
(echo '#define MDBX_BUILD_TIMESTAMP "$(shell date +%Y-%m-%dT%H:%M:%S%z)"' \
|
||||
&& echo '#define MDBX_BUILD_FLAGS "$(CFLAGS) $(LDFLAGS) $(LIBS)"' \
|
||||
&& echo '#define MDBX_BUILD_COMPILER "$(shell set -o pipefail; $(CC) --version | head -1 || echo 'Please use GCC or CLANG compatible compiler')"' \
|
||||
@ -205,10 +207,10 @@ src/elements/config.h: src/elements/version.c $(lastword $(MAKEFILE_LIST))
|
||||
&& echo '#define MDBX_BUILD_SOURCERY $(MDBX_BUILD_SOURCERY)' \
|
||||
) > $@
|
||||
|
||||
mdbx-dylib.o: src/elements/config.h src/elements/version.c src/alloy.c $(ALLOY_DEPS) $(lastword $(MAKEFILE_LIST))
|
||||
mdbx-dylib.o: src/config.h src/version.c src/alloy.c $(ALLOY_DEPS) $(lastword $(MAKEFILE_LIST))
|
||||
$(CC) $(CFLAGS) $(MDBX_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -DLIBMDBX_EXPORTS=1 -c src/alloy.c -o $@
|
||||
|
||||
mdbx-static.o: src/elements/config.h src/elements/version.c src/alloy.c $(ALLOY_DEPS) $(lastword $(MAKEFILE_LIST))
|
||||
mdbx-static.o: src/config.h src/version.c src/alloy.c $(ALLOY_DEPS) $(lastword $(MAKEFILE_LIST))
|
||||
$(CC) $(CFLAGS) $(MDBX_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -ULIBMDBX_EXPORTS -c src/alloy.c -o $@
|
||||
|
||||
.PHONY: dist
|
||||
@ -218,50 +220,52 @@ libmdbx-sources-$(MDBX_VERSION_SUFFIX).tar.gz: $(addprefix dist/, $(DIST_SRC) $(
|
||||
$(TAR) -c $(shell LC_ALL=C $(TAR) --help | grep -q -- '--owner' && echo '--owner=0 --group=0') -f - -C dist $(DIST_SRC) $(DIST_EXTRA) | gzip -c > $@ \
|
||||
&& rm dist/@tmp-shared_internals.inc
|
||||
|
||||
dist/mdbx.h: mdbx.h src/elements/version.c $(lastword $(MAKEFILE_LIST))
|
||||
dist/mdbx.h: mdbx.h src/version.c $(lastword $(MAKEFILE_LIST))
|
||||
mkdir -p dist && cp $< $@
|
||||
|
||||
dist/Makefile: Makefile
|
||||
mkdir -p dist && cp $< $@
|
||||
|
||||
dist/GNUmakefile: GNUmakefile
|
||||
mkdir -p dist && sed -e '/^#> dist-cutoff-begin/,/^#< dist-cutoff-end/d' $< > $@
|
||||
|
||||
dist/@tmp-shared_internals.inc: src/elements/version.c $(ALLOY_DEPS) $(lastword $(MAKEFILE_LIST))
|
||||
dist/@tmp-shared_internals.inc: src/version.c $(ALLOY_DEPS) $(lastword $(MAKEFILE_LIST))
|
||||
mkdir -p dist && sed \
|
||||
-e 's|#pragma once|#define MDBX_ALLOY 1\n#define MDBX_BUILD_SOURCERY $(MDBX_BUILD_SOURCERY)|' \
|
||||
-e 's|#include "../../mdbx.h"|@INCLUDE "mdbx.h"|' \
|
||||
-e '/#include "defs.h"/r src/elements/defs.h' \
|
||||
-e '/#include "osal.h"/r src/elements/osal.h' \
|
||||
-e '/#include "options.h"/r src/elements/options.h' \
|
||||
src/elements/internals.h > $@
|
||||
-e 's|#include "../mdbx.h"|@INCLUDE "mdbx.h"|' \
|
||||
-e '/#include "defs.h"/r src/defs.h' \
|
||||
-e '/#include "osal.h"/r src/osal.h' \
|
||||
-e '/#include "options.h"/r src/options.h' \
|
||||
src/internals.h > $@
|
||||
|
||||
dist/mdbx.c: dist/@tmp-shared_internals.inc $(lastword $(MAKEFILE_LIST))
|
||||
mkdir -p dist && (cat dist/@tmp-shared_internals.inc \
|
||||
&& cat src/elements/core.c src/elements/osal.c src/elements/version.c src/elements/lck-windows.c src/elements/lck-posix.c \
|
||||
&& cat src/core.c src/osal.c src/version.c src/lck-windows.c src/lck-posix.c \
|
||||
) | grep -v -e '#include "' -e '#pragma once' | sed 's|@INCLUDE|#include|' > $@
|
||||
|
||||
define dist-tool-rule
|
||||
dist/$(1).c: src/tools/$(1).c src/tools/wingetopt.h src/tools/wingetopt.c \
|
||||
dist/$(1).c: src/$(1).c src/wingetopt.h src/wingetopt.c \
|
||||
dist/@tmp-shared_internals.inc $(lastword $(MAKEFILE_LIST))
|
||||
mkdir -p dist && sed \
|
||||
-e '/#include "..\/elements\/internals.h"/r dist/@tmp-shared_internals.inc' \
|
||||
-e '/#include "wingetopt.h"/r src/tools/wingetopt.c' \
|
||||
src/tools/$(1).c \
|
||||
-e '/#include "internals.h"/r dist/@tmp-shared_internals.inc' \
|
||||
-e '/#include "wingetopt.h"/r src/wingetopt.c' \
|
||||
src/$(1).c \
|
||||
| grep -v -e '#include "' -e '#pragma once' -e '#define MDBX_ALLOY' \
|
||||
| sed 's|@INCLUDE|#include|' > $$@
|
||||
|
||||
endef
|
||||
$(foreach file,$(TOOLS),$(eval $(call dist-tool-rule,$(file))))
|
||||
|
||||
define dist-extra-rule
|
||||
dist/$(1): $(1)
|
||||
mkdir -p $$(dir $$@) && sed -e '/^#> dist-cutoff-begin/,/^#< dist-cutoff-end/d' $$< > $$@
|
||||
|
||||
endef
|
||||
$(foreach file,$(filter-out man1/% VERSION %.in,$(DIST_EXTRA)),$(eval $(call dist-extra-rule,$(file))))
|
||||
|
||||
dist/VERSION: src/version.c
|
||||
mkdir -p dist/ && echo "$(MDBX_VERSION_GIT).$(MDBX_REVISION_GIT)" > $@
|
||||
|
||||
dist/config.h.in: src/config.h.in
|
||||
mkdir -p dist/cmake/ && cp $< $@
|
||||
|
||||
dist/man1/mdbx_%.1: src/man1/mdbx_%.1
|
||||
mkdir -p dist/man1/ && cp $< $@
|
||||
dist/LICENSE: LICENSE
|
||||
mkdir -p dist/man1/ && cp $< $@
|
||||
dist/README.md: README.md
|
||||
mkdir -p dist/man1/ && cp $< $@
|
||||
dist/CMakeLists.txt: CMakeLists.dist-minimal
|
||||
mkdir -p dist/man1/ && cp $< $@
|
||||
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
|
@ -26,8 +26,6 @@ if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
|
||||
message(FATAL_ERROR "This module required C or C++ to be enabled")
|
||||
endif()
|
||||
|
||||
include(CMakeDependentOption)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_LOADED)
|
||||
include(CheckCXXSourceRuns)
|
||||
include(CheckCXXSourceCompiles)
|
||||
@ -38,6 +36,9 @@ if(CMAKE_C_COMPILER_LOADED)
|
||||
include(CheckCSourceCompiles)
|
||||
include(CheckCCompilerFlag)
|
||||
endif()
|
||||
include(CMakeDependentOption)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckIncludeFiles)
|
||||
|
||||
# Check if the same compile family is used for both C and CXX
|
||||
if(CMAKE_C_COMPILER_LOADED AND CMAKE_CXX_COMPILER_LOADED AND
|
||||
@ -439,7 +440,7 @@ if(ENABLE_BACKTRACE)
|
||||
endif()
|
||||
|
||||
macro(setup_compile_flags)
|
||||
# LY: save initial C/CXX flags
|
||||
# save initial C/CXX flags
|
||||
if(NOT INITIAL_CMAKE_FLAGS_SAVED)
|
||||
if(MSVC)
|
||||
string(REGEX REPLACE "^(.*)(/EHsc)( *)(.*)$" "\\1/EHs\\3\\4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
@ -453,7 +454,7 @@ macro(setup_compile_flags)
|
||||
set(INITIAL_CMAKE_FLAGS_SAVED TRUE CACHE INTERNAL "State of initial CMake's flags" FORCE)
|
||||
endif()
|
||||
|
||||
# LY: reset C/CXX flags
|
||||
# reset C/CXX flags
|
||||
set(CXX_FLAGS ${INITIAL_CMAKE_CXX_FLAGS})
|
||||
set(C_FLAGS ${INITIAL_CMAKE_C_FLAGS})
|
||||
set(EXE_LINKER_FLAGS ${INITIAL_CMAKE_EXE_LINKER_FLAGS})
|
||||
@ -661,7 +662,7 @@ macro(setup_compile_flags)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# LY: push C/CXX flags into the cache
|
||||
# push C/CXX flags into the cache
|
||||
set(CMAKE_CXX_FLAGS ${CXX_FLAGS} CACHE STRING "Flags used by the C++ compiler during all build types" FORCE)
|
||||
set(CMAKE_C_FLAGS ${C_FLAGS} CACHE STRING "Flags used by the C compiler during all build types" FORCE)
|
||||
set(CMAKE_EXE_LINKER_FLAGS ${EXE_LINKER_FLAGS} CACHE STRING "Flags used by the linker" FORCE)
|
||||
|
@ -61,7 +61,7 @@ macro(set_source_files_compile_flags)
|
||||
unset(_lang)
|
||||
endmacro(set_source_files_compile_flags)
|
||||
|
||||
macro(fetch_version name version_file)
|
||||
macro(fetch_version name version_file parent_scope)
|
||||
set(${name}_VERSION "")
|
||||
set(${name}_GIT_DESCRIBE "")
|
||||
set(${name}_GIT_TIMESTAMP "")
|
||||
@ -69,7 +69,7 @@ macro(fetch_version name version_file)
|
||||
set(${name}_GIT_COMMIT "")
|
||||
set(${name}_GIT_REVISION 0)
|
||||
set(${name}_GIT_VERSION "")
|
||||
if(GIT)
|
||||
if(GIT AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
execute_process(COMMAND ${GIT} describe --tags --long --dirty=-dirty
|
||||
OUTPUT_VARIABLE ${name}_GIT_DESCRIBE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
@ -137,7 +137,9 @@ macro(fetch_version name version_file)
|
||||
endif()
|
||||
|
||||
if(NOT ${name}_GIT_VERSION OR NOT ${name}_GIT_TIMESTAMP OR NOT ${name}_GIT_REVISION)
|
||||
message(WARNING "Unable to retrive ${name} version from git.")
|
||||
if(GIT AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
message(WARNING "Unable to retrive ${name} version from git.")
|
||||
endif()
|
||||
set(${name}_GIT_VERSION "0;0;0;0")
|
||||
set(${name}_GIT_TIMESTAMP "")
|
||||
set(${name}_GIT_REVISION 0)
|
||||
@ -166,18 +168,33 @@ macro(fetch_version name version_file)
|
||||
list(GET ${name}_VERSION_LIST 2 "${name}_VERSION_RELEASE")
|
||||
list(GET ${name}_VERSION_LIST 3 "${name}_VERSION_REVISION")
|
||||
|
||||
set(${name}_VERSION_MAJOR ${${name}_VERSION_MAJOR} PARENT_SCOPE)
|
||||
set(${name}_VERSION_MINOR ${${name}_VERSION_MINOR} PARENT_SCOPE)
|
||||
set(${name}_VERSION_RELEASE ${${name}_VERSION_RELEASE} PARENT_SCOPE)
|
||||
set(${name}_VERSION_REVISION ${${name}_VERSION_REVISION} PARENT_SCOPE)
|
||||
set(${name}_VERSION ${${name}_VERSION} PARENT_SCOPE)
|
||||
if(parent_scope)
|
||||
set(${name}_VERSION_MAJOR ${${name}_VERSION_MAJOR} PARENT_SCOPE)
|
||||
set(${name}_VERSION_MINOR ${${name}_VERSION_MINOR} PARENT_SCOPE)
|
||||
set(${name}_VERSION_RELEASE ${${name}_VERSION_RELEASE} PARENT_SCOPE)
|
||||
set(${name}_VERSION_REVISION ${${name}_VERSION_REVISION} PARENT_SCOPE)
|
||||
set(${name}_VERSION ${${name}_VERSION} PARENT_SCOPE)
|
||||
|
||||
set(${name}_GIT_DESCRIBE ${${name}_GIT_DESCRIBE} PARENT_SCOPE)
|
||||
set(${name}_GIT_TIMESTAMP ${${name}_GIT_TIMESTAMP} PARENT_SCOPE)
|
||||
set(${name}_GIT_TREE ${${name}_GIT_TREE} PARENT_SCOPE)
|
||||
set(${name}_GIT_COMMIT ${${name}_GIT_COMMIT} PARENT_SCOPE)
|
||||
set(${name}_GIT_REVISION ${${name}_GIT_REVISION} PARENT_SCOPE)
|
||||
set(${name}_GIT_VERSION ${${name}_GIT_VERSION} PARENT_SCOPE)
|
||||
set(${name}_GIT_DESCRIBE ${${name}_GIT_DESCRIBE} PARENT_SCOPE)
|
||||
set(${name}_GIT_TIMESTAMP ${${name}_GIT_TIMESTAMP} PARENT_SCOPE)
|
||||
set(${name}_GIT_TREE ${${name}_GIT_TREE} PARENT_SCOPE)
|
||||
set(${name}_GIT_COMMIT ${${name}_GIT_COMMIT} PARENT_SCOPE)
|
||||
set(${name}_GIT_REVISION ${${name}_GIT_REVISION} PARENT_SCOPE)
|
||||
set(${name}_GIT_VERSION ${${name}_GIT_VERSION} PARENT_SCOPE)
|
||||
else()
|
||||
set(${name}_VERSION_MAJOR ${${name}_VERSION_MAJOR})
|
||||
set(${name}_VERSION_MINOR ${${name}_VERSION_MINOR})
|
||||
set(${name}_VERSION_RELEASE ${${name}_VERSION_RELEASE})
|
||||
set(${name}_VERSION_REVISION ${${name}_VERSION_REVISION})
|
||||
set(${name}_VERSION ${${name}_VERSION})
|
||||
|
||||
set(${name}_GIT_DESCRIBE ${${name}_GIT_DESCRIBE})
|
||||
set(${name}_GIT_TIMESTAMP ${${name}_GIT_TIMESTAMP})
|
||||
set(${name}_GIT_TREE ${${name}_GIT_TREE})
|
||||
set(${name}_GIT_COMMIT ${${name}_GIT_COMMIT})
|
||||
set(${name}_GIT_REVISION ${${name}_GIT_REVISION})
|
||||
set(${name}_GIT_VERSION ${${name}_GIT_VERSION})
|
||||
endif()
|
||||
endmacro(fetch_version)
|
||||
|
||||
cmake_policy(POP)
|
||||
|
@ -1,269 +0,0 @@
|
||||
##
|
||||
## Copyright 2020 Leonid Yuriev <leo@yuriev.ru>
|
||||
## and other libmdbx authors: please see AUTHORS file.
|
||||
## All rights reserved.
|
||||
##
|
||||
## Redistribution and use in source and binary forms, with or without
|
||||
## modification, are permitted only as authorized by the OpenLDAP
|
||||
## Public License.
|
||||
##
|
||||
## A copy of this license is available in the file LICENSE in the
|
||||
## top-level directory of the distribution or, alternatively, at
|
||||
## <http://www.OpenLDAP.org/license.html>.
|
||||
##
|
||||
|
||||
# Get version
|
||||
fetch_version(MDBX "${CMAKE_CURRENT_SOURCE_DIR}/../VERSION")
|
||||
message(STATUS "libmdbx version is ${MDBX_VERSION}")
|
||||
|
||||
if(MDBX_ALLOY_MODE)
|
||||
set(LIBMDBX_SOURCES alloy.c)
|
||||
else()
|
||||
set(LIBMDBX_SOURCES
|
||||
elements/options.h elements/defs.h elements/internals.h elements/osal.h
|
||||
elements/core.c elements/osal.c elements/lck-posix.c elements/lck-windows.c)
|
||||
endif()
|
||||
list(APPEND LIBMDBX_SOURCES ../mdbx.h
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/elements/version.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/elements/config.h")
|
||||
|
||||
if(MDBX_BUILD_SHARED_LIBRARY)
|
||||
add_library(mdbx SHARED ${LIBMDBX_SOURCES})
|
||||
target_compile_definitions(mdbx PRIVATE LIBMDBX_EXPORTS INTERFACE LIBMDBX_IMPORTS)
|
||||
set(MDBX_LIBDEP_MODE PRIVATE)
|
||||
else()
|
||||
add_library(mdbx STATIC ${LIBMDBX_SOURCES})
|
||||
set(MDBX_LIBDEP_MODE PUBLIC)
|
||||
endif()
|
||||
|
||||
if(CC_HAS_VISIBILITY AND (LTO_ENABLED OR INTERPROCEDURAL_OPTIMIZATION))
|
||||
set_target_properties(mdbx PROPERTIES LINK_FLAGS "-fvisibility=hidden")
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
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}")
|
||||
set(MDBX_NTDLL_EXTRA_IMPLIB ${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.lib)
|
||||
add_custom_command(OUTPUT ${MDBX_NTDLL_EXTRA_IMPLIB}
|
||||
COMMENT "Create extra-import-library for ntdll.dll"
|
||||
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/elements/ntdll.def"
|
||||
COMMAND ${MSVC_LIB_EXE} /def:"${CMAKE_CURRENT_SOURCE_DIR}/elements/ntdll.def" /out:"${MDBX_NTDLL_EXTRA_IMPLIB}" ${INITIAL_CMAKE_STATIC_LINKER_FLAGS})
|
||||
else()
|
||||
message(SEND_ERROR "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}")
|
||||
set(MDBX_NTDLL_EXTRA_IMPLIB "${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.a")
|
||||
add_custom_command(OUTPUT ${MDBX_NTDLL_EXTRA_IMPLIB}
|
||||
COMMENT "Create extra-import-library for ntdll.dll"
|
||||
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/elements/ntdll.def"
|
||||
COMMAND ${DLLTOOL} -d "${CMAKE_CURRENT_SOURCE_DIR}/elements/ntdll.def" -l "${MDBX_NTDLL_EXTRA_IMPLIB}")
|
||||
else()
|
||||
message(SEND_ERROR "dlltool not found")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_link_libraries(mdbx ${MDBX_LIBDEP_MODE} ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(mdbx ${MDBX_LIBDEP_MODE} ntdll.lib)
|
||||
if(MDBX_NTDLL_EXTRA_IMPLIB)
|
||||
# LY: Sometimes Cmake requires a nightmarish magic for simple things.
|
||||
# 1) create a target out of the library compilation result
|
||||
add_custom_target(ntdll_extra_target DEPENDS ${MDBX_NTDLL_EXTRA_IMPLIB})
|
||||
# 2) create an library target out of the library compilation result
|
||||
add_library(ntdll_extra STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(ntdll_extra ntdll_extra_target)
|
||||
# 3) specify where the library is (and where to find the headers)
|
||||
set_target_properties(ntdll_extra
|
||||
PROPERTIES
|
||||
IMPORTED_LOCATION ${MDBX_NTDLL_EXTRA_IMPLIB})
|
||||
target_link_libraries(mdbx ${MDBX_LIBDEP_MODE} ntdll_extra)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Solaris")
|
||||
target_link_libraries(mdbx ${MDBX_LIBDEP_MODE} kstat)
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
|
||||
target_link_libraries(mdbx ${MDBX_LIBDEP_MODE} log)
|
||||
endif()
|
||||
|
||||
set_target_properties(mdbx PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON
|
||||
PUBLIC_HEADER "../mdbx.h")
|
||||
|
||||
if(CC_HAS_FASTMATH)
|
||||
target_compile_options(mdbx PRIVATE "-ffast-math")
|
||||
endif()
|
||||
if(BUILD_FOR_NATIVE_CPU AND CC_HAS_ARCH_NATIVE)
|
||||
target_compile_options(mdbx PUBLIC "-march=native")
|
||||
endif()
|
||||
if(CC_HAS_VISIBILITY)
|
||||
target_compile_options(mdbx PRIVATE "-fvisibility=hidden")
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# library build info (used in library version output)
|
||||
#
|
||||
set(MDBX_BUILD_FLAGS "")
|
||||
|
||||
# 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}})
|
||||
list(APPEND MDBX_BUILD_FLAGS ${CMAKE_C_DEFINES_${CMAKE_BUILD_TYPE_UPPERCASE}})
|
||||
endif()
|
||||
|
||||
# append linker dll's options
|
||||
if(LIBMDBX_TYPE STREQUAL "SHARED")
|
||||
list(APPEND MDBX_BUILD_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
|
||||
endif()
|
||||
|
||||
# get definitions
|
||||
get_target_property(defs_list mdbx COMPILE_DEFINITIONS)
|
||||
if(defs_list)
|
||||
list(APPEND MDBX_BUILD_FLAGS ${defs_list})
|
||||
endif()
|
||||
|
||||
# get target compile options
|
||||
get_target_property(options_list mdbx COMPILE_OPTIONS)
|
||||
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
|
||||
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}>")
|
||||
else()
|
||||
message(STATUS "MDBX Compile Flags: ${MDBX_BUILD_FLAGS}")
|
||||
endif()
|
||||
|
||||
# get compiler info
|
||||
execute_process(COMMAND sh -c "${CMAKE_C_COMPILER} --version | head -1"
|
||||
OUTPUT_VARIABLE MDBX_BUILD_COMPILER
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE rc)
|
||||
if(rc OR NOT MDBX_BUILD_COMPILER)
|
||||
string(STRIP "${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}" MDBX_BUILD_COMPILER)
|
||||
endif()
|
||||
|
||||
# make a build-target triplet
|
||||
if(CMAKE_C_COMPILER_TARGET)
|
||||
set(MDBX_BUILD_TARGET "${CMAKE_C_COMPILER_TARGET}")
|
||||
elseif(CMAKE_C_PLATFORM_ID AND NOT CMAKE_C_PLATFORM_ID STREQUAL CMAKE_SYSTEM_NAME)
|
||||
string(STRIP "${CMAKE_C_PLATFORM_ID}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
elseif(CMAKE_LIBRARY_ARCHITECTURE)
|
||||
string(STRIP "${CMAKE_LIBRARY_ARCHITECTURE}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
elseif(CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_C_PLATFORM_ID STREQUAL CMAKE_SYSTEM_NAME)
|
||||
string(STRIP "${CMAKE_GENERATOR_PLATFORM}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
elseif(CMAKE_SYSTEM_ARCH)
|
||||
string(STRIP "${CMAKE_SYSTEM_ARCH}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
else()
|
||||
string(STRIP "${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}" MDBX_BUILD_TARGET)
|
||||
endif()
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
add_definitions(-DMDBX_BUILD_CONFIG="$<CONFIG>")
|
||||
else()
|
||||
set(MDBX_BUILD_CONFIG ${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
|
||||
# options
|
||||
string(TIMESTAMP MDBX_BUILD_TIMESTAMP UTC)
|
||||
set(options VERSION C_COMPILER CXX_COMPILER)
|
||||
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()
|
||||
set(value "undefined")
|
||||
endif()
|
||||
message(STATUS "${item}: ${value}")
|
||||
endforeach(item)
|
||||
|
||||
# generate version and config files
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/elements/version.c.in"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/elements/version.c" ESCAPE_QUOTES)
|
||||
|
||||
file(SHA256 "${CMAKE_CURRENT_SOURCE_DIR}/elements/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}")
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/elements/config.h.in"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/elements/config.h" ESCAPE_QUOTES)
|
||||
add_definitions(-DMDBX_CONFIG_H="config.h")
|
||||
|
||||
# installation
|
||||
if(MDBX_BUILD_SHARED_LIBRARY)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
install(TARGETS mdbx EXPORT libmdbx
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT runtime
|
||||
OBJECTS
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include
|
||||
COMPONENT devel
|
||||
INCLUDES
|
||||
DESTINATION include
|
||||
COMPONENT devel)
|
||||
else()
|
||||
install(TARGETS mdbx EXPORT libmdbx
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT runtime
|
||||
NAMELINK_COMPONENT devel
|
||||
OBJECTS
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT devel
|
||||
PUBLIC_HEADER
|
||||
DESTINATION include
|
||||
COMPONENT devel
|
||||
INCLUDES
|
||||
DESTINATION include
|
||||
COMPONENT devel)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MDBX_BUILD_TOOLS)
|
||||
add_subdirectory(tools)
|
||||
endif()
|
14
src/alloy.c
14
src/alloy.c
@ -11,15 +11,15 @@
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>. */
|
||||
|
||||
#define MDBX_ALLOY 1 /* amalgamated build */
|
||||
#include "elements/internals.h" /* must be included first */
|
||||
#define MDBX_ALLOY 1 /* alloyed build */
|
||||
#include "internals.h" /* must be included first */
|
||||
|
||||
#include "elements/core.c"
|
||||
#include "elements/osal.c"
|
||||
#include "elements/version.c"
|
||||
#include "core.c"
|
||||
#include "osal.c"
|
||||
#include "version.c"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include "elements/lck-windows.c"
|
||||
#include "lck-windows.c"
|
||||
#else
|
||||
#include "elements/lck-posix.c"
|
||||
#include "lck-posix.c"
|
||||
#endif
|
||||
|
@ -4,9 +4,6 @@
|
||||
/* *INDENT-OFF* */
|
||||
/* clang-format off */
|
||||
|
||||
#cmakedefine HAVE_VALGRIND_MEMCHECK_H
|
||||
#cmakedefine HAS_RELAXED_CONSTEXPR
|
||||
|
||||
#cmakedefine LTO_ENABLED
|
||||
#cmakedefine MDBX_USE_VALGRIND
|
||||
#cmakedefine ENABLE_GPROF
|
||||
@ -34,7 +31,7 @@
|
||||
#cmakedefine01 MDBX_CONFIG_MANUAL_TLS_CALLBACK
|
||||
#cmakedefine01 MDBX_AVOID_CRT
|
||||
|
||||
/* MacOS */
|
||||
/* MacOS & iOS */
|
||||
#cmakedefine01 MDBX_OSX_SPEED_INSTEADOF_DURABILITY
|
||||
|
||||
/* POSIX */
|
||||
@ -47,7 +44,7 @@
|
||||
/* Build Info */
|
||||
#cmakedefine MDBX_BUILD_TIMESTAMP "@MDBX_BUILD_TIMESTAMP@"
|
||||
#cmakedefine MDBX_BUILD_TARGET "@MDBX_BUILD_TARGET@"
|
||||
#cmakedefine MDBX_BUILD_CONFIG "@MDBX_BUILD_CONFIG@"
|
||||
#cmakedefine MDBX_BUILD_TYPE "@MDBX_BUILD_TYPE@"
|
||||
#cmakedefine MDBX_BUILD_COMPILER "@MDBX_BUILD_COMPILER@"
|
||||
#cmakedefine MDBX_BUILD_FLAGS "@MDBX_BUILD_FLAGS@"
|
||||
#cmakedefine MDBX_BUILD_SOURCERY @MDBX_BUILD_SOURCERY@
|
@ -18181,12 +18181,12 @@ __dll_export
|
||||
#endif
|
||||
#endif /* MDBX_BUILD_TARGET */
|
||||
|
||||
#ifdef MDBX_BUILD_CONFIG
|
||||
#ifdef MDBX_BUILD_TYPE
|
||||
# if defined(_MSC_VER)
|
||||
# pragma message("Configuration-depended MDBX_BUILD_CONFIG: " MDBX_BUILD_CONFIG)
|
||||
# pragma message("Configuration-depended MDBX_BUILD_TYPE: " MDBX_BUILD_TYPE)
|
||||
# endif
|
||||
"-" MDBX_BUILD_CONFIG
|
||||
#endif /* MDBX_BUILD_CONFIG */
|
||||
"-" MDBX_BUILD_TYPE
|
||||
#endif /* MDBX_BUILD_TYPE */
|
||||
,
|
||||
"MDBX_DEBUG=" STRINGIFY(MDBX_DEBUG)
|
||||
#ifdef MDBX_LOGLEVEL_BUILD
|
@ -90,7 +90,7 @@
|
||||
#pragma warning(disable : 4200) /* nonstandard extension used: zero-sized array in struct/union */
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#include "../../mdbx.h"
|
||||
#include "../mdbx.h"
|
||||
#include "defs.h"
|
||||
|
||||
#if defined(__GNUC__) && !__GNUC_PREREQ(4,2)
|
@ -21,7 +21,7 @@
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define MDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#include "../elements/internals.h"
|
||||
#include "internals.h"
|
||||
|
||||
typedef struct flagbit {
|
||||
int bit;
|
@ -21,7 +21,7 @@
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define MDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#include "../elements/internals.h"
|
||||
#include "internals.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include "wingetopt.h"
|
@ -21,7 +21,7 @@
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define MDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#include "../elements/internals.h"
|
||||
#include "internals.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
@ -21,7 +21,7 @@
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define MDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#include "../elements/internals.h"
|
||||
#include "internals.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
@ -21,7 +21,7 @@
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define MDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#include "../elements/internals.h"
|
||||
#include "internals.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include "wingetopt.h"
|
@ -1,60 +0,0 @@
|
||||
set(MDBX_TOOLS mdbx_chk mdbx_copy mdbx_dump mdbx_load mdbx_stat)
|
||||
|
||||
# use, i.e. don't skip the full RPATH for the build tree
|
||||
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
||||
|
||||
# when building, don't use the install RPATH already (but later on when installing)
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
|
||||
|
||||
# add the automatically determined parts of the RPATH
|
||||
# which point to directories outside the build tree to the install RPATH
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
|
||||
# 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)
|
||||
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()
|
||||
|
||||
foreach(TOOL ${MDBX_TOOLS})
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
add_executable(${TOOL} ${TOOL}.c wingetopt.c wingetopt.h)
|
||||
else()
|
||||
add_executable(${TOOL} ${TOOL}.c)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${TOOL} mdbx ${CMAKE_THREAD_LIBS_INIT})
|
||||
set_target_properties(${TOOL} PROPERTIES
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON
|
||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
||||
endforeach()
|
||||
|
||||
if(LIB_MATH)
|
||||
target_link_libraries(mdbx_chk ${LIB_MATH})
|
||||
target_link_libraries(mdbx_stat ${LIB_MATH})
|
||||
endif()
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
mdbx_chk
|
||||
mdbx_stat
|
||||
mdbx_copy
|
||||
mdbx_dump
|
||||
mdbx_load
|
||||
RUNTIME
|
||||
DESTINATION bin
|
||||
COMPONENT runtime)
|
||||
|
||||
install(
|
||||
FILES
|
||||
../man1/mdbx_chk.1
|
||||
../man1/mdbx_stat.1
|
||||
../man1/mdbx_copy.1
|
||||
../man1/mdbx_dump.1
|
||||
../man1/mdbx_load.1
|
||||
DESTINATION man/man1
|
||||
COMPONENT doc)
|
@ -1,9 +1,3 @@
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
set(TEST_OSAL windows)
|
||||
else()
|
||||
set(TEST_OSAL unix)
|
||||
endif()
|
||||
|
||||
add_executable(mdbx_test
|
||||
base.h
|
||||
cases.cc
|
||||
@ -21,7 +15,8 @@ add_executable(mdbx_test
|
||||
log.h
|
||||
main.cc
|
||||
osal.h
|
||||
osal-${TEST_OSAL}.cc
|
||||
osal-unix.cc
|
||||
osal-windows.cc
|
||||
test.cc
|
||||
test.h
|
||||
try.cc
|
||||
@ -35,19 +30,15 @@ add_executable(mdbx_test
|
||||
set_target_properties(mdbx_test PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>
|
||||
CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
target_setup_options(mdbx_test)
|
||||
|
||||
if(CC_HAS_FASTMATH)
|
||||
target_compile_options(mdbx_test PRIVATE "-ffast-math")
|
||||
endif()
|
||||
if(CC_HAS_VISIBILITY AND (LTO_ENABLED OR INTERPROCEDURAL_OPTIMIZATION))
|
||||
set_target_properties(mdbx_test PROPERTIES LINK_FLAGS "-fvisibility=hidden")
|
||||
endif()
|
||||
|
||||
target_link_libraries(mdbx_test mdbx ${LIB_MATH} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(mdbx_test ${TOOL_MDBX_LIB} ${LIB_MATH} ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(mdbx_test winmm.lib)
|
||||
endif()
|
||||
|
||||
if(UNIX AND NOT SUBPROJECT)
|
||||
add_subdirectory(pcrf)
|
||||
add_executable(pcrf_test pcrf/pcrf_test.c)
|
||||
target_include_directories(pcrf_test PRIVATE "${PROJECT_SOURCE_DIR}")
|
||||
target_link_libraries(pcrf_test ${TOOL_MDBX_LIB})
|
||||
endif()
|
||||
|
@ -84,14 +84,14 @@
|
||||
#define MDBX_INTERNAL_VAR extern
|
||||
#define MDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#include "../mdbx.h"
|
||||
#include "../src/elements/defs.h"
|
||||
#include "../src/elements/osal.h"
|
||||
#include "../src/defs.h"
|
||||
#include "../src/osal.h"
|
||||
|
||||
#if !defined(__thread) && (defined(_MSC_VER) || defined(__DMC__))
|
||||
#define __thread __declspec(thread)
|
||||
#endif /* __thread */
|
||||
|
||||
#include "../src/elements/options.h"
|
||||
#include "../src/options.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#if !(defined(_WIN32) || defined(_WIN64))
|
||||
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <sys/mman.h>
|
||||
@ -529,3 +531,5 @@ std::string osal_tempdir(void) {
|
||||
int osal_removefile(const std::string &pathname) {
|
||||
return unlink(pathname.c_str()) ? errno : MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* !Windows */
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
static std::unordered_map<unsigned, HANDLE> events;
|
||||
static HANDLE hBarrierSemaphore, hBarrierEvent;
|
||||
static HANDLE hProgressActiveEvent, hProgressPassiveEvent;
|
||||
@ -459,3 +461,5 @@ std::string osal_tempdir(void) {
|
||||
int osal_removefile(const std::string &pathname) {
|
||||
return DeleteFileA(pathname.c_str()) ? MDBX_SUCCESS : GetLastError();
|
||||
}
|
||||
|
||||
#endif /* Windows */
|
||||
|
@ -1,5 +0,0 @@
|
||||
set(TARGET pcrf_test)
|
||||
add_executable(${TARGET} pcrf_test.c)
|
||||
target_include_directories(${TARGET} PRIVATE "${PROJECT_SOURCE_DIR}")
|
||||
target_link_libraries(${TARGET} mdbx)
|
||||
|
Loading…
x
Reference in New Issue
Block a user