2019-09-09 18:40:24 +08:00
##
2021-01-26 12:26:09 +08:00
## Copyright 2020-2021 Leonid Yuriev <leo@yuriev.ru>
2019-08-31 22:13:02 +08:00
## 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. }
2020-02-18 07:22:47 +08:00
## Please see README.md at https://github.com/erthink/libmdbx
2019-08-31 22:13:02 +08:00
##
## 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 )
2020-04-08 04:06:18 +08:00
2019-08-31 22:13:02 +08:00
cmake_policy ( PUSH )
cmake_policy ( VERSION 3.8.2 )
2020-05-10 08:41:28 +08:00
if ( NOT CMAKE_VERSION VERSION_LESS 3.15 )
cmake_policy ( SET CMP0091 NEW )
endif ( )
2019-10-24 21:40:40 +08:00
if ( NOT CMAKE_VERSION VERSION_LESS 3.13 )
cmake_policy ( SET CMP0077 NEW )
endif ( )
2019-08-31 22:13:02 +08:00
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 ( )
2020-04-15 22:09:37 +08:00
if ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git" AND
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t / C M a k e L i s t s . t x t " A N D
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / c o r e . c " A N D
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / a l l o y . c " A N D
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / c o n f i g . h . i n " A N D
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / v e r s i o n . c . i n " A N D
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m a n 1 " A N D
2020-08-23 01:19:46 +08:00
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m d b x _ c h k . c " A N D
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m d b x . c + + " )
2020-04-15 22:09:37 +08: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" )
elseif ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" AND
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / m d b x . c " A N D
2020-08-23 01:19:46 +08:00
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / m d b x . c + + " A N D
2020-04-15 22:09:37 +08:00
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c o n f i g . h . i n " A N D
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / m a n 1 " A N D
E X I S T S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / m d b x _ c h k . 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 ( )
2019-08-31 22:13:02 +08:00
if ( DEFINED PROJECT_NAME )
set ( SUBPROJECT ON )
2019-09-05 16:57:52 +08:00
set ( NOT_SUBPROJECT OFF )
2020-04-15 22:09:37 +08:00
if ( NOT MDBX_AMALGAMATED_SOURCE AND NOT DEFINED BUILD_TESTING )
2019-08-31 22:13:02 +08:00
set ( BUILD_TESTING OFF )
endif ( )
2020-09-27 21:49:55 +08:00
enable_language ( C )
2019-08-31 22:13:02 +08:00
else ( )
set ( SUBPROJECT OFF )
2019-09-05 16:57:52 +08:00
set ( NOT_SUBPROJECT ON )
2020-09-27 21:49:55 +08:00
project ( libmdbx C )
2020-04-15 22:09:37 +08:00
if ( NOT MDBX_AMALGAMATED_SOURCE AND NOT DEFINED BUILD_TESTING )
2019-08-31 22:13:02 +08:00
set ( BUILD_TESTING ON )
endif ( )
endif ( )
2020-09-27 21:45:00 +08:00
if ( MDBX_AMALGAMATED_SOURCE AND DEFINED MDBX_ENABLE_TESTS AND MDBX_ENABLE_TESTS )
message ( WARNING "MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: But amalgamated source code don't includes tests." )
set ( MDBX_ENABLE_TESTS OFF )
endif ( )
2020-09-27 21:49:55 +08:00
# Try to find a C++ compiler unless sure that this is unnecessary.
2020-09-29 04:47:37 +08:00
if ( NOT CMAKE_CXX_COMPILER_LOADED )
2020-09-27 21:49:55 +08:00
include ( CheckLanguage )
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 ) ) )
check_language ( CXX )
if ( CMAKE_CXX_COMPILER )
enable_language ( CXX )
endif ( )
endif ( )
else ( )
enable_language ( CXX )
endif ( )
2019-09-11 03:41:53 +08:00
if ( NOT CMAKE_BUILD_TYPE )
2019-09-19 21:43:16 +08:00
set ( CMAKE_BUILD_TYPE MinSizeRel CACHE STRING
2019-09-11 03:41:53 +08:00
" C h o o s e t h e t y p e o f b u i l d , o p t i o n s a r e : D e b u g R e l e a s e R e l W i t h D e b I n f o M i n S i z e R e l . "
F O R C E )
endif ( )
2020-04-08 04:07:32 +08:00
if ( NOT_SUBPROJECT AND ( CMAKE_CROSSCOMPILING OR IOS ) )
set ( CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY )
endif ( )
2019-08-31 22:13:02 +08: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 21:35:30 +08: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 22:13:02 +08:00
include ( CheckFunctionExists )
include ( FindPackageMessage )
include ( GNUInstallDirs )
if ( CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION LESS 1900 )
message ( SEND_ERROR "MSVC compiler ${MSVC_VERSION} is too old for building MDBX."
" A t l e a s t ' M i c r o s o f t V i s u a l S t u d i o 2 0 1 5 ' i s r e q u i r e d . " )
endif ( )
# Set default build type to Release. This is to ease a User's life.
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE Release CACHE STRING
" C h o o s e t h e t y p e o f b u i l d , o p t i o n s a r e : D e b u g R e l e a s e R e l W i t h D e b I n f o M i n S i z e R e l . "
F O R C E )
endif ( )
string ( TOUPPER ${ CMAKE_BUILD_TYPE } CMAKE_BUILD_TYPE_UPPERCASE )
2020-10-06 00:12:20 +08:00
set ( CMAKE_THREAD_PREFER_PTHREAD TRUE )
set ( THREADS_PREFER_PTHREAD_FLAG TRUE )
find_package ( Threads REQUIRED )
2019-08-31 22:13:02 +08:00
include ( cmake/utils.cmake )
include ( cmake/compiler.cmake )
include ( cmake/profile.cmake )
2020-10-06 00:12:20 +08:00
# Workaround for `-pthread` toolchain/cmake bug
if ( NOT APPLE AND NOT MSVC
A N D C M A K E _ U S E _ P T H R E A D S _ I N I T A N D N O T C M A K E _ T H R E A D _ L I B S _ I N I T
AND ( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG ) )
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 ( )
2019-08-31 22:13:02 +08:00
CHECK_FUNCTION_EXISTS ( pow NOT_NEED_LIBM )
if ( NOT_NEED_LIBM )
set ( LIB_MATH "" )
else ( )
set ( CMAKE_REQUIRED_LIBRARIES m )
CHECK_FUNCTION_EXISTS ( pow HAVE_LIBM )
if ( HAVE_LIBM )
set ( LIB_MATH m )
else ( )
message ( FATAL_ERROR "No libm found for math support" )
endif ( )
endif ( )
2019-09-03 07:24:19 +08:00
if ( SUBPROJECT )
if ( NOT DEFINED BUILD_SHARED_LIBS )
2019-09-05 16:57:52 +08:00
option ( BUILD_SHARED_LIBS "Build shared libraries (DLLs)" OFF )
endif ( )
if ( NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE )
2020-09-22 11:51:47 +08:00
option ( CMAKE_POSITION_INDEPENDENT_CODE "Generate position independent (PIC)" ON )
2019-09-03 07:24:19 +08:00
endif ( )
else ( )
2019-09-05 16:57:52 +08:00
option ( BUILD_SHARED_LIBS "Build shared libraries (DLLs)" ON )
2020-09-22 11:51:47 +08:00
option ( CMAKE_POSITION_INDEPENDENT_CODE "Generate position independent (PIC)" ON )
2019-08-31 22:13:02 +08:00
if ( CC_HAS_ARCH_NATIVE )
2019-09-05 16:57:52 +08:00
option ( BUILD_FOR_NATIVE_CPU "Generate code for the compiling machine CPU" OFF )
2019-08-31 22:13:02 +08:00
endif ( )
if ( CMAKE_CONFIGURATION_TYPES OR NOT CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG" )
set ( INTERPROCEDURAL_OPTIMIZATION_DEFAULT ON )
else ( )
set ( INTERPROCEDURAL_OPTIMIZATION_DEFAULT OFF )
endif ( )
if ( CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE
O R G C C _ L T O _ A V A I L A B L E O R M S V C _ L T O _ A V A I L A B L E O R C L A N G _ L T O _ A V A I L A B L E )
2019-09-05 16:57:52 +08:00
option ( INTERPROCEDURAL_OPTIMIZATION "Enable interprocedural/LTO optimization" ${ INTERPROCEDURAL_OPTIMIZATION_DEFAULT } )
2019-08-31 22:13:02 +08:00
endif ( )
if ( INTERPROCEDURAL_OPTIMIZATION )
if ( GCC_LTO_AVAILABLE )
set ( LTO_ENABLED TRUE )
set ( CMAKE_AR ${ CMAKE_GCC_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 )
message ( STATUS "MDBX indulge Link-Time Optimization by GCC" )
elseif ( CLANG_LTO_AVAILABLE )
set ( LTO_ENABLED TRUE )
set ( CMAKE_AR ${ CMAKE_CLANG_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 )
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 22:09:37 +08:00
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
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t / v a l g r i n d _ s u p p r e s s . t x t "
C A C H E F I L E P A T H " S u p p r e s s i o n s f i l e f o r V a l g r i n d " F O R C E )
set ( MEMORYCHECK_COMMAND_OPTIONS
" - - t r a c e - c h i l d r e n = y e s - - l e a k - c h e c k = f u l l - - t r a c k - o r i g i n s = y e s - - e r r o r - e x i t c o d e = 4 2 - - e r r o r - m a r k e r s = @ - - e r r o r s - f o r - l e a k - k i n d s = d e f i n i t e - - f a i r - s c h e d = y e s - - s u p p r e s s i o n s = $ { M E M O R Y C H E C K _ S U P P R E S S I O N S _ F I L E } "
C A C H E S T R I N G " V a l g r i n d o p t i o n s " F O R C E )
set ( VALGRIND_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS}" CACHE STRING "Valgrind options" FORCE )
endif ( )
2019-08-31 22:13:02 +08:00
2020-04-15 22:09:37 +08:00
# Enable 'make tags' target.
find_program ( CTAGS ctags )
if ( CTAGS )
add_custom_target ( tags COMMAND ${ CTAGS } -R -f tags
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } )
add_custom_target ( ctags DEPENDS tags )
endif ( CTAGS )
2020-05-05 23:52:32 +08:00
if ( UNIX )
find_program ( CLANG_FORMAT
N A M E S c l a n g - f o r m a t - 1 2 c l a n g - f o r m a t - 1 1 c l a n g - f o r m a t - 1 0 c l a n g - f o r m a t )
if ( CLANG_FORMAT )
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 10.0 )
# Enable 'make reformat' target.
add_custom_target ( reformat
V E R B A T I M
C O M M A N D
g i t l s - f i l e s |
g r e p - E \ \ . \ ( c | c x x | c c | c p p | h | h x x | h p p \ ) \ ( \ \ . i n \ ) ? \ $ |
x a r g s $ { C L A N G _ F O R M A T } - i - - s t y l e = f i l e
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ S O U R C E _ D I R } )
endif ( )
endif ( )
2020-04-15 22:09:37 +08:00
endif ( )
2019-08-31 22:13:02 +08:00
2020-04-15 22:09:37 +08:00
if ( NOT "${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}" )
add_custom_target ( distclean )
add_custom_command ( TARGET distclean
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e _ d i r e c t o r y " $ { P R O J E C T _ B I N A R Y _ D I R } "
C O M M E N T " R e m o v i n g t h e b u i l d d i r e c t o r y a n d i t s c o n t e n t " )
elseif ( IS_DIRECTORY .git AND GIT )
add_custom_target ( distclean )
add_custom_command ( TARGET distclean
W O R K I N G _ D I R E C T O R Y $ { P R O J E C T _ S O U R C E _ D I R }
C O M M A N D $ { G I T } s u b m o d u l e f o r e a c h - - r e c u r s i v e g i t c l e a n - f - X - d
C O M M A N D $ { G I T } c l e a n - f - X - d
C O M M E N T " R e m o v i n g a l l b u i l d f i l e s f r o m t h e s o u r c e d i r e c t o r y " )
endif ( )
endif ( NOT MDBX_AMALGAMATED_SOURCE )
2019-08-31 22:13:02 +08:00
setup_compile_flags ( )
2019-09-03 07:24:19 +08:00
endif ( SUBPROJECT )
2019-08-31 22:13:02 +08:00
2019-10-22 17:14:26 +08:00
list ( FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11 )
2020-08-23 01:19:46 +08: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 )
if ( NOT DEFINED MDBX_CXX_STANDARD )
if ( DEFINED CMAKE_CXX_STANDARD )
set ( MDBX_CXX_STANDARD ${ CMAKE_CXX_STANDARD } )
elseif ( NOT HAS_CXX20 LESS 0 )
set ( MDBX_CXX_STANDARD 20 )
elseif ( NOT HAS_CXX17 LESS 0 )
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 )
else ( )
set ( MDBX_CXX_STANDARD 98 )
endif ( )
endif ( )
2020-11-28 18:07:58 +08:00
if ( NOT DEFINED MDBX_C_STANDARD )
# MSVC >= 19.28 (Microsoft Visual Studio 16.8) is mad!
# It unable process Windows SDK headers in the C11 mode!
if ( HAS_C11 LESS 0 OR ( MSVC AND MSVC_VERSION GREATER 1927 ) )
set ( MDBX_C_STANDARD 99 )
else ( )
set ( MDBX_C_STANDARD 11 )
endif ( )
2019-10-22 17:14:26 +08:00
endif ( )
2019-08-31 22:13:02 +08:00
2020-04-15 22:09:37 +08:00
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}"
C O M M E N T " C r e a t e e x t r a - i m p o r t - l i b r a r y f o r n t d l l . d l l "
M A I N _ D E P E N D E N C Y " $ { M D B X _ S O U R C E _ D I R } / n t d l l . d e f "
C O M M A N D $ { M S V C _ L I B _ E X E } / d e f : " $ { M D B X _ S O U R C E _ D I R } / n t d l l . d e f " / o u t : " $ { M D B X _ N T D L L _ E X T R A _ I M P L I B } " $ { I N I T I A L _ C M A K E _ S T A T I C _ L I N K E R _ F L A G S } )
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}"
C O M M E N T " C r e a t e e x t r a - i m p o r t - l i b r a r y f o r n t d l l . d l l "
M A I N _ D E P E N D E N C Y " $ { M D B X _ S O U R C E _ D I R } / n t d l l . d e f "
C O M M A N D $ { D L L T O O L } - d " $ { M D B X _ S O U R C E _ D I R } / n t d l l . d e f " - l " $ { M D B X _ N T D L L _ E X T R A _ I M P L I B } " )
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
P R O P E R T I E S
I M P O R T E D _ L O C A T I O N " $ { M D B X _ N T D L L _ E X T R A _ I M P L I B } " )
endif ( )
endif ( )
2019-12-05 04:05:49 +08:00
################################################################################
################################################################################
2019-09-03 07:24:19 +08:00
#
2019-12-05 04:05:49 +08:00
# #### ##### ##### # #### # # ####
# # # # # # # # # ## # #
# # # # # # # # # # # # ####
# # # ##### # # # # # # # #
# # # # # # # # # ## # #
# #### # # # #### # # ####
2019-09-03 07:24:19 +08:00
#
2019-10-25 13:10:15 +08:00
set ( MDBX_BUILD_OPTIONS ENABLE_ASAN MDBX_USE_VALGRIND ENABLE_GPROF ENABLE_GCOV )
2020-09-27 21:45:00 +08: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 )
set ( CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO" )
endif ( )
else ( )
set ( MDBX_BUILD_TOOLS_DEFAULT ON )
endif ( )
2020-04-15 22:09:37 +08:00
add_mdbx_option ( MDBX_INSTALL_STATIC "Build and install libmdbx for static linking" OFF )
2019-09-05 16:57:52 +08:00
add_mdbx_option ( MDBX_BUILD_SHARED_LIBRARY "Build libmdbx as shared library (DLL)" ${ BUILD_SHARED_LIBS } )
2020-04-08 04:07:32 +08:00
add_mdbx_option ( MDBX_BUILD_TOOLS "Build MDBX tools (mdbx_chk/stat/dump/load/copy)" ${ MDBX_BUILD_TOOLS_DEFAULT } )
2020-09-27 19:16:26 +08:00
CMAKE_DEPENDENT_OPTION ( MDBX_INSTALL_MANPAGES "Install man-pages for MDBX tools (mdbx_chk/stat/dump/load/copy)" ON MDBX_BUILD_TOOLS OFF )
2019-09-03 07:24:19 +08:00
add_mdbx_option ( MDBX_TXN_CHECKOWNER "Checking transaction matches the calling thread inside libmdbx's API" ON )
2020-07-22 19:53:15 +08:00
add_mdbx_option ( MDBX_ENV_CHECKPID "Paranoid checking PID inside libmdbx's API" AUTO )
mark_as_advanced ( MDBX_ENV_CHECKPID )
2019-10-06 19:59:53 +08:00
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Linux" )
2020-04-15 22:09:37 +08:00
add_mdbx_option ( MDBX_DISABLE_GNU_SOURCE "Don't use GNU/Linux libc extensions" OFF )
2019-10-06 19:59:53 +08:00
mark_as_advanced ( MDBX_DISABLE_GNU_SOURCE )
endif ( )
2020-04-15 22:09:37 +08:00
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Darwin" OR IOS )
2019-09-03 07:24:19 +08:00
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" )
2020-04-15 22:09:37 +08:00
if ( MDBX_NTDLL_EXTRA_IMPLIB )
2020-08-23 01:19:46 +08:00
add_mdbx_option ( MDBX_AVOID_CRT "Avoid dependence from MSVC CRT and use ntdll.dll instead" OFF )
2019-09-03 07:24:19 +08:00
endif ( )
2020-04-15 22:09:37 +08:00
add_mdbx_option ( MDBX_CONFIG_MANUAL_TLS_CALLBACK
" P r o v i d e mdbx_dll_handler ( ) f o r m a n u a l i n i t i a l i z a t i o n " O F F )
mark_as_advanced ( MDBX_CONFIG_MANUAL_TLS_CALLBACK )
2019-09-03 07:24:19 +08:00
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 ( )
2019-12-05 04:05:49 +08:00
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 )
2020-04-15 22:09:37 +08:00
add_mdbx_option ( MDBX_TRUST_RTC "Does a system have battery-backed Real-Time Clock or just a fake" AUTO )
2019-12-05 04:05:49 +08:00
mark_as_advanced ( MDBX_TRUST_RTC )
2020-04-15 22:09:37 +08:00
option ( MDBX_FORCE_ASSERTIONS "Force enable assertion checking" OFF )
2021-02-07 07:35:44 +08:00
option ( MDBX_DISABLE_PAGECHECKS "Disable some checks to reduce an overhead and detection probability of database corruption to a values closer to the LMDB" OFF )
2020-04-15 22:09:37 +08:00
if ( NOT MDBX_AMALGAMATED_SOURCE )
add_mdbx_option ( MDBX_ALLOY_BUILD "Build MDBX library through single/alloyed object file" ON )
2020-08-23 01:19:46 +08:00
endif ( )
2020-04-15 22:09:37 +08:00
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 ( )
2020-09-29 04:47:37 +08:00
if ( CMAKE_CXX_COMPILER_LOADED AND MDBX_CXX_STANDARD GREATER_EQUAL 11 AND MDBX_CXX_STANDARD LESS 83 )
2020-08-23 01:19:46 +08:00
if ( NOT MDBX_AMALGAMATED_SOURCE )
option ( MDBX_ENABLE_TESTS "Build MDBX tests" ${ BUILD_TESTING } )
endif ( )
if ( NOT MDBX_AVOID_CRT
2020-09-14 00:50:53 +08:00
A N D NOT ( CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8 )
2020-08-23 01:19:46 +08:00
A N D NOT ( CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4 )
A N D NOT ( MSVC AND MSVC_VERSION LESS 1900 ) )
option ( MDBX_BUILD_CXX "Build C++ portion" ON )
else ( )
set ( MDBX_BUILD_CXX FALSE )
endif ( )
else ( )
set ( MDBX_BUILD_CXX FALSE )
2020-09-27 21:45:00 +08:00
set ( MDBX_ENABLE_TESTS FALSE )
2020-08-23 01:19:46 +08:00
endif ( )
2020-04-15 22:09:37 +08:00
################################################################################
################################################################################
2020-09-29 04:47:37 +08:00
if ( MDBX_BUILD_CXX AND NOT CMAKE_CXX_COMPILER_LOADED )
2020-09-27 21:49:55 +08:00
message ( FATAL_ERROR "MDBX_BUILD_CXX=${MDBX_BUILD_CXX}: The C++ compiler is required to build the C++API." )
endif ( )
2020-04-15 22:09:37 +08:00
# Get version
2020-04-30 08:45:47 +08:00
fetch_version ( MDBX "${CMAKE_CURRENT_SOURCE_DIR}" FALSE )
2020-04-15 22:09:37 +08:00
message ( STATUS "libmdbx version is ${MDBX_VERSION}" )
# sources list
2020-10-02 05:05:02 +08:00
set ( LIBMDBX_PUBLIC_HEADERS mdbx.h )
set ( LIBMDBX_SOURCES mdbx.h "${CMAKE_CURRENT_BINARY_DIR}/config.h" )
2020-04-15 22:09:37 +08:00
if ( MDBX_AMALGAMATED_SOURCE )
list ( APPEND LIBMDBX_SOURCES mdbx.c )
else ( )
# generate version file
configure_file ( "${MDBX_SOURCE_DIR}/version.c.in"
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / v e r s i o n . c " E S C A P E _ Q U O T E S )
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-23 01:19:46 +08:00
list ( APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/alloy.c" )
2020-04-15 22:09:37 +08:00
include_directories ( "${MDBX_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" )
else ( )
list ( APPEND LIBMDBX_SOURCES
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / v e r s i o n . c "
" $ { M D B X _ S O U R C E _ D I R } / o p t i o n s . h " " $ { M D B X _ S O U R C E _ D I R } / d e f s . h "
" $ { M D B X _ S O U R C E _ D I R } / i n t e r n a l s . h " " $ { M D B X _ S O U R C E _ D I R } / o s a l . h "
" $ { M D B X _ S O U R C E _ D I R } / c o r e . c " " $ { M D B X _ S O U R C E _ D I R } / o s a l . c "
" $ { M D B X _ S O U R C E _ D I R } / l c k - p o s i x . c " " $ { M D B X _ S O U R C E _ D I R } / l c k - w i n d o w s . c " )
include_directories ( "${MDBX_SOURCE_DIR}" )
endif ( )
endif ( MDBX_AMALGAMATED_SOURCE )
2020-08-23 01:19:46 +08:00
if ( MDBX_BUILD_CXX )
message ( STATUS "Use C${MDBX_C_STANDARD} and C++${MDBX_CXX_STANDARD} for libmdbx" )
2020-10-02 05:05:02 +08:00
list ( APPEND LIBMDBX_PUBLIC_HEADERS mdbx.h++ )
2020-08-23 01:19:46 +08:00
list ( APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/mdbx.c++" mdbx.h++ )
else ( )
message ( STATUS "Use C${MDBX_C_STANDARD} for libmdbx but C++ portion is disabled" )
endif ( )
2020-04-15 22:09:37 +08:00
macro ( target_setup_options TARGET )
if ( DEFINED INTERPROCEDURAL_OPTIMIZATION )
set_target_properties ( ${ TARGET } PROPERTIES
I N T E R P R O C E D U R A L _ O P T I M I Z A T I O N $ < B O O L : $ { I N T E R P R O C E D U R A L _ O P T I M I Z A T I O N } > )
endif ( )
2020-08-23 01:19:46 +08:00
set_target_properties ( ${ TARGET } PROPERTIES
C _ S T A N D A R D $ { M D B X _ C _ S T A N D A R D } C _ S T A N D A R D _ R E Q U I R E D O N )
if ( MDBX_BUILD_CXX )
set_target_properties ( ${ TARGET } PROPERTIES
C X X _ S T A N D A R D $ { M D B X _ C X X _ S T A N D A R D } C X X _ S T A N D A R D _ R E Q U I R E D O N )
endif ( )
2020-04-15 22:09:37 +08:00
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 )
2020-10-06 00:12:20 +08:00
target_link_libraries ( ${ TARGET } ${ MODE } Threads::Threads )
2020-04-15 22:09:37 +08:00
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Windows" )
target_link_libraries ( ${ TARGET } ${ MODE } ntdll.lib )
2020-05-10 08:41:28 +08:00
if ( MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_AVOID_CRT )
2020-04-15 22:09:37 +08:00
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 ( )
2020-08-23 01:19:46 +08:00
if ( LIBCXX_FILESYSTEM AND MDBX_BUILD_CXX )
target_link_libraries ( ${ TARGET } ${ MODE } ${ LIBCXX_FILESYSTEM } )
endif ( )
2020-04-15 22:09:37 +08: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 ( )
2020-10-02 05:05:02 +08:00
set_target_properties ( mdbx-static PROPERTIES PUBLIC_HEADER "${LIBMDBX_PUBLIC_HEADERS}" )
2020-04-17 05:37:29 +08:00
target_compile_definitions ( mdbx-static PRIVATE MDBX_BUILD_SHARED_LIBRARY=0 )
2020-04-15 22:09:37 +08: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 ( )
2019-09-03 07:24:19 +08:00
################################################################################
2020-04-15 22:09:37 +08:00
# build shared library
if ( MDBX_BUILD_SHARED_LIBRARY )
add_library ( mdbx SHARED ${ LIBMDBX_SOURCES } )
2020-10-02 05:05:02 +08:00
set_target_properties ( mdbx PROPERTIES PUBLIC_HEADER "${LIBMDBX_PUBLIC_HEADERS}" )
2020-04-17 05:37:29 +08:00
target_compile_definitions ( mdbx PRIVATE LIBMDBX_EXPORTS MDBX_BUILD_SHARED_LIBRARY=1 INTERFACE LIBMDBX_IMPORTS )
2020-04-15 22:09:37 +08:00
target_setup_options ( mdbx )
libmdbx_setup_libs ( mdbx PRIVATE )
2020-05-10 08:41:28 +08:00
if ( MSVC )
if ( MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_AVOID_CRT )
set_property ( TARGET mdbx PROPERTY LINKER_FLAGS "/NODEFAULTLIB" )
else ( )
set_property ( TARGET mdbx PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" )
endif ( )
endif ( )
2020-04-15 22:09:37 +08: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 } )
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 ( )
2021-03-10 19:43:49 +08:00
foreach ( TOOL mdbx_chk mdbx_copy mdbx_stat mdbx_dump mdbx_load mdbx_drop )
2020-04-15 22:09:37 +08:00
add_executable ( ${ TOOL } mdbx.h ${ MDBX_SOURCE_DIR } / ${ TOOL } .c ${ WINGETOPT_SRC } )
2020-06-26 07:57:46 +08:00
if ( MDBX_C_STANDARD )
set_target_properties ( ${ TOOL } PROPERTIES
C _ S T A N D A R D $ { M D B X _ C _ S T A N D A R D } C _ S T A N D A R D _ R E Q U I R E D O N )
endif ( )
2020-04-15 22:09:37 +08:00
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
2020-09-27 19:16:26 +08:00
if ( NOT DEFINED MDBX_DLL_INSTALL_DESTINATION )
if ( WIN32 )
set ( MDBX_DLL_INSTALL_DESTINATION bin )
else ( )
set ( MDBX_DLL_INSTALL_DESTINATION lib )
endif ( )
endif ( )
2020-04-15 22:09:37 +08:00
if ( MDBX_BUILD_SHARED_LIBRARY )
if ( CMAKE_VERSION VERSION_LESS 3.12 )
install ( TARGETS mdbx EXPORT libmdbx
2020-09-27 19:16:26 +08:00
L I B R A R Y D E S T I N A T I O N $ { M D B X _ D L L _ I N S T A L L _ D E S T I N A T I O N } C O M P O N E N T r u n t i m e
2020-05-01 20:14:50 +08:00
O B J E C T S D E S T I N A T I O N l i b C O M P O N E N T d e v e l
A R C H I V E D E S T I N A T I O N l i b C O M P O N E N T d e v e l
P U B L I C _ H E A D E R D E S T I N A T I O N i n c l u d e C O M P O N E N T d e v e l
I N C L U D E S D E S T I N A T I O N i n c l u d e C O M P O N E N T d e v e l )
2020-04-15 22:09:37 +08:00
else ( )
install ( TARGETS mdbx EXPORT libmdbx
2020-09-27 19:16:26 +08:00
L I B R A R Y D E S T I N A T I O N $ { M D B X _ D L L _ I N S T A L L _ D E S T I N A T I O N } C O M P O N E N T r u n t i m e
2020-04-15 22:09:37 +08:00
N A M E L I N K _ C O M P O N E N T d e v e l
2020-05-01 20:14:50 +08:00
O B J E C T S D E S T I N A T I O N l i b C O M P O N E N T d e v e l
A R C H I V E D E S T I N A T I O N l i b C O M P O N E N T d e v e l
P U B L I C _ H E A D E R D E S T I N A T I O N i n c l u d e C O M P O N E N T d e v e l
I N C L U D E S D E S T I N A T I O N i n c l u d e C O M P O N E N T d e v e l )
2020-04-15 22:09:37 +08:00
endif ( )
endif ( MDBX_BUILD_SHARED_LIBRARY )
# mdbx-tools installation
if ( MDBX_BUILD_TOOLS )
2020-09-27 19:16:26 +08:00
if ( NOT DEFINED MDBX_TOOLS_INSTALL_DESTINATION )
set ( MDBX_TOOLS_INSTALL_DESTINATION bin )
endif ( )
2020-04-15 22:09:37 +08:00
install (
T A R G E T S
m d b x _ c h k
m d b x _ s t a t
m d b x _ c o p y
m d b x _ d u m p
m d b x _ l o a d
2021-03-10 19:43:49 +08:00
m d b x _ d r o p
2020-04-15 22:09:37 +08:00
R U N T I M E
2020-09-27 19:16:26 +08:00
D E S T I N A T I O N $ { M D B X _ T O O L S _ I N S T A L L _ D E S T I N A T I O N }
2020-04-15 22:09:37 +08:00
C O M P O N E N T r u n t i m e )
2020-09-27 19:16:26 +08:00
if ( MDBX_INSTALL_MANPAGES )
if ( NOT DEFINED MDBX_MAN_INSTALL_DESTINATION )
set ( MDBX_MAN_INSTALL_DESTINATION man/man1 )
endif ( )
install (
F I L E S
" $ { M D B X _ S O U R C E _ D I R } / m a n 1 / m d b x _ c h k . 1 "
" $ { M D B X _ S O U R C E _ D I R } / m a n 1 / m d b x _ s t a t . 1 "
" $ { M D B X _ S O U R C E _ D I R } / m a n 1 / m d b x _ c o p y . 1 "
" $ { M D B X _ S O U R C E _ D I R } / m a n 1 / m d b x _ d u m p . 1 "
" $ { M D B X _ S O U R C E _ D I R } / m a n 1 / m d b x _ l o a d . 1 "
2021-03-10 19:43:49 +08:00
" $ { M D B X _ S O U R C E _ D I R } / m a n 1 / m d b x _ d r o p . 1 "
2020-09-27 19:16:26 +08:00
D E S T I N A T I O N $ { M D B X _ M A N _ I N S T A L L _ D E S T I N A T I O N }
C O M P O N E N T d o c )
endif ( )
2020-04-15 22:09:37 +08:00
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
2020-09-27 19:16:26 +08:00
L I B R A R Y D E S T I N A T I O N l i b C O M P O N E N T d e v e l
2020-05-01 20:14:50 +08:00
O B J E C T S D E S T I N A T I O N l i b C O M P O N E N T d e v e l
A R C H I V E D E S T I N A T I O N l i b C O M P O N E N T d e v e l
P U B L I C _ H E A D E R D E S T I N A T I O N i n c l u d e C O M P O N E N T d e v e l
I N C L U D E S D E S T I N A T I O N i n c l u d e C O M P O N E N T d e v e l )
2020-04-15 22:09:37 +08:00
else ( )
install ( TARGETS mdbx-static EXPORT libmdbx
2020-09-27 19:16:26 +08:00
L I B R A R Y D E S T I N A T I O N l i b C O M P O N E N T d e v e l
2020-04-15 22:09:37 +08:00
N A M E L I N K _ C O M P O N E N T d e v e l
2020-05-01 20:14:50 +08:00
O B J E C T S D E S T I N A T I O N l i b C O M P O N E N T d e v e l
A R C H I V E D E S T I N A T I O N l i b C O M P O N E N T d e v e l
P U B L I C _ H E A D E R D E S T I N A T I O N i n c l u d e C O M P O N E N T d e v e l
I N C L U D E S D E S T I N A T I O N i n c l u d e C O M P O N E N T d e v e l )
2020-04-15 22:09:37 +08:00
endif ( )
endif ( MDBX_INSTALL_STATIC )
################################################################################
# collect options & build info
string ( TIMESTAMP MDBX_BUILD_TIMESTAMP UTC )
set ( MDBX_BUILD_FLAGS ${ CMAKE_C_FLAGS } )
2020-08-23 01:19:46 +08:00
if ( MDBX_BUILD_CXX )
set ( MDBX_BUILD_FLAGS ${ CMAKE_CXX_FLAGS } )
endif ( )
2020-04-15 22:09:37 +08: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-23 01:19:46 +08:00
if ( MDBX_BUILD_CXX )
list ( APPEND MDBX_BUILD_FLAGS ${ CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE } } )
endif ( )
2020-04-15 22:09:37 +08:00
endif ( )
2020-11-17 18:51:10 +08: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 22:09:37 +08:00
# get definitions
2020-11-17 18:51:10 +08:00
get_target_property ( defs_list ${ target4fetch } COMPILE_DEFINITIONS )
2020-04-15 22:09:37 +08:00
if ( defs_list )
list ( APPEND MDBX_BUILD_FLAGS ${ defs_list } )
endif ( )
# get target compile options
2020-11-17 18:51:10 +08:00
get_target_property ( options_list ${ target4fetch } COMPILE_OPTIONS )
2020-04-15 22:09:37 +08: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
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"
O U T P U T _ V A R I A B L E M D B X _ B U I L D _ C O M P I L E R
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
E R R O R _ Q U I E T
R E S U L T _ V A R I A B L E r c )
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 )
2020-09-29 04:47:37 +08:00
# via per-configuration define
2020-04-15 22:09:37 +08:00
add_definitions ( -DMDBX_BUILD_TYPE= "$<CONFIG>" )
2020-09-30 09:01:48 +08:00
set ( MDBX_BUILD_TYPE "<CONFIGURATION DEPENDENT>" )
2020-04-15 22:09:37 +08:00
else ( )
set ( MDBX_BUILD_TYPE ${ CMAKE_BUILD_TYPE } )
endif ( )
# options
2020-09-29 04:47:37 +08:00
set ( options VERSION C_COMPILER CXX_COMPILER MDBX_BUILD_TARGET MDBX_BUILD_TYPE )
2020-04-15 22:09:37 +08: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 ( )
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"
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c o n f i g . h " E S C A P E _ Q U O T E S )
add_definitions ( -DMDBX_CONFIG_H= "${CMAKE_CURRENT_BINARY_DIR}/config.h" )
2019-09-03 07:24:19 +08:00
################################################################################
2020-04-15 22:09:37 +08:00
if ( NOT MDBX_AMALGAMATED_SOURCE AND MDBX_ENABLE_TESTS )
2020-09-29 04:47:37 +08:00
if ( NOT CMAKE_CXX_COMPILER_LOADED )
2020-09-27 21:49:55 +08:00
message ( FATAL_ERROR "MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: The C++ compiler is required to build the tests." )
endif ( )
2019-08-31 22:13:02 +08:00
add_subdirectory ( test )
endif ( )
2020-09-27 21:45:00 +08:00
################################################################################
2019-09-05 16:57:52 +08: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 } )
set ( PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.${CPACK_PACKAGE_VERSION_COMMIT}" )
message ( STATUS "libmdbx package version is ${PACKAGE_VERSION}" )
2019-08-31 22:13:02 +08:00
cmake_policy ( POP )