From a2984c604de7ff7d0f48a55b21e9671c80022304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Wed, 13 Nov 2024 15:03:16 +0300 Subject: [PATCH] =?UTF-8?q?mdbx-cmake:=20=D0=BF=D0=B5=D1=80=D0=B5=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20cmake-=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82?= =?UTF-8?q?=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 890 ++++++++++++++++++++++++++----------------- cmake/compiler.cmake | 614 +++++++++++++++++++---------- cmake/profile.cmake | 30 +- cmake/utils.cmake | 253 ++++++++---- test/CMakeLists.txt | 306 +++++++++------ 5 files changed, 1344 insertions(+), 749 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d575c3db..793b8a60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,27 @@ -## Copyright (c) 2020-2024 Леонид Юрьев aka Leonid Yuriev -## SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2020-2024 Леонид Юрьев aka Leonid Yuriev +# SPDX-License-Identifier: Apache-2.0 -## -## libmdbx = { Revised and extended descendant of Symas LMDB. } -## Please see README.md at https://gitflic.ru/project/erthink/libmdbx -## -## Libmdbx is superior to LMDB in terms of features and reliability, -## not inferior in performance. libmdbx works on Linux, FreeBSD, MacOS X -## and other systems compliant with POSIX.1-2008, but also support Windows -## as a complementary platform. -## -## The next version is under active non-public development and will be -## released as MithrilDB and libmithrildb for libraries & packages. -## Admittedly mythical Mithril is resembling silver but being stronger and -## lighter than steel. Therefore MithrilDB is rightly relevant name. -## -## MithrilDB will be radically different from libmdbx by the new database -## format and API based on C++17, as well as the Apache 2.0 License. -## The goal of this revolution is to provide a clearer and robust API, -## add more features and new valuable properties of database. -## -## The Future will (be) Positive. Всё будет хорошо. -## +# +# libmdbx = { Revised and extended descendant of Symas LMDB. } Please see +# README.md at https://gitflic.ru/project/erthink/libmdbx +# +# Libmdbx is superior to LMDB in terms of features and reliability, not inferior +# in performance. libmdbx works on Linux, FreeBSD, MacOS X and other systems +# compliant with POSIX.1-2008, but also support Windows as a complementary +# platform. +# +# The next version is under active non-public development and will be released +# as MithrilDB and libmithrildb for libraries & packages. Admittedly mythical +# Mithril is resembling silver but being stronger and lighter than steel. +# Therefore MithrilDB is rightly relevant name. +# +# MithrilDB will be radically different from libmdbx by the new database format +# and API based on C++17, as well as the Apache 2.0 License. The goal of this +# revolution is to provide a clearer and robust API, add more features and new +# valuable properties of database. +# +# The Future will (be) Positive. Всё будет хорошо. +# if(CMAKE_VERSION VERSION_LESS 3.8.2) cmake_minimum_required(VERSION 3.0.2) @@ -57,142 +57,147 @@ else() set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE FALSE) endif() -if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/COPYRIGHT" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/NOTICE" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/README.md" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h++" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/alloy.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-cursor.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-env.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-extra.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-key-transform.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-txn.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/atomics-ops.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/atomics-types.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/audit.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/chk.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cogs.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cogs.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/coherency.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cold.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/copy.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cursor.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cursor.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dbi.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dbi.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/debug_begin.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/debug_end.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dpl.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dpl.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dxb.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/env-opts.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/env.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/essentials.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/gc-get.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/gc-put.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/gc.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/global.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/internals.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/layout-dxb.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/layout-lck.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck-posix.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck-windows.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/logging_and_debug.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/logging_and_debug.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_chk.1" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_copy.1" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_drop.1" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_dump.1" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_load.1" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_stat.1" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/mdbx.c++" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/meta.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/meta.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/misc.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/mvcc-readers.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/node.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/node.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/ntdll.def" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/options.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/osal.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/osal.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-get.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-iov.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-iov.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-ops.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-ops.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-search.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/pnl.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/pnl.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/preface.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/proto.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/range-estimate.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/refund.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/sort.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/spill.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/spill.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/table.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tls.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tls.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/chk.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/copy.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/drop.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/dump.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/load.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/stat.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/wingetopt.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/wingetopt.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tree.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/txl.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/txl.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/txn.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/unaligned.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/utils.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/utils.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/version.c.in" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/walk.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/walk.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/windows-import.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/windows-import.h") +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/COPYRIGHT" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/NOTICE" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/README.md" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h++" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/alloy.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-cursor.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-env.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-extra.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-key-transform.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/api-txn.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/atomics-ops.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/atomics-types.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/audit.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/chk.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cogs.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cogs.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/coherency.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cold.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/copy.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cursor.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/cursor.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dbi.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dbi.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/debug_begin.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/debug_end.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dpl.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dpl.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/dxb.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/env-opts.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/env.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/essentials.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/gc-get.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/gc-put.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/gc.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/global.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/internals.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/layout-dxb.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/layout-lck.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck-posix.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck-windows.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/lck.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/logging_and_debug.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/logging_and_debug.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_chk.1" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_copy.1" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_drop.1" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_dump.1" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_load.1" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/man1/mdbx_stat.1" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/mdbx.c++" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/meta.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/meta.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/misc.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/mvcc-readers.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/node.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/node.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/ntdll.def" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/options.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/osal.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/osal.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-get.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-iov.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-iov.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-ops.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-ops.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/page-search.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/pnl.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/pnl.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/preface.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/proto.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/range-estimate.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/refund.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/sort.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/spill.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/spill.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/table.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tls.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tls.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/chk.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/copy.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/drop.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/dump.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/load.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/stat.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/wingetopt.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tools/wingetopt.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/tree.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/txl.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/txl.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/txn.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/unaligned.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/utils.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/utils.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/version.c.in" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/walk.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/walk.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/windows-import.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/windows-import.h") 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.json" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/NOTICE" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.c++" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h++" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_chk.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_copy.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_dump.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_load.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_stat.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_drop.c" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ntdll.def" AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in") +elseif( + EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.json" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/NOTICE" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.c++" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx.h++" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_chk.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_copy.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_dump.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_load.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_stat.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mdbx_drop.c" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ntdll.def" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in") set(MDBX_AMALGAMATED_SOURCE TRUE) set(MDBX_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") else() - message(FATAL_ERROR "\n" - "The set of libmdbx source code files is incomplete! " - "Instead just follow the https://libmdbx.dqdkfa.ru/usage.html " - "PLEASE, AVOID USING ANY OTHER TECHNIQUES.") + message( + FATAL_ERROR + "\nThe set of libmdbx source code files is incomplete! " + "Instead just follow the https://libmdbx.dqdkfa.ru/usage.html " + "PLEASE, AVOID USING ANY OTHER TECHNIQUES.") endif() if(DEFINED PROJECT_NAME) - option(MDBX_FORCE_BUILD_AS_MAIN_PROJECT "Force libmdbx to full control build options even it added as a subdirectory to your project." OFF) + option( + MDBX_FORCE_BUILD_AS_MAIN_PROJECT + "Force libmdbx to full control build options even it added as a subdirectory to your project." + OFF) endif() if(DEFINED PROJECT_NAME AND NOT MDBX_FORCE_BUILD_AS_MAIN_PROJECT) @@ -215,15 +220,20 @@ if(NOT MDBX_AMALGAMATED_SOURCE) include(CTest) option(MDBX_ENABLE_TESTS "Build libmdbx tests." ${BUILD_TESTING}) elseif(DEFINED MDBX_ENABLE_TESTS AND MDBX_ENABLE_TESTS) - message(WARNING "MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: But amalgamated source code don't includes tests.") + message( + WARNING + "MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: But amalgamated source code don't includes tests." + ) set(MDBX_ENABLE_TESTS OFF) endif() # Try to find a C++ compiler unless sure that this is unnecessary. -if (NOT CMAKE_CXX_COMPILER_LOADED) +if(NOT CMAKE_CXX_COMPILER_LOADED) 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))) + 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) @@ -235,9 +245,12 @@ 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 - "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." - FORCE) + set(CMAKE_BUILD_TYPE + Release + CACHE + STRING + "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." + FORCE) endif() string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE) @@ -279,8 +292,9 @@ 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." - " At least 'Microsoft Visual Studio 2015' is required.") + message( + SEND_ERROR "MSVC compiler ${MSVC_VERSION} is too old for building MDBX." + " At least 'Microsoft Visual Studio 2015' is required.") endif() if(NOT DEFINED THREADS_PREFER_PTHREAD_FLAG) @@ -293,9 +307,11 @@ include(cmake/compiler.cmake) include(cmake/profile.cmake) # Workaround for `-pthread` toolchain/cmake bug -if(NOT APPLE AND NOT MSVC - AND CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_THREAD_LIBS_INIT - AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)) +if(NOT APPLE + AND NOT MSVC + AND CMAKE_USE_PTHREADS_INIT + AND NOT CMAKE_THREAD_LIBS_INIT + AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)) 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") @@ -305,12 +321,12 @@ if(NOT APPLE AND NOT MSVC endif() endif() -CHECK_FUNCTION_EXISTS(pow NOT_NEED_LIBM) +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) + check_function_exists(pow HAVE_LIBM) if(HAVE_LIBM) set(LIB_MATH m) else() @@ -323,52 +339,94 @@ if(SUBPROJECT) option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" OFF) endif() if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) - option(CMAKE_POSITION_INDEPENDENT_CODE "Generate position independent (PIC)" ON) + option(CMAKE_POSITION_INDEPENDENT_CODE + "Generate position independent (PIC)" ON) endif() set(MDBX_MANAGE_BUILD_FLAGS_DEFAULT OFF) else() option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" ON) - option(CMAKE_POSITION_INDEPENDENT_CODE "Generate position independent (PIC)" ON) - if (CC_HAS_ARCH_NATIVE) - option(BUILD_FOR_NATIVE_CPU "Generate code for the compiling machine CPU" OFF) + option(CMAKE_POSITION_INDEPENDENT_CODE "Generate position independent (PIC)" + ON) + if(CC_HAS_ARCH_NATIVE) + option(BUILD_FOR_NATIVE_CPU "Generate code for the compiling machine CPU" + OFF) endif() if(CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE - OR GCC_LTO_AVAILABLE OR MSVC_LTO_AVAILABLE OR CLANG_LTO_AVAILABLE) - if((CMAKE_CONFIGURATION_TYPES OR NOT CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG") AND - ((MSVC_LTO_AVAILABLE AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19) OR - (GCC_LTO_AVAILABLE AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7) OR - (CLANG_LTO_AVAILABLE AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5))) + OR GCC_LTO_AVAILABLE + OR MSVC_LTO_AVAILABLE + OR CLANG_LTO_AVAILABLE) + if((CMAKE_CONFIGURATION_TYPES OR NOT CMAKE_BUILD_TYPE_UPPERCASE STREQUAL + "DEBUG") + AND ((MSVC_LTO_AVAILABLE AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19 + ) + OR (GCC_LTO_AVAILABLE AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS + 7) + OR (CLANG_LTO_AVAILABLE AND NOT CMAKE_C_COMPILER_VERSION + VERSION_LESS 5) + )) set(INTERPROCEDURAL_OPTIMIZATION_DEFAULT ON) else() set(INTERPROCEDURAL_OPTIMIZATION_DEFAULT OFF) endif() - option(INTERPROCEDURAL_OPTIMIZATION "Enable interprocedural/LTO optimization." ${INTERPROCEDURAL_OPTIMIZATION_DEFAULT}) + option(INTERPROCEDURAL_OPTIMIZATION + "Enable interprocedural/LTO optimization." + ${INTERPROCEDURAL_OPTIMIZATION_DEFAULT}) 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_C_COMPILER_AR ${CMAKE_AR} CACHE PATH "Path to ar program with LTO-plugin" FORCE) - set(CMAKE_CXX_COMPILER_AR ${CMAKE_AR} CACHE PATH "Path to ar program with LTO-plugin" FORCE) - set(CMAKE_NM ${CMAKE_GCC_NM} CACHE PATH "Path to nm program with LTO-plugin" FORCE) - set(CMAKE_RANLIB ${CMAKE_GCC_RANLIB} CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) - set(CMAKE_C_COMPILER_RANLIB ${CMAKE_RANLIB} CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) - set(CMAKE_CXX_COMPILER_RANLIB ${CMAKE_RANLIB} CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) + set(CMAKE_AR + ${CMAKE_GCC_AR} + CACHE PATH "Path to ar program with LTO-plugin" FORCE) + set(CMAKE_C_COMPILER_AR + ${CMAKE_AR} + CACHE PATH "Path to ar program with LTO-plugin" FORCE) + set(CMAKE_CXX_COMPILER_AR + ${CMAKE_AR} + CACHE PATH "Path to ar program with LTO-plugin" FORCE) + set(CMAKE_NM + ${CMAKE_GCC_NM} + CACHE PATH "Path to nm program with LTO-plugin" FORCE) + set(CMAKE_RANLIB + ${CMAKE_GCC_RANLIB} + CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) + set(CMAKE_C_COMPILER_RANLIB + ${CMAKE_RANLIB} + CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) + set(CMAKE_CXX_COMPILER_RANLIB + ${CMAKE_RANLIB} + CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) message(STATUS "MDBX indulge Link-Time Optimization by GCC") elseif(CLANG_LTO_AVAILABLE) set(LTO_ENABLED TRUE) if(CMAKE_CLANG_LD) - set(CMAKE_LINKER ${CMAKE_CLANG_LD} CACHE PATH "Path to lld or ld program with LTO-plugin" FORCE) + set(CMAKE_LINKER + ${CMAKE_CLANG_LD} + CACHE PATH "Path to lld or ld program with LTO-plugin" FORCE) endif() - set(CMAKE_AR ${CMAKE_CLANG_AR} CACHE PATH "Path to ar program with LTO-plugin" FORCE) - set(CMAKE_C_COMPILER_AR ${CMAKE_AR} CACHE PATH "Path to ar program with LTO-plugin" FORCE) - set(CMAKE_CXX_COMPILER_AR ${CMAKE_AR} CACHE PATH "Path to ar program with LTO-plugin" FORCE) - set(CMAKE_NM ${CMAKE_CLANG_NM} CACHE PATH "Path to nm program with LTO-plugin" FORCE) - set(CMAKE_RANLIB ${CMAKE_CLANG_RANLIB} CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) - set(CMAKE_C_COMPILER_RANLIB ${CMAKE_RANLIB} CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) - set(CMAKE_CXX_COMPILER_RANLIB ${CMAKE_RANLIB} CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) + set(CMAKE_AR + ${CMAKE_CLANG_AR} + CACHE PATH "Path to ar program with LTO-plugin" FORCE) + set(CMAKE_C_COMPILER_AR + ${CMAKE_AR} + CACHE PATH "Path to ar program with LTO-plugin" FORCE) + set(CMAKE_CXX_COMPILER_AR + ${CMAKE_AR} + CACHE PATH "Path to ar program with LTO-plugin" FORCE) + set(CMAKE_NM + ${CMAKE_CLANG_NM} + CACHE PATH "Path to nm program with LTO-plugin" FORCE) + set(CMAKE_RANLIB + ${CMAKE_CLANG_RANLIB} + CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) + set(CMAKE_C_COMPILER_RANLIB + ${CMAKE_RANLIB} + CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) + set(CMAKE_CXX_COMPILER_RANLIB + ${CMAKE_RANLIB} + CACHE PATH "Path to ranlib program with LTO-plugin" FORCE) message(STATUS "MDBX indulge Link-Time Optimization by CLANG") elseif(MSVC_LTO_AVAILABLE) set(LTO_ENABLED TRUE) @@ -388,40 +446,45 @@ else() 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. + # (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) + "${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 --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) + "--trace-children=yes --leak-check=full --track-origins=yes --track-origins=yes --error-exitcode=42 --error-markers=@ --errors-for-leak-kinds=definite --fair-sched=yes --suppressions=${MEMORYCHECK_SUPPRESSIONS_FILE}" + CACHE STRING "Valgrind options" FORCE) + set(VALGRIND_COMMAND_OPTIONS + "${MEMORYCHECK_COMMAND_OPTIONS}" + CACHE STRING "Valgrind options" FORCE) endif() # Enable 'make tags' target. find_program(CTAGS ctags) if(CTAGS) - add_custom_target(tags COMMAND ${CTAGS} -R -f tags + add_custom_target( + tags + COMMAND ${CTAGS} -R -f tags WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) add_custom_target(ctags DEPENDS tags) endif(CTAGS) if(UNIX) - find_program(CLANG_FORMAT - NAMES clang-format-13 clang-format) + find_program(CLANG_FORMAT NAMES clang-format-13 clang-format) 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 13.0) + execute_process(COMMAND ${CLANG_FORMAT} "--version" + OUTPUT_VARIABLE clang_format_version_info) + string(REGEX MATCH "version ([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" + clang_format_version_info CLANG_FORMAT_VERSION) + if(clang_format_version_info AND NOT CLANG_FORMAT_VERSION VERSION_LESS + 13.0) # Enable 'make reformat' target. - add_custom_target(reformat + 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 + 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() endif() @@ -429,12 +492,16 @@ else() if(NOT "${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}") add_custom_target(distclean) - add_custom_command(TARGET distclean POST_BUILD + add_custom_command( + TARGET distclean + POST_BUILD 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 POST_BUILD + add_custom_command( + TARGET distclean + POST_BUILD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT} submodule foreach --recursive git clean -f -X -d COMMAND ${GIT} clean -f -X -d @@ -445,7 +512,9 @@ else() set(MDBX_MANAGE_BUILD_FLAGS_DEFAULT ON) endif(SUBPROJECT) -option(MDBX_MANAGE_BUILD_FLAGS "Allow libmdbx to configure/manage/override its own build flags" ${MDBX_MANAGE_BUILD_FLAGS_DEFAULT}) +option(MDBX_MANAGE_BUILD_FLAGS + "Allow libmdbx to configure/manage/override its own build flags" + ${MDBX_MANAGE_BUILD_FLAGS_DEFAULT}) if(MDBX_MANAGE_BUILD_FLAGS) setup_compile_flags() endif() @@ -462,13 +531,16 @@ if(NOT DEFINED MDBX_CXX_STANDARD) if(DEFINED CMAKE_CXX_STANDARD) set(MDBX_CXX_STANDARD ${CMAKE_CXX_STANDARD}) elseif(NOT HAS_CXX23 LESS 0 - AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)) + AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION + VERSION_LESS 12)) set(MDBX_CXX_STANDARD 23) elseif(NOT HAS_CXX20 LESS 0 - AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10)) + AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION + VERSION_LESS 10)) set(MDBX_CXX_STANDARD 20) elseif(NOT HAS_CXX17 LESS 0 - AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)) + AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION + VERSION_LESS 5)) set(MDBX_CXX_STANDARD 17) elseif(NOT HAS_CXX14 LESS 0) set(MDBX_CXX_STANDARD 14) @@ -484,15 +556,20 @@ endif() list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11) list(FIND CMAKE_C_COMPILE_FEATURES c_std_23 HAS_C23) 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(MSVC AND MSVC_VERSION GREATER 1927 AND NOT MSVC_VERSION GREATER 1929) + # MSVC >= 19.28 (Microsoft Visual Studio 16.8) is mad! It unable process + # Windows SDK headers in the C11 mode! + if(MSVC + AND MSVC_VERSION GREATER 1927 + AND NOT MSVC_VERSION GREATER 1929) set(MDBX_C_STANDARD 99) set(C_FALLBACK_11 OFF) set(C_FALLBACK_GNU11 OFF) elseif(NOT HAS_C23 LESS 0) set(MDBX_C_STANDARD 23) - elseif(HAS_C11 LESS 0 AND NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11) + elseif( + HAS_C11 LESS 0 + AND NOT C_FALLBACK_GNU11 + AND NOT C_FALLBACK_11) set(MDBX_C_STANDARD 99) else() set(MDBX_C_STANDARD 11) @@ -509,11 +586,16 @@ if(WIN32 AND EXISTS "${MDBX_SOURCE_DIR}/ntdll.def") 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}" + 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}) + 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() @@ -526,32 +608,35 @@ if(WIN32 AND EXISTS "${MDBX_SOURCE_DIR}/ntdll.def") 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}" + 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}") + 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 + # 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 + # (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}") + # (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() -################################################################################ -################################################################################ +# ############################################################################## +# ~~~ # # #### ##### ##### # #### # # #### # # # # # # # # # ## # # @@ -560,8 +645,11 @@ endif() # # # # # # # # # ## # # # #### # # # #### # # #### # +# ~~~ +# ############################################################################## -set(MDBX_BUILD_OPTIONS ENABLE_UBSAN ENABLE_ASAN ENABLE_MEMCHECK ENABLE_GPROF ENABLE_GCOV) +set(MDBX_BUILD_OPTIONS ENABLE_UBSAN ENABLE_ASAN ENABLE_MEMCHECK ENABLE_GPROF + ENABLE_GCOV) macro(add_mdbx_option NAME DESCRIPTION DEFAULT) list(APPEND MDBX_BUILD_OPTIONS ${NAME}) if(NOT ${DEFAULT} STREQUAL "AUTO") @@ -581,48 +669,81 @@ else() set(MDBX_BUILD_TOOLS_DEFAULT ON) endif() -add_mdbx_option(MDBX_INSTALL_STATIC "Build and install libmdbx for static linking" OFF) -add_mdbx_option(MDBX_BUILD_SHARED_LIBRARY "Build libmdbx as shared library (DLL)" ${BUILD_SHARED_LIBS}) -add_mdbx_option(MDBX_BUILD_TOOLS "Build MDBX tools (mdbx_chk/stat/dump/load/copy)" ${MDBX_BUILD_TOOLS_DEFAULT}) -CMAKE_DEPENDENT_OPTION(MDBX_INSTALL_MANPAGES "Install man-pages for MDBX tools (mdbx_chk/stat/dump/load/copy)" ON MDBX_BUILD_TOOLS OFF) -add_mdbx_option(MDBX_TXN_CHECKOWNER "Checking transaction matches the calling thread inside libmdbx's API" ON) -add_mdbx_option(MDBX_ENV_CHECKPID "Paranoid checking PID inside libmdbx's API" AUTO) +add_mdbx_option(MDBX_INSTALL_STATIC + "Build and install libmdbx for static linking" OFF) +add_mdbx_option(MDBX_BUILD_SHARED_LIBRARY + "Build libmdbx as shared library (DLL)" ${BUILD_SHARED_LIBS}) +add_mdbx_option( + MDBX_BUILD_TOOLS "Build MDBX tools (mdbx_chk/stat/dump/load/copy)" + ${MDBX_BUILD_TOOLS_DEFAULT}) +cmake_dependent_option( + MDBX_INSTALL_MANPAGES + "Install man-pages for MDBX tools (mdbx_chk/stat/dump/load/copy)" ON + MDBX_BUILD_TOOLS OFF) +add_mdbx_option( + MDBX_TXN_CHECKOWNER + "Checking transaction matches the calling thread inside libmdbx's API" ON) +add_mdbx_option(MDBX_ENV_CHECKPID "Paranoid checking PID inside libmdbx's API" + AUTO) mark_as_advanced(MDBX_ENV_CHECKPID) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use GNU/Linux libc extensions" 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" OR IOS) - add_mdbx_option(MDBX_OSX_SPEED_INSTEADOF_DURABILITY "Disable use fcntl(F_FULLFSYNC) in favor of speed" OFF) + 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(WIN32) if(MDBX_NTDLL_EXTRA_IMPLIB) - add_mdbx_option(MDBX_WITHOUT_MSVC_CRT "Avoid dependence from MSVC CRT and use ntdll.dll instead" OFF) + add_mdbx_option( + MDBX_WITHOUT_MSVC_CRT + "Avoid dependence from MSVC CRT and use ntdll.dll instead" OFF) endif() set(MDBX_AVOID_MSYNC_DEFAULT ON) else() - add_mdbx_option(MDBX_USE_OFDLOCKS "Use Open file description locks (aka OFD locks, non-POSIX)" AUTO) + add_mdbx_option( + MDBX_USE_OFDLOCKS + "Use Open file description locks (aka OFD locks, non-POSIX)" AUTO) mark_as_advanced(MDBX_USE_OFDLOCKS) set(MDBX_AVOID_MSYNC_DEFAULT OFF) endif() -add_mdbx_option(MDBX_AVOID_MSYNC "Controls dirty pages tracking, spilling and persisting in MDBX_WRITEMAP mode" ${MDBX_AVOID_MSYNC_DEFAULT}) -add_mdbx_option(MDBX_LOCKING "Locking method (Windows=-1, SysV=5, POSIX=1988, POSIX=2001, POSIX=2008, Futexes=1995)" AUTO) +add_mdbx_option( + MDBX_AVOID_MSYNC + "Controls dirty pages tracking, spilling and persisting in MDBX_WRITEMAP mode" + ${MDBX_AVOID_MSYNC_DEFAULT}) +add_mdbx_option( + MDBX_LOCKING + "Locking method (Windows=-1, SysV=5, POSIX=1988, POSIX=2001, POSIX=2008, Futexes=1995)" + AUTO) 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) add_mdbx_option(MDBX_FORCE_ASSERTIONS "Force enable assertion checking" OFF) -add_mdbx_option(MDBX_DISABLE_VALIDATION "Disable some checks to reduce an overhead and detection probability of database corruption to a values closer to the LMDB" OFF) +add_mdbx_option( + MDBX_DISABLE_VALIDATION + "Disable some checks to reduce an overhead and detection probability of database corruption to a values closer to the LMDB" + OFF) mark_as_advanced(MDBX_DISABLE_VALIDATION) -add_mdbx_option(MDBX_ENABLE_REFUND "Zerocost auto-compactification during write-transactions" ON) -add_mdbx_option(MDBX_ENABLE_MADVISE "Using POSIX' madvise() and/or similar hints" ON) -if (CMAKE_TARGET_BITNESS GREATER 32) +add_mdbx_option(MDBX_ENABLE_REFUND + "Zerocost auto-compactification during write-transactions" ON) +add_mdbx_option(MDBX_ENABLE_MADVISE + "Using POSIX' madvise() and/or similar hints" ON) +if(CMAKE_TARGET_BITNESS GREATER 32) set(MDBX_BIGFOOT_DEFAULT ON) else() set(MDBX_BIGFOOT_DEFAULT OFF) endif() -add_mdbx_option(MDBX_ENABLE_BIGFOOT "Chunking long list of retired pages during huge transactions commit to avoid use sequences of pages" ${MDBX_BIGFOOT_DEFAULT}) -add_mdbx_option(MDBX_ENABLE_PGOP_STAT "Gathering statistics for page operations" ON) +add_mdbx_option( + MDBX_ENABLE_BIGFOOT + "Chunking long list of retired pages during huge transactions commit to avoid use sequences of pages" + ${MDBX_BIGFOOT_DEFAULT}) +add_mdbx_option(MDBX_ENABLE_PGOP_STAT + "Gathering statistics for page operations" ON) add_mdbx_option(MDBX_ENABLE_PROFGC "Profiling of GC search and updates" OFF) mark_as_advanced(MDBX_ENABLE_PROFGC) add_mdbx_option(MDBX_ENABLE_DBI_SPARSE "FIXME" ON) @@ -634,23 +755,30 @@ if(NOT MDBX_AMALGAMATED_SOURCE) else() set(MDBX_ALLOY_BUILD_DEFAULT ON) endif() - add_mdbx_option(MDBX_ALLOY_BUILD "Build MDBX library through single/alloyed object file" ${MDBX_ALLOY_BUILD_DEFAULT}) + add_mdbx_option( + MDBX_ALLOY_BUILD "Build MDBX library through single/alloyed object file" + ${MDBX_ALLOY_BUILD_DEFAULT}) endif() 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) + add_mdbx_option(MDBX_LINK_TOOLS_NONSTATIC + "Link MDBX tools with non-static libmdbx" OFF) else() unset(MDBX_LINK_TOOLS_NONSTATIC CACHE) endif() -if(CMAKE_CXX_COMPILER_LOADED AND MDBX_CXX_STANDARD LESS 83 AND NOT MDBX_CXX_STANDARD LESS 11) +if(CMAKE_CXX_COMPILER_LOADED + AND MDBX_CXX_STANDARD LESS 83 + AND NOT MDBX_CXX_STANDARD LESS 11) if(NOT MDBX_AMALGAMATED_SOURCE) option(MDBX_ENABLE_TESTS "Build MDBX tests" ${BUILD_TESTING}) endif() if(NOT MDBX_WITHOUT_MSVC_CRT - AND NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) - AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.9) - AND NOT (MSVC AND MSVC_VERSION LESS 1900)) + AND NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION + VERSION_LESS 4.8) + AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION + VERSION_LESS 3.9) + AND NOT (MSVC AND MSVC_VERSION LESS 1900)) option(MDBX_BUILD_CXX "Build C++ portion" ON) else() set(MDBX_BUILD_CXX FALSE) @@ -664,11 +792,13 @@ if(CI) add_definitions(-DMDBX_CI="${CI}") endif() -################################################################################ -################################################################################ +# ############################################################################## if(MDBX_BUILD_CXX AND NOT CMAKE_CXX_COMPILER_LOADED) - message(FATAL_ERROR "MDBX_BUILD_CXX=${MDBX_BUILD_CXX}: The C++ compiler is required to build the C++API.") + message( + FATAL_ERROR + "MDBX_BUILD_CXX=${MDBX_BUILD_CXX}: The C++ compiler is required to build the C++API." + ) endif() if(MDBX_BUILD_CXX) @@ -677,7 +807,8 @@ if(MDBX_BUILD_CXX) endif() # Get version -fetch_version(MDBX "${CMAKE_CURRENT_SOURCE_DIR}" FALSE "${CMAKE_CURRENT_BINARY_DIR}") +fetch_version(MDBX "${CMAKE_CURRENT_SOURCE_DIR}" FALSE + "${CMAKE_CURRENT_BINARY_DIR}") message(STATUS "libmdbx version is ${MDBX_VERSION}") # sources list @@ -688,7 +819,7 @@ if(MDBX_AMALGAMATED_SOURCE) else() # generate version file configure_file("${MDBX_SOURCE_DIR}/version.c.in" - "${CMAKE_CURRENT_BINARY_DIR}/version.c" ESCAPE_QUOTES) + "${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}") @@ -697,7 +828,9 @@ else() list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/alloy.c") include_directories("${MDBX_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") else() - list(APPEND LIBMDBX_SOURCES + list( + APPEND + LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/api-cursor.c" "${MDBX_SOURCE_DIR}/api-env.c" "${MDBX_SOURCE_DIR}/api-extra.c" @@ -769,56 +902,60 @@ else() "${MDBX_SOURCE_DIR}/utils.h" "${MDBX_SOURCE_DIR}/walk.c" "${MDBX_SOURCE_DIR}/walk.h" - "${CMAKE_CURRENT_BINARY_DIR}/version.c" - ) + "${CMAKE_CURRENT_BINARY_DIR}/version.c") if(NOT MSVC) list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/lck-posix.c") endif() if(NOT APPLE) - list(APPEND LIBMDBX_SOURCES - "${MDBX_SOURCE_DIR}/windows-import.h" - "${MDBX_SOURCE_DIR}/windows-import.c" - "${MDBX_SOURCE_DIR}/lck-windows.c" - ) + list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/windows-import.h" + "${MDBX_SOURCE_DIR}/windows-import.c" + "${MDBX_SOURCE_DIR}/lck-windows.c") endif() include_directories("${MDBX_SOURCE_DIR}") endif() endif(MDBX_AMALGAMATED_SOURCE) if(MDBX_BUILD_CXX) - message(STATUS "Use C${MDBX_C_STANDARD} and C++${MDBX_CXX_STANDARD} for libmdbx") + message( + STATUS "Use C${MDBX_C_STANDARD} and C++${MDBX_CXX_STANDARD} for libmdbx") list(APPEND LIBMDBX_PUBLIC_HEADERS mdbx.h++) 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") + message( + STATUS "Use C${MDBX_C_STANDARD} for libmdbx but C++ portion is disabled") endif() if(SUBPROJECT AND MSVC) if(MSVC_VERSION LESS 1900) - message(FATAL_ERROR "At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required.") + message( + FATAL_ERROR + "At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required." + ) endif() add_compile_options("/utf-8") endif() macro(target_setup_options TARGET) if(DEFINED INTERPROCEDURAL_OPTIMIZATION) - set_target_properties(${TARGET} PROPERTIES - INTERPROCEDURAL_OPTIMIZATION $) + set_target_properties( + ${TARGET} PROPERTIES INTERPROCEDURAL_OPTIMIZATION + $) endif() if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11) - set_target_properties(${TARGET} PROPERTIES - C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON) + set_target_properties(${TARGET} PROPERTIES C_STANDARD ${MDBX_C_STANDARD} + C_STANDARD_REQUIRED ON) endif() if(MDBX_BUILD_CXX) if(NOT CXX_FALLBACK_GNU11 AND NOT CXX_FALLBACK_11) - set_target_properties(${TARGET} PROPERTIES - CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON) + set_target_properties( + ${TARGET} PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} + CXX_STANDARD_REQUIRED ON) endif() if(MSVC AND NOT MSVC_VERSION LESS 1910) target_compile_options(${TARGET} INTERFACE "/Zc:__cplusplus") endif() endif() - if(CC_HAS_FASTMATH - AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10)) + if(CC_HAS_FASTMATH AND NOT (CMAKE_COMPILER_IS_CLANG + AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10)) target_compile_options(${TARGET} PRIVATE "-ffast-math") endif() if(CC_HAS_VISIBILITY) @@ -836,18 +973,27 @@ macro(libmdbx_setup_libs TARGET MODE) target_link_libraries(${TARGET} ${MODE} Threads::Threads) endif() if(WIN32) - target_link_libraries(${TARGET} ${MODE} ntdll user32 kernel32 advapi32 ole32) + target_link_libraries( + ${TARGET} + ${MODE} + ntdll + user32 + kernel32 + advapi32 + ole32) if(MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_WITHOUT_MSVC_CRT) target_link_libraries(${TARGET} ${MODE} ntdll_extra) endif() - elseif(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Solaris") + 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() if(LIBCXX_FILESYSTEM AND MDBX_BUILD_CXX) - if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.25.23 - AND NOT CMAKE_VERSION VERSION_LESS 3.13) + if(CMAKE_COMPILER_IS_ELBRUSCXX + AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.25.23 + AND NOT CMAKE_VERSION VERSION_LESS 3.13) target_link_options(${TARGET} PUBLIC "-Wl,--allow-multiple-definition") endif() target_link_libraries(${TARGET} PUBLIC ${LIBCXX_FILESYSTEM}) @@ -860,7 +1006,8 @@ if(MDBX_INSTALL_STATIC) else() add_library(mdbx-static STATIC EXCLUDE_FROM_ALL ${LIBMDBX_SOURCES}) endif() -set_target_properties(mdbx-static PROPERTIES PUBLIC_HEADER "${LIBMDBX_PUBLIC_HEADERS}") +set_target_properties(mdbx-static PROPERTIES PUBLIC_HEADER + "${LIBMDBX_PUBLIC_HEADERS}") target_compile_definitions(mdbx-static PRIVATE MDBX_BUILD_SHARED_LIBRARY=0) target_setup_options(mdbx-static) libmdbx_setup_libs(mdbx-static INTERFACE) @@ -871,20 +1018,26 @@ else() endif() target_include_directories(mdbx-static INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}") -################################################################################ +# ############################################################################## # build shared library if(MDBX_BUILD_SHARED_LIBRARY) add_library(mdbx SHARED ${LIBMDBX_SOURCES}) - set_target_properties(mdbx PROPERTIES PUBLIC_HEADER "${LIBMDBX_PUBLIC_HEADERS}") - target_compile_definitions(mdbx PRIVATE LIBMDBX_EXPORTS MDBX_BUILD_SHARED_LIBRARY=1 INTERFACE LIBMDBX_IMPORTS) + set_target_properties(mdbx PROPERTIES PUBLIC_HEADER + "${LIBMDBX_PUBLIC_HEADERS}") + target_compile_definitions( + mdbx + PRIVATE LIBMDBX_EXPORTS MDBX_BUILD_SHARED_LIBRARY=1 + INTERFACE LIBMDBX_IMPORTS) target_setup_options(mdbx) libmdbx_setup_libs(mdbx PRIVATE) if(MSVC) if(MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_WITHOUT_MSVC_CRT) set_property(TARGET mdbx PROPERTY LINKER_FLAGS "/NODEFAULTLIB") else() - set_property(TARGET mdbx PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + set_property( + TARGET mdbx PROPERTY MSVC_RUNTIME_LIBRARY + "MultiThreaded$<$:Debug>DLL") endif() endif() if(CC_HAS_VISIBILITY AND (LTO_ENABLED OR INTERPROCEDURAL_OPTIMIZATION)) @@ -900,15 +1053,18 @@ if(MDBX_BUILD_SHARED_LIBRARY AND MDBX_LINK_TOOLS_NONSTATIC) # 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) + # 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 + # 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) + # 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") @@ -918,8 +1074,8 @@ if(MDBX_BUILD_SHARED_LIBRARY AND MDBX_LINK_TOOLS_NONSTATIC) endif() if(WIN32) - # Windows don't have RPATH feature, - # therefore we should prepare PATH or copy DLL(s) + # Windows don't have RPATH feature, therefore we should prepare PATH or copy + # DLL(s) set(TOOL_MDBX_DLLCRUTCH "Crutch for ${CMAKE_SYSTEM_NAME}") if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_VERSION VERSION_LESS 3.0) # will use LOCATION property to compose DLLPATH @@ -937,18 +1093,21 @@ endif() if(MDBX_BUILD_TOOLS) set(WINGETOPT_SRC "") if(WIN32) - set(WINGETOPT_SRC ${MDBX_SOURCE_DIR}/tools/wingetopt.c ${MDBX_SOURCE_DIR}/tools/wingetopt.h) + set(WINGETOPT_SRC ${MDBX_SOURCE_DIR}/tools/wingetopt.c + ${MDBX_SOURCE_DIR}/tools/wingetopt.h) endif() foreach(TOOL chk copy stat dump load drop) if(MDBX_AMALGAMATED_SOURCE) add_executable(mdbx_${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/mdbx_${TOOL}.c) else() - add_executable(mdbx_${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/tools/${TOOL}.c ${WINGETOPT_SRC}) + add_executable(mdbx_${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/tools/${TOOL}.c + ${WINGETOPT_SRC}) endif() if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11) - set_target_properties(mdbx_${TOOL} PROPERTIES - C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON) + set_target_properties( + mdbx_${TOOL} PROPERTIES C_STANDARD ${MDBX_C_STANDARD} + C_STANDARD_REQUIRED ON) endif() target_setup_options(mdbx_${TOOL}) target_link_libraries(mdbx_${TOOL} ${TOOL_MDBX_LIB}) @@ -959,7 +1118,7 @@ if(MDBX_BUILD_TOOLS) endif() endif() -################################################################################ +# ############################################################################## # mdbx-shared-lib installation if(NOT DEFINED MDBX_DLL_INSTALL_DESTINATION) @@ -971,19 +1130,28 @@ if(NOT DEFINED MDBX_DLL_INSTALL_DESTINATION) endif() if(MDBX_BUILD_SHARED_LIBRARY) if(CMAKE_VERSION VERSION_LESS 3.12) - install(TARGETS mdbx EXPORT libmdbx + install( + TARGETS mdbx + EXPORT libmdbx LIBRARY DESTINATION ${MDBX_DLL_INSTALL_DESTINATION} COMPONENT runtime ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel) + INCLUDES + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT devel) else() - install(TARGETS mdbx EXPORT libmdbx - LIBRARY DESTINATION ${MDBX_DLL_INSTALL_DESTINATION} COMPONENT runtime - NAMELINK_COMPONENT devel + install( + TARGETS mdbx + EXPORT libmdbx + LIBRARY DESTINATION ${MDBX_DLL_INSTALL_DESTINATION} + COMPONENT runtime + NAMELINK_COMPONENT devel OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel) + INCLUDES + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT devel) endif() endif(MDBX_BUILD_SHARED_LIBRARY) @@ -992,29 +1160,20 @@ if(MDBX_BUILD_TOOLS) if(NOT DEFINED MDBX_TOOLS_INSTALL_DESTINATION) set(MDBX_TOOLS_INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - install( - TARGETS - mdbx_chk - mdbx_stat - mdbx_copy - mdbx_dump - mdbx_load - mdbx_drop - RUNTIME - DESTINATION ${MDBX_TOOLS_INSTALL_DESTINATION} - COMPONENT runtime) + install(TARGETS mdbx_chk mdbx_stat mdbx_copy mdbx_dump mdbx_load mdbx_drop + RUNTIME DESTINATION ${MDBX_TOOLS_INSTALL_DESTINATION} + COMPONENT runtime) if(MDBX_INSTALL_MANPAGES) if(NOT DEFINED MDBX_MAN_INSTALL_DESTINATION) set(MDBX_MAN_INSTALL_DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) endif() 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" - "${MDBX_SOURCE_DIR}/man1/mdbx_drop.1" + FILES "${MDBX_SOURCE_DIR}/man1/mdbx_chk.1" + "${MDBX_SOURCE_DIR}/man1/mdbx_stat.1" + "${MDBX_SOURCE_DIR}/man1/mdbx_copy.1" + "${MDBX_SOURCE_DIR}/man1/mdbx_dump.1" + "${MDBX_SOURCE_DIR}/man1/mdbx_load.1" + "${MDBX_SOURCE_DIR}/man1/mdbx_drop.1" DESTINATION ${MDBX_MAN_INSTALL_DESTINATION} COMPONENT doc) endif() @@ -1023,24 +1182,33 @@ 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 + install( + TARGETS mdbx-static + EXPORT libmdbx LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel) + INCLUDES + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT devel) else() - install(TARGETS mdbx-static EXPORT libmdbx - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel - NAMELINK_COMPONENT devel + install( + TARGETS mdbx-static + EXPORT libmdbx + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT devel + NAMELINK_COMPONENT devel OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel) + INCLUDES + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT devel) endif() endif(MDBX_INSTALL_STATIC) -################################################################################ +# ############################################################################## # collect options & build info if(NOT DEFINED MDBX_BUILD_TIMESTAMP) @@ -1055,7 +1223,8 @@ endif() if(NOT CMAKE_CONFIGURATION_TYPES) list(APPEND MDBX_BUILD_FLAGS ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}) if(MDBX_BUILD_CXX) - list(APPEND MDBX_BUILD_FLAGS ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}) + list(APPEND MDBX_BUILD_FLAGS + ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}) endif() endif() @@ -1082,20 +1251,25 @@ 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} ") - add_definitions(-DMDBX_BUILD_FLAGS_CONFIG="$<$:${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_DEFINES_DEBUG}>$<$:${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_DEFINES_RELEASE}>$<$:${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CMAKE_C_DEFINES_RELWITHDEBINFO}>$<$:${CMAKE_C_FLAGS_MINSIZEREL} ${CMAKE_C_DEFINES_MINSIZEREL}>") + message( + STATUS + "MDBX Compile Flags: ${MDBX_BUILD_FLAGS} ") + add_definitions( + -DMDBX_BUILD_FLAGS_CONFIG="$<$:${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_DEFINES_DEBUG}>$<$:${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_DEFINES_RELEASE}>$<$:${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CMAKE_C_DEFINES_RELWITHDEBINFO}>$<$:${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" +execute_process( + COMMAND sh -c "${CMAKE_C_COMPILER} --version | head -1" OUTPUT_VARIABLE MDBX_BUILD_COMPILER - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET + 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) + string(STRIP "${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}" + MDBX_BUILD_COMPILER) endif() # make a build-target triplet @@ -1104,7 +1278,8 @@ if(CMAKE_C_COMPILER_TARGET) else() if(CMAKE_C_COMPILER_ARCHITECTURE_ID) string(STRIP "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MDBX_BUILD_TARGET) - elseif(CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL CMAKE_SYSTEM_NAME) + elseif(CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL + CMAKE_SYSTEM_NAME) string(STRIP "${CMAKE_GENERATOR_PLATFORM}" MDBX_BUILD_TARGET) elseif(CMAKE_SYSTEM_ARCH) string(STRIP "${CMAKE_SYSTEM_ARCH}" MDBX_BUILD_TARGET) @@ -1116,14 +1291,19 @@ else() set(MDBX_BUILD_TARGET "unknown") endif() if(CMAKE_C_COMPILER_ABI - AND NOT (CMAKE_C_COMPILER_ABI MATCHES ".*${MDBX_BUILD_TARGET}.*" OR MDBX_BUILD_TARGET MATCHES ".*${CMAKE_C_COMPILER_ABI}.*")) - string(CONCAT MDBX_BUILD_TARGET "${MDBX_BUILD_TARGET}-${CMAKE_C_COMPILER_ABI}") + AND NOT (CMAKE_C_COMPILER_ABI MATCHES ".*${MDBX_BUILD_TARGET}.*" + OR MDBX_BUILD_TARGET MATCHES ".*${CMAKE_C_COMPILER_ABI}.*")) + string(CONCAT MDBX_BUILD_TARGET + "${MDBX_BUILD_TARGET}-${CMAKE_C_COMPILER_ABI}") endif() if(CMAKE_C_PLATFORM_ID - AND NOT (CMAKE_SYSTEM_NAME - AND (CMAKE_C_PLATFORM_ID MATCHES ".*${CMAKE_SYSTEM_NAME}.*" OR CMAKE_SYSTEM_NAME MATCHES ".*${CMAKE_C_PLATFORM_ID}.*")) - AND NOT (CMAKE_C_PLATFORM_ID MATCHES ".*${CMAKE_C_PLATFORM_ID}.*" OR MDBX_BUILD_TARGET MATCHES ".*${CMAKE_C_PLATFORM_ID}.*")) - string(CONCAT MDBX_BUILD_TARGET "${MDBX_BUILD_TARGET}-${CMAKE_C_COMPILER_ABI}") + AND NOT (CMAKE_SYSTEM_NAME + AND (CMAKE_C_PLATFORM_ID MATCHES ".*${CMAKE_SYSTEM_NAME}.*" + OR CMAKE_SYSTEM_NAME MATCHES ".*${CMAKE_C_PLATFORM_ID}.*")) + AND NOT (CMAKE_C_PLATFORM_ID MATCHES ".*${CMAKE_C_PLATFORM_ID}.*" + OR MDBX_BUILD_TARGET MATCHES ".*${CMAKE_C_PLATFORM_ID}.*")) + string(CONCAT MDBX_BUILD_TARGET + "${MDBX_BUILD_TARGET}-${CMAKE_C_COMPILER_ABI}") endif() if(CMAKE_SYSTEM_NAME) string(CONCAT MDBX_BUILD_TARGET "${MDBX_BUILD_TARGET}-${CMAKE_SYSTEM_NAME}") @@ -1140,7 +1320,8 @@ else() endif() # options -set(options VERSION C_COMPILER CXX_COMPILER MDBX_BUILD_TARGET MDBX_BUILD_TYPE ${MDBX_BUILD_OPTIONS}) +set(options VERSION C_COMPILER CXX_COMPILER MDBX_BUILD_TARGET MDBX_BUILD_TYPE + ${MDBX_BUILD_OPTIONS}) foreach(item IN LISTS options) if(DEFINED ${item}) set(value "${${item}}") @@ -1158,27 +1339,32 @@ 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) + "${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) if(NOT CMAKE_CXX_COMPILER_LOADED) - message(FATAL_ERROR "MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: The C++ compiler is required to build the tests.") + message( + FATAL_ERROR + "MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: The C++ compiler is required to build the tests." + ) endif() add_subdirectory(test) endif() -################################################################################ +# ############################################################################## -if (NOT SUBPROJECT) +if(NOT SUBPROJECT) 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}") + 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}") endif() diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake index f9c23c20..0ee15952 100644 --- a/cmake/compiler.cmake +++ b/cmake/compiler.cmake @@ -1,5 +1,5 @@ -## Copyright (c) 2010-2024 Леонид Юрьев aka Leonid Yuriev -## SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2010-2024 Леонид Юрьев aka Leonid Yuriev +# SPDX-License-Identifier: Apache-2.0 if(CMAKE_VERSION VERSION_LESS 3.8.2) cmake_minimum_required(VERSION 3.0.2) @@ -32,8 +32,11 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.9) endif() if(CMAKE_VERSION MATCHES ".*MSVC.*" AND CMAKE_VERSION VERSION_LESS 3.16) - message(FATAL_ERROR "CMake from MSVC kit is unfit! " - "Please use MSVC2019 with modern CMake the original CMake from https://cmake.org/download/") + message( + FATAL_ERROR + "CMake from MSVC kit is unfit! " + "Please use MSVC2019 with modern CMake the original CMake from https://cmake.org/download/" + ) endif() if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)) @@ -55,11 +58,12 @@ 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 - NOT (CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID)) +if(CMAKE_C_COMPILER_LOADED + AND CMAKE_CXX_COMPILER_LOADED + AND NOT (CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID)) message(WARNING "CMAKE_C_COMPILER_ID (${CMAKE_C_COMPILER_ID}) is different " - "from CMAKE_CXX_COMPILER_ID (${CMAKE_CXX_COMPILER_ID}). " - "The final binary may be unusable.") + "from CMAKE_CXX_COMPILER_ID (${CMAKE_CXX_COMPILER_ID}). " + "The final binary may be unusable.") endif() if(CMAKE_CXX_COMPILER_LOADED) @@ -76,27 +80,32 @@ macro(check_compiler_flag flag variable) endif() endmacro(check_compiler_flag) -# We support building with Clang and gcc. First check -# what we're using for build. -if(CMAKE_C_COMPILER_LOADED AND CMAKE_C_COMPILER_ID MATCHES ".*[Cc][Ll][Aa][Nn][Gg].*") - set(CMAKE_COMPILER_IS_CLANG ON) - set(CMAKE_COMPILER_IS_GNUCC OFF) +# We support building with Clang and gcc. First check what we're using for +# build. +if(CMAKE_C_COMPILER_LOADED AND CMAKE_C_COMPILER_ID MATCHES + ".*[Cc][Ll][Aa][Nn][Gg].*") + set(CMAKE_COMPILER_IS_CLANG ON) + set(CMAKE_COMPILER_IS_GNUCC OFF) endif() -if(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_ID MATCHES ".*[Cc][Ll][Aa][Nn][Gg].*") - set(CMAKE_COMPILER_IS_CLANG ON) +if(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_ID MATCHES + ".*[Cc][Ll][Aa][Nn][Gg].*") + set(CMAKE_COMPILER_IS_CLANG ON) set(CMAKE_COMPILER_IS_GNUCXX OFF) endif() if(CMAKE_C_COMPILER_LOADED) # Check for Elbrus lcc - execute_process(COMMAND ${CMAKE_C_COMPILER} --version + execute_process( + COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE tmp_lcc_probe_version - RESULT_VARIABLE tmp_lcc_probe_result ERROR_QUIET) + RESULT_VARIABLE tmp_lcc_probe_result + ERROR_QUIET) if(tmp_lcc_probe_result EQUAL 0) string(FIND "${tmp_lcc_probe_version}" "lcc:" tmp_lcc_marker) string(FIND "${tmp_lcc_probe_version}" ":e2k-" tmp_e2k_marker) if(tmp_lcc_marker GREATER -1 AND tmp_e2k_marker GREATER tmp_lcc_marker) - execute_process(COMMAND ${CMAKE_C_COMPILER} -print-version + execute_process( + COMMAND ${CMAKE_C_COMPILER} -print-version OUTPUT_VARIABLE CMAKE_C_COMPILER_VERSION RESULT_VARIABLE tmp_lcc_probe_result OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -115,20 +124,24 @@ endif() if(CMAKE_CXX_COMPILER_LOADED) # Check for Elbrus l++ - execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version + execute_process( + COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE tmp_lxx_probe_version - RESULT_VARIABLE tmp_lxx_probe_result ERROR_QUIET) + RESULT_VARIABLE tmp_lxx_probe_result + ERROR_QUIET) if(tmp_lxx_probe_result EQUAL 0) string(FIND "${tmp_lxx_probe_version}" "lcc:" tmp_lcc_marker) string(FIND "${tmp_lxx_probe_version}" ":e2k-" tmp_e2k_marker) if(tmp_lcc_marker GREATER -1 AND tmp_e2k_marker GREATER tmp_lcc_marker) - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-version + execute_process( + COMMAND ${CMAKE_CXX_COMPILER} -print-version OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION RESULT_VARIABLE tmp_lxx_probe_result OUTPUT_STRIP_TRAILING_WHITESPACE) set(CMAKE_COMPILER_IS_ELBRUSCXX ON) set(CMAKE_CXX_COMPILER_ID "Elbrus") - message(STATUS "Detected Elbrus C++ compiler ${CMAKE_CXX_COMPILER_VERSION}") + message( + STATUS "Detected Elbrus C++ compiler ${CMAKE_CXX_COMPILER_VERSION}") else() set(CMAKE_COMPILER_IS_ELBRUSCXX OFF) endif() @@ -139,20 +152,20 @@ if(CMAKE_CXX_COMPILER_LOADED) unset(tmp_lxx_probe_result) endif() -# Hard coding the compiler version is ugly from cmake POV, but -# at least gives user a friendly error message. The most critical -# demand for C++ compiler is support of C++11 lambdas, added -# only in version 4.5 https://gcc.gnu.org/projects/cxx0x.html +# Hard coding the compiler version is ugly from cmake POV, but at least gives +# user a friendly error message. The most critical demand for C++ compiler is +# support of C++11 lambdas, added only in version 4.5 +# https://gcc.gnu.org/projects/cxx0x.html if(CMAKE_COMPILER_IS_GNUCC) - if(CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 - AND NOT CMAKE_COMPILER_IS_ELBRUSC) + if(CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 AND NOT + CMAKE_COMPILER_IS_ELBRUSC) message(FATAL_ERROR " Your GCC version is ${CMAKE_C_COMPILER_VERSION}, please update") endif() endif() if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.5 - AND NOT CMAKE_COMPILER_IS_ELBRUSCXX) + AND NOT CMAKE_COMPILER_IS_ELBRUSCXX) message(FATAL_ERROR " Your G++ version is ${CMAKE_CXX_COMPILER_VERSION}, please update") endif() @@ -162,7 +175,8 @@ if(CMAKE_CL_64) set(MSVC64 1) endif() if(WIN32 AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}) - execute_process(COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -dumpmachine + execute_process( + COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -dumpmachine OUTPUT_VARIABLE __GCC_TARGET_MACHINE OUTPUT_STRIP_TRAILING_WHITESPACE) if(__GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64") @@ -172,9 +186,12 @@ if(WIN32 AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}) 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)) + 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) @@ -182,9 +199,9 @@ if(NOT DEFINED IOS) endif() if(NOT DEFINED CMAKE_TARGET_BITNESS) - if (CMAKE_SIZEOF_VOID_P LESS 4) + if(CMAKE_SIZEOF_VOID_P LESS 4) set(CMAKE_TARGET_BITNESS 16) - elseif (CMAKE_SIZEOF_VOID_P LESS 8) + elseif(CMAKE_SIZEOF_VOID_P LESS 8) set(CMAKE_TARGET_BITNESS 32) else() set(CMAKE_TARGET_BITNESS 64) @@ -193,10 +210,12 @@ endif() if(NOT CMAKE_SYSTEM_ARCH) if(CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ARCHITECTURE_ID) - string(TOLOWER "${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ARCHITECTURE_ID}" CMAKE_SYSTEM_ARCH) + string(TOLOWER "${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ARCHITECTURE_ID}" + CMAKE_SYSTEM_ARCH) if(CMAKE_SYSTEM_ARCH STREQUAL "x86") set(X86_32 TRUE) - elseif(CMAKE_SYSTEM_ARCH STREQUAL "x86_64" OR CMAKE_SYSTEM_ARCH STREQUAL "x64") + elseif(CMAKE_SYSTEM_ARCH STREQUAL "x86_64" OR CMAKE_SYSTEM_ARCH STREQUAL + "x64") set(X86_64 TRUE) set(CMAKE_SYSTEM_ARCH "x86_64") elseif(CMAKE_SYSTEM_ARCH MATCHES "^(aarch.*|arm.*)") @@ -225,12 +244,18 @@ if(NOT CMAKE_SYSTEM_ARCH) set(MIPS32 TRUE) endif() endif() - elseif(CMAKE_COMPILER_IS_ELBRUSC OR CMAKE_COMPILER_IS_ELBRUSCXX - OR CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ID STREQUAL "LCC" - OR CMAKE_SYSTEM_PROCESSOR MATCHES "e2k.*|E2K.*|elbrus.*|ELBRUS.*") + elseif( + CMAKE_COMPILER_IS_ELBRUSC + OR CMAKE_COMPILER_IS_ELBRUSCXX + OR CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ID STREQUAL "LCC" + OR CMAKE_SYSTEM_PROCESSOR MATCHES "e2k.*|E2K.*|elbrus.*|ELBRUS.*") set(E2K TRUE) set(CMAKE_SYSTEM_ARCH "Elbrus") - elseif(MSVC64 OR MINGW64 OR MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING)) + elseif( + MSVC64 + OR MINGW64 + OR MINGW + OR (MSVC AND NOT CMAKE_CROSSCOMPILING)) if(CMAKE_TARGET_BITNESS EQUAL 64) set(X86_64 TRUE) set(CMAKE_SYSTEM_ARCH "x86_64") @@ -238,7 +263,8 @@ if(NOT CMAKE_SYSTEM_ARCH) set(X86_32 TRUE) set(CMAKE_SYSTEM_ARCH "x86") endif() - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|[xXiI]86_64.*|AMD64.*|[iI][3-6]86.*|[xXiI]86.*") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES + "amd64.*|[xXiI]86_64.*|AMD64.*|[iI][3-6]86.*|[xXiI]86.*") if(CMAKE_TARGET_BITNESS EQUAL 64) set(X86_64 TRUE) set(CMAKE_SYSTEM_ARCH "x86_64") @@ -310,22 +336,29 @@ if(NOT DEFINED CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET) set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET TRUE) elseif(CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR) set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET FALSE) - elseif(CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME - AND ((CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_PROCESSOR) - OR (CMAKE_SYSTEM_ARCH STREQUAL CMAKE_HOST_ARCH) - OR (WIN32 AND CMAKE_HOST_WIN32 AND X86_32 AND CMAKE_HOST_ARCH STREQUAL "x86_64"))) + elseif( + CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME + AND ((CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_PROCESSOR) + OR (CMAKE_SYSTEM_ARCH STREQUAL CMAKE_HOST_ARCH) + OR (WIN32 + AND CMAKE_HOST_WIN32 + AND X86_32 + AND CMAKE_HOST_ARCH STREQUAL "x86_64" + ) + )) set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET TRUE) - message(STATUS - "Assume СAN RUN A BUILT EXECUTABLES," - " since host (${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_ARCH})" - " match target (${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_ARCH})") + message(STATUS "Assume СAN RUN A BUILT EXECUTABLES," + " since host (${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_ARCH})" + " match target (${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_ARCH})") else() if(CMAKE_C_COMPILER_LOADED) include(CheckCSourceRuns) - check_c_source_runs("int main(void) { return 0; }" CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET) + check_c_source_runs("int main(void) { return 0; }" + CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET) elseif(CMAKE_CXX_COMPILER_LOADED) include(CheckCXXSourceRuns) - check_cxx_source_runs("int main(void) { return 0; }" CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET) + check_cxx_source_runs("int main(void) { return 0; }" + CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET) endif() if(NOT CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET) message(STATUS "Force CMAKE_CROSSCOMPILING to TRUE") @@ -340,14 +373,15 @@ if(MSVC) check_compiler_flag("/fsanitize=undefined" CC_HAS_UBSAN) else() # - # GCC started to warn for unused result starting from 4.2, and - # this is when it introduced -Wno-unused-result - # GCC can also be built on top of llvm runtime (on mac). + # GCC started to warn for unused result starting from 4.2, and this is when it + # introduced -Wno-unused-result GCC can also be built on top of llvm runtime + # (on mac). check_compiler_flag("-Wno-unknown-pragmas" CC_HAS_WNO_UNKNOWN_PRAGMAS) check_compiler_flag("-Wextra" CC_HAS_WEXTRA) check_compiler_flag("-Werror" CC_HAS_WERROR) check_compiler_flag("-fexceptions" CC_HAS_FEXCEPTIONS) - check_compiler_flag("-fno-semantic-interposition" CC_HAS_FNO_SEMANTIC_INTERPOSITION) + check_compiler_flag("-fno-semantic-interposition" + CC_HAS_FNO_SEMANTIC_INTERPOSITION) if(CMAKE_CXX_COMPILER_LOADED) check_cxx_compiler_flag("-fcxx-exceptions" CC_HAS_FCXX_EXCEPTIONS) endif() @@ -367,17 +401,21 @@ else() # Check for an omp support set(CMAKE_REQUIRED_FLAGS "-fopenmp -Werror") if(CMAKE_CXX_COMPILER_LOADED) - check_cxx_source_compiles("int main(void) { + check_cxx_source_compiles( + "int main(void) { #pragma omp for for(int i = 0, j = 0; i != 42; i = 1 + i * 12345) j += i % 43; return j; - }" HAVE_OPENMP) + }" + HAVE_OPENMP) else() - check_c_source_compiles("int main(void) { + check_c_source_compiles( + "int main(void) { #pragma omp for for(int i = 0, j = 0; i != 42; i = 1 + i * 12345) j += i % 43; return j; - }" HAVE_OPENMP) + }" + HAVE_OPENMP) endif() set(CMAKE_REQUIRED_FLAGS "") endif() @@ -413,41 +451,66 @@ if(CMAKE_C_COMPILER_LOADED) endif() # Check for LTO support by GCC -if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} AND NOT CMAKE_COMPILER_IS_ELBRUSC AND NOT CMAKE_COMPILER_IS_ELBRUSCXX) +if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} + AND NOT CMAKE_COMPILER_IS_ELBRUSC + AND NOT CMAKE_COMPILER_IS_ELBRUSCXX) unset(gcc_collect) unset(gcc_lto_wrapper) if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 4.7) - execute_process(COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -v - OUTPUT_VARIABLE gcc_info_v ERROR_VARIABLE gcc_info_v) + execute_process( + COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -v + OUTPUT_VARIABLE gcc_info_v + ERROR_VARIABLE gcc_info_v) - string(REGEX MATCH "^(.+\nCOLLECT_GCC=)([^ \n]+)(\n.+)$" gcc_collect_valid ${gcc_info_v}) + string(REGEX MATCH "^(.+\nCOLLECT_GCC=)([^ \n]+)(\n.+)$" gcc_collect_valid + ${gcc_info_v}) if(gcc_collect_valid) - string(REGEX REPLACE "^(.+\nCOLLECT_GCC=)([^ \n]+)(\n.+)$" "\\2" gcc_collect ${gcc_info_v}) + string(REGEX REPLACE "^(.+\nCOLLECT_GCC=)([^ \n]+)(\n.+)$" "\\2" + gcc_collect ${gcc_info_v}) endif() - string(REGEX MATCH "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" gcc_lto_wrapper_valid ${gcc_info_v}) + string(REGEX MATCH + "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" + gcc_lto_wrapper_valid ${gcc_info_v}) if(gcc_lto_wrapper_valid) - string(REGEX REPLACE "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" "\\2" gcc_lto_wrapper ${gcc_info_v}) + string(REGEX + REPLACE "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" + "\\2" gcc_lto_wrapper ${gcc_info_v}) endif() set(gcc_suffix "") if(gcc_collect_valid AND gcc_collect) - string(REGEX MATCH "^(.*(cc|\\+\\+))(-.+)$" gcc_suffix_valid ${gcc_collect}) + string(REGEX MATCH "^(.*(cc|\\+\\+))(-.+)$" gcc_suffix_valid + ${gcc_collect}) if(gcc_suffix_valid) - string(REGEX REPLACE "^(.*(cc|\\+\\+))(-.+)$" "\\3" gcc_suffix ${gcc_collect}) + string(REGEX REPLACE "^(.*(cc|\\+\\+))(-.+)$" "\\3" gcc_suffix + ${gcc_collect}) endif() endif() - get_filename_component(gcc_dir ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY) + get_filename_component(gcc_dir ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} + DIRECTORY) if(NOT CMAKE_GCC_AR) - find_program(CMAKE_GCC_AR NAMES "gcc${gcc_suffix}-ar" "gcc-ar${gcc_suffix}" PATHS "${gcc_dir}" NO_DEFAULT_PATH) + find_program( + CMAKE_GCC_AR + NAMES "gcc${gcc_suffix}-ar" "gcc-ar${gcc_suffix}" + PATHS "${gcc_dir}" + NO_DEFAULT_PATH) endif() if(NOT CMAKE_GCC_NM) - find_program(CMAKE_GCC_NM NAMES "gcc${gcc_suffix}-nm" "gcc-nm${gcc_suffix}" PATHS "${gcc_dir}" NO_DEFAULT_PATH) + find_program( + CMAKE_GCC_NM + NAMES "gcc${gcc_suffix}-nm" "gcc-nm${gcc_suffix}" + PATHS "${gcc_dir}" + NO_DEFAULT_PATH) endif() if(NOT CMAKE_GCC_RANLIB) - find_program(CMAKE_GCC_RANLIB NAMES "gcc${gcc_suffix}-ranlib" "gcc-ranlib${gcc_suffix}" PATHS "${gcc_dir}" NO_DEFAULT_PATH) + find_program( + CMAKE_GCC_RANLIB + NAMES "gcc${gcc_suffix}-ranlib" "gcc-ranlib${gcc_suffix}" + PATHS "${gcc_dir}" + NO_DEFAULT_PATH) endif() unset(gcc_dir) @@ -459,8 +522,14 @@ if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} AND NOT CMAKE_COMPILER_IS_ELBRUSC unset(gcc_info_v) endif() - if(CMAKE_GCC_AR AND CMAKE_GCC_NM AND CMAKE_GCC_RANLIB AND gcc_lto_wrapper) - message(STATUS "Found GCC's LTO toolset: ${gcc_lto_wrapper}, ${CMAKE_GCC_AR}, ${CMAKE_GCC_RANLIB}") + if(CMAKE_GCC_AR + AND CMAKE_GCC_NM + AND CMAKE_GCC_RANLIB + AND gcc_lto_wrapper) + message( + STATUS + "Found GCC's LTO toolset: ${gcc_lto_wrapper}, ${CMAKE_GCC_AR}, ${CMAKE_GCC_RANLIB}" + ) set(GCC_LTO_CFLAGS "-flto -fno-fat-lto-objects -fuse-linker-plugin") set(GCC_LTO_AVAILABLE TRUE) message(STATUS "Link-Time Optimization by GCC is available") @@ -485,17 +554,22 @@ endif() # Check for LTO support by CLANG if(CMAKE_COMPILER_IS_CLANG) if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 3.5) - execute_process(COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -print-search-dirs - OUTPUT_VARIABLE clang_search_dirs RESULT_VARIABLE clang_probe_result ERROR_QUIET) + execute_process( + COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -print-search-dirs + OUTPUT_VARIABLE clang_search_dirs + RESULT_VARIABLE clang_probe_result + ERROR_QUIET) unset(clang_bindirs) unset(clang_bindirs_x) unset(clang_libdirs) unset(clang_libdirs_x) if(clang_probe_result EQUAL 0) - string(REGEX MATCH "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" regexp_valid ${clang_search_dirs}) + string(REGEX MATCH "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" + regexp_valid ${clang_search_dirs}) if(regexp_valid) - string(REGEX REPLACE "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" "\\3" list ${clang_search_dirs}) + string(REGEX REPLACE "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" "\\3" + list ${clang_search_dirs}) string(REPLACE ":" ";" list "${list}") foreach(dir IN LISTS list) get_filename_component(dir "${dir}" REALPATH) @@ -508,9 +582,11 @@ if(CMAKE_COMPILER_IS_CLANG) list(APPEND clang_bindirs "${clang_bindirs_x}") list(REMOVE_DUPLICATES clang_bindirs) endif() - string(REGEX MATCH "(^|\n.*)(.*libraries: =)([^\n]+)((\n.*)|$)" regexp_valid ${clang_search_dirs}) + string(REGEX MATCH "(^|\n.*)(.*libraries: =)([^\n]+)((\n.*)|$)" + regexp_valid ${clang_search_dirs}) if(regexp_valid) - string(REGEX REPLACE "(^|\n.*)(.*libraries: =)([^\n]+)((\n.*)|$)" "\\3" list ${clang_search_dirs}) + string(REGEX REPLACE "(^|\n.*)(.*libraries: =)([^\n]+)((\n.*)|$)" "\\3" + list ${clang_search_dirs}) string(REPLACE ":" ";" list "${list}") foreach(dir IN LISTS list) get_filename_component(dir "${dir}" REALPATH) @@ -524,57 +600,97 @@ if(CMAKE_COMPILER_IS_CLANG) list(REMOVE_DUPLICATES clang_libdirs) endif() else() - get_filename_component(clang_bindirs ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY) + get_filename_component(clang_bindirs + ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY) if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") set(clang_libdirs ${clang_bindirs}) else() - get_filename_component(clang_libdirs "${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER}/../lib" REALPATH) + get_filename_component( + clang_libdirs "${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER}/../lib" + REALPATH) endif() endif() if(clang_bindirs AND clang_libdirs) - message(STATUS "Found CLANG/LLVM directories: ${clang_bindirs}, ${clang_libdirs}") + message( + STATUS + "Found CLANG/LLVM directories: ${clang_bindirs}, ${clang_libdirs}") else() message(STATUS "Could NOT find CLANG/LLVM directories (bin and/or lib).") endif() if(NOT CMAKE_CLANG_LD AND clang_bindirs) - find_program(CMAKE_CLANG_LD NAMES lld-link ld.lld "ld${CMAKE_TARGET_BITNESS}.lld" lld llvm-link llvm-ld PATHS ${clang_bindirs} NO_DEFAULT_PATH) + find_program( + CMAKE_CLANG_LD + NAMES lld-link ld.lld "ld${CMAKE_TARGET_BITNESS}.lld" lld llvm-link + llvm-ld + PATHS ${clang_bindirs} + NO_DEFAULT_PATH) endif() if(NOT CMAKE_CLANG_AR AND clang_bindirs) - find_program(CMAKE_CLANG_AR NAMES llvm-ar ar PATHS ${clang_bindirs} NO_DEFAULT_PATH) + find_program( + CMAKE_CLANG_AR + NAMES llvm-ar ar + PATHS ${clang_bindirs} + NO_DEFAULT_PATH) endif() if(NOT CMAKE_CLANG_NM AND clang_bindirs) - find_program(CMAKE_CLANG_NM NAMES llvm-nm nm PATHS ${clang_bindirs} NO_DEFAULT_PATH) + find_program( + CMAKE_CLANG_NM + NAMES llvm-nm nm + PATHS ${clang_bindirs} + NO_DEFAULT_PATH) endif() if(NOT CMAKE_CLANG_RANLIB AND clang_bindirs) - find_program(CMAKE_CLANG_RANLIB NAMES llvm-ranlib ranlib PATHS ${clang_bindirs} NO_DEFAULT_PATH) + find_program( + CMAKE_CLANG_RANLIB + NAMES llvm-ranlib ranlib + PATHS ${clang_bindirs} + NO_DEFAULT_PATH) endif() set(clang_lto_plugin_name "LLVMgold${CMAKE_SHARED_LIBRARY_SUFFIX}") if(NOT CMAKE_LD_GOLD AND clang_bindirs) - find_program(CMAKE_LD_GOLD NAMES ld.gold PATHS ${clang_bindirs}) + find_program( + CMAKE_LD_GOLD + NAMES ld.gold + PATHS ${clang_bindirs}) endif() if(NOT CLANG_LTO_PLUGIN AND clang_libdirs) - find_file(CLANG_LTO_PLUGIN ${clang_lto_plugin_name} PATHS ${clang_libdirs} NO_DEFAULT_PATH) + find_file( + CLANG_LTO_PLUGIN ${clang_lto_plugin_name} + PATHS ${clang_libdirs} + NO_DEFAULT_PATH) endif() if(CLANG_LTO_PLUGIN) message(STATUS "Found CLANG/LLVM's plugin for LTO: ${CLANG_LTO_PLUGIN}") else() - message(STATUS "Could NOT find CLANG/LLVM's plugin (${clang_lto_plugin_name}) for LTO.") + message( + STATUS + "Could NOT find CLANG/LLVM's plugin (${clang_lto_plugin_name}) for LTO." + ) endif() if(CMAKE_CLANG_LD) message(STATUS "Found CLANG/LLVM's linker for LTO: ${CMAKE_CLANG_LD}") else() - message(STATUS "Could NOT find CLANG/LLVM's linker (lld, llvm-ld, llvm-link) for LTO.") + message( + STATUS + "Could NOT find CLANG/LLVM's linker (lld, llvm-ld, llvm-link) for LTO." + ) endif() - if(CMAKE_CLANG_AR AND CMAKE_CLANG_RANLIB AND CMAKE_CLANG_NM) - message(STATUS "Found CLANG/LLVM's binutils for LTO: ${CMAKE_CLANG_AR}, ${CMAKE_CLANG_RANLIB}, ${CMAKE_CLANG_NM}") + if(CMAKE_CLANG_AR + AND CMAKE_CLANG_RANLIB + AND CMAKE_CLANG_NM) + message( + STATUS + "Found CLANG/LLVM's binutils for LTO: ${CMAKE_CLANG_AR}, ${CMAKE_CLANG_RANLIB}, ${CMAKE_CLANG_NM}" + ) else() - message(STATUS "Could NOT find CLANG/LLVM's binutils (ar, ranlib, nm) for LTO.") + message( + STATUS "Could NOT find CLANG/LLVM's binutils (ar, ranlib, nm) for LTO.") endif() unset(clang_lto_plugin_name) @@ -584,20 +700,26 @@ if(CMAKE_COMPILER_IS_CLANG) unset(clang_search_dirs) endif() - if(CMAKE_CLANG_AR AND CMAKE_CLANG_NM AND CMAKE_CLANG_RANLIB - AND ((CLANG_LTO_PLUGIN AND CMAKE_LD_GOLD) - OR (CMAKE_CLANG_LD - AND NOT (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" - AND CMAKE_SYSTEM_NAME STREQUAL "Linux")) - OR APPLE)) + if(CMAKE_CLANG_AR + AND CMAKE_CLANG_NM + AND CMAKE_CLANG_RANLIB + AND ((CLANG_LTO_PLUGIN AND CMAKE_LD_GOLD) + OR (CMAKE_CLANG_LD AND NOT (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" + AND CMAKE_SYSTEM_NAME STREQUAL "Linux")) + OR APPLE + )) if(ANDROID AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 12) set(CLANG_LTO_AVAILABLE FALSE) - message(STATUS "Link-Time Optimization by CLANG/LLVM is available but unusable due https://reviews.llvm.org/D79919") + message( + STATUS + "Link-Time Optimization by CLANG/LLVM is available but unusable due https://reviews.llvm.org/D79919" + ) else() set(CLANG_LTO_AVAILABLE TRUE) message(STATUS "Link-Time Optimization by CLANG/LLVM is available") endif() - elseif(CMAKE_TOOLCHAIN_FILE AND NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 7.0) + elseif(CMAKE_TOOLCHAIN_FILE + AND NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 7.0) set(CLANG_LTO_AVAILABLE TRUE) if(NOT CMAKE_CLANG_LD) set(CMAKE_CLANG_LD ${CMAKE_LINKER}) @@ -611,7 +733,10 @@ if(CMAKE_COMPILER_IS_CLANG) if(NOT CMAKE_CLANG_RANLIB) set(CMAKE_CLANG_RANLIB ${CMAKE_RANLIB}) endif() - message(STATUS "Assume Link-Time Optimization by CLANG/LLVM is available via ${CMAKE_TOOLCHAIN_FILE}") + message( + STATUS + "Assume Link-Time Optimization by CLANG/LLVM is available via ${CMAKE_TOOLCHAIN_FILE}" + ) else() set(CLANG_LTO_AVAILABLE FALSE) message(STATUS "Link-Time Optimization by CLANG/LLVM is NOT available") @@ -619,17 +744,22 @@ if(CMAKE_COMPILER_IS_CLANG) endif() # Perform build type specific configuration. -option(ENABLE_BACKTRACE "Enable output of fiber backtrace information in 'show +option( + ENABLE_BACKTRACE + "Enable output of fiber backtrace information in 'show fiber' administrative command. Only works on x86 architectures, if compiled with gcc. If GNU binutils and binutils-dev libraries are installed, backtrace is output with resolved function (symbol) names. Otherwise only frame - addresses are printed." OFF) + addresses are printed." + OFF) set(HAVE_BFD FALSE) if(ENABLE_BACKTRACE) if(NOT (X86_32 OR X86_64) OR NOT CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}) # We only know this option to work with gcc - message(FATAL_ERROR "ENABLE_BACKTRACE option is set but the system + message( + FATAL_ERROR + "ENABLE_BACKTRACE option is set but the system is not x86 based (${CMAKE_SYSTEM_PROCESSOR}) or the compiler is not GNU GCC (${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER}).") endif() @@ -642,15 +772,19 @@ if(ENABLE_BACKTRACE) if(IBERTY_LIBRARY) check_library_exists(${IBERTY_LIBRARY} cplus_demangle "" HAVE_IBERTY_LIB) endif() - set(CMAKE_REQUIRED_DEFINITIONS -DPACKAGE=${PACKAGE} -DPACKAGE_VERSION=${PACKAGE_VERSION}) + set(CMAKE_REQUIRED_DEFINITIONS -DPACKAGE=${PACKAGE} + -DPACKAGE_VERSION=${PACKAGE_VERSION}) check_include_files(bfd.h HAVE_BFD_H) set(CMAKE_REQUIRED_DEFINITIONS) find_package(ZLIB) - if(HAVE_BFD_LIB AND HAVE_BFD_H AND HAVE_IBERTY_LIB AND ZLIB_FOUND) + if(HAVE_BFD_LIB + AND HAVE_BFD_H + AND HAVE_IBERTY_LIB + AND ZLIB_FOUND) set(HAVE_BFD ON) set(BFD_LIBRARIES ${BFD_LIBRARY} ${IBERTY_LIBRARY} ${ZLIB_LIBRARIES}) find_package_message(BFD_LIBRARIES "Found libbfd and dependencies" - ${BFD_LIBRARIES}) + ${BFD_LIBRARIES}) if(TARGET_OS_FREEBSD AND NOT TARGET_OS_DEBIAN_FREEBSD) set(BFD_LIBRARIES ${BFD_LIBRARIES} iconv) endif() @@ -661,16 +795,30 @@ macro(setup_compile_flags) # save initial C/CXX flags if(NOT INITIAL_CMAKE_FLAGS_SAVED) if(CMAKE_CXX_COMPILER_LOADED) - set(INITIAL_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) + set(INITIAL_CMAKE_CXX_FLAGS + ${CMAKE_CXX_FLAGS} + CACHE STRING "Initial CMake's flags" FORCE) endif() if(CMAKE_C_COMPILER_LOADED) - set(INITIAL_CMAKE_C_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) + set(INITIAL_CMAKE_C_FLAGS + ${CMAKE_C_FLAGS} + CACHE STRING "Initial CMake's flags" FORCE) endif() - set(INITIAL_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) - set(INITIAL_CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) - set(INITIAL_CMAKE_STATIC_LINKER_FLAGS ${CMAKE_STATIC_LINKER_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) - set(INITIAL_CMAKE_MODULE_LINKER_FLAGS ${CMAKE_MODULE_LINKER_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) - set(INITIAL_CMAKE_FLAGS_SAVED TRUE CACHE INTERNAL "State of initial CMake's flags" FORCE) + set(INITIAL_CMAKE_EXE_LINKER_FLAGS + ${CMAKE_EXE_LINKER_FLAGS} + CACHE STRING "Initial CMake's flags" FORCE) + set(INITIAL_CMAKE_SHARED_LINKER_FLAGS + ${CMAKE_SHARED_LINKER_FLAGS} + CACHE STRING "Initial CMake's flags" FORCE) + set(INITIAL_CMAKE_STATIC_LINKER_FLAGS + ${CMAKE_STATIC_LINKER_FLAGS} + CACHE STRING "Initial CMake's flags" FORCE) + set(INITIAL_CMAKE_MODULE_LINKER_FLAGS + ${CMAKE_MODULE_LINKER_FLAGS} + CACHE STRING "Initial CMake's flags" FORCE) + set(INITIAL_CMAKE_FLAGS_SAVED + TRUE + CACHE INTERNAL "State of initial CMake's flags" FORCE) endif() # reset C/CXX flags @@ -711,14 +859,16 @@ macro(setup_compile_flags) add_compile_flags("C;CXX" "-fno-semantic-interposition") endif() if(MSVC) - # checks for /EHa or /clr options exists, - # i.e. is enabled structured async WinNT exceptions - string(REGEX MATCH "^(.* )*[-/]EHc*a( .*)*$" msvc_async_eh_enabled "${CXX_FLAGS}" "${C_FLAGS}") - string(REGEX MATCH "^(.* )*[-/]clr( .*)*$" msvc_clr_enabled "${CXX_FLAGS}" "${C_FLAGS}") + # checks for /EHa or /clr options exists, i.e. is enabled structured async + # WinNT exceptions + string(REGEX MATCH "^(.* )*[-/]EHc*a( .*)*$" msvc_async_eh_enabled + "${CXX_FLAGS}" "${C_FLAGS}") + string(REGEX MATCH "^(.* )*[-/]clr( .*)*$" msvc_clr_enabled "${CXX_FLAGS}" + "${C_FLAGS}") # remote any /EH? options string(REGEX REPLACE "( *[-/]-*EH[csa]+ *)+" "" CXX_FLAGS "${CXX_FLAGS}") string(REGEX REPLACE "( *[-/]-*EH[csa]+ *)+" "" C_FLAGS "${C_FLAGS}") - if (msvc_clr_enabled STREQUAL "") + if(msvc_clr_enabled STREQUAL "") if(NOT msvc_async_eh_enabled STREQUAL "") add_compile_flags("C;CXX" "/EHa") else() @@ -727,8 +877,9 @@ macro(setup_compile_flags) endif() endif(MSVC) - if(CC_HAS_WNO_ATTRIBUTES AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} - AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 9) + if(CC_HAS_WNO_ATTRIBUTES + AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} + AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 9) # GCC < 9.x generates false-positive warnings for optimization attributes add_compile_flags("C;CXX" "-Wno-attributes") if(LTO_ENABLED) @@ -737,21 +888,20 @@ macro(setup_compile_flags) endif() # In C a global variable without a storage specifier (static/extern) and - # without an initialiser is called a ’tentative definition’. The - # language permits multiple tentative definitions in the single - # translation unit; i.e. int foo; int foo; is perfectly ok. GNU - # toolchain goes even further, allowing multiple tentative definitions - # in *different* translation units. Internally, variables introduced via - # tentative definitions are implemented as ‘common’ symbols. Linker - # permits multiple definitions if they are common symbols, and it picks - # one arbitrarily for inclusion in the binary being linked. + # without an initialiser is called a ’tentative definition’. The language + # permits multiple tentative definitions in the single translation unit; i.e. + # int foo; int foo; is perfectly ok. GNU toolchain goes even further, allowing + # multiple tentative definitions in *different* translation units. Internally, + # variables introduced via tentative definitions are implemented as ‘common’ + # symbols. Linker permits multiple definitions if they are common symbols, and + # it picks one arbitrarily for inclusion in the binary being linked. # - # -fno-common forces GNU toolchain to behave in a more - # standard-conformant way in respect to tentative definitions and it - # prevents common symbols generation. Since we are a cross-platform - # project it really makes sense. There are toolchains that don’t - # implement GNU style handling of the tentative definitions and there - # are platforms lacking proper support for common symbols (osx). + # -fno-common forces GNU toolchain to behave in a more standard-conformant way + # in respect to tentative definitions and it prevents common symbols + # generation. Since we are a cross-platform project it really makes sense. + # There are toolchains that don’t implement GNU style handling of the + # tentative definitions and there are platforms lacking proper support for + # common symbols (osx). if(CC_HAS_FNO_COMMON) add_compile_flags("C;CXX" "-fno-common") endif() @@ -770,10 +920,9 @@ macro(setup_compile_flags) add_compile_flags("C;CXX" "/Gy") endif() - # We must set -fno-omit-frame-pointer here, since we rely - # on frame pointer when getting a backtrace, and it must - # be used consistently across all object files. - # The same reasoning applies to -fno-stack-protector switch. + # We must set -fno-omit-frame-pointer here, since we rely on frame pointer + # when getting a backtrace, and it must be used consistently across all object + # files. The same reasoning applies to -fno-stack-protector switch. if(ENABLE_BACKTRACE) if(CC_HAS_FNO_OMIT_FRAME_POINTER) add_compile_flags("C;CXX" "-fno-omit-frame-pointer") @@ -782,7 +931,10 @@ macro(setup_compile_flags) if(MSVC) if(MSVC_VERSION LESS 1900) - message(FATAL_ERROR "At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required.") + message( + FATAL_ERROR + "At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required." + ) endif() if(NOT MSVC_VERSION LESS 1910) add_compile_flags("CXX" "/Zc:__cplusplus") @@ -803,9 +955,12 @@ macro(setup_compile_flags) add_definitions("-D__STDC_CONSTANT_MACROS=1") add_definitions("-D_HAS_EXCEPTIONS=1") - # Only add -Werror if it's a debug build, done by developers. - # Release builds should not cause extra trouble. - if(CC_HAS_WERROR AND (CI OR CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE STREQUAL "Debug")) + # Only add -Werror if it's a debug build, done by developers. Release builds + # should not cause extra trouble. + if(CC_HAS_WERROR + AND (CI + OR CMAKE_CONFIGURATION_TYPES + OR CMAKE_BUILD_TYPE STREQUAL "Debug")) if(MSVC) add_compile_flags("C;CXX" "/WX") elseif(CMAKE_COMPILER_IS_CLANG) @@ -821,17 +976,17 @@ macro(setup_compile_flags) endif() endif() - if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} - AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 5) + AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 5) # G++ bug. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31488 add_compile_flags("CXX" "-Wno-invalid-offsetof") endif() if(MINGW) - # Disable junk MINGW's warnings that issued due to incompatibilities - # and shortcomings of MINGW, - # since the code is checked by builds with GCC, CLANG and MSVC. - add_compile_flags("C;CXX" "-Wno-format-extra-args" "-Wno-format" "-Wno-cast-function-type" "-Wno-implicit-fallthrough") + # Disable junk MINGW's warnings that issued due to incompatibilities and + # shortcomings of MINGW, since the code is checked by builds with GCC, CLANG + # and MSVC. + add_compile_flags("C;CXX" "-Wno-format-extra-args" "-Wno-format" + "-Wno-cast-function-type" "-Wno-implicit-fallthrough") endif() if(ENABLE_ASAN) @@ -845,7 +1000,8 @@ macro(setup_compile_flags) if(ENABLE_UBSAN) if(NOT MSVC) - add_compile_flags("C;CXX" "-fsanitize=undefined" "-fsanitize-undefined-trap-on-error") + add_compile_flags("C;CXX" "-fsanitize=undefined" + "-fsanitize-undefined-trap-on-error") else() add_compile_flags("C;CXX" "/fsanitize=undefined") endif() @@ -854,13 +1010,17 @@ macro(setup_compile_flags) if(ENABLE_GCOV) if(NOT HAVE_GCOV) - message(FATAL_ERROR "ENABLE_GCOV option requested but gcov library is not found") + message( + FATAL_ERROR "ENABLE_GCOV option requested but gcov library is not found" + ) endif() add_compile_flags("C;CXX" "-fprofile-arcs" "-ftest-coverage") set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") - set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") - set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") + set(SHARED_LINKER_FLAGS + "${SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") + set(MODULE_LINKER_FLAGS + "${MODULE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") # add_library(gcov SHARED IMPORTED) endif() @@ -870,12 +1030,16 @@ macro(setup_compile_flags) if(CMAKE_COMPILER_IS_GNUCC AND LTO_ENABLED) add_compile_flags("C;CXX" ${GCC_LTO_CFLAGS}) - set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} ${GCC_LTO_CFLAGS} -fverbose-asm -fwhole-program") - set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} ${GCC_LTO_CFLAGS} -fverbose-asm") - set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} ${GCC_LTO_CFLAGS} -fverbose-asm") + set(EXE_LINKER_FLAGS + "${EXE_LINKER_FLAGS} ${GCC_LTO_CFLAGS} -fverbose-asm -fwhole-program") + set(SHARED_LINKER_FLAGS + "${SHARED_LINKER_FLAGS} ${GCC_LTO_CFLAGS} -fverbose-asm") + set(MODULE_LINKER_FLAGS + "${MODULE_LINKER_FLAGS} ${GCC_LTO_CFLAGS} -fverbose-asm") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5) # Pass the same optimization flags to the linker - set(compile_flags "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}") + set(compile_flags + "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}") set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} ${compile_flags}") set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} ${compile_flags}") set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} ${compile_flags}") @@ -885,32 +1049,53 @@ macro(setup_compile_flags) endif() endif() - if(MSVC AND NOT CMAKE_COMPILER_IS_CLANG AND LTO_ENABLED) + if(MSVC + AND NOT CMAKE_COMPILER_IS_CLANG + AND LTO_ENABLED) add_compile_flags("C;CXX" "/GL") foreach(linkmode IN ITEMS EXE SHARED STATIC MODULE) set(${linkmode}_LINKER_FLAGS "${${linkmode}_LINKER_FLAGS} /LTCG") - string(REGEX REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" ${linkmode}_LINKER_FLAGS "${${linkmode}_LINKER_FLAGS}") + string(REGEX + REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" + ${linkmode}_LINKER_FLAGS "${${linkmode}_LINKER_FLAGS}") string(STRIP "${${linkmode}_LINKER_FLAGS}" ${linkmode}_LINKER_FLAGS) - foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES ITEMS Release MinSizeRel RelWithDebInfo Debug) + foreach( + config IN + LISTS CMAKE_CONFIGURATION_TYPES + ITEMS Release MinSizeRel RelWithDebInfo Debug) string(TOUPPER "${config}" config_uppercase) if(DEFINED "CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}") - string(REGEX REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" altered_flags "${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}") + string( + REGEX + REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" + altered_flags + "${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}") string(STRIP "${altered_flags}" altered_flags) - if(NOT "${altered_flags}" STREQUAL "${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}") - set(CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase} "${altered_flags}" CACHE STRING "Altered: '/INCREMENTAL' removed for LTO" FORCE) + if(NOT "${altered_flags}" STREQUAL + "${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}") + set(CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase} + "${altered_flags}" + CACHE STRING "Altered: '/INCREMENTAL' removed for LTO" FORCE) endif() endif() endforeach(config) endforeach(linkmode) unset(linkmode) - foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES ITEMS Release MinSizeRel RelWithDebInfo) + foreach( + config IN + LISTS CMAKE_CONFIGURATION_TYPES + ITEMS Release MinSizeRel RelWithDebInfo) foreach(lang IN ITEMS C CXX) string(TOUPPER "${config}" config_uppercase) if(DEFINED "CMAKE_${lang}_FLAGS_${config_uppercase}") - string(REPLACE "/O2" "/Ox" altered_flags "${CMAKE_${lang}_FLAGS_${config_uppercase}}") - if(NOT "${altered_flags}" STREQUAL "${CMAKE_${lang}_FLAGS_${config_uppercase}}") - set(CMAKE_${lang}_FLAGS_${config_uppercase} "${altered_flags}" CACHE STRING "Altered: '/O2' replaced by '/Ox' for LTO" FORCE) + string(REPLACE "/O2" "/Ox" altered_flags + "${CMAKE_${lang}_FLAGS_${config_uppercase}}") + if(NOT "${altered_flags}" STREQUAL + "${CMAKE_${lang}_FLAGS_${config_uppercase}}") + set(CMAKE_${lang}_FLAGS_${config_uppercase} + "${altered_flags}" + CACHE STRING "Altered: '/O2' replaced by '/Ox' for LTO" FORCE) endif() endif() unset(config_uppercase) @@ -935,25 +1120,46 @@ macro(setup_compile_flags) endif() add_compile_flags("C;CXX" ${CLANG_LTO_FLAG}) if(NOT MSVC) - set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm -fwhole-program") - set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm") - set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm") + set(EXE_LINKER_FLAGS + "${EXE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm -fwhole-program") + set(SHARED_LINKER_FLAGS + "${SHARED_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm") + set(MODULE_LINKER_FLAGS + "${MODULE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm") endif() endif() # push C/CXX flags into the cache if(CMAKE_CXX_COMPILER_LOADED) - set(CMAKE_CXX_FLAGS ${CXX_FLAGS} CACHE STRING "Flags used by the C++ compiler during all build types" FORCE) + set(CMAKE_CXX_FLAGS + ${CXX_FLAGS} + CACHE STRING "Flags used by the C++ compiler during all build types" + FORCE) unset(CXX_FLAGS) endif() if(CMAKE_C_COMPILER_LOADED) - set(CMAKE_C_FLAGS ${C_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) unset(C_FLAGS) endif() - set(CMAKE_EXE_LINKER_FLAGS ${EXE_LINKER_FLAGS} CACHE STRING "Flags used by the linker" FORCE) - set(CMAKE_SHARED_LINKER_FLAGS ${SHARED_LINKER_FLAGS} CACHE STRING "Flags used by the linker during the creation of dll's" FORCE) - set(CMAKE_STATIC_LINKER_FLAGS ${STATIC_LINKER_FLAGS} CACHE STRING "Flags used by the linker during the creation of static libraries" FORCE) - set(CMAKE_MODULE_LINKER_FLAGS ${MODULE_LINKER_FLAGS} CACHE STRING "Flags used by the linker during the creation of modules" FORCE) + set(CMAKE_EXE_LINKER_FLAGS + ${EXE_LINKER_FLAGS} + CACHE STRING "Flags used by the linker" FORCE) + set(CMAKE_SHARED_LINKER_FLAGS + ${SHARED_LINKER_FLAGS} + CACHE STRING "Flags used by the linker during the creation of dll's" + FORCE) + set(CMAKE_STATIC_LINKER_FLAGS + ${STATIC_LINKER_FLAGS} + CACHE STRING + "Flags used by the linker during the creation of static libraries" + FORCE) + set(CMAKE_MODULE_LINKER_FLAGS + ${MODULE_LINKER_FLAGS} + CACHE STRING "Flags used by the linker during the creation of modules" + FORCE) unset(EXE_LINKER_FLAGS) unset(SHARED_LINKER_FLAGS) unset(STATIC_LINKER_FLAGS) @@ -963,7 +1169,9 @@ endmacro(setup_compile_flags) macro(probe_libcxx_filesystem) if(CMAKE_CXX_COMPILER_LOADED AND NOT DEFINED LIBCXX_FILESYSTEM) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 HAS_CXX11) - if(NOT HAS_CXX11 LESS 0 OR CXX_FALLBACK_GNU11 OR CXX_FALLBACK_11) + if(NOT HAS_CXX11 LESS 0 + OR CXX_FALLBACK_GNU11 + OR CXX_FALLBACK_11) include(CMakePushCheckState) include(CheckCXXSourceCompiles) cmake_push_check_state() @@ -976,7 +1184,8 @@ macro(probe_libcxx_filesystem) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_14 HAS_CXX14) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_17 HAS_CXX17) if(NOT HAS_CXX17 LESS 0 - AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)) + AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION + VERSION_LESS 5)) set(CMAKE_CXX_STANDARD 17) elseif(NOT HAS_CXX14 LESS 0) set(CMAKE_CXX_STANDARD 14) @@ -989,16 +1198,20 @@ macro(probe_libcxx_filesystem) endif() set(stdfs_probe_clear_cxx_standard ON) endif() - if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.25.23) + if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION + VERSION_LESS 1.25.23) if(CMAKE_VERSION VERSION_LESS 3.14) - set(stdfs_probe_flags ${stdfs_probe_flags} "-Wl,--allow-multiple-definition") + set(stdfs_probe_flags ${stdfs_probe_flags} + "-Wl,--allow-multiple-definition") else() - set(CMAKE_REQUIRED_LINK_OPTIONS ${stdfs_probe_save_link_options} "-Wl,--allow-multiple-definition") + set(CMAKE_REQUIRED_LINK_OPTIONS ${stdfs_probe_save_link_options} + "-Wl,--allow-multiple-definition") endif() endif() set(CMAKE_REQUIRED_FLAGS ${stdfs_probe_flags}) - set(stdfs_probe_code [[ + set(stdfs_probe_code + [[ #if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4 #define __GLIBCXX_BITSIZE_INT_N_0 128 #define __GLIBCXX_TYPE_INT_N_0 __int128 @@ -1048,25 +1261,40 @@ macro(probe_libcxx_filesystem) check_cxx_source_compiles("${stdfs_probe_code}" LIBCXX_FILESYSTEM_none) if(LIBCXX_FILESYSTEM_none) - message(STATUS "No linking with additional library needed for std::filesystem") + message( + STATUS "No linking with additional library needed for std::filesystem" + ) else() set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries} "stdc++fs") - check_cxx_source_compiles("${stdfs_probe_code}" LIBCXX_FILESYSTEM_stdcxxfs) + check_cxx_source_compiles("${stdfs_probe_code}" + LIBCXX_FILESYSTEM_stdcxxfs) if(LIBCXX_FILESYSTEM_stdcxxfs) set(LIBCXX_FILESYSTEM "stdc++fs") - message(STATUS "Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem") + message( + STATUS + "Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem" + ) else() set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries} "c++fs") - check_cxx_source_compiles("${stdfs_probe_code}" LIBCXX_FILESYSTEM_cxxfs) + check_cxx_source_compiles("${stdfs_probe_code}" + LIBCXX_FILESYSTEM_cxxfs) if(LIBCXX_FILESYSTEM_cxxfs) set(LIBCXX_FILESYSTEM "c++fs") - message(STATUS "Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem") + message( + STATUS + "Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem" + ) else() - set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries} "c++experimental") - check_cxx_source_compiles("${stdfs_probe_code}" LIBCXX_FILESYSTEM_cxxexperimental) + set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries} + "c++experimental") + check_cxx_source_compiles("${stdfs_probe_code}" + LIBCXX_FILESYSTEM_cxxexperimental) if(LIBCXX_FILESYSTEM_cxxexperimental) set(LIBCXX_FILESYSTEM "c++experimental") - message(STATUS "Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem") + message( + STATUS + "Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem" + ) else() message(STATUS "No support for std::filesystem") endif() diff --git a/cmake/profile.cmake b/cmake/profile.cmake index 9331a0bb..d325724e 100644 --- a/cmake/profile.cmake +++ b/cmake/profile.cmake @@ -1,5 +1,5 @@ -## Copyright (c) 2012-2024 Леонид Юрьев aka Leonid Yuriev -## SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2012-2024 Леонид Юрьев aka Leonid Yuriev +# SPDX-License-Identifier: Apache-2.0 if(CMAKE_VERSION VERSION_LESS 3.8.2) cmake_minimum_required(VERSION 3.0.2) @@ -14,7 +14,7 @@ cmake_policy(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION}) unset(MEMCHECK_OPTION_NAME) if(NOT DEFINED ENABLE_MEMCHECK) - if (DEFINED MDBX_USE_VALGRIND) + if(DEFINED MDBX_USE_VALGRIND) set(MEMCHECK_OPTION_NAME "MDBX_USE_VALGRIND") elseif(DEFINED ENABLE_VALGRIND) set(MEMCHECK_OPTION_NAME "ENABLE_VALGRIND") @@ -23,7 +23,7 @@ if(NOT DEFINED ENABLE_MEMCHECK) endif() if(MEMCHECK_OPTION_NAME STREQUAL "ENABLE_MEMCHECK") option(ENABLE_MEMCHECK - "Enable integration with valgrind, a memory analyzing tool" OFF) + "Enable integration with valgrind, a memory analyzing tool" OFF) elseif(${MEMCHECK_OPTION_NAME}) set(ENABLE_MEMCHECK ON) else() @@ -34,17 +34,20 @@ endif() include(CheckLibraryExists) check_library_exists(gcov __gcov_flush "" HAVE_GCOV) -option(ENABLE_GCOV - "Enable integration with gcov, a code coverage program" OFF) +option(ENABLE_GCOV "Enable integration with gcov, a code coverage program" OFF) option(ENABLE_GPROF - "Enable integration with gprof, a performance analyzing tool" OFF) + "Enable integration with gprof, a performance analyzing tool" OFF) -option(ENABLE_ASAN - "Enable AddressSanitizer, a fast memory error detector based on compiler instrumentation" OFF) +option( + ENABLE_ASAN + "Enable AddressSanitizer, a fast memory error detector based on compiler instrumentation" + OFF) -option(ENABLE_UBSAN - "Enable UndefinedBehaviorSanitizer, a fast undefined behavior detector based on compiler instrumentation" OFF) +option( + ENABLE_UBSAN + "Enable UndefinedBehaviorSanitizer, a fast undefined behavior detector based on compiler instrumentation" + OFF) if(ENABLE_MEMCHECK) if(CMAKE_CXX_COMPILER_LOADED) @@ -55,7 +58,10 @@ if(ENABLE_MEMCHECK) check_include_file(valgrind/memcheck.h HAVE_VALGRIND_MEMCHECK_H) endif() if(NOT HAVE_VALGRIND_MEMCHECK_H) - message(FATAL_ERROR "${MEMCHECK_OPTION_NAME} option is set but valgrind/memcheck.h is not found") + message( + FATAL_ERROR + "${MEMCHECK_OPTION_NAME} option is set but valgrind/memcheck.h is not found" + ) endif() endif() diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 0348d96d..3a5fddde 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -1,5 +1,5 @@ -## Copyright (c) 2012-2024 Леонид Юрьев aka Leonid Yuriev -## SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2012-2024 Леонид Юрьев aka Leonid Yuriev +# SPDX-License-Identifier: Apache-2.0 if(CMAKE_VERSION VERSION_LESS 3.8.2) cmake_minimum_required(VERSION 3.0.2) @@ -27,8 +27,10 @@ macro(add_compile_flags languages) endmacro(add_compile_flags) macro(remove_flag varname flag) - string(REGEX REPLACE "^(.*)( ${flag} )(.*)$" "\\1 \\3" ${varname} ${${varname}}) - string(REGEX REPLACE "^((.+ )*)(${flag})(( .+)*)$" "\\1\\4" ${varname} ${${varname}}) + string(REGEX REPLACE "^(.*)( ${flag} )(.*)$" "\\1 \\3" ${varname} + ${${varname}}) + string(REGEX REPLACE "^((.+ )*)(${flag})(( .+)*)$" "\\1\\4" ${varname} + ${${varname}}) endmacro(remove_flag) macro(remove_compile_flag languages flag) @@ -49,9 +51,9 @@ macro(set_source_files_compile_flags) set(_lang "") if("${_file_ext}" STREQUAL ".m") set(_lang OBJC) - # CMake believes that Objective C is a flavor of C++, not C, - # and uses g++ compiler for .m files. - # LANGUAGE property forces CMake to use CC for ${file} + # CMake believes that Objective C is a flavor of C++, not C, and uses g++ + # compiler for .m files. LANGUAGE property forces CMake to use CC for + # ${file} set_source_files_properties(${file} PROPERTIES LANGUAGE C) elseif("${_file_ext}" STREQUAL ".mm") set(_lang OBJCXX) @@ -65,15 +67,15 @@ macro(set_source_files_compile_flags) set(_flags "${_flags} ${CMAKE_${_lang}_FLAGS}") endif() # message(STATUS "Set (${file} ${_flags}") - set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS - "${_flags}") + set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "${_flags}") endif() endforeach() unset(_file_ext) unset(_lang) endmacro(set_source_files_compile_flags) -macro(fetch_version name source_root_directory parent_scope build_directory_for_json_output) +macro(fetch_version name source_root_directory parent_scope + build_directory_for_json_output) set(_version_4dot "") set(_git_describe "") set(_git_timestamp "") @@ -86,7 +88,8 @@ macro(fetch_version name source_root_directory parent_scope build_directory_for_ find_program(GIT git) if(GIT) - execute_process(COMMAND ${GIT} rev-parse --show-toplevel + execute_process( + COMMAND ${GIT} rev-parse --show-toplevel OUTPUT_VARIABLE _git_root ERROR_VARIABLE _git_root_error OUTPUT_STRIP_TRAILING_WHITESPACE @@ -94,9 +97,11 @@ macro(fetch_version name source_root_directory parent_scope build_directory_for_ RESULT_VARIABLE _rc) if(_rc OR _git_root STREQUAL "") if(EXISTS "${source_root_directory}/.git") - message(ERROR "`git rev-parse --show-toplevel` failed '${_git_root_error}'") + message(ERROR + "`git rev-parse --show-toplevel` failed '${_git_root_error}'") else() - message(VERBOSE "`git rev-parse --show-toplevel` failed '${_git_root_error}'") + message(VERBOSE + "`git rev-parse --show-toplevel` failed '${_git_root_error}'") endif() else() set(_source_root "${source_root_directory}") @@ -105,7 +110,10 @@ macro(fetch_version name source_root_directory parent_scope build_directory_for_ cmake_path(NORMAL_PATH _source_root) endif() if(_source_root STREQUAL _git_root AND EXISTS "${_git_root}/VERSION.json") - message(FATAL_ERROR "Несколько источников информации о версии, допустим только один из: репозиторий git, либо файл VERSION.json") + message( + FATAL_ERROR + "Несколько источников информации о версии, допустим только один из: репозиторий git, либо файл VERSION.json" + ) endif() endif() endif() @@ -114,9 +122,14 @@ macro(fetch_version name source_root_directory parent_scope build_directory_for_ set(_version_from "${source_root_directory}/VERSION.json") if(CMAKE_VERSION VERSION_LESS 3.19) - message(FATAL_ERROR "Требуется CMake версии >= 3.19 для чтения VERSION.json") + message( + FATAL_ERROR "Требуется CMake версии >= 3.19 для чтения VERSION.json") endif() - file(STRINGS "${_version_from}" _versioninfo_json NEWLINE_CONSUME LIMIT_COUNT 9 LIMIT_INPUT 999 ENCODING UTF-8) + file( + STRINGS "${_version_from}" _versioninfo_json NEWLINE_CONSUME + LIMIT_COUNT 9 + LIMIT_INPUT 999 + ENCODING UTF-8) string(JSON _git_describe GET ${_versioninfo_json} git_describe) string(JSON _git_timestamp GET "${_versioninfo_json}" "git_timestamp") string(JSON _git_tree GET "${_versioninfo_json}" "git_tree") @@ -126,7 +139,9 @@ macro(fetch_version name source_root_directory parent_scope build_directory_for_ string(REPLACE "." ";" _version_list "${_version_4dot}") if(NOT _version_4dot) - message(ERROR "Unable to retrieve ${name} version from \"${_version_from}\" file.") + message( + ERROR + "Unable to retrieve ${name} version from \"${_version_from}\" file.") set(_version_list ${_git_version}) string(REPLACE ";" "." _version_4dot "${_git_version}") else() @@ -136,158 +151,221 @@ macro(fetch_version name source_root_directory parent_scope build_directory_for_ elseif(_git_root AND _source_root STREQUAL _git_root) set(_version_from git) - execute_process(COMMAND ${GIT} show --no-patch --format=%cI HEAD + execute_process( + COMMAND ${GIT} show --no-patch --format=%cI HEAD OUTPUT_VARIABLE _git_timestamp OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc OR _git_timestamp STREQUAL "%cI") - execute_process(COMMAND ${GIT} show --no-patch --format=%ci HEAD + execute_process( + COMMAND ${GIT} show --no-patch --format=%ci HEAD OUTPUT_VARIABLE _git_timestamp OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc OR _git_timestamp STREQUAL "%ci") - message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%cI HEAD` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`show --no-patch --format=%cI HEAD` failed)" + ) endif() endif() - execute_process(COMMAND ${GIT} show --no-patch --format=%T HEAD + execute_process( + COMMAND ${GIT} show --no-patch --format=%T HEAD OUTPUT_VARIABLE _git_tree OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc OR _git_tree STREQUAL "") - message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%T HEAD` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`show --no-patch --format=%T HEAD` failed)" + ) endif() - execute_process(COMMAND ${GIT} show --no-patch --format=%H HEAD + execute_process( + COMMAND ${GIT} show --no-patch --format=%H HEAD OUTPUT_VARIABLE _git_commit OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc OR _git_commit STREQUAL "") - message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%H HEAD` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`show --no-patch --format=%H HEAD` failed)" + ) endif() - execute_process(COMMAND ${GIT} status --untracked-files=no --porcelain + execute_process( + COMMAND ${GIT} status --untracked-files=no --porcelain OUTPUT_VARIABLE _git_status OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc) - message(FATAL_ERROR "Please install latest version of git (`status --untracked-files=no --porcelain` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`status --untracked-files=no --porcelain` failed)" + ) endif() if(NOT _git_status STREQUAL "") set(_git_commit "${_git_commit}-dirty") endif() unset(_git_status) - execute_process(COMMAND ${GIT} rev-list --tags --count + execute_process( + COMMAND ${GIT} rev-list --tags --count OUTPUT_VARIABLE _tag_count OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc) - message(FATAL_ERROR "Please install latest version of git (`git rev-list --tags --count` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`git rev-list --tags --count` failed)" + ) endif() if(_tag_count EQUAL 0) - execute_process(COMMAND ${GIT} rev-list --all --count + execute_process( + COMMAND ${GIT} rev-list --all --count OUTPUT_VARIABLE _whole_count OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc) - message(FATAL_ERROR "Please install latest version of git (`git rev-list --all --count` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`git rev-list --all --count` failed)" + ) endif() if(_whole_count GREATER 42) - message(FATAL_ERROR "Please fetch tags (no any tags for ${_whole_count} commits)") + message( + FATAL_ERROR + "Please fetch tags (no any tags for ${_whole_count} commits)") endif() set(_git_version "0;0;0") - execute_process(COMMAND ${GIT} rev-list --count --all --no-merges + execute_process( + COMMAND ${GIT} rev-list --count --all --no-merges OUTPUT_VARIABLE _git_revision OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc OR _git_revision STREQUAL "") - message(FATAL_ERROR "Please install latest version of git (`rev-list --count --all --no-merges` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`rev-list --count --all --no-merges` failed)" + ) endif() else(_tag_count EQUAL 0) - execute_process(COMMAND ${GIT} describe --tags --long --dirty=-dirty "--match=v[0-9]*" + execute_process( + COMMAND ${GIT} describe --tags --long --dirty=-dirty "--match=v[0-9]*" OUTPUT_VARIABLE _git_describe OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc OR _git_describe STREQUAL "") - execute_process(COMMAND ${GIT} rev-list --all --count + execute_process( + COMMAND ${GIT} rev-list --all --count OUTPUT_VARIABLE _whole_count OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} - RESULT_VARIABLE _rc) - if(_rc) - message(FATAL_ERROR "Please install latest version of git (`git rev-list --all --count` failed)") + RESULT_VARIABLE _rc) + if(_rc) + message( + FATAL_ERROR + "Please install latest version of git (`git rev-list --all --count` failed)" + ) endif() if(_whole_count GREATER 42) - message(FATAL_ERROR "Please fetch tags (`describe --tags --long --dirty --match=v[0-9]*` failed)") + message( + FATAL_ERROR + "Please fetch tags (`describe --tags --long --dirty --match=v[0-9]*` failed)" + ) else() - execute_process(COMMAND ${GIT} describe --all --long --dirty=-dirty + execute_process( + COMMAND ${GIT} describe --all --long --dirty=-dirty OUTPUT_VARIABLE _git_describe OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc OR _git_describe STREQUAL "") - message(FATAL_ERROR "Please install latest version of git (`git rev-list --tags --count` and/or `git rev-list --all --count` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`git rev-list --tags --count` and/or `git rev-list --all --count` failed)" + ) endif() endif() endif() - execute_process(COMMAND ${GIT} describe --tags --abbrev=0 "--match=v[0-9]*" + execute_process( + COMMAND ${GIT} describe --tags --abbrev=0 "--match=v[0-9]*" OUTPUT_VARIABLE _last_release_tag OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc) - message(FATAL_ERROR "Please install latest version of git (`describe --tags --abbrev=0 --match=v[0-9]*` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`describe --tags --abbrev=0 --match=v[0-9]*` failed)" + ) endif() - if (_last_release_tag) + if(_last_release_tag) set(_git_revlist_arg "${_last_release_tag}..HEAD") else() - execute_process(COMMAND ${GIT} tag --sort=-version:refname + execute_process( + COMMAND ${GIT} tag --sort=-version:refname OUTPUT_VARIABLE _tag_list OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc) - message(FATAL_ERROR "Please install latest version of git (`tag --sort=-version:refname` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`tag --sort=-version:refname` failed)" + ) endif() string(REGEX REPLACE "\n" ";" _tag_list "${_tag_list}") set(_git_revlist_arg "HEAD") foreach(_tag IN LISTS _tag_list) if(NOT _last_release_tag) - string(REGEX MATCH "^v[0-9]+(\.[0-9]+)+" _last_release_tag "${_tag}") + string(REGEX MATCH "^v[0-9]+(\.[0-9]+)+" _last_release_tag + "${_tag}") set(_git_revlist_arg "${_tag}..HEAD") endif() endforeach(_tag) endif() - execute_process(COMMAND ${GIT} rev-list --count "${_git_revlist_arg}" + execute_process( + COMMAND ${GIT} rev-list --count "${_git_revlist_arg}" OUTPUT_VARIABLE _git_revision OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${source_root_directory} RESULT_VARIABLE _rc) if(_rc OR _git_revision STREQUAL "") - message(FATAL_ERROR "Please install latest version of git (`rev-list --count ${_git_revlist_arg}` failed)") + message( + FATAL_ERROR + "Please install latest version of git (`rev-list --count ${_git_revlist_arg}` failed)" + ) endif() - string(REGEX MATCH "^(v)?([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" _git_version_valid "${_git_describe}") + string(REGEX MATCH "^(v)?([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" + _git_version_valid "${_git_describe}") if(_git_version_valid) - string(REGEX REPLACE "^(v)?([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" "\\2;\\3;\\4" _git_version ${_git_describe}) + string(REGEX REPLACE "^(v)?([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" + "\\2;\\3;\\4" _git_version ${_git_describe}) else() - string(REGEX MATCH "^(v)?([0-9]+)\\.([0-9]+)(.*)?" _git_version_valid "${_git_describe}") + string(REGEX MATCH "^(v)?([0-9]+)\\.([0-9]+)(.*)?" _git_version_valid + "${_git_describe}") if(_git_version_valid) - string(REGEX REPLACE "^(v)?([0-9]+)\\.([0-9]+)(.*)?" "\\2;\\3;0" _git_version ${_git_describe}) + string(REGEX REPLACE "^(v)?([0-9]+)\\.([0-9]+)(.*)?" "\\2;\\3;0" + _git_version ${_git_describe}) else() - message(AUTHOR_WARNING "Bad ${name} version \"${_git_describe}\"; falling back to 0.0.0 (have you made an initial release?)") + message( + AUTHOR_WARNING + "Bad ${name} version \"${_git_describe}\"; falling back to 0.0.0 (have you made an initial release?)" + ) set(_git_version "0;0;0") endif() endif() @@ -298,7 +376,10 @@ macro(fetch_version name source_root_directory parent_scope build_directory_for_ string(REPLACE ";" "." _version_4dot "${_version_list}") elseif(GIT) - message(FATAL_ERROR "Нет источника информации о версии (${source_root_directory}), требуется один из: репозиторий git, либо VERSION.json") + message( + FATAL_ERROR + "Нет источника информации о версии (${source_root_directory}), требуется один из: репозиторий git, либо VERSION.json" + ) else() message(FATAL_ERROR "Требуется git для получения информации о версии") endif() @@ -309,24 +390,53 @@ macro(fetch_version name source_root_directory parent_scope build_directory_for_ list(GET _version_list 2 _version_release) list(GET _version_list 3 _version_revision) - if(NOT _git_describe OR NOT _git_timestamp OR NOT _git_tree OR NOT _git_commit OR _git_revision STREQUAL "" OR NOT _version_list_length EQUAL 4 OR _version_major STREQUAL "" OR _version_minor STREQUAL "" OR _version_release STREQUAL "" OR _version_revision STREQUAL "") + if(NOT _git_describe + OR NOT _git_timestamp + OR NOT _git_tree + OR NOT _git_commit + OR _git_revision STREQUAL "" + OR NOT _version_list_length EQUAL 4 + OR _version_major STREQUAL "" + OR _version_minor STREQUAL "" + OR _version_release STREQUAL "" + OR _version_revision STREQUAL "") message(ERROR "Unable to retrieve ${name} version from ${_version_from}.") else() list(APPEND _git_version "${_git_revision}") endif() if(${parent_scope}) - set(${name}_VERSION_MAJOR "${_version_major}" PARENT_SCOPE) - set(${name}_VERSION_MINOR "${_version_minor}" PARENT_SCOPE) - set(${name}_VERSION_RELEASE "${_version_release}" PARENT_SCOPE) - set(${name}_VERSION_REVISION "${_version_revision}" PARENT_SCOPE) - set(${name}_VERSION "${_version_4dot}" PARENT_SCOPE) + set(${name}_VERSION_MAJOR + "${_version_major}" + PARENT_SCOPE) + set(${name}_VERSION_MINOR + "${_version_minor}" + PARENT_SCOPE) + set(${name}_VERSION_RELEASE + "${_version_release}" + PARENT_SCOPE) + set(${name}_VERSION_REVISION + "${_version_revision}" + PARENT_SCOPE) + set(${name}_VERSION + "${_version_4dot}" + PARENT_SCOPE) - set(${name}_GIT_DESCRIBE "${_git_describe}" PARENT_SCOPE) - set(${name}_GIT_TIMESTAMP "${_git_timestamp}" PARENT_SCOPE) - set(${name}_GIT_TREE "${_git_tree}" PARENT_SCOPE) - set(${name}_GIT_COMMIT "${_git_commit}" PARENT_SCOPE) - set(${name}_GIT_REVISION "${_git_revision}" PARENT_SCOPE) + set(${name}_GIT_DESCRIBE + "${_git_describe}" + PARENT_SCOPE) + set(${name}_GIT_TIMESTAMP + "${_git_timestamp}" + PARENT_SCOPE) + set(${name}_GIT_TREE + "${_git_tree}" + PARENT_SCOPE) + set(${name}_GIT_COMMIT + "${_git_commit}" + PARENT_SCOPE) + set(${name}_GIT_REVISION + "${_git_revision}" + PARENT_SCOPE) else() set(${name}_VERSION_MAJOR "${_version_major}") set(${name}_VERSION_MINOR "${_version_minor}") @@ -342,13 +452,18 @@ macro(fetch_version name source_root_directory parent_scope build_directory_for_ endif() if(_version_from STREQUAL "git") - string(CONFIGURE "{ + string( + CONFIGURE + "{ \"git_describe\" : \"@_git_describe@\", \"git_timestamp\" : \"@_git_timestamp@\", \"git_tree\" : \"@_git_tree@\", \"git_commit\" : \"@_git_commit@\", - \"version_4dot\" : \"@_version_4dot@\"\n}" _versioninfo_json @ONLY ESCAPE_QUOTES) - file(WRITE "${build_directory_for_json_output}/VERSION.json" "${_versioninfo_json}") + \"version_4dot\" : \"@_version_4dot@\"\n}" + _versioninfo_json + @ONLY ESCAPE_QUOTES) + file(WRITE "${build_directory_for_json_output}/VERSION.json" + "${_versioninfo_json}") endif() endmacro(fetch_version) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d4322f61..6784b96b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,38 +1,37 @@ -## Copyright (c) 2020-2024 Леонид Юрьев aka Leonid Yuriev -## SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2020-2024 Леонид Юрьев aka Leonid Yuriev +# SPDX-License-Identifier: Apache-2.0 enable_language(CXX) include(../cmake/compiler.cmake) set(LIBMDBX_TEST_SOURCES - base.h++ - cases.c++ - chrono.c++ - chrono.h++ - config.c++ - config.h++ - copy.c++ - dead.c++ - hill.c++ - jitter.c++ - keygen.c++ - keygen.h++ - log.c++ - log.h++ - main.c++ - osal.h++ - osal-unix.c++ - osal-windows.c++ - test.c++ - test.h++ - try.c++ - utils.c++ - utils.h++ - append.c++ - ttl.c++ - nested.c++ - fork.c++ - ) + base.h++ + cases.c++ + chrono.c++ + chrono.h++ + config.c++ + config.h++ + copy.c++ + dead.c++ + hill.c++ + jitter.c++ + keygen.c++ + keygen.h++ + log.c++ + log.h++ + main.c++ + osal.h++ + osal-unix.c++ + osal-windows.c++ + test.c++ + test.h++ + try.c++ + utils.c++ + utils.h++ + append.c++ + ttl.c++ + nested.c++ + fork.c++) if(NOT MDBX_BUILD_CXX) probe_libcxx_filesystem() @@ -43,12 +42,13 @@ add_executable(mdbx_test ${LIBMDBX_TEST_SOURCES}) target_compile_definitions(mdbx_test PRIVATE MDBX_BUILD_TEST=1 MDBX_BUILD_CXX=1) if(MDBX_CXX_STANDARD) - set_target_properties(mdbx_test PROPERTIES - CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON) + set_target_properties(mdbx_test PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} + CXX_STANDARD_REQUIRED ON) endif() -set_target_properties(mdbx_test PROPERTIES - INTERPROCEDURAL_OPTIMIZATION $) +set_target_properties( + mdbx_test PROPERTIES INTERPROCEDURAL_OPTIMIZATION + $) target_setup_options(mdbx_test) if(NOT MDBX_BUILD_CXX) @@ -59,15 +59,17 @@ if(NOT MDBX_BUILD_CXX) endif() if(NOT MDBX_BUILD_CXX AND LIBCXX_FILESYSTEM) - if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.25.23 - AND NOT CMAKE_VERSION VERSION_LESS 3.13) + if(CMAKE_COMPILER_IS_ELBRUSCXX + AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.25.23 + AND NOT CMAKE_VERSION VERSION_LESS 3.13) target_link_options(mdbx_test PRIVATE "-Wl,--allow-multiple-definition") endif() target_link_libraries(mdbx_test ${LIBCXX_FILESYSTEM}) endif() if(CMAKE_VERSION VERSION_LESS 3.1) - target_link_libraries(mdbx_test ${TOOL_MDBX_LIB} ${LIB_MATH} ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(mdbx_test ${TOOL_MDBX_LIB} ${LIB_MATH} + ${CMAKE_THREAD_LIBS_INIT}) else() target_link_libraries(mdbx_test ${TOOL_MDBX_LIB} ${LIB_MATH} Threads::Threads) endif() @@ -79,10 +81,14 @@ function(add_extra_test name) set(options DISABLED) set(oneValueArgs TIMEOUT) set(multiValueArgs SOURCE LIBRARY DEPEND DLLPATH) - cmake_parse_arguments(params "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + cmake_parse_arguments(params "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) if(params_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unknown keywords given to add_extra_test(): \"${params_UNPARSED_ARGUMENTS}\".") + message( + FATAL_ERROR + "Unknown keywords given to add_extra_test(): \"${params_UNPARSED_ARGUMENTS}\"." + ) endif() macro(oops) @@ -97,13 +103,12 @@ function(add_extra_test name) add_executable(${target} ${params_SOURCE}) target_include_directories(${target} PRIVATE "${PROJECT_SOURCE_DIR}") target_link_libraries(${target} ${TOOL_MDBX_LIB}) - set_target_properties(${target} PROPERTIES - SKIP_BUILD_RPATH FALSE - BUILD_WITH_INSTALL_RPATH FALSE) + set_target_properties(${target} PROPERTIES SKIP_BUILD_RPATH FALSE + BUILD_WITH_INSTALL_RPATH FALSE) if(MDBX_BUILD_CXX AND MDBX_CXX_STANDARD) - set_target_properties(${target} PROPERTIES - CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON) + set_target_properties(${target} PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} + CXX_STANDARD_REQUIRED ON) endif() if(params_DEPEND) @@ -115,26 +120,32 @@ function(add_extra_test name) foreach(dep IN LISTS params_LIBRARY) get_target_property(type ${dep} TYPE) if(type STREQUAL SHARED_LIBRARY) - # Windows don't have RPATH feature, - # therefore we should prepare PATH or copy DLL(s)... + # Windows don't have RPATH feature, therefore we should prepare PATH or + # copy DLL(s)... if(CMAKE_CONFIGURATION_TYPES) - # Could not provide static ENVIRONMENT property with configuration-depended path + # Could not provide static ENVIRONMENT property with + # configuration-depended path set(dir FALSE) else(CMAKE_CONFIGURATION_TYPES) - get_target_property(filename ${dep} IMPORTED_LOCATION_${CMAKE_BUILD_TYPE_UPPERCASE}) + get_target_property(filename ${dep} + IMPORTED_LOCATION_${CMAKE_BUILD_TYPE_UPPERCASE}) if(NOT filename) get_target_property(filename ${dep} IMPORTED_LOCATION) endif() - get_target_property(filename ${dep} LOCATION_${CMAKE_BUILD_TYPE_UPPERCASE}) + get_target_property(filename ${dep} + LOCATION_${CMAKE_BUILD_TYPE_UPPERCASE}) if(NOT filename) get_target_property(filename ${dep} LOCATION) endif() if(filename) get_filename_component(dir ${filename} DIRECTORY) else(filename) - get_target_property(dir ${dep} LIBRARY_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE_UPPERCASE}) + get_target_property( + dir ${dep} LIBRARY_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE_UPPERCASE}) if(NOT dir) - get_target_property(dir ${dep} RUNTIME_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE_UPPERCASE}) + get_target_property( + dir ${dep} + RUNTIME_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE_UPPERCASE}) endif() if(NOT dir) get_target_property(dir ${dep} LIBRARY_OUTPUT_DIRECTORY) @@ -148,23 +159,35 @@ function(add_extra_test name) list(APPEND params_DLLPATH ${dir}) else(dir) # Path is configuration-depended or not available, should copy dll - add_custom_command(TARGET ${target} POST_BUILD - COMMAND if exist "$" - ${CMAKE_COMMAND} -E copy_if_different "$" "$") - add_custom_command(TARGET ${target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" "$" - COMMENT "${TOOL_MDBX_DLLCRUTCH}: Copy shared library ${dep} for test ${target}") + add_custom_command( + TARGET ${target} + POST_BUILD + COMMAND + if exist "$" ${CMAKE_COMMAND} -E + copy_if_different "$" + "$") + add_custom_command( + TARGET ${target} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$" "$" + COMMENT + "${TOOL_MDBX_DLLCRUTCH}: Copy shared library ${dep} for test ${target}" + ) endif(dir) endif() endforeach(dep) endif(TOOL_MDBX_DLLCRUTCH) - if(NOT params_DISABLED AND NOT (CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR)) + if(NOT params_DISABLED AND NOT (CMAKE_CROSSCOMPILING + AND NOT CMAKE_CROSSCOMPILING_EMULATOR)) add_test(extra_${name} ${MDBX_OUTPUT_DIR}/${target}) if(params_TIMEOUT) - if(MEMORYCHECK_COMMAND OR CMAKE_MEMORYCHECK_COMMAND OR ENABLE_MEMCHECK) - # FIXME: unless there are any other ideas how to fix the - # timeouts problem when testing under Valgrind. + if(MEMORYCHECK_COMMAND + OR CMAKE_MEMORYCHECK_COMMAND + OR ENABLE_MEMCHECK) + # FIXME: unless there are any other ideas how to fix the timeouts + # problem when testing under Valgrind. math(EXPR params_TIMEOUT "${params_TIMEOUT} * 42") endif() set_tests_properties(extra_${name} PROPERTIES TIMEOUT ${params_TIMEOUT}) @@ -183,7 +206,8 @@ function(add_extra_test name) else() string(REPLACE ";" ":" params_DLLPATH_ENV "${params_DLLPATH_ENV}") endif() - set_tests_properties(extra_${name} PROPERTIES ENVIRONMENT "PATH=${params_DLLPATH_ENV}") + set_tests_properties(extra_${name} + PROPERTIES ENVIRONMENT "PATH=${params_DLLPATH_ENV}") endif() endif() endfunction(add_extra_test) @@ -196,80 +220,116 @@ if(NOT SUBPROJECT) endif() endif() -################################################################################ +# ############################################################################## -if (CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR) +if(CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR) message(WARNING "No emulator to run cross-compiled tests") - add_test(NAME fake_since_no_crosscompiling_emulator COMMAND ${CMAKE_COMMAND} -E - echo "No emulator to run cross-compiled tests") + add_test(NAME fake_since_no_crosscompiling_emulator + COMMAND ${CMAKE_COMMAND} -E echo + "No emulator to run cross-compiled tests") else() - string(RANDOM LENGTH 9 ALPHABET "1234567890" test_seed) - message(STATUS "The ${test_seed} will be used for seeding tests. Re-run cmake to re-seed it.") + string( + RANDOM + LENGTH 9 + ALPHABET "1234567890" test_seed) + message( + STATUS + "The ${test_seed} will be used for seeding tests. Re-run cmake to re-seed it." + ) - add_test(NAME smoke COMMAND ${MDBX_OUTPUT_DIR}/mdbx_test - --loglevel=verbose - --prng-seed=${test_seed} - --progress --console=no --pathname=smoke.db --dont-cleanup-after basic) - set_tests_properties(smoke PROPERTIES - TIMEOUT 600 - RUN_SERIAL OFF) + add_test( + NAME smoke + COMMAND + ${MDBX_OUTPUT_DIR}/mdbx_test --loglevel=verbose --prng-seed=${test_seed} + --progress --console=no --pathname=smoke.db --dont-cleanup-after basic) + set_tests_properties(smoke PROPERTIES TIMEOUT 600 RUN_SERIAL OFF) if(MDBX_BUILD_TOOLS) add_test(NAME smoke_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv smoke.db) - set_tests_properties(smoke_chk PROPERTIES - DEPENDS smoke - TIMEOUT 60 - FAIL_REGULAR_EXPRESSION "cooperative mode" - REQUIRED_FILES smoke.db) - add_test(NAME smoke_chk_copy COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv smoke.db-copy) - set_tests_properties(smoke_chk_copy PROPERTIES - DEPENDS smoke - TIMEOUT 60 - FAIL_REGULAR_EXPRESSION "cooperative mode" - REQUIRED_FILES smoke.db-copy) + set_tests_properties( + smoke_chk + PROPERTIES DEPENDS + smoke + TIMEOUT + 60 + FAIL_REGULAR_EXPRESSION + "cooperative mode" + REQUIRED_FILES + smoke.db) + add_test(NAME smoke_chk_copy COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv + smoke.db-copy) + set_tests_properties( + smoke_chk_copy + PROPERTIES DEPENDS + smoke + TIMEOUT + 60 + FAIL_REGULAR_EXPRESSION + "cooperative mode" + REQUIRED_FILES + smoke.db-copy) endif() - add_test(NAME dupsort_writemap COMMAND ${MDBX_OUTPUT_DIR}/mdbx_test - --loglevel=notice - --prng-seed=${test_seed} - --table=+data.fixed --keygen.split=29 --datalen=rnd --progress --console=no - --repeat=2 --pathname=dupsort_writemap.db --dont-cleanup-after basic) - set_tests_properties(dupsort_writemap PROPERTIES - TIMEOUT 3600 - RUN_SERIAL OFF) + add_test( + NAME dupsort_writemap + COMMAND + ${MDBX_OUTPUT_DIR}/mdbx_test --loglevel=notice --prng-seed=${test_seed} + --table=+data.fixed --keygen.split=29 --datalen=rnd --progress + --console=no --repeat=2 --pathname=dupsort_writemap.db + --dont-cleanup-after basic) + set_tests_properties(dupsort_writemap PROPERTIES TIMEOUT 3600 RUN_SERIAL OFF) if(MDBX_BUILD_TOOLS) - add_test(NAME dupsort_writemap_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvvwc dupsort_writemap.db) - set_tests_properties(dupsort_writemap_chk PROPERTIES - DEPENDS dupsort_writemap - TIMEOUT 60 - REQUIRED_FILES dupsort_writemap.db) - add_test(NAME dupsort_writemap_chk_copy COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvvc dupsort_writemap.db-copy) - set_tests_properties(dupsort_writemap_chk_copy PROPERTIES - DEPENDS dupsort_writemap - TIMEOUT 60 - FAIL_REGULAR_EXPRESSION "monopolistic mode" - REQUIRED_FILES dupsort_writemap.db-copy) + add_test(NAME dupsort_writemap_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk + -nvvwc dupsort_writemap.db) + set_tests_properties( + dupsort_writemap_chk PROPERTIES DEPENDS dupsort_writemap TIMEOUT 60 + REQUIRED_FILES dupsort_writemap.db) + add_test(NAME dupsort_writemap_chk_copy + COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvvc dupsort_writemap.db-copy) + set_tests_properties( + dupsort_writemap_chk_copy + PROPERTIES DEPENDS + dupsort_writemap + TIMEOUT + 60 + FAIL_REGULAR_EXPRESSION + "monopolistic mode" + REQUIRED_FILES + dupsort_writemap.db-copy) endif() - add_test(NAME uniq_nested COMMAND ${MDBX_OUTPUT_DIR}/mdbx_test - --loglevel=notice - --mode=-writemap,-nosync-safe,-lifo --progress --console=no --repeat=2 --pathname=uniq_nested.db --dont-cleanup-after basic) - set_tests_properties(uniq_nested PROPERTIES - TIMEOUT 1800 - RUN_SERIAL OFF) + add_test( + NAME uniq_nested + COMMAND + ${MDBX_OUTPUT_DIR}/mdbx_test --loglevel=notice + --mode=-writemap,-nosync-safe,-lifo --progress --console=no --repeat=2 + --pathname=uniq_nested.db --dont-cleanup-after basic) + set_tests_properties(uniq_nested PROPERTIES TIMEOUT 1800 RUN_SERIAL OFF) if(MDBX_BUILD_TOOLS) - add_test(NAME uniq_nested_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvvw uniq_nested.db) - set_tests_properties(uniq_nested_chk PROPERTIES - DEPENDS uniq_nested - TIMEOUT 60 - FAIL_REGULAR_EXPRESSION "cooperative mode" - REQUIRED_FILES uniq_nested.db) - add_test(NAME uniq_nested_chk_copy COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv uniq_nested.db-copy) - set_tests_properties(uniq_nested_chk_copy PROPERTIES - DEPENDS uniq_nested - TIMEOUT 60 - FAIL_REGULAR_EXPRESSION "cooperative mode" - REQUIRED_FILES uniq_nested.db-copy) + add_test(NAME uniq_nested_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvvw + uniq_nested.db) + set_tests_properties( + uniq_nested_chk + PROPERTIES DEPENDS + uniq_nested + TIMEOUT + 60 + FAIL_REGULAR_EXPRESSION + "cooperative mode" + REQUIRED_FILES + uniq_nested.db) + add_test(NAME uniq_nested_chk_copy COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv + uniq_nested.db-copy) + set_tests_properties( + uniq_nested_chk_copy + PROPERTIES DEPENDS + uniq_nested + TIMEOUT + 60 + FAIL_REGULAR_EXPRESSION + "cooperative mode" + REQUIRED_FILES + uniq_nested.db-copy) endif() if(NOT SUBPROJECT)