mdbx-cmake: новые настройки cmake-format (косметика).

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2024-12-12 11:20:34 +03:00
parent b687e835e9
commit f2dc60aa53
6 changed files with 308 additions and 652 deletions

3
.cmake-format.yaml Normal file
View File

@ -0,0 +1,3 @@
format:
line_width: 120
tab_size: 2

View File

@ -1,25 +1,20 @@
# Copyright (c) 2020-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> # Copyright (c) 2020-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> ###############################################
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
# Donations are welcome to ETH `0xD104d8f8B2dC312aaD74899F83EBf3EEBDC1EA3A`. # Donations are welcome to ETH `0xD104d8f8B2dC312aaD74899F83EBf3EEBDC1EA3A`. Всё будет хорошо!
# Всё будет хорошо!
# libmdbx = { Revised and extended descendant of Symas LMDB. } Please see # libmdbx = { Revised and extended descendant of Symas LMDB. } Please see README.md at
# README.md at https://gitflic.ru/project/erthink/libmdbx # https://gitflic.ru/project/erthink/libmdbx
# #
# Libmdbx is superior to LMDB in terms of features and reliability, not inferior # Libmdbx is superior to LMDB in terms of features and reliability, not inferior in performance. libmdbx works on Linux,
# in performance. libmdbx works on Linux, FreeBSD, MacOS X and other systems # FreeBSD, MacOS X and other systems compliant with POSIX.1-2008, but also support Windows as a complementary platform.
# 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 # The next version is under active non-public development and will be released as MithrilDB and libmithrildb for
# as MithrilDB and libmithrildb for libraries & packages. Admittedly mythical # libraries & packages. Admittedly mythical Mithril is resembling silver but being stronger and lighter than steel.
# Mithril is resembling silver but being stronger and lighter than steel.
# Therefore MithrilDB is rightly relevant name. # Therefore MithrilDB is rightly relevant name.
# #
# MithrilDB will be radically different from libmdbx by the new database format # MithrilDB will be radically different from libmdbx by the new database format and API based on C++17, as well as the
# and API based on C++17, as well as the Apache 2.0 License. The goal of this # Apache 2.0 License. The goal of this revolution is to provide a clearer and robust API, add more features and new
# revolution is to provide a clearer and robust API, add more features and new
# valuable properties of database. # valuable properties of database.
if(CMAKE_VERSION VERSION_LESS 3.8.2) if(CMAKE_VERSION VERSION_LESS 3.8.2)
@ -190,8 +185,7 @@ else()
message( message(
FATAL_ERROR FATAL_ERROR
"\nThe set of libmdbx source code files is incomplete! " "\nThe set of libmdbx source code files is incomplete! "
"Instead just follow the https://libmdbx.dqdkfa.ru/usage.html " "Instead just follow the https://libmdbx.dqdkfa.ru/usage.html " "PLEASE, AVOID USING ANY OTHER TECHNIQUES.")
"PLEASE, AVOID USING ANY OTHER TECHNIQUES.")
endif() endif()
# Provide version # Provide version
@ -199,15 +193,12 @@ include(cmake/utils.cmake)
set(MDBX_BUILD_METADATA set(MDBX_BUILD_METADATA
"${MDBX_BUILD_METADATA}" "${MDBX_BUILD_METADATA}"
CACHE STRING "An extra/custom information provided during libmdbx build") CACHE STRING "An extra/custom information provided during libmdbx build")
semver_provide(MDBX "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" semver_provide(MDBX "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" "${MDBX_BUILD_METADATA}" FALSE)
"${MDBX_BUILD_METADATA}" FALSE)
message(STATUS "libmdbx version is ${MDBX_VERSION}") message(STATUS "libmdbx version is ${MDBX_VERSION}")
if(DEFINED PROJECT_NAME) if(DEFINED PROJECT_NAME)
option( option(MDBX_FORCE_BUILD_AS_MAIN_PROJECT
MDBX_FORCE_BUILD_AS_MAIN_PROJECT "Force libmdbx to full control build options even it added as a subdirectory to your project." OFF)
"Force libmdbx to full control build options even it added as a subdirectory to your project."
OFF)
endif() endif()
if(DEFINED PROJECT_NAME AND NOT MDBX_FORCE_BUILD_AS_MAIN_PROJECT) if(DEFINED PROJECT_NAME AND NOT MDBX_FORCE_BUILD_AS_MAIN_PROJECT)
@ -230,10 +221,7 @@ if(NOT MDBX_AMALGAMATED_SOURCE)
include(CTest) include(CTest)
option(MDBX_ENABLE_TESTS "Build libmdbx tests." ${BUILD_TESTING}) option(MDBX_ENABLE_TESTS "Build libmdbx tests." ${BUILD_TESTING})
elseif(DEFINED MDBX_ENABLE_TESTS AND MDBX_ENABLE_TESTS) elseif(DEFINED MDBX_ENABLE_TESTS AND MDBX_ENABLE_TESTS)
message( message(WARNING "MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: But amalgamated source code don't includes tests.")
WARNING
"MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: But amalgamated source code don't includes tests."
)
set(MDBX_ENABLE_TESTS OFF) set(MDBX_ENABLE_TESTS OFF)
endif() endif()
@ -242,8 +230,7 @@ if(NOT CMAKE_CXX_COMPILER_LOADED)
include(CheckLanguage) include(CheckLanguage)
if(NOT DEFINED MDBX_BUILD_CXX if(NOT DEFINED MDBX_BUILD_CXX
OR MDBX_BUILD_CXX OR MDBX_BUILD_CXX
OR (NOT MDBX_AMALGAMATED_SOURCE AND (NOT DEFINED MDBX_ENABLE_TESTS OR (NOT MDBX_AMALGAMATED_SOURCE AND (NOT DEFINED MDBX_ENABLE_TESTS OR MDBX_ENABLE_TESTS)))
OR MDBX_ENABLE_TESTS)))
check_language(CXX) check_language(CXX)
if(CMAKE_CXX_COMPILER) if(CMAKE_CXX_COMPILER)
enable_language(CXX) enable_language(CXX)
@ -257,10 +244,7 @@ endif()
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE set(CMAKE_BUILD_TYPE
Release Release
CACHE CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif() endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE) string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE)
@ -303,10 +287,8 @@ include(GNUInstallDirs)
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION LESS 1900) if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION LESS 1900)
message( message(
SEND_ERROR SEND_ERROR "MSVC compiler ${MSVC_VERSION} is too old for building MDBX."
"MSVC compiler ${MSVC_VERSION} is too old for building MDBX." " At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required.")
" At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required."
)
endif() endif()
if(NOT DEFINED THREADS_PREFER_PTHREAD_FLAG) if(NOT DEFINED THREADS_PREFER_PTHREAD_FLAG)
@ -350,38 +332,29 @@ if(SUBPROJECT)
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" OFF) option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" OFF)
endif() endif()
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
option(CMAKE_POSITION_INDEPENDENT_CODE option(CMAKE_POSITION_INDEPENDENT_CODE "Generate position independent (PIC)" ON)
"Generate position independent (PIC)" ON)
endif() endif()
set(MDBX_MANAGE_BUILD_FLAGS_DEFAULT OFF) set(MDBX_MANAGE_BUILD_FLAGS_DEFAULT OFF)
else() else()
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" ON) option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)" ON)
option(CMAKE_POSITION_INDEPENDENT_CODE "Generate position independent (PIC)" option(CMAKE_POSITION_INDEPENDENT_CODE "Generate position independent (PIC)" ON)
ON)
if(CC_HAS_ARCH_NATIVE) if(CC_HAS_ARCH_NATIVE)
option(BUILD_FOR_NATIVE_CPU "Generate code for the compiling machine CPU" option(BUILD_FOR_NATIVE_CPU "Generate code for the compiling machine CPU" OFF)
OFF)
endif() endif()
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE if(CMAKE_INTERPROCEDURAL_OPTIMIZATION_AVAILABLE
OR GCC_LTO_AVAILABLE OR GCC_LTO_AVAILABLE
OR MSVC_LTO_AVAILABLE OR MSVC_LTO_AVAILABLE
OR CLANG_LTO_AVAILABLE) OR CLANG_LTO_AVAILABLE)
if((CMAKE_CONFIGURATION_TYPES OR NOT CMAKE_BUILD_TYPE_UPPERCASE STREQUAL if((CMAKE_CONFIGURATION_TYPES OR NOT CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG")
"DEBUG") AND ((MSVC_LTO_AVAILABLE AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19)
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 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) set(INTERPROCEDURAL_OPTIMIZATION_DEFAULT ON)
else() else()
set(INTERPROCEDURAL_OPTIMIZATION_DEFAULT OFF) set(INTERPROCEDURAL_OPTIMIZATION_DEFAULT OFF)
endif() endif()
option(INTERPROCEDURAL_OPTIMIZATION option(INTERPROCEDURAL_OPTIMIZATION "Enable interprocedural/LTO optimization."
"Enable interprocedural/LTO optimization."
${INTERPROCEDURAL_OPTIMIZATION_DEFAULT}) ${INTERPROCEDURAL_OPTIMIZATION_DEFAULT})
endif() endif()
@ -457,8 +430,8 @@ else()
if(NOT MDBX_AMALGAMATED_SOURCE) if(NOT MDBX_AMALGAMATED_SOURCE)
find_program(VALGRIND valgrind) find_program(VALGRIND valgrind)
if(VALGRIND) if(VALGRIND)
# (LY) cmake is ugly and nasty. Therefore memcheck-options should be # (LY) cmake is ugly and nasty. Therefore memcheck-options should be defined before including ctest. Otherwise
# defined before including ctest. Otherwise ctest may ignore it. # ctest may ignore it.
set(MEMORYCHECK_SUPPRESSIONS_FILE set(MEMORYCHECK_SUPPRESSIONS_FILE
"${CMAKE_CURRENT_SOURCE_DIR}/test/valgrind_suppress.txt" "${CMAKE_CURRENT_SOURCE_DIR}/test/valgrind_suppress.txt"
CACHE FILEPATH "Suppressions file for Valgrind" FORCE) CACHE FILEPATH "Suppressions file for Valgrind" FORCE)
@ -483,19 +456,15 @@ else()
if(UNIX) 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) if(CLANG_FORMAT)
execute_process(COMMAND ${CLANG_FORMAT} "--version" execute_process(COMMAND ${CLANG_FORMAT} "--version" OUTPUT_VARIABLE clang_format_version_info)
OUTPUT_VARIABLE clang_format_version_info) string(REGEX MATCH "version ([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" clang_format_version_info CLANG_FORMAT_VERSION)
string(REGEX MATCH "version ([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" if(clang_format_version_info AND NOT CLANG_FORMAT_VERSION VERSION_LESS 13.0)
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. # Enable 'make reformat' target.
add_custom_target( add_custom_target(
reformat reformat
VERBATIM VERBATIM
COMMAND COMMAND git ls-files | grep -E \\.\(c|cxx|cc|cpp|h|hxx|hpp\)\(\\.in\)?\$ | xargs ${CLANG_FORMAT} -i
git ls-files | grep -E \\.\(c|cxx|cc|cpp|h|hxx|hpp\)\(\\.in\)?\$ | --style=file
xargs ${CLANG_FORMAT} -i --style=file
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endif() endif()
endif() endif()
@ -523,8 +492,7 @@ else()
set(MDBX_MANAGE_BUILD_FLAGS_DEFAULT ON) set(MDBX_MANAGE_BUILD_FLAGS_DEFAULT ON)
endif(SUBPROJECT) endif(SUBPROJECT)
option(MDBX_MANAGE_BUILD_FLAGS option(MDBX_MANAGE_BUILD_FLAGS "Allow libmdbx to configure/manage/override its own build flags"
"Allow libmdbx to configure/manage/override its own build flags"
${MDBX_MANAGE_BUILD_FLAGS_DEFAULT}) ${MDBX_MANAGE_BUILD_FLAGS_DEFAULT})
if(MDBX_MANAGE_BUILD_FLAGS) if(MDBX_MANAGE_BUILD_FLAGS)
setup_compile_flags() setup_compile_flags()
@ -541,17 +509,11 @@ if(NOT DEFINED MDBX_CXX_STANDARD)
endif() endif()
if(DEFINED CMAKE_CXX_STANDARD) if(DEFINED CMAKE_CXX_STANDARD)
set(MDBX_CXX_STANDARD ${CMAKE_CXX_STANDARD}) set(MDBX_CXX_STANDARD ${CMAKE_CXX_STANDARD})
elseif(NOT HAS_CXX23 LESS 0 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) set(MDBX_CXX_STANDARD 23)
elseif(NOT HAS_CXX20 LESS 0 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) set(MDBX_CXX_STANDARD 20)
elseif(NOT HAS_CXX17 LESS 0 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) set(MDBX_CXX_STANDARD 17)
elseif(NOT HAS_CXX14 LESS 0) elseif(NOT HAS_CXX14 LESS 0)
set(MDBX_CXX_STANDARD 14) set(MDBX_CXX_STANDARD 14)
@ -574,8 +536,7 @@ if(NOT DEFINED MDBX_C_STANDARD)
set(MDBX_C_STANDARD ${CMAKE_C_STANDARD}) set(MDBX_C_STANDARD ${CMAKE_C_STANDARD})
elseif( elseif(
MSVC MSVC
# MSVC >= 19.28 (Microsoft Visual Studio 16.8) is mad! It unable process # MSVC >= 19.28 (Microsoft Visual Studio 16.8) is mad! It unable process Windows SDK headers in the C11 mode!
# Windows SDK headers in the C11 mode!
AND MSVC_VERSION GREATER 1927 AND MSVC_VERSION GREATER 1927
AND NOT MSVC_VERSION GREATER 1929) AND NOT MSVC_VERSION GREATER 1929)
set(MDBX_C_STANDARD 99) set(MDBX_C_STANDARD 99)
@ -603,15 +564,12 @@ if(WIN32 AND EXISTS "${MDBX_SOURCE_DIR}/ntdll.def")
endif() endif()
if(MSVC_LIB_EXE) if(MSVC_LIB_EXE)
message(STATUS "Found MSVC's lib tool: ${MSVC_LIB_EXE}") message(STATUS "Found MSVC's lib tool: ${MSVC_LIB_EXE}")
set(MDBX_NTDLL_EXTRA_IMPLIB set(MDBX_NTDLL_EXTRA_IMPLIB "${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.lib")
"${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.lib")
add_custom_command( add_custom_command(
OUTPUT "${MDBX_NTDLL_EXTRA_IMPLIB}" OUTPUT "${MDBX_NTDLL_EXTRA_IMPLIB}"
COMMENT "Create extra-import-library for ntdll.dll" COMMENT "Create extra-import-library for ntdll.dll"
MAIN_DEPENDENCY "${MDBX_SOURCE_DIR}/ntdll.def" MAIN_DEPENDENCY "${MDBX_SOURCE_DIR}/ntdll.def"
COMMAND COMMAND ${MSVC_LIB_EXE} /def:"${MDBX_SOURCE_DIR}/ntdll.def" /out:"${MDBX_NTDLL_EXTRA_IMPLIB}"
${MSVC_LIB_EXE} /def:"${MDBX_SOURCE_DIR}/ntdll.def"
/out:"${MDBX_NTDLL_EXTRA_IMPLIB}"
${INITIAL_CMAKE_STATIC_LINKER_FLAGS}) ${INITIAL_CMAKE_STATIC_LINKER_FLAGS})
else() else()
message(WARNING "MSVC's lib tool not found") message(WARNING "MSVC's lib tool not found")
@ -625,14 +583,12 @@ if(WIN32 AND EXISTS "${MDBX_SOURCE_DIR}/ntdll.def")
endif() endif()
if(DLLTOOL) if(DLLTOOL)
message(STATUS "Found dlltool: ${DLLTOOL}") message(STATUS "Found dlltool: ${DLLTOOL}")
set(MDBX_NTDLL_EXTRA_IMPLIB set(MDBX_NTDLL_EXTRA_IMPLIB "${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.a")
"${CMAKE_CURRENT_BINARY_DIR}/mdbx_ntdll_extra.a")
add_custom_command( add_custom_command(
OUTPUT "${MDBX_NTDLL_EXTRA_IMPLIB}" OUTPUT "${MDBX_NTDLL_EXTRA_IMPLIB}"
COMMENT "Create extra-import-library for ntdll.dll" COMMENT "Create extra-import-library for ntdll.dll"
MAIN_DEPENDENCY "${MDBX_SOURCE_DIR}/ntdll.def" MAIN_DEPENDENCY "${MDBX_SOURCE_DIR}/ntdll.def"
COMMAND ${DLLTOOL} -d "${MDBX_SOURCE_DIR}/ntdll.def" -l COMMAND ${DLLTOOL} -d "${MDBX_SOURCE_DIR}/ntdll.def" -l "${MDBX_NTDLL_EXTRA_IMPLIB}")
"${MDBX_NTDLL_EXTRA_IMPLIB}")
else() else()
message(WARNING "dlltool not found") message(WARNING "dlltool not found")
endif() endif()
@ -647,12 +603,11 @@ if(WIN32 AND EXISTS "${MDBX_SOURCE_DIR}/ntdll.def")
add_library(ntdll_extra STATIC IMPORTED GLOBAL) add_library(ntdll_extra STATIC IMPORTED GLOBAL)
add_dependencies(ntdll_extra ntdll_extra_target) add_dependencies(ntdll_extra ntdll_extra_target)
# (3) specify where the library is (and where to find the headers) # (3) specify where the library is (and where to find the headers)
set_target_properties(ntdll_extra PROPERTIES IMPORTED_LOCATION set_target_properties(ntdll_extra PROPERTIES IMPORTED_LOCATION "${MDBX_NTDLL_EXTRA_IMPLIB}")
"${MDBX_NTDLL_EXTRA_IMPLIB}")
endif() endif()
endif() endif()
# ############################################################################## # ######################################################################################################################
# ~~~ # ~~~
# #
# #### ##### ##### # #### # # #### # #### ##### ##### # #### # # ####
@ -663,10 +618,9 @@ endif()
# #### # # # #### # # #### # #### # # # #### # # ####
# #
# ~~~ # ~~~
# ############################################################################## # ######################################################################################################################
set(MDBX_BUILD_OPTIONS ENABLE_UBSAN ENABLE_ASAN ENABLE_MEMCHECK ENABLE_GPROF set(MDBX_BUILD_OPTIONS ENABLE_UBSAN ENABLE_ASAN ENABLE_MEMCHECK ENABLE_GPROF ENABLE_GCOV)
ENABLE_GCOV)
macro(add_mdbx_option NAME DESCRIPTION DEFAULT) macro(add_mdbx_option NAME DESCRIPTION DEFAULT)
list(APPEND MDBX_BUILD_OPTIONS ${NAME}) list(APPEND MDBX_BUILD_OPTIONS ${NAME})
if(NOT ${DEFAULT} STREQUAL "AUTO") if(NOT ${DEFAULT} STREQUAL "AUTO")
@ -686,51 +640,32 @@ else()
set(MDBX_BUILD_TOOLS_DEFAULT ON) set(MDBX_BUILD_TOOLS_DEFAULT ON)
endif() endif()
add_mdbx_option(MDBX_INSTALL_STATIC add_mdbx_option(MDBX_INSTALL_STATIC "Build and install libmdbx for static linking" OFF)
"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_SHARED_LIBRARY add_mdbx_option(MDBX_BUILD_TOOLS "Build MDBX tools (mdbx_chk/stat/dump/load/copy/drop)" ${MDBX_BUILD_TOOLS_DEFAULT})
"Build libmdbx as shared library (DLL)" ${BUILD_SHARED_LIBS}) cmake_dependent_option(MDBX_INSTALL_MANPAGES "Install man-pages for MDBX tools (mdbx_chk/stat/dump/load/copy)" ON
add_mdbx_option(
MDBX_BUILD_TOOLS "Build MDBX tools (mdbx_chk/stat/dump/load/copy/drop)"
${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) MDBX_BUILD_TOOLS OFF)
add_mdbx_option( add_mdbx_option(MDBX_TXN_CHECKOWNER "Checking transaction matches the calling thread inside libmdbx's API" ON)
MDBX_TXN_CHECKOWNER add_mdbx_option(MDBX_ENV_CHECKPID "Checking PID inside libmdbx's API against reuse DB environment after the fork()"
"Checking transaction matches the calling thread inside libmdbx's API" ON)
add_mdbx_option(
MDBX_ENV_CHECKPID
"Checking PID inside libmdbx's API against reuse DB environment after the fork()"
AUTO) AUTO)
mark_as_advanced(MDBX_ENV_CHECKPID) mark_as_advanced(MDBX_ENV_CHECKPID)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use GNU/Linux libc extensions" add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use GNU/Linux libc extensions" OFF)
OFF)
mark_as_advanced(MDBX_DISABLE_GNU_SOURCE) mark_as_advanced(MDBX_DISABLE_GNU_SOURCE)
endif() endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR IOS) if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR IOS)
add_mdbx_option(MDBX_APPLE_SPEED_INSTEADOF_DURABILITY add_mdbx_option(MDBX_APPLE_SPEED_INSTEADOF_DURABILITY "Disable use fcntl(F_FULLFSYNC) in favor of speed" OFF)
"Disable use fcntl(F_FULLFSYNC) in favor of speed" OFF)
mark_as_advanced(MDBX_APPLE_SPEED_INSTEADOF_DURABILITY) mark_as_advanced(MDBX_APPLE_SPEED_INSTEADOF_DURABILITY)
endif() endif()
if(WIN32) if(WIN32)
if(MDBX_NTDLL_EXTRA_IMPLIB) if(MDBX_NTDLL_EXTRA_IMPLIB)
add_mdbx_option( add_mdbx_option(MDBX_WITHOUT_MSVC_CRT "Avoid dependence from MSVC CRT and use ntdll.dll instead" OFF)
MDBX_WITHOUT_MSVC_CRT
"Avoid dependence from MSVC CRT and use ntdll.dll instead" OFF)
endif() endif()
set(MDBX_AVOID_MSYNC_DEFAULT ON) set(MDBX_AVOID_MSYNC_DEFAULT ON)
else() else()
add_mdbx_option( add_mdbx_option(MDBX_USE_OFDLOCKS "Use Open file description locks (aka OFD locks, non-POSIX)" AUTO)
MDBX_USE_OFDLOCKS
"Use Open file description locks (aka OFD locks, non-POSIX)" AUTO)
mark_as_advanced(MDBX_USE_OFDLOCKS) mark_as_advanced(MDBX_USE_OFDLOCKS)
add_mdbx_option( add_mdbx_option(MDBX_USE_MINCORE "Use Unix' mincore() to determine whether DB-pages are resident in memory" ON)
MDBX_USE_MINCORE
"Use Unix' mincore() to determine whether DB-pages are resident in memory"
ON)
mark_as_advanced(MDBX_USE_MINCORE) mark_as_advanced(MDBX_USE_MINCORE)
set(MDBX_AVOID_MSYNC_DEFAULT OFF) set(MDBX_AVOID_MSYNC_DEFAULT OFF)
endif() endif()
@ -738,19 +673,12 @@ add_mdbx_option(
MDBX_AVOID_MSYNC MDBX_AVOID_MSYNC
"Disable in-memory database updating with consequent flush-to-disk/msync syscall in `MDBX_WRITEMAP` mode" "Disable in-memory database updating with consequent flush-to-disk/msync syscall in `MDBX_WRITEMAP` mode"
${MDBX_AVOID_MSYNC_DEFAULT}) ${MDBX_AVOID_MSYNC_DEFAULT})
add_mdbx_option( add_mdbx_option(MDBX_MMAP_NEEDS_JOLT "Assume system needs explicit syscall to sync/flush/write modified mapped memory"
MDBX_MMAP_NEEDS_JOLT
"Assume system needs explicit syscall to sync/flush/write modified mapped memory"
AUTO) AUTO)
mark_as_advanced(MDBX_MMAP_NEEDS_JOLT) mark_as_advanced(MDBX_MMAP_NEEDS_JOLT)
add_mdbx_option( add_mdbx_option(MDBX_LOCKING "Locking method (Windows=-1, SystemV=5, POSIX=1988, POSIX=2001, POSIX=2008)" AUTO)
MDBX_LOCKING
"Locking method (Windows=-1, SystemV=5, POSIX=1988, POSIX=2001, POSIX=2008)"
AUTO)
mark_as_advanced(MDBX_LOCKING) mark_as_advanced(MDBX_LOCKING)
add_mdbx_option( add_mdbx_option(MDBX_TRUST_RTC "Does a system have battery-backed Real-Time Clock or just a fake" AUTO)
MDBX_TRUST_RTC
"Does a system have battery-backed Real-Time Clock or just a fake" AUTO)
mark_as_advanced(MDBX_TRUST_RTC) mark_as_advanced(MDBX_TRUST_RTC)
add_mdbx_option(MDBX_FORCE_ASSERTIONS "Force enable assertion checking" OFF) add_mdbx_option(MDBX_FORCE_ASSERTIONS "Force enable assertion checking" OFF)
add_mdbx_option( add_mdbx_option(
@ -758,24 +686,18 @@ add_mdbx_option(
"Disable some checks to reduce an overhead and detection probability of database corruption to a values closer to the LMDB" "Disable some checks to reduce an overhead and detection probability of database corruption to a values closer to the LMDB"
OFF) OFF)
mark_as_advanced(MDBX_DISABLE_VALIDATION) mark_as_advanced(MDBX_DISABLE_VALIDATION)
add_mdbx_option(MDBX_ENABLE_REFUND add_mdbx_option(MDBX_ENABLE_REFUND "Zerocost auto-compactification during write-transactions" ON)
"Zerocost auto-compactification during write-transactions" ON)
add_mdbx_option( add_mdbx_option(
MDBX_ENABLE_BIGFOOT MDBX_ENABLE_BIGFOOT
"Chunking long list of retired pages during huge transactions commit to avoid use sequences of pages" "Chunking long list of retired pages during huge transactions commit to avoid use sequences of pages" ON)
ON) add_mdbx_option(MDBX_ENABLE_PGOP_STAT "Gathering statistics for page operations" ON)
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) add_mdbx_option(MDBX_ENABLE_PROFGC "Profiling of GC search and updates" OFF)
mark_as_advanced(MDBX_ENABLE_PROFGC) mark_as_advanced(MDBX_ENABLE_PROFGC)
add_mdbx_option( add_mdbx_option(
MDBX_ENABLE_DBI_SPARSE MDBX_ENABLE_DBI_SPARSE
"Support for sparse sets of DBI handles to reduce overhead when starting and processing transactions" "Support for sparse sets of DBI handles to reduce overhead when starting and processing transactions" ON)
ON) add_mdbx_option(MDBX_ENABLE_DBI_LOCKFREE
add_mdbx_option( "Support for deferred releasing and a lockfree path to quickly open DBI handles" ON)
MDBX_ENABLE_DBI_LOCKFREE
"Support for deferred releasing and a lockfree path to quickly open DBI handles"
ON)
if(NOT MDBX_AMALGAMATED_SOURCE) if(NOT MDBX_AMALGAMATED_SOURCE)
if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG") if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG")
@ -783,14 +705,11 @@ if(NOT MDBX_AMALGAMATED_SOURCE)
else() else()
set(MDBX_ALLOY_BUILD_DEFAULT ON) set(MDBX_ALLOY_BUILD_DEFAULT ON)
endif() endif()
add_mdbx_option( add_mdbx_option(MDBX_ALLOY_BUILD "Build MDBX library through single/alloyed object file" ${MDBX_ALLOY_BUILD_DEFAULT})
MDBX_ALLOY_BUILD "Build MDBX library through single/alloyed object file"
${MDBX_ALLOY_BUILD_DEFAULT})
endif() endif()
if((MDBX_BUILD_TOOLS OR MDBX_ENABLE_TESTS) AND MDBX_BUILD_SHARED_LIBRARY) if((MDBX_BUILD_TOOLS OR MDBX_ENABLE_TESTS) AND MDBX_BUILD_SHARED_LIBRARY)
add_mdbx_option(MDBX_LINK_TOOLS_NONSTATIC add_mdbx_option(MDBX_LINK_TOOLS_NONSTATIC "Link MDBX tools with non-static libmdbx" OFF)
"Link MDBX tools with non-static libmdbx" OFF)
else() else()
unset(MDBX_LINK_TOOLS_NONSTATIC CACHE) unset(MDBX_LINK_TOOLS_NONSTATIC CACHE)
endif() endif()
@ -802,10 +721,8 @@ if(CMAKE_CXX_COMPILER_LOADED
option(MDBX_ENABLE_TESTS "Build MDBX tests" ${BUILD_TESTING}) option(MDBX_ENABLE_TESTS "Build MDBX tests" ${BUILD_TESTING})
endif() endif()
if(NOT MDBX_WITHOUT_MSVC_CRT if(NOT MDBX_WITHOUT_MSVC_CRT
AND NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION AND NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
VERSION_LESS 4.8) AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.9)
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 (MSVC AND MSVC_VERSION LESS 1900))
option(MDBX_BUILD_CXX "Build C++ portion" ON) option(MDBX_BUILD_CXX "Build C++ portion" ON)
else() else()
@ -820,13 +737,10 @@ if(CI)
add_definitions(-DMDBX_CI="${CI}") add_definitions(-DMDBX_CI="${CI}")
endif() endif()
# ############################################################################## # ######################################################################################################################
if(MDBX_BUILD_CXX AND NOT CMAKE_CXX_COMPILER_LOADED) if(MDBX_BUILD_CXX AND NOT CMAKE_CXX_COMPILER_LOADED)
message( message(FATAL_ERROR "MDBX_BUILD_CXX=${MDBX_BUILD_CXX}: The C++ compiler is required to build the C++API.")
FATAL_ERROR
"MDBX_BUILD_CXX=${MDBX_BUILD_CXX}: The C++ compiler is required to build the C++API."
)
endif() endif()
if(MDBX_BUILD_CXX) if(MDBX_BUILD_CXX)
@ -841,8 +755,7 @@ if(MDBX_AMALGAMATED_SOURCE)
list(APPEND LIBMDBX_SOURCES mdbx.c) list(APPEND LIBMDBX_SOURCES mdbx.c)
else() else()
# generate version file # generate version file
configure_file("${MDBX_SOURCE_DIR}/version.c.in" 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) file(SHA256 "${CMAKE_CURRENT_BINARY_DIR}/version.c" MDBX_SOURCERY_DIGEST)
string(MAKE_C_IDENTIFIER "${MDBX_GIT_DESCRIBE}" MDBX_SOURCERY_SUFFIX) string(MAKE_C_IDENTIFIER "${MDBX_GIT_DESCRIBE}" MDBX_SOURCERY_SUFFIX)
set(MDBX_BUILD_SOURCERY "${MDBX_SOURCERY_DIGEST}_${MDBX_SOURCERY_SUFFIX}") set(MDBX_BUILD_SOURCERY "${MDBX_SOURCERY_DIGEST}_${MDBX_SOURCERY_SUFFIX}")
@ -930,21 +843,18 @@ else()
list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/lck-posix.c") list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/lck-posix.c")
endif() endif()
if(NOT APPLE) if(NOT APPLE)
list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/windows-import.h" list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/windows-import.h" "${MDBX_SOURCE_DIR}/windows-import.c"
"${MDBX_SOURCE_DIR}/windows-import.c"
"${MDBX_SOURCE_DIR}/lck-windows.c") "${MDBX_SOURCE_DIR}/lck-windows.c")
endif() endif()
include_directories("${MDBX_SOURCE_DIR}") include_directories("${MDBX_SOURCE_DIR}")
endif() endif()
endif(MDBX_AMALGAMATED_SOURCE) endif(MDBX_AMALGAMATED_SOURCE)
if(MDBX_BUILD_CXX) if(MDBX_BUILD_CXX)
message( message(STATUS "Use C${MDBX_C_STANDARD} and C++${MDBX_CXX_STANDARD} for libmdbx")
STATUS "Use C${MDBX_C_STANDARD} and C++${MDBX_CXX_STANDARD} for libmdbx")
list(APPEND LIBMDBX_PUBLIC_HEADERS mdbx.h++) list(APPEND LIBMDBX_PUBLIC_HEADERS mdbx.h++)
list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/mdbx.c++" mdbx.h++) list(APPEND LIBMDBX_SOURCES "${MDBX_SOURCE_DIR}/mdbx.c++" mdbx.h++)
else() else()
message( message(STATUS "Use C${MDBX_C_STANDARD} for libmdbx but C++ portion is disabled")
STATUS "Use C${MDBX_C_STANDARD} for libmdbx but C++ portion is disabled")
endif() endif()
if(MSVC) if(MSVC)
@ -953,26 +863,20 @@ endif()
macro(target_setup_options TARGET) macro(target_setup_options TARGET)
if(DEFINED INTERPROCEDURAL_OPTIMIZATION) if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
set_target_properties( set_target_properties(${TARGET} PROPERTIES INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
${TARGET} PROPERTIES INTERPROCEDURAL_OPTIMIZATION
$<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
endif() endif()
if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11) if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11)
set_target_properties(${TARGET} PROPERTIES C_STANDARD ${MDBX_C_STANDARD} set_target_properties(${TARGET} PROPERTIES C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
C_STANDARD_REQUIRED ON)
endif() endif()
if(MDBX_BUILD_CXX) if(MDBX_BUILD_CXX)
if(NOT CXX_FALLBACK_GNU11 AND NOT CXX_FALLBACK_11) if(NOT CXX_FALLBACK_GNU11 AND NOT CXX_FALLBACK_11)
set_target_properties( set_target_properties(${TARGET} PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
${TARGET} PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD}
CXX_STANDARD_REQUIRED ON)
endif() endif()
if(MSVC AND NOT MSVC_VERSION LESS 1910) if(MSVC AND NOT MSVC_VERSION LESS 1910)
target_compile_options(${TARGET} INTERFACE "/Zc:__cplusplus") target_compile_options(${TARGET} INTERFACE "/Zc:__cplusplus")
endif() endif()
endif() endif()
if(CC_HAS_FASTMATH AND NOT (CMAKE_COMPILER_IS_CLANG if(CC_HAS_FASTMATH AND NOT (CMAKE_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10))
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10))
target_compile_options(${TARGET} PRIVATE "-ffast-math") target_compile_options(${TARGET} PRIVATE "-ffast-math")
endif() endif()
if(CC_HAS_VISIBILITY) if(CC_HAS_VISIBILITY)
@ -1001,8 +905,7 @@ macro(libmdbx_setup_libs TARGET MODE)
if(MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_WITHOUT_MSVC_CRT) if(MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_WITHOUT_MSVC_CRT)
target_link_libraries(${TARGET} ${MODE} ntdll_extra) target_link_libraries(${TARGET} ${MODE} ntdll_extra)
endif() endif()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL elseif(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Solaris")
"Solaris")
target_link_libraries(${TARGET} ${MODE} kstat) target_link_libraries(${TARGET} ${MODE} kstat)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Android") elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
target_link_libraries(${TARGET} ${MODE} log) target_link_libraries(${TARGET} ${MODE} log)
@ -1023,8 +926,7 @@ if(MDBX_INSTALL_STATIC)
else() else()
add_library(mdbx-static STATIC EXCLUDE_FROM_ALL ${LIBMDBX_SOURCES}) add_library(mdbx-static STATIC EXCLUDE_FROM_ALL ${LIBMDBX_SOURCES})
endif() endif()
set_target_properties(mdbx-static PROPERTIES PUBLIC_HEADER set_target_properties(mdbx-static PROPERTIES PUBLIC_HEADER "${LIBMDBX_PUBLIC_HEADERS}")
"${LIBMDBX_PUBLIC_HEADERS}")
target_compile_definitions(mdbx-static PRIVATE MDBX_BUILD_SHARED_LIBRARY=0) target_compile_definitions(mdbx-static PRIVATE MDBX_BUILD_SHARED_LIBRARY=0)
target_setup_options(mdbx-static) target_setup_options(mdbx-static)
libmdbx_setup_libs(mdbx-static INTERFACE) libmdbx_setup_libs(mdbx-static INTERFACE)
@ -1035,13 +937,12 @@ else()
endif() endif()
target_include_directories(mdbx-static INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(mdbx-static INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
# ############################################################################## # ######################################################################################################################
# build shared library # build shared library
if(MDBX_BUILD_SHARED_LIBRARY) if(MDBX_BUILD_SHARED_LIBRARY)
add_library(mdbx SHARED ${LIBMDBX_SOURCES}) add_library(mdbx SHARED ${LIBMDBX_SOURCES})
set_target_properties(mdbx PROPERTIES PUBLIC_HEADER set_target_properties(mdbx PROPERTIES PUBLIC_HEADER "${LIBMDBX_PUBLIC_HEADERS}")
"${LIBMDBX_PUBLIC_HEADERS}")
target_compile_definitions( target_compile_definitions(
mdbx mdbx
PRIVATE LIBMDBX_EXPORTS MDBX_BUILD_SHARED_LIBRARY=1 PRIVATE LIBMDBX_EXPORTS MDBX_BUILD_SHARED_LIBRARY=1
@ -1052,9 +953,7 @@ if(MDBX_BUILD_SHARED_LIBRARY)
if(MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_WITHOUT_MSVC_CRT) if(MDBX_NTDLL_EXTRA_IMPLIB AND MDBX_WITHOUT_MSVC_CRT)
set_property(TARGET mdbx PROPERTY LINKER_FLAGS "/NODEFAULTLIB") set_property(TARGET mdbx PROPERTY LINKER_FLAGS "/NODEFAULTLIB")
else() else()
set_property( set_property(TARGET mdbx PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
TARGET mdbx PROPERTY MSVC_RUNTIME_LIBRARY
"MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif() endif()
endif() endif()
if(CC_HAS_VISIBILITY AND (LTO_ENABLED OR INTERPROCEDURAL_OPTIMIZATION)) if(CC_HAS_VISIBILITY AND (LTO_ENABLED OR INTERPROCEDURAL_OPTIMIZATION))
@ -1070,18 +969,15 @@ if(MDBX_BUILD_SHARED_LIBRARY AND MDBX_LINK_TOOLS_NONSTATIC)
# use, i.e. don't skip the full RPATH for the build tree # use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already (but later on when # when building, don't use the install RPATH already (but later on when installing)
# installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# add the automatically determined parts of the RPATH which point to # add the automatically determined parts of the RPATH which point to directories outside the build tree to the install
# directories outside the build tree to the install RPATH # RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system # the RPATH to be used when installing, but only if it's not a system directory
# directory list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
"${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if(isSystemDir EQUAL -1) if(isSystemDir EQUAL -1)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(CMAKE_INSTALL_RPATH "@executable_path/../lib") set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
@ -1091,8 +987,7 @@ if(MDBX_BUILD_SHARED_LIBRARY AND MDBX_LINK_TOOLS_NONSTATIC)
endif() endif()
if(WIN32) if(WIN32)
# Windows don't have RPATH feature, therefore we should prepare PATH or copy # Windows don't have RPATH feature, therefore we should prepare PATH or copy DLL(s)
# DLL(s)
set(TOOL_MDBX_DLLCRUTCH "Crutch for ${CMAKE_SYSTEM_NAME}") set(TOOL_MDBX_DLLCRUTCH "Crutch for ${CMAKE_SYSTEM_NAME}")
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_VERSION VERSION_LESS 3.0) if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_VERSION VERSION_LESS 3.0)
# will use LOCATION property to compose DLLPATH # will use LOCATION property to compose DLLPATH
@ -1110,21 +1005,17 @@ endif()
if(MDBX_BUILD_TOOLS) if(MDBX_BUILD_TOOLS)
set(WINGETOPT_SRC "") set(WINGETOPT_SRC "")
if(WIN32) if(WIN32)
set(WINGETOPT_SRC ${MDBX_SOURCE_DIR}/tools/wingetopt.c set(WINGETOPT_SRC ${MDBX_SOURCE_DIR}/tools/wingetopt.c ${MDBX_SOURCE_DIR}/tools/wingetopt.h)
${MDBX_SOURCE_DIR}/tools/wingetopt.h)
endif() endif()
foreach(TOOL chk copy stat dump load drop) foreach(TOOL chk copy stat dump load drop)
if(MDBX_AMALGAMATED_SOURCE) if(MDBX_AMALGAMATED_SOURCE)
add_executable(mdbx_${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/mdbx_${TOOL}.c) add_executable(mdbx_${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/mdbx_${TOOL}.c)
else() else()
add_executable(mdbx_${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/tools/${TOOL}.c add_executable(mdbx_${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/tools/${TOOL}.c ${WINGETOPT_SRC})
${WINGETOPT_SRC})
endif() endif()
if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11) if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11)
set_target_properties( set_target_properties(mdbx_${TOOL} PROPERTIES C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
mdbx_${TOOL} PROPERTIES C_STANDARD ${MDBX_C_STANDARD}
C_STANDARD_REQUIRED ON)
endif() endif()
target_setup_options(mdbx_${TOOL}) target_setup_options(mdbx_${TOOL})
target_link_libraries(mdbx_${TOOL} ${TOOL_MDBX_LIB}) target_link_libraries(mdbx_${TOOL} ${TOOL_MDBX_LIB})
@ -1135,7 +1026,7 @@ if(MDBX_BUILD_TOOLS)
endif() endif()
endif() endif()
# ############################################################################## # ######################################################################################################################
# mdbx-shared-lib installation # mdbx-shared-lib installation
if(NOT DEFINED MDBX_DLL_INSTALL_DESTINATION) if(NOT DEFINED MDBX_DLL_INSTALL_DESTINATION)
@ -1178,19 +1069,15 @@ if(MDBX_BUILD_TOOLS)
set(MDBX_TOOLS_INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR}) set(MDBX_TOOLS_INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR})
endif() endif()
install(TARGETS mdbx_chk mdbx_stat mdbx_copy mdbx_dump mdbx_load mdbx_drop install(TARGETS mdbx_chk mdbx_stat mdbx_copy mdbx_dump mdbx_load mdbx_drop
RUNTIME DESTINATION ${MDBX_TOOLS_INSTALL_DESTINATION} RUNTIME DESTINATION ${MDBX_TOOLS_INSTALL_DESTINATION} COMPONENT runtime)
COMPONENT runtime)
if(MDBX_INSTALL_MANPAGES) if(MDBX_INSTALL_MANPAGES)
if(NOT DEFINED MDBX_MAN_INSTALL_DESTINATION) if(NOT DEFINED MDBX_MAN_INSTALL_DESTINATION)
set(MDBX_MAN_INSTALL_DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) set(MDBX_MAN_INSTALL_DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
endif() endif()
install( install(
FILES "${MDBX_SOURCE_DIR}/man1/mdbx_chk.1" FILES "${MDBX_SOURCE_DIR}/man1/mdbx_chk.1" "${MDBX_SOURCE_DIR}/man1/mdbx_stat.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_copy.1" "${MDBX_SOURCE_DIR}/man1/mdbx_load.1" "${MDBX_SOURCE_DIR}/man1/mdbx_drop.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} DESTINATION ${MDBX_MAN_INSTALL_DESTINATION}
COMPONENT doc) COMPONENT doc)
endif() endif()
@ -1225,7 +1112,7 @@ if(MDBX_INSTALL_STATIC)
endif() endif()
endif(MDBX_INSTALL_STATIC) endif(MDBX_INSTALL_STATIC)
# ############################################################################## # ######################################################################################################################
# collect options & build info # collect options & build info
if(NOT DEFINED MDBX_BUILD_TIMESTAMP) if(NOT DEFINED MDBX_BUILD_TIMESTAMP)
@ -1244,8 +1131,7 @@ endif()
if(NOT CMAKE_CONFIGURATION_TYPES) if(NOT CMAKE_CONFIGURATION_TYPES)
list(APPEND MDBX_BUILD_FLAGS ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}) list(APPEND MDBX_BUILD_FLAGS ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}})
if(MDBX_BUILD_CXX) if(MDBX_BUILD_CXX)
list(APPEND MDBX_BUILD_FLAGS list(APPEND MDBX_BUILD_FLAGS ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}})
${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}})
endif() endif()
endif() endif()
@ -1272,9 +1158,7 @@ list(REMOVE_DUPLICATES MDBX_BUILD_FLAGS)
string(REPLACE ";" " " MDBX_BUILD_FLAGS "${MDBX_BUILD_FLAGS}") string(REPLACE ";" " " MDBX_BUILD_FLAGS "${MDBX_BUILD_FLAGS}")
if(CMAKE_CONFIGURATION_TYPES) if(CMAKE_CONFIGURATION_TYPES)
# add dynamic part via per-configuration define # add dynamic part via per-configuration define
message( message(STATUS "MDBX Compile Flags: ${MDBX_BUILD_FLAGS} <AND CONFIGURATION DEPENDENT>")
STATUS
"MDBX Compile Flags: ${MDBX_BUILD_FLAGS} <AND CONFIGURATION DEPENDENT>")
add_definitions( add_definitions(
-DMDBX_BUILD_FLAGS_CONFIG="$<$<CONFIG:Debug>:${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_DEFINES_DEBUG}>$<$<CONFIG:Release>:${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_DEFINES_RELEASE}>$<$<CONFIG:RelWithDebInfo>:${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CMAKE_C_DEFINES_RELWITHDEBINFO}>$<$<CONFIG:MinSizeRel>:${CMAKE_C_FLAGS_MINSIZEREL} ${CMAKE_C_DEFINES_MINSIZEREL}>" -DMDBX_BUILD_FLAGS_CONFIG="$<$<CONFIG:Debug>:${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_DEFINES_DEBUG}>$<$<CONFIG:Release>:${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_DEFINES_RELEASE}>$<$<CONFIG:RelWithDebInfo>:${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CMAKE_C_DEFINES_RELWITHDEBINFO}>$<$<CONFIG:MinSizeRel>:${CMAKE_C_FLAGS_MINSIZEREL} ${CMAKE_C_DEFINES_MINSIZEREL}>"
) )
@ -1289,8 +1173,7 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
RESULT_VARIABLE rc) RESULT_VARIABLE rc)
if(rc OR NOT MDBX_BUILD_COMPILER) if(rc OR NOT MDBX_BUILD_COMPILER)
string(STRIP "${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}" string(STRIP "${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}" MDBX_BUILD_COMPILER)
MDBX_BUILD_COMPILER)
endif() endif()
# make a build-target triplet # make a build-target triplet
@ -1299,8 +1182,7 @@ if(CMAKE_C_COMPILER_TARGET)
else() else()
if(CMAKE_C_COMPILER_ARCHITECTURE_ID) if(CMAKE_C_COMPILER_ARCHITECTURE_ID)
string(STRIP "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MDBX_BUILD_TARGET) string(STRIP "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MDBX_BUILD_TARGET)
elseif(CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL elseif(CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL CMAKE_SYSTEM_NAME)
CMAKE_SYSTEM_NAME)
string(STRIP "${CMAKE_GENERATOR_PLATFORM}" MDBX_BUILD_TARGET) string(STRIP "${CMAKE_GENERATOR_PLATFORM}" MDBX_BUILD_TARGET)
elseif(CMAKE_SYSTEM_ARCH) elseif(CMAKE_SYSTEM_ARCH)
string(STRIP "${CMAKE_SYSTEM_ARCH}" MDBX_BUILD_TARGET) string(STRIP "${CMAKE_SYSTEM_ARCH}" MDBX_BUILD_TARGET)
@ -1311,20 +1193,16 @@ else()
else() else()
set(MDBX_BUILD_TARGET "unknown") set(MDBX_BUILD_TARGET "unknown")
endif() endif()
if(CMAKE_C_COMPILER_ABI if(CMAKE_C_COMPILER_ABI AND NOT (CMAKE_C_COMPILER_ABI MATCHES ".*${MDBX_BUILD_TARGET}.*"
AND NOT (CMAKE_C_COMPILER_ABI MATCHES ".*${MDBX_BUILD_TARGET}.*"
OR MDBX_BUILD_TARGET MATCHES ".*${CMAKE_C_COMPILER_ABI}.*")) OR MDBX_BUILD_TARGET MATCHES ".*${CMAKE_C_COMPILER_ABI}.*"))
string(CONCAT MDBX_BUILD_TARGET string(CONCAT MDBX_BUILD_TARGET "${MDBX_BUILD_TARGET}-${CMAKE_C_COMPILER_ABI}")
"${MDBX_BUILD_TARGET}-${CMAKE_C_COMPILER_ABI}")
endif() endif()
if(CMAKE_C_PLATFORM_ID if(CMAKE_C_PLATFORM_ID
AND NOT (CMAKE_SYSTEM_NAME AND NOT (CMAKE_SYSTEM_NAME AND (CMAKE_C_PLATFORM_ID MATCHES ".*${CMAKE_SYSTEM_NAME}.*"
AND (CMAKE_C_PLATFORM_ID MATCHES ".*${CMAKE_SYSTEM_NAME}.*"
OR CMAKE_SYSTEM_NAME MATCHES ".*${CMAKE_C_PLATFORM_ID}.*")) OR CMAKE_SYSTEM_NAME MATCHES ".*${CMAKE_C_PLATFORM_ID}.*"))
AND NOT (CMAKE_C_PLATFORM_ID MATCHES ".*${CMAKE_C_PLATFORM_ID}.*" AND NOT (CMAKE_C_PLATFORM_ID MATCHES ".*${CMAKE_C_PLATFORM_ID}.*" OR MDBX_BUILD_TARGET MATCHES
OR MDBX_BUILD_TARGET MATCHES ".*${CMAKE_C_PLATFORM_ID}.*")) ".*${CMAKE_C_PLATFORM_ID}.*"))
string(CONCAT MDBX_BUILD_TARGET string(CONCAT MDBX_BUILD_TARGET "${MDBX_BUILD_TARGET}-${CMAKE_C_COMPILER_ABI}")
"${MDBX_BUILD_TARGET}-${CMAKE_C_COMPILER_ABI}")
endif() endif()
if(CMAKE_SYSTEM_NAME) if(CMAKE_SYSTEM_NAME)
string(CONCAT MDBX_BUILD_TARGET "${MDBX_BUILD_TARGET}-${CMAKE_SYSTEM_NAME}") string(CONCAT MDBX_BUILD_TARGET "${MDBX_BUILD_TARGET}-${CMAKE_SYSTEM_NAME}")
@ -1341,8 +1219,7 @@ else()
endif() endif()
# options # options
set(options VERSION C_COMPILER CXX_COMPILER MDBX_BUILD_TARGET MDBX_BUILD_TYPE set(options VERSION C_COMPILER CXX_COMPILER MDBX_BUILD_TARGET MDBX_BUILD_TYPE ${MDBX_BUILD_OPTIONS})
${MDBX_BUILD_OPTIONS})
foreach(item IN LISTS options) foreach(item IN LISTS options)
if(DEFINED ${item}) if(DEFINED ${item})
set(value "${${item}}") set(value "${${item}}")
@ -1359,23 +1236,19 @@ foreach(item IN LISTS options)
endforeach(item) endforeach(item)
# provide config.h for library build info # provide config.h for library build info
configure_file("${MDBX_SOURCE_DIR}/config.h.in" 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") add_definitions(-DMDBX_CONFIG_H="${CMAKE_CURRENT_BINARY_DIR}/config.h")
# ############################################################################## # ######################################################################################################################
if(NOT MDBX_AMALGAMATED_SOURCE AND MDBX_ENABLE_TESTS) if(NOT MDBX_AMALGAMATED_SOURCE AND MDBX_ENABLE_TESTS)
if(NOT CMAKE_CXX_COMPILER_LOADED) if(NOT CMAKE_CXX_COMPILER_LOADED)
message( message(FATAL_ERROR "MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: The C++ compiler is required to build the tests.")
FATAL_ERROR
"MDBX_ENABLE_TESTS=${MDBX_ENABLE_TESTS}: The C++ compiler is required to build the tests."
)
endif() endif()
add_subdirectory(test) add_subdirectory(test)
endif() endif()
# ############################################################################## # ######################################################################################################################
if(NOT SUBPROJECT) if(NOT SUBPROJECT)
set(PACKAGE "libmdbx") set(PACKAGE "libmdbx")

View File

@ -1,4 +1,4 @@
# Copyright (c) 2010-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> # Copyright (c) 2010-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> ###############################################
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if(CMAKE_VERSION VERSION_LESS 3.8.2) if(CMAKE_VERSION VERSION_LESS 3.8.2)
@ -32,11 +32,8 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.9)
endif() endif()
if(CMAKE_VERSION MATCHES ".*MSVC.*" AND CMAKE_VERSION VERSION_LESS 3.16) if(CMAKE_VERSION MATCHES ".*MSVC.*" AND CMAKE_VERSION VERSION_LESS 3.16)
message( message(FATAL_ERROR "CMake from MSVC kit is unfit! "
FATAL_ERROR "Please use MSVC2019 with modern CMake the original CMake from https://cmake.org/download/")
"CMake from MSVC kit is unfit! "
"Please use MSVC2019 with modern CMake the original CMake from https://cmake.org/download/"
)
endif() endif()
if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)) if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
@ -62,8 +59,7 @@ if(CMAKE_C_COMPILER_LOADED
AND CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_LOADED
AND NOT (CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID)) AND NOT (CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID))
message(WARNING "CMAKE_C_COMPILER_ID (${CMAKE_C_COMPILER_ID}) is different " message(WARNING "CMAKE_C_COMPILER_ID (${CMAKE_C_COMPILER_ID}) is different "
"from CMAKE_CXX_COMPILER_ID (${CMAKE_CXX_COMPILER_ID}). " "from CMAKE_CXX_COMPILER_ID (${CMAKE_CXX_COMPILER_ID}). " "The final binary may be unusable.")
"The final binary may be unusable.")
endif() endif()
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
@ -80,15 +76,12 @@ macro(check_compiler_flag flag variable)
endif() endif()
endmacro(check_compiler_flag) endmacro(check_compiler_flag)
# We support building with Clang and gcc. First check what we're using for # We support building with Clang and gcc. First check what we're using for build.
# build. if(CMAKE_C_COMPILER_LOADED AND CMAKE_C_COMPILER_ID MATCHES ".*[Cc][Ll][Aa][Nn][Gg].*")
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_CLANG ON)
set(CMAKE_COMPILER_IS_GNUCC OFF) set(CMAKE_COMPILER_IS_GNUCC OFF)
endif() endif()
if(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_ID MATCHES if(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_ID MATCHES ".*[Cc][Ll][Aa][Nn][Gg].*")
".*[Cc][Ll][Aa][Nn][Gg].*")
set(CMAKE_COMPILER_IS_CLANG ON) set(CMAKE_COMPILER_IS_CLANG ON)
set(CMAKE_COMPILER_IS_GNUCXX OFF) set(CMAKE_COMPILER_IS_GNUCXX OFF)
endif() endif()
@ -140,8 +133,7 @@ if(CMAKE_CXX_COMPILER_LOADED)
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CMAKE_COMPILER_IS_ELBRUSCXX ON) set(CMAKE_COMPILER_IS_ELBRUSCXX ON)
set(CMAKE_CXX_COMPILER_ID "Elbrus") set(CMAKE_CXX_COMPILER_ID "Elbrus")
message( message(STATUS "Detected Elbrus C++ compiler ${CMAKE_CXX_COMPILER_VERSION}")
STATUS "Detected Elbrus C++ compiler ${CMAKE_CXX_COMPILER_VERSION}")
else() else()
set(CMAKE_COMPILER_IS_ELBRUSCXX OFF) set(CMAKE_COMPILER_IS_ELBRUSCXX OFF)
endif() endif()
@ -152,20 +144,17 @@ if(CMAKE_CXX_COMPILER_LOADED)
unset(tmp_lxx_probe_result) unset(tmp_lxx_probe_result)
endif() endif()
# Hard coding the compiler version is ugly from cmake POV, but at least gives # Hard coding the compiler version is ugly from cmake POV, but at least gives user a friendly error message. The most
# user a friendly error message. The most critical demand for C++ compiler is # critical demand for C++ compiler is support of C++11 lambdas, added only in version 4.5
# support of C++11 lambdas, added only in version 4.5
# https://gcc.gnu.org/projects/cxx0x.html # https://gcc.gnu.org/projects/cxx0x.html
if(CMAKE_COMPILER_IS_GNUCC) if(CMAKE_COMPILER_IS_GNUCC)
if(CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 AND NOT if(CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 AND NOT CMAKE_COMPILER_IS_ELBRUSC)
CMAKE_COMPILER_IS_ELBRUSC)
message(FATAL_ERROR " message(FATAL_ERROR "
Your GCC version is ${CMAKE_C_COMPILER_VERSION}, please update") Your GCC version is ${CMAKE_C_COMPILER_VERSION}, please update")
endif() endif()
endif() endif()
if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.5 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.5 AND NOT CMAKE_COMPILER_IS_ELBRUSCXX)
AND NOT CMAKE_COMPILER_IS_ELBRUSCXX)
message(FATAL_ERROR " message(FATAL_ERROR "
Your G++ version is ${CMAKE_CXX_COMPILER_VERSION}, please update") Your G++ version is ${CMAKE_CXX_COMPILER_VERSION}, please update")
endif() endif()
@ -210,12 +199,10 @@ endif()
if(NOT CMAKE_SYSTEM_ARCH) if(NOT CMAKE_SYSTEM_ARCH)
if(CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ARCHITECTURE_ID) if(CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ARCHITECTURE_ID)
string(TOLOWER "${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ARCHITECTURE_ID}" string(TOLOWER "${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ARCHITECTURE_ID}" CMAKE_SYSTEM_ARCH)
CMAKE_SYSTEM_ARCH)
if(CMAKE_SYSTEM_ARCH STREQUAL "x86") if(CMAKE_SYSTEM_ARCH STREQUAL "x86")
set(X86_32 TRUE) set(X86_32 TRUE)
elseif(CMAKE_SYSTEM_ARCH STREQUAL "x86_64" OR CMAKE_SYSTEM_ARCH STREQUAL elseif(CMAKE_SYSTEM_ARCH STREQUAL "x86_64" OR CMAKE_SYSTEM_ARCH STREQUAL "x64")
"x64")
set(X86_64 TRUE) set(X86_64 TRUE)
set(CMAKE_SYSTEM_ARCH "x86_64") set(CMAKE_SYSTEM_ARCH "x86_64")
elseif(CMAKE_SYSTEM_ARCH MATCHES "^(aarch.*|arm.*)") elseif(CMAKE_SYSTEM_ARCH MATCHES "^(aarch.*|arm.*)")
@ -263,8 +250,7 @@ if(NOT CMAKE_SYSTEM_ARCH)
set(X86_32 TRUE) set(X86_32 TRUE)
set(CMAKE_SYSTEM_ARCH "x86") set(CMAKE_SYSTEM_ARCH "x86")
endif() endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|[xXiI]86_64.*|AMD64.*|[iI][3-6]86.*|[xXiI]86.*")
"amd64.*|[xXiI]86_64.*|AMD64.*|[iI][3-6]86.*|[xXiI]86.*")
if(CMAKE_TARGET_BITNESS EQUAL 64) if(CMAKE_TARGET_BITNESS EQUAL 64)
set(X86_64 TRUE) set(X86_64 TRUE)
set(CMAKE_SYSTEM_ARCH "x86_64") set(CMAKE_SYSTEM_ARCH "x86_64")
@ -347,18 +333,15 @@ if(NOT DEFINED CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET)
) )
)) ))
set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET TRUE) set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET TRUE)
message(STATUS "Assume СAN RUN A BUILT EXECUTABLES," message(STATUS "Assume СAN RUN A BUILT EXECUTABLES," " since host (${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_ARCH})"
" since host (${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_ARCH})"
" match target (${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_ARCH})") " match target (${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_ARCH})")
else() else()
if(CMAKE_C_COMPILER_LOADED) if(CMAKE_C_COMPILER_LOADED)
include(CheckCSourceRuns) include(CheckCSourceRuns)
check_c_source_runs("int main(void) { return 0; }" check_c_source_runs("int main(void) { return 0; }" CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET)
CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET)
elseif(CMAKE_CXX_COMPILER_LOADED) elseif(CMAKE_CXX_COMPILER_LOADED)
include(CheckCXXSourceRuns) include(CheckCXXSourceRuns)
check_cxx_source_runs("int main(void) { return 0; }" check_cxx_source_runs("int main(void) { return 0; }" CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET)
CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET)
endif() endif()
if(NOT CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET) if(NOT CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET)
message(STATUS "Force CMAKE_CROSSCOMPILING to TRUE") message(STATUS "Force CMAKE_CROSSCOMPILING to TRUE")
@ -373,15 +356,13 @@ if(MSVC)
check_compiler_flag("/fsanitize=undefined" CC_HAS_UBSAN) check_compiler_flag("/fsanitize=undefined" CC_HAS_UBSAN)
else() else()
# #
# GCC started to warn for unused result starting from 4.2, and this is when it # GCC started to warn for unused result starting from 4.2, and this is when it introduced -Wno-unused-result GCC can
# introduced -Wno-unused-result GCC can also be built on top of llvm runtime # also be built on top of llvm runtime (on mac).
# (on mac).
check_compiler_flag("-Wno-unknown-pragmas" CC_HAS_WNO_UNKNOWN_PRAGMAS) check_compiler_flag("-Wno-unknown-pragmas" CC_HAS_WNO_UNKNOWN_PRAGMAS)
check_compiler_flag("-Wextra" CC_HAS_WEXTRA) check_compiler_flag("-Wextra" CC_HAS_WEXTRA)
check_compiler_flag("-Werror" CC_HAS_WERROR) check_compiler_flag("-Werror" CC_HAS_WERROR)
check_compiler_flag("-fexceptions" CC_HAS_FEXCEPTIONS) check_compiler_flag("-fexceptions" CC_HAS_FEXCEPTIONS)
check_compiler_flag("-fno-semantic-interposition" check_compiler_flag("-fno-semantic-interposition" CC_HAS_FNO_SEMANTIC_INTERPOSITION)
CC_HAS_FNO_SEMANTIC_INTERPOSITION)
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
check_cxx_compiler_flag("-fcxx-exceptions" CC_HAS_FCXX_EXCEPTIONS) check_cxx_compiler_flag("-fcxx-exceptions" CC_HAS_FCXX_EXCEPTIONS)
endif() endif()
@ -463,34 +444,26 @@ if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}
OUTPUT_VARIABLE gcc_info_v OUTPUT_VARIABLE gcc_info_v
ERROR_VARIABLE gcc_info_v) ERROR_VARIABLE gcc_info_v)
string(REGEX MATCH "^(.+\nCOLLECT_GCC=)([^ \n]+)(\n.+)$" gcc_collect_valid string(REGEX MATCH "^(.+\nCOLLECT_GCC=)([^ \n]+)(\n.+)$" gcc_collect_valid ${gcc_info_v})
${gcc_info_v})
if(gcc_collect_valid) if(gcc_collect_valid)
string(REGEX REPLACE "^(.+\nCOLLECT_GCC=)([^ \n]+)(\n.+)$" "\\2" string(REGEX REPLACE "^(.+\nCOLLECT_GCC=)([^ \n]+)(\n.+)$" "\\2" gcc_collect ${gcc_info_v})
gcc_collect ${gcc_info_v})
endif() endif()
string(REGEX MATCH string(REGEX MATCH "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" gcc_lto_wrapper_valid ${gcc_info_v})
"^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$"
gcc_lto_wrapper_valid ${gcc_info_v})
if(gcc_lto_wrapper_valid) if(gcc_lto_wrapper_valid)
string(REGEX string(REGEX REPLACE "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" "\\2" gcc_lto_wrapper
REPLACE "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" ${gcc_info_v})
"\\2" gcc_lto_wrapper ${gcc_info_v})
endif() endif()
set(gcc_suffix "") set(gcc_suffix "")
if(gcc_collect_valid AND gcc_collect) if(gcc_collect_valid AND gcc_collect)
string(REGEX MATCH "^(.*(cc|\\+\\+))(-.+)$" gcc_suffix_valid string(REGEX MATCH "^(.*(cc|\\+\\+))(-.+)$" gcc_suffix_valid ${gcc_collect})
${gcc_collect})
if(gcc_suffix_valid) if(gcc_suffix_valid)
string(REGEX REPLACE "^(.*(cc|\\+\\+))(-.+)$" "\\3" gcc_suffix string(REGEX REPLACE "^(.*(cc|\\+\\+))(-.+)$" "\\3" gcc_suffix ${gcc_collect})
${gcc_collect})
endif() endif()
endif() endif()
get_filename_component(gcc_dir ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} get_filename_component(gcc_dir ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY)
DIRECTORY)
if(NOT CMAKE_GCC_AR) if(NOT CMAKE_GCC_AR)
find_program( find_program(
CMAKE_GCC_AR CMAKE_GCC_AR
@ -526,10 +499,7 @@ if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}
AND CMAKE_GCC_NM AND CMAKE_GCC_NM
AND CMAKE_GCC_RANLIB AND CMAKE_GCC_RANLIB
AND gcc_lto_wrapper) AND gcc_lto_wrapper)
message( message(STATUS "Found GCC's LTO toolset: ${gcc_lto_wrapper}, ${CMAKE_GCC_AR}, ${CMAKE_GCC_RANLIB}")
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_CFLAGS "-flto -fno-fat-lto-objects -fuse-linker-plugin")
set(GCC_LTO_AVAILABLE TRUE) set(GCC_LTO_AVAILABLE TRUE)
message(STATUS "Link-Time Optimization by GCC is available") message(STATUS "Link-Time Optimization by GCC is available")
@ -565,11 +535,9 @@ if(CMAKE_COMPILER_IS_CLANG)
unset(clang_libdirs) unset(clang_libdirs)
unset(clang_libdirs_x) unset(clang_libdirs_x)
if(clang_probe_result EQUAL 0) if(clang_probe_result EQUAL 0)
string(REGEX MATCH "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" string(REGEX MATCH "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" regexp_valid ${clang_search_dirs})
regexp_valid ${clang_search_dirs})
if(regexp_valid) if(regexp_valid)
string(REGEX REPLACE "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" "\\3" string(REGEX REPLACE "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" "\\3" list ${clang_search_dirs})
list ${clang_search_dirs})
string(REPLACE ":" ";" list "${list}") string(REPLACE ":" ";" list "${list}")
foreach(dir IN LISTS list) foreach(dir IN LISTS list)
get_filename_component(dir "${dir}" REALPATH) get_filename_component(dir "${dir}" REALPATH)
@ -582,11 +550,9 @@ if(CMAKE_COMPILER_IS_CLANG)
list(APPEND clang_bindirs "${clang_bindirs_x}") list(APPEND clang_bindirs "${clang_bindirs_x}")
list(REMOVE_DUPLICATES clang_bindirs) list(REMOVE_DUPLICATES clang_bindirs)
endif() endif()
string(REGEX MATCH "(^|\n.*)(.*libraries: =)([^\n]+)((\n.*)|$)" string(REGEX MATCH "(^|\n.*)(.*libraries: =)([^\n]+)((\n.*)|$)" regexp_valid ${clang_search_dirs})
regexp_valid ${clang_search_dirs})
if(regexp_valid) if(regexp_valid)
string(REGEX REPLACE "(^|\n.*)(.*libraries: =)([^\n]+)((\n.*)|$)" "\\3" string(REGEX REPLACE "(^|\n.*)(.*libraries: =)([^\n]+)((\n.*)|$)" "\\3" list ${clang_search_dirs})
list ${clang_search_dirs})
string(REPLACE ":" ";" list "${list}") string(REPLACE ":" ";" list "${list}")
foreach(dir IN LISTS list) foreach(dir IN LISTS list)
get_filename_component(dir "${dir}" REALPATH) get_filename_component(dir "${dir}" REALPATH)
@ -600,21 +566,16 @@ if(CMAKE_COMPILER_IS_CLANG)
list(REMOVE_DUPLICATES clang_libdirs) list(REMOVE_DUPLICATES clang_libdirs)
endif() endif()
else() else()
get_filename_component(clang_bindirs get_filename_component(clang_bindirs ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY)
${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(clang_libdirs ${clang_bindirs}) set(clang_libdirs ${clang_bindirs})
else() else()
get_filename_component( get_filename_component(clang_libdirs "${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER}/../lib" REALPATH)
clang_libdirs "${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER}/../lib"
REALPATH)
endif() endif()
endif() endif()
if(clang_bindirs AND clang_libdirs) if(clang_bindirs AND clang_libdirs)
message( message(STATUS "Found CLANG/LLVM directories: ${clang_bindirs}, ${clang_libdirs}")
STATUS
"Found CLANG/LLVM directories: ${clang_bindirs}, ${clang_libdirs}")
else() else()
message(STATUS "Could NOT find CLANG/LLVM directories (bin and/or lib).") message(STATUS "Could NOT find CLANG/LLVM directories (bin and/or lib).")
endif() endif()
@ -622,8 +583,7 @@ if(CMAKE_COMPILER_IS_CLANG)
if(NOT CMAKE_CLANG_LD AND clang_bindirs) if(NOT CMAKE_CLANG_LD AND clang_bindirs)
find_program( find_program(
CMAKE_CLANG_LD CMAKE_CLANG_LD
NAMES lld-link ld.lld "ld${CMAKE_TARGET_BITNESS}.lld" lld llvm-link NAMES lld-link ld.lld "ld${CMAKE_TARGET_BITNESS}.lld" lld llvm-link llvm-ld
llvm-ld
PATHS ${clang_bindirs} PATHS ${clang_bindirs}
NO_DEFAULT_PATH) NO_DEFAULT_PATH)
endif() endif()
@ -666,31 +626,21 @@ if(CMAKE_COMPILER_IS_CLANG)
if(CLANG_LTO_PLUGIN) if(CLANG_LTO_PLUGIN)
message(STATUS "Found CLANG/LLVM's plugin for LTO: ${CLANG_LTO_PLUGIN}") message(STATUS "Found CLANG/LLVM's plugin for LTO: ${CLANG_LTO_PLUGIN}")
else() else()
message( message(STATUS "Could NOT find CLANG/LLVM's plugin (${clang_lto_plugin_name}) for LTO.")
STATUS
"Could NOT find CLANG/LLVM's plugin (${clang_lto_plugin_name}) for LTO."
)
endif() endif()
if(CMAKE_CLANG_LD) if(CMAKE_CLANG_LD)
message(STATUS "Found CLANG/LLVM's linker for LTO: ${CMAKE_CLANG_LD}") message(STATUS "Found CLANG/LLVM's linker for LTO: ${CMAKE_CLANG_LD}")
else() else()
message( message(STATUS "Could NOT find CLANG/LLVM's linker (lld, llvm-ld, llvm-link) for LTO.")
STATUS
"Could NOT find CLANG/LLVM's linker (lld, llvm-ld, llvm-link) for LTO."
)
endif() endif()
if(CMAKE_CLANG_AR if(CMAKE_CLANG_AR
AND CMAKE_CLANG_RANLIB AND CMAKE_CLANG_RANLIB
AND CMAKE_CLANG_NM) AND CMAKE_CLANG_NM)
message( message(STATUS "Found CLANG/LLVM's binutils for LTO: ${CMAKE_CLANG_AR}, ${CMAKE_CLANG_RANLIB}, ${CMAKE_CLANG_NM}")
STATUS
"Found CLANG/LLVM's binutils for LTO: ${CMAKE_CLANG_AR}, ${CMAKE_CLANG_RANLIB}, ${CMAKE_CLANG_NM}"
)
else() else()
message( message(STATUS "Could NOT find CLANG/LLVM's binutils (ar, ranlib, nm) for LTO.")
STATUS "Could NOT find CLANG/LLVM's binutils (ar, ranlib, nm) for LTO.")
endif() endif()
unset(clang_lto_plugin_name) unset(clang_lto_plugin_name)
@ -704,22 +654,17 @@ if(CMAKE_COMPILER_IS_CLANG)
AND CMAKE_CLANG_NM AND CMAKE_CLANG_NM
AND CMAKE_CLANG_RANLIB AND CMAKE_CLANG_RANLIB
AND ((CLANG_LTO_PLUGIN AND CMAKE_LD_GOLD) AND ((CLANG_LTO_PLUGIN AND CMAKE_LD_GOLD)
OR (CMAKE_CLANG_LD AND NOT (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR (CMAKE_CLANG_LD AND NOT (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_NAME STREQUAL "Linux"))
AND CMAKE_SYSTEM_NAME STREQUAL "Linux")) OR APPLE))
OR APPLE
))
if(ANDROID AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 12) if(ANDROID AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 12)
set(CLANG_LTO_AVAILABLE FALSE) set(CLANG_LTO_AVAILABLE FALSE)
message( message(
STATUS STATUS "Link-Time Optimization by CLANG/LLVM is available but unusable due https://reviews.llvm.org/D79919")
"Link-Time Optimization by CLANG/LLVM is available but unusable due https://reviews.llvm.org/D79919"
)
else() else()
set(CLANG_LTO_AVAILABLE TRUE) set(CLANG_LTO_AVAILABLE TRUE)
message(STATUS "Link-Time Optimization by CLANG/LLVM is available") message(STATUS "Link-Time Optimization by CLANG/LLVM is available")
endif() endif()
elseif(CMAKE_TOOLCHAIN_FILE elseif(CMAKE_TOOLCHAIN_FILE AND NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 7.0)
AND NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 7.0)
set(CLANG_LTO_AVAILABLE TRUE) set(CLANG_LTO_AVAILABLE TRUE)
if(NOT CMAKE_CLANG_LD) if(NOT CMAKE_CLANG_LD)
set(CMAKE_CLANG_LD ${CMAKE_LINKER}) set(CMAKE_CLANG_LD ${CMAKE_LINKER})
@ -733,10 +678,7 @@ if(CMAKE_COMPILER_IS_CLANG)
if(NOT CMAKE_CLANG_RANLIB) if(NOT CMAKE_CLANG_RANLIB)
set(CMAKE_CLANG_RANLIB ${CMAKE_RANLIB}) set(CMAKE_CLANG_RANLIB ${CMAKE_RANLIB})
endif() endif()
message( message(STATUS "Assume Link-Time Optimization by CLANG/LLVM is available via ${CMAKE_TOOLCHAIN_FILE}")
STATUS
"Assume Link-Time Optimization by CLANG/LLVM is available via ${CMAKE_TOOLCHAIN_FILE}"
)
else() else()
set(CLANG_LTO_AVAILABLE FALSE) set(CLANG_LTO_AVAILABLE FALSE)
message(STATUS "Link-Time Optimization by CLANG/LLVM is NOT available") message(STATUS "Link-Time Optimization by CLANG/LLVM is NOT available")
@ -772,8 +714,7 @@ if(ENABLE_BACKTRACE)
if(IBERTY_LIBRARY) if(IBERTY_LIBRARY)
check_library_exists(${IBERTY_LIBRARY} cplus_demangle "" HAVE_IBERTY_LIB) check_library_exists(${IBERTY_LIBRARY} cplus_demangle "" HAVE_IBERTY_LIB)
endif() endif()
set(CMAKE_REQUIRED_DEFINITIONS -DPACKAGE=${PACKAGE} set(CMAKE_REQUIRED_DEFINITIONS -DPACKAGE=${PACKAGE} -DPACKAGE_VERSION=${PACKAGE_VERSION})
-DPACKAGE_VERSION=${PACKAGE_VERSION})
check_include_files(bfd.h HAVE_BFD_H) check_include_files(bfd.h HAVE_BFD_H)
set(CMAKE_REQUIRED_DEFINITIONS) set(CMAKE_REQUIRED_DEFINITIONS)
find_package(ZLIB) find_package(ZLIB)
@ -783,8 +724,7 @@ if(ENABLE_BACKTRACE)
AND ZLIB_FOUND) AND ZLIB_FOUND)
set(HAVE_BFD ON) set(HAVE_BFD ON)
set(BFD_LIBRARIES ${BFD_LIBRARY} ${IBERTY_LIBRARY} ${ZLIB_LIBRARIES}) set(BFD_LIBRARIES ${BFD_LIBRARY} ${IBERTY_LIBRARY} ${ZLIB_LIBRARIES})
find_package_message(BFD_LIBRARIES "Found libbfd and dependencies" find_package_message(BFD_LIBRARIES "Found libbfd and dependencies" ${BFD_LIBRARIES})
${BFD_LIBRARIES})
if(TARGET_OS_FREEBSD AND NOT TARGET_OS_DEBIAN_FREEBSD) if(TARGET_OS_FREEBSD AND NOT TARGET_OS_DEBIAN_FREEBSD)
set(BFD_LIBRARIES ${BFD_LIBRARIES} iconv) set(BFD_LIBRARIES ${BFD_LIBRARIES} iconv)
endif() endif()
@ -859,12 +799,9 @@ macro(setup_compile_flags)
add_compile_flags("C;CXX" "-fno-semantic-interposition") add_compile_flags("C;CXX" "-fno-semantic-interposition")
endif() endif()
if(MSVC) if(MSVC)
# checks for /EHa or /clr options exists, i.e. is enabled structured async # checks for /EHa or /clr options exists, i.e. is enabled structured async WinNT exceptions
# WinNT exceptions string(REGEX MATCH "^(.* )*[-/]EHc*a( .*)*$" msvc_async_eh_enabled "${CXX_FLAGS}" "${C_FLAGS}")
string(REGEX MATCH "^(.* )*[-/]EHc*a( .*)*$" msvc_async_eh_enabled string(REGEX MATCH "^(.* )*[-/]clr( .*)*$" msvc_clr_enabled "${CXX_FLAGS}" "${C_FLAGS}")
"${CXX_FLAGS}" "${C_FLAGS}")
string(REGEX MATCH "^(.* )*[-/]clr( .*)*$" msvc_clr_enabled "${CXX_FLAGS}"
"${C_FLAGS}")
# remote any /EH? options # remote any /EH? options
string(REGEX REPLACE "( *[-/]-*EH[csa]+ *)+" "" CXX_FLAGS "${CXX_FLAGS}") string(REGEX REPLACE "( *[-/]-*EH[csa]+ *)+" "" CXX_FLAGS "${CXX_FLAGS}")
string(REGEX REPLACE "( *[-/]-*EH[csa]+ *)+" "" C_FLAGS "${C_FLAGS}") string(REGEX REPLACE "( *[-/]-*EH[csa]+ *)+" "" C_FLAGS "${C_FLAGS}")
@ -887,21 +824,17 @@ macro(setup_compile_flags)
endif() endif()
endif() endif()
# In C a global variable without a storage specifier (static/extern) and # In C a global variable without a storage specifier (static/extern) and without an initialiser is called a tentative
# without an initialiser is called a tentative definition. The language # definition. The language permits multiple tentative definitions in the single translation unit; i.e. int foo; int
# permits multiple tentative definitions in the single translation unit; i.e. # foo; is perfectly ok. GNU toolchain goes even further, allowing multiple tentative definitions in *different*
# int foo; int foo; is perfectly ok. GNU toolchain goes even further, allowing # translation units. Internally, variables introduced via tentative definitions are implemented as common symbols.
# multiple tentative definitions in *different* translation units. Internally, # Linker permits multiple definitions if they are common symbols, and it picks one arbitrarily for inclusion in the
# variables introduced via tentative definitions are implemented as common # binary being linked.
# 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 # -fno-common forces GNU toolchain to behave in a more standard-conformant way in respect to tentative definitions and
# in respect to tentative definitions and it prevents common symbols # it prevents common symbols generation. Since we are a cross-platform project it really makes sense. There are
# generation. Since we are a cross-platform project it really makes sense. # toolchains that dont implement GNU style handling of the tentative definitions and there are platforms lacking
# There are toolchains that dont implement GNU style handling of the # proper support for common symbols (osx).
# tentative definitions and there are platforms lacking proper support for
# common symbols (osx).
if(CC_HAS_FNO_COMMON) if(CC_HAS_FNO_COMMON)
add_compile_flags("C;CXX" "-fno-common") add_compile_flags("C;CXX" "-fno-common")
endif() endif()
@ -920,9 +853,8 @@ macro(setup_compile_flags)
add_compile_flags("C;CXX" "/Gy") add_compile_flags("C;CXX" "/Gy")
endif() endif()
# We must set -fno-omit-frame-pointer here, since we rely on frame pointer # We must set -fno-omit-frame-pointer here, since we rely on frame pointer when getting a backtrace, and it must be
# when getting a backtrace, and it must be used consistently across all object # used consistently across all object files. The same reasoning applies to -fno-stack-protector switch.
# files. The same reasoning applies to -fno-stack-protector switch.
if(ENABLE_BACKTRACE) if(ENABLE_BACKTRACE)
if(CC_HAS_FNO_OMIT_FRAME_POINTER) if(CC_HAS_FNO_OMIT_FRAME_POINTER)
add_compile_flags("C;CXX" "-fno-omit-frame-pointer") add_compile_flags("C;CXX" "-fno-omit-frame-pointer")
@ -933,8 +865,7 @@ macro(setup_compile_flags)
if(MSVC_VERSION LESS 1900) if(MSVC_VERSION LESS 1900)
message( message(
FATAL_ERROR FATAL_ERROR
"At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required." "At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required.")
)
endif() endif()
if(NOT MSVC_VERSION LESS 1910) if(NOT MSVC_VERSION LESS 1910)
add_compile_flags("CXX" "/Zc:__cplusplus") add_compile_flags("CXX" "/Zc:__cplusplus")
@ -955,8 +886,7 @@ macro(setup_compile_flags)
add_definitions("-D__STDC_CONSTANT_MACROS=1") add_definitions("-D__STDC_CONSTANT_MACROS=1")
add_definitions("-D_HAS_EXCEPTIONS=1") add_definitions("-D_HAS_EXCEPTIONS=1")
# Only add -Werror if it's a debug build, done by developers. Release builds # Only add -Werror if it's a debug build, done by developers. Release builds should not cause extra trouble.
# should not cause extra trouble.
if(CC_HAS_WERROR if(CC_HAS_WERROR
AND (CI AND (CI
OR CMAKE_CONFIGURATION_TYPES OR CMAKE_CONFIGURATION_TYPES
@ -976,17 +906,15 @@ macro(setup_compile_flags)
endif() endif()
endif() endif()
if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} 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 # G++ bug. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31488
add_compile_flags("CXX" "-Wno-invalid-offsetof") add_compile_flags("CXX" "-Wno-invalid-offsetof")
endif() endif()
if(MINGW) if(MINGW)
# Disable junk MINGW's warnings that issued due to incompatibilities and # Disable junk MINGW's warnings that issued due to incompatibilities and shortcomings of MINGW, since the code is
# shortcomings of MINGW, since the code is checked by builds with GCC, CLANG # checked by builds with GCC, CLANG and MSVC.
# and MSVC. add_compile_flags("C;CXX" "-Wno-format-extra-args" "-Wno-format" "-Wno-cast-function-type"
add_compile_flags("C;CXX" "-Wno-format-extra-args" "-Wno-format" "-Wno-implicit-fallthrough")
"-Wno-cast-function-type" "-Wno-implicit-fallthrough")
endif() endif()
if(ENABLE_ASAN) if(ENABLE_ASAN)
@ -1000,8 +928,7 @@ macro(setup_compile_flags)
if(ENABLE_UBSAN) if(ENABLE_UBSAN)
if(NOT MSVC) if(NOT MSVC)
add_compile_flags("C;CXX" "-fsanitize=undefined" add_compile_flags("C;CXX" "-fsanitize=undefined" "-fsanitize-undefined-trap-on-error")
"-fsanitize-undefined-trap-on-error")
else() else()
add_compile_flags("C;CXX" "/fsanitize=undefined") add_compile_flags("C;CXX" "/fsanitize=undefined")
endif() endif()
@ -1010,17 +937,13 @@ macro(setup_compile_flags)
if(ENABLE_GCOV) if(ENABLE_GCOV)
if(NOT HAVE_GCOV) if(NOT HAVE_GCOV)
message( message(FATAL_ERROR "ENABLE_GCOV option requested but gcov library is not found")
FATAL_ERROR "ENABLE_GCOV option requested but gcov library is not found"
)
endif() endif()
add_compile_flags("C;CXX" "-fprofile-arcs" "-ftest-coverage") add_compile_flags("C;CXX" "-fprofile-arcs" "-ftest-coverage")
set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
set(SHARED_LINKER_FLAGS set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
"${SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
set(MODULE_LINKER_FLAGS
"${MODULE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
# add_library(gcov SHARED IMPORTED) # add_library(gcov SHARED IMPORTED)
endif() endif()
@ -1030,16 +953,12 @@ macro(setup_compile_flags)
if(CMAKE_COMPILER_IS_GNUCC AND LTO_ENABLED) if(CMAKE_COMPILER_IS_GNUCC AND LTO_ENABLED)
add_compile_flags("C;CXX" ${GCC_LTO_CFLAGS}) add_compile_flags("C;CXX" ${GCC_LTO_CFLAGS})
set(EXE_LINKER_FLAGS set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} ${GCC_LTO_CFLAGS} -fverbose-asm -fwhole-program")
"${EXE_LINKER_FLAGS} ${GCC_LTO_CFLAGS} -fverbose-asm -fwhole-program") set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} ${GCC_LTO_CFLAGS} -fverbose-asm")
set(SHARED_LINKER_FLAGS set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} ${GCC_LTO_CFLAGS} -fverbose-asm")
"${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) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
# Pass the same optimization flags to the linker # Pass the same optimization flags to the linker
set(compile_flags set(compile_flags "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
"${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} ${compile_flags}") set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} ${compile_flags}")
set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} ${compile_flags}") set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} ${compile_flags}")
set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} ${compile_flags}") set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} ${compile_flags}")
@ -1055,9 +974,8 @@ macro(setup_compile_flags)
add_compile_flags("C;CXX" "/GL") add_compile_flags("C;CXX" "/GL")
foreach(linkmode IN ITEMS EXE SHARED STATIC MODULE) foreach(linkmode IN ITEMS EXE SHARED STATIC MODULE)
set(${linkmode}_LINKER_FLAGS "${${linkmode}_LINKER_FLAGS} /LTCG") set(${linkmode}_LINKER_FLAGS "${${linkmode}_LINKER_FLAGS} /LTCG")
string(REGEX string(REGEX REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" ${linkmode}_LINKER_FLAGS
REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" "${${linkmode}_LINKER_FLAGS}")
${linkmode}_LINKER_FLAGS "${${linkmode}_LINKER_FLAGS}")
string(STRIP "${${linkmode}_LINKER_FLAGS}" ${linkmode}_LINKER_FLAGS) string(STRIP "${${linkmode}_LINKER_FLAGS}" ${linkmode}_LINKER_FLAGS)
foreach( foreach(
config IN config IN
@ -1065,14 +983,10 @@ macro(setup_compile_flags)
ITEMS Release MinSizeRel RelWithDebInfo Debug) ITEMS Release MinSizeRel RelWithDebInfo Debug)
string(TOUPPER "${config}" config_uppercase) string(TOUPPER "${config}" config_uppercase)
if(DEFINED "CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}") if(DEFINED "CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}")
string( string(REGEX REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" altered_flags
REGEX
REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5"
altered_flags
"${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}") "${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}")
string(STRIP "${altered_flags}" altered_flags) string(STRIP "${altered_flags}" altered_flags)
if(NOT "${altered_flags}" STREQUAL if(NOT "${altered_flags}" STREQUAL "${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}")
"${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}")
set(CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase} set(CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}
"${altered_flags}" "${altered_flags}"
CACHE STRING "Altered: '/INCREMENTAL' removed for LTO" FORCE) CACHE STRING "Altered: '/INCREMENTAL' removed for LTO" FORCE)
@ -1089,10 +1003,8 @@ macro(setup_compile_flags)
foreach(lang IN ITEMS C CXX) foreach(lang IN ITEMS C CXX)
string(TOUPPER "${config}" config_uppercase) string(TOUPPER "${config}" config_uppercase)
if(DEFINED "CMAKE_${lang}_FLAGS_${config_uppercase}") if(DEFINED "CMAKE_${lang}_FLAGS_${config_uppercase}")
string(REPLACE "/O2" "/Ox" altered_flags string(REPLACE "/O2" "/Ox" altered_flags "${CMAKE_${lang}_FLAGS_${config_uppercase}}")
"${CMAKE_${lang}_FLAGS_${config_uppercase}}") if(NOT "${altered_flags}" STREQUAL "${CMAKE_${lang}_FLAGS_${config_uppercase}}")
if(NOT "${altered_flags}" STREQUAL
"${CMAKE_${lang}_FLAGS_${config_uppercase}}")
set(CMAKE_${lang}_FLAGS_${config_uppercase} set(CMAKE_${lang}_FLAGS_${config_uppercase}
"${altered_flags}" "${altered_flags}"
CACHE STRING "Altered: '/O2' replaced by '/Ox' for LTO" FORCE) CACHE STRING "Altered: '/O2' replaced by '/Ox' for LTO" FORCE)
@ -1120,12 +1032,9 @@ macro(setup_compile_flags)
endif() endif()
add_compile_flags("C;CXX" ${CLANG_LTO_FLAG}) add_compile_flags("C;CXX" ${CLANG_LTO_FLAG})
if(NOT MSVC) if(NOT MSVC)
set(EXE_LINKER_FLAGS set(EXE_LINKER_FLAGS "${EXE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm -fwhole-program")
"${EXE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm -fwhole-program") set(SHARED_LINKER_FLAGS "${SHARED_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm")
set(SHARED_LINKER_FLAGS set(MODULE_LINKER_FLAGS "${MODULE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm")
"${SHARED_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm")
set(MODULE_LINKER_FLAGS
"${MODULE_LINKER_FLAGS} ${CLANG_LTO_FLAG} -fverbose-asm")
endif() endif()
endif() endif()
@ -1133,15 +1042,13 @@ macro(setup_compile_flags)
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
set(CMAKE_CXX_FLAGS set(CMAKE_CXX_FLAGS
${CXX_FLAGS} ${CXX_FLAGS}
CACHE STRING "Flags used by the C++ compiler during all build types" CACHE STRING "Flags used by the C++ compiler during all build types" FORCE)
FORCE)
unset(CXX_FLAGS) unset(CXX_FLAGS)
endif() endif()
if(CMAKE_C_COMPILER_LOADED) if(CMAKE_C_COMPILER_LOADED)
set(CMAKE_C_FLAGS set(CMAKE_C_FLAGS
${C_FLAGS} ${C_FLAGS}
CACHE STRING "Flags used by the C compiler during all build types" CACHE STRING "Flags used by the C compiler during all build types" FORCE)
FORCE)
unset(C_FLAGS) unset(C_FLAGS)
endif() endif()
set(CMAKE_EXE_LINKER_FLAGS set(CMAKE_EXE_LINKER_FLAGS
@ -1149,17 +1056,13 @@ macro(setup_compile_flags)
CACHE STRING "Flags used by the linker" FORCE) CACHE STRING "Flags used by the linker" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS set(CMAKE_SHARED_LINKER_FLAGS
${SHARED_LINKER_FLAGS} ${SHARED_LINKER_FLAGS}
CACHE STRING "Flags used by the linker during the creation of dll's" CACHE STRING "Flags used by the linker during the creation of dll's" FORCE)
FORCE)
set(CMAKE_STATIC_LINKER_FLAGS set(CMAKE_STATIC_LINKER_FLAGS
${STATIC_LINKER_FLAGS} ${STATIC_LINKER_FLAGS}
CACHE STRING CACHE STRING "Flags used by the linker during the creation of static libraries" FORCE)
"Flags used by the linker during the creation of static libraries"
FORCE)
set(CMAKE_MODULE_LINKER_FLAGS set(CMAKE_MODULE_LINKER_FLAGS
${MODULE_LINKER_FLAGS} ${MODULE_LINKER_FLAGS}
CACHE STRING "Flags used by the linker during the creation of modules" CACHE STRING "Flags used by the linker during the creation of modules" FORCE)
FORCE)
unset(EXE_LINKER_FLAGS) unset(EXE_LINKER_FLAGS)
unset(SHARED_LINKER_FLAGS) unset(SHARED_LINKER_FLAGS)
unset(STATIC_LINKER_FLAGS) unset(STATIC_LINKER_FLAGS)
@ -1183,9 +1086,7 @@ macro(probe_libcxx_filesystem)
if(NOT DEFINED CMAKE_CXX_STANDARD) if(NOT DEFINED CMAKE_CXX_STANDARD)
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_14 HAS_CXX14) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_14 HAS_CXX14)
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_17 HAS_CXX17) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_17 HAS_CXX17)
if(NOT HAS_CXX17 LESS 0 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) set(CMAKE_CXX_STANDARD 17)
elseif(NOT HAS_CXX14 LESS 0) elseif(NOT HAS_CXX14 LESS 0)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
@ -1198,14 +1099,11 @@ macro(probe_libcxx_filesystem)
endif() endif()
set(stdfs_probe_clear_cxx_standard ON) set(stdfs_probe_clear_cxx_standard ON)
endif() endif()
if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.25.23)
VERSION_LESS 1.25.23)
if(CMAKE_VERSION VERSION_LESS 3.14) if(CMAKE_VERSION VERSION_LESS 3.14)
set(stdfs_probe_flags ${stdfs_probe_flags} set(stdfs_probe_flags ${stdfs_probe_flags} "-Wl,--allow-multiple-definition")
"-Wl,--allow-multiple-definition")
else() else()
set(CMAKE_REQUIRED_LINK_OPTIONS ${stdfs_probe_save_link_options} set(CMAKE_REQUIRED_LINK_OPTIONS ${stdfs_probe_save_link_options} "-Wl,--allow-multiple-definition")
"-Wl,--allow-multiple-definition")
endif() endif()
endif() endif()
set(CMAKE_REQUIRED_FLAGS ${stdfs_probe_flags}) set(CMAKE_REQUIRED_FLAGS ${stdfs_probe_flags})
@ -1261,40 +1159,25 @@ macro(probe_libcxx_filesystem)
check_cxx_source_compiles("${stdfs_probe_code}" LIBCXX_FILESYSTEM_none) check_cxx_source_compiles("${stdfs_probe_code}" LIBCXX_FILESYSTEM_none)
if(LIBCXX_FILESYSTEM_none) if(LIBCXX_FILESYSTEM_none)
message( message(STATUS "No linking with additional library needed for std::filesystem")
STATUS "No linking with additional library needed for std::filesystem"
)
else() else()
set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries} "stdc++fs") set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries} "stdc++fs")
check_cxx_source_compiles("${stdfs_probe_code}" check_cxx_source_compiles("${stdfs_probe_code}" LIBCXX_FILESYSTEM_stdcxxfs)
LIBCXX_FILESYSTEM_stdcxxfs)
if(LIBCXX_FILESYSTEM_stdcxxfs) if(LIBCXX_FILESYSTEM_stdcxxfs)
set(LIBCXX_FILESYSTEM "stdc++fs") set(LIBCXX_FILESYSTEM "stdc++fs")
message( message(STATUS "Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem")
STATUS
"Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem"
)
else() else()
set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries} "c++fs") set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries} "c++fs")
check_cxx_source_compiles("${stdfs_probe_code}" check_cxx_source_compiles("${stdfs_probe_code}" LIBCXX_FILESYSTEM_cxxfs)
LIBCXX_FILESYSTEM_cxxfs)
if(LIBCXX_FILESYSTEM_cxxfs) if(LIBCXX_FILESYSTEM_cxxfs)
set(LIBCXX_FILESYSTEM "c++fs") set(LIBCXX_FILESYSTEM "c++fs")
message( message(STATUS "Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem")
STATUS
"Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem"
)
else() else()
set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries} set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries} "c++experimental")
"c++experimental") check_cxx_source_compiles("${stdfs_probe_code}" LIBCXX_FILESYSTEM_cxxexperimental)
check_cxx_source_compiles("${stdfs_probe_code}"
LIBCXX_FILESYSTEM_cxxexperimental)
if(LIBCXX_FILESYSTEM_cxxexperimental) if(LIBCXX_FILESYSTEM_cxxexperimental)
set(LIBCXX_FILESYSTEM "c++experimental") set(LIBCXX_FILESYSTEM "c++experimental")
message( message(STATUS "Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem")
STATUS
"Linking with ${LIBCXX_FILESYSTEM} is required for std::filesystem"
)
else() else()
message(STATUS "No support for std::filesystem") message(STATUS "No support for std::filesystem")
endif() endif()

View File

@ -1,4 +1,4 @@
# Copyright (c) 2012-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> # Copyright (c) 2012-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> ###############################################
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if(CMAKE_VERSION VERSION_LESS 3.8.2) if(CMAKE_VERSION VERSION_LESS 3.8.2)
@ -22,8 +22,7 @@ if(NOT DEFINED ENABLE_MEMCHECK)
set(MEMCHECK_OPTION_NAME "ENABLE_MEMCHECK") set(MEMCHECK_OPTION_NAME "ENABLE_MEMCHECK")
endif() endif()
if(MEMCHECK_OPTION_NAME STREQUAL "ENABLE_MEMCHECK") if(MEMCHECK_OPTION_NAME STREQUAL "ENABLE_MEMCHECK")
option(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}) elseif(${MEMCHECK_OPTION_NAME})
set(ENABLE_MEMCHECK ON) set(ENABLE_MEMCHECK ON)
else() else()
@ -36,18 +35,12 @@ 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 option(ENABLE_GPROF "Enable integration with gprof, a performance analyzing tool" OFF)
"Enable integration with gprof, a performance analyzing tool" OFF)
option( option(ENABLE_ASAN "Enable AddressSanitizer, a fast memory error detector based on compiler instrumentation" OFF)
ENABLE_ASAN
"Enable AddressSanitizer, a fast memory error detector based on compiler instrumentation"
OFF)
option( option(ENABLE_UBSAN
ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer, a fast undefined behavior detector based on compiler instrumentation" OFF)
"Enable UndefinedBehaviorSanitizer, a fast undefined behavior detector based on compiler instrumentation"
OFF)
if(ENABLE_MEMCHECK) if(ENABLE_MEMCHECK)
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
@ -58,10 +51,7 @@ if(ENABLE_MEMCHECK)
check_include_file(valgrind/memcheck.h HAVE_VALGRIND_MEMCHECK_H) check_include_file(valgrind/memcheck.h HAVE_VALGRIND_MEMCHECK_H)
endif() endif()
if(NOT HAVE_VALGRIND_MEMCHECK_H) if(NOT HAVE_VALGRIND_MEMCHECK_H)
message( message(FATAL_ERROR "${MEMCHECK_OPTION_NAME} option is set but valgrind/memcheck.h is not found")
FATAL_ERROR
"${MEMCHECK_OPTION_NAME} option is set but valgrind/memcheck.h is not found"
)
endif() endif()
endif() endif()

View File

@ -1,4 +1,4 @@
# Copyright (c) 2012-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> # Copyright (c) 2012-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> ###############################################
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if(CMAKE_VERSION VERSION_LESS 3.8.2) if(CMAKE_VERSION VERSION_LESS 3.8.2)
@ -27,10 +27,8 @@ macro(add_compile_flags languages)
endmacro(add_compile_flags) endmacro(add_compile_flags)
macro(remove_flag varname flag) macro(remove_flag varname flag)
string(REGEX REPLACE "^(.*)( ${flag} )(.*)$" "\\1 \\3" ${varname} string(REGEX REPLACE "^(.*)( ${flag} )(.*)$" "\\1 \\3" ${varname} ${${varname}})
${${varname}}) string(REGEX REPLACE "^((.+ )*)(${flag})(( .+)*)$" "\\1\\4" ${varname} ${${varname}})
string(REGEX REPLACE "^((.+ )*)(${flag})(( .+)*)$" "\\1\\4" ${varname}
${${varname}})
endmacro(remove_flag) endmacro(remove_flag)
macro(remove_compile_flag languages flag) macro(remove_compile_flag languages flag)
@ -51,9 +49,8 @@ macro(set_source_files_compile_flags)
set(_lang "") set(_lang "")
if("${_file_ext}" STREQUAL ".m") if("${_file_ext}" STREQUAL ".m")
set(_lang OBJC) set(_lang OBJC)
# CMake believes that Objective C is a flavor of C++, not C, and uses g++ # CMake believes that Objective C is a flavor of C++, not C, and uses g++ compiler for .m files. LANGUAGE property
# compiler for .m files. LANGUAGE property forces CMake to use CC for # forces CMake to use CC for ${file}
# ${file}
set_source_files_properties(${file} PROPERTIES LANGUAGE C) set_source_files_properties(${file} PROPERTIES LANGUAGE C)
elseif("${_file_ext}" STREQUAL ".mm") elseif("${_file_ext}" STREQUAL ".mm")
set(_lang OBJCXX) set(_lang OBJCXX)
@ -87,10 +84,8 @@ macro(semver_parse str)
set(_semver_prerelease "") set(_semver_prerelease "")
set(_semver_buildmetadata_withplus "") set(_semver_buildmetadata_withplus "")
set(_semver_buildmetadata "") set(_semver_buildmetadata "")
if("${str}" if("${str}" MATCHES
MATCHES "^v?(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))?([-+]-*[0-9a-zA-Z]+.*)?$")
"^v?(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))?([-+]-*[0-9a-zA-Z]+.*)?$"
)
set(_semver_major ${CMAKE_MATCH_1}) set(_semver_major ${CMAKE_MATCH_1})
set(_semver_minor ${CMAKE_MATCH_2}) set(_semver_minor ${CMAKE_MATCH_2})
set(_semver_patch ${CMAKE_MATCH_3}) set(_semver_patch ${CMAKE_MATCH_3})
@ -102,13 +97,11 @@ macro(semver_parse str)
elseif("${_semver_extra}" MATCHES "^([.-][a-zA-Z0-9-]+)*(\\+[^+]+)?$") elseif("${_semver_extra}" MATCHES "^([.-][a-zA-Z0-9-]+)*(\\+[^+]+)?$")
set(_semver_prerelease_withdash "${CMAKE_MATCH_1}") set(_semver_prerelease_withdash "${CMAKE_MATCH_1}")
if(NOT "${_semver_prerelease_withdash}" STREQUAL "") if(NOT "${_semver_prerelease_withdash}" STREQUAL "")
string(SUBSTRING "${_semver_prerelease_withdash}" 1 -1 string(SUBSTRING "${_semver_prerelease_withdash}" 1 -1 _semver_prerelease)
_semver_prerelease)
endif() endif()
set(_semver_buildmetadata_withplus "${CMAKE_MATCH_2}") set(_semver_buildmetadata_withplus "${CMAKE_MATCH_2}")
if(NOT "${_semver_buildmetadata_withplus}" STREQUAL "") if(NOT "${_semver_buildmetadata_withplus}" STREQUAL "")
string(SUBSTRING "${_semver_buildmetadata_withplus}" 1 -1 string(SUBSTRING "${_semver_buildmetadata_withplus}" 1 -1 _semver_buildmetadata)
_semver_buildmetadata)
endif() endif()
set(_semver_ok TRUE) set(_semver_ok TRUE)
else() else()
@ -117,19 +110,14 @@ macro(semver_parse str)
) )
endif() endif()
else() else()
set(_semver_err set(_semver_err "Версионная отметка в целом не соответствует шаблону `0.0.0[.0][-foo][+bar]` SemVer-спецификации")
"Версионная отметка в целом не соответствует шаблону `0.0.0[.0][-foo][+bar]` SemVer-спецификации"
)
endif() endif()
endmacro(semver_parse) endmacro(semver_parse)
function(_semver_parse_probe str expect) function(_semver_parse_probe str expect)
semver_parse(${str}) semver_parse(${str})
if(expect AND NOT _semver_ok) if(expect AND NOT _semver_ok)
message( message(FATAL_ERROR "semver_parse(${str}) expect SUCCESS, got ${_semver_ok}: ${_semver_err}")
FATAL_ERROR
"semver_parse(${str}) expect SUCCESS, got ${_semver_ok}: ${_semver_err}"
)
elseif(NOT expect AND _semver_ok) elseif(NOT expect AND _semver_ok)
message(FATAL_ERROR "semver_parse(${str}) expect FAIL, got ${_semver_ok}") message(FATAL_ERROR "semver_parse(${str}) expect FAIL, got ${_semver_ok}")
endif() endif()
@ -150,8 +138,7 @@ function(semver_parse_selfcheck)
_semver_parse_probe("1.0.0-alpha.1" TRUE) _semver_parse_probe("1.0.0-alpha.1" TRUE)
_semver_parse_probe("1.0.0-alpha0.valid" TRUE) _semver_parse_probe("1.0.0-alpha0.valid" TRUE)
_semver_parse_probe("1.0.0-alpha.0valid" TRUE) _semver_parse_probe("1.0.0-alpha.0valid" TRUE)
_semver_parse_probe("1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay" _semver_parse_probe("1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay" TRUE)
TRUE)
_semver_parse_probe("1.0.0-rc.1+build.1" TRUE) _semver_parse_probe("1.0.0-rc.1+build.1" TRUE)
_semver_parse_probe("2.0.0-rc.1+build.123" TRUE) _semver_parse_probe("2.0.0-rc.1+build.123" TRUE)
_semver_parse_probe("1.2.3-beta" TRUE) _semver_parse_probe("1.2.3-beta" TRUE)
@ -167,14 +154,12 @@ function(semver_parse_selfcheck)
_semver_parse_probe("1.2.3----R-S.12.9.1--.12+meta" TRUE) _semver_parse_probe("1.2.3----R-S.12.9.1--.12+meta" TRUE)
_semver_parse_probe("1.2.3----RC-SNAPSHOT.12.9.1--.12" TRUE) _semver_parse_probe("1.2.3----RC-SNAPSHOT.12.9.1--.12" TRUE)
_semver_parse_probe("1.0.0+0.build.1-rc.10000aaa-kk-0.1" TRUE) _semver_parse_probe("1.0.0+0.build.1-rc.10000aaa-kk-0.1" TRUE)
_semver_parse_probe( _semver_parse_probe("99999999999999999999999.999999999999999999.99999999999999999" TRUE)
"99999999999999999999999.999999999999999999.99999999999999999" TRUE)
_semver_parse_probe("v1.0.0-0A.is.legal" TRUE) _semver_parse_probe("v1.0.0-0A.is.legal" TRUE)
_semver_parse_probe("1" FALSE) _semver_parse_probe("1" FALSE)
_semver_parse_probe("1.2" FALSE) _semver_parse_probe("1.2" FALSE)
# _semver_parse_probe("1.2.3-0123" FALSE) # _semver_parse_probe("1.2.3-0123" FALSE) _semver_parse_probe("1.2.3-0123.0123" FALSE)
# _semver_parse_probe("1.2.3-0123.0123" FALSE)
_semver_parse_probe("1.1.2+.123" FALSE) _semver_parse_probe("1.1.2+.123" FALSE)
_semver_parse_probe("+invalid" FALSE) _semver_parse_probe("+invalid" FALSE)
_semver_parse_probe("-invalid" FALSE) _semver_parse_probe("-invalid" FALSE)
@ -238,10 +223,7 @@ macro(git_get_versioninfo source_root_directory)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc) RESULT_VARIABLE _rc)
if(_rc OR "${_git_timestamp}" STREQUAL "%ci") if(_rc OR "${_git_timestamp}" STREQUAL "%ci")
message( message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%cI HEAD` failed)")
FATAL_ERROR
"Please install latest version of git (`show --no-patch --format=%cI HEAD` failed)"
)
endif() endif()
endif() endif()
@ -252,10 +234,7 @@ macro(git_get_versioninfo source_root_directory)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc) RESULT_VARIABLE _rc)
if(_rc OR "${_git_tree}" STREQUAL "") if(_rc OR "${_git_tree}" STREQUAL "")
message( message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%T HEAD` failed)")
FATAL_ERROR
"Please install latest version of git (`show --no-patch --format=%T HEAD` failed)"
)
endif() endif()
execute_process( execute_process(
@ -265,10 +244,7 @@ macro(git_get_versioninfo source_root_directory)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc) RESULT_VARIABLE _rc)
if(_rc OR "${_git_commit}" STREQUAL "") if(_rc OR "${_git_commit}" STREQUAL "")
message( message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%H HEAD` failed)")
FATAL_ERROR
"Please install latest version of git (`show --no-patch --format=%H HEAD` failed)"
)
endif() endif()
execute_process( execute_process(
@ -278,10 +254,7 @@ macro(git_get_versioninfo source_root_directory)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc) RESULT_VARIABLE _rc)
if(_rc) if(_rc)
message( message(FATAL_ERROR "Please install latest version of git (`status --untracked-files=no --porcelain` failed)")
FATAL_ERROR
"Please install latest version of git (`status --untracked-files=no --porcelain` failed)"
)
endif() endif()
if(NOT "${_git_status}" STREQUAL "") if(NOT "${_git_status}" STREQUAL "")
set(_git_commit "DIRTY-${_git_commit}") set(_git_commit "DIRTY-${_git_commit}")
@ -311,18 +284,12 @@ macro(git_get_versioninfo source_root_directory)
if(_rc) if(_rc)
message( message(
FATAL_ERROR FATAL_ERROR
"Please install latest version of git (`git rev-list --count --no-merges --remove-empty HEAD` failed)" "Please install latest version of git (`git rev-list --count --no-merges --remove-empty HEAD` failed)")
)
endif() endif()
if(_git_whole_count GREATER 42 AND "${_git_tags_dump}" STREQUAL "") if(_git_whole_count GREATER 42 AND "${_git_tags_dump}" STREQUAL "")
message( message(FATAL_ERROR "Please fetch tags (`describe --tags --abbrev=0 --match=v[0-9]*` failed)")
FATAL_ERROR
"Please fetch tags (`describe --tags --abbrev=0 --match=v[0-9]*` failed)"
)
else() else()
message( message(NOTICE "Falling back to version `0.0.0` (have you made an initial release?")
NOTICE
"Falling back to version `0.0.0` (have you made an initial release?")
endif() endif()
set(_git_last_vtag "0.0.0") set(_git_last_vtag "0.0.0")
set(_git_trailing_commits ${_git_whole_count}) set(_git_trailing_commits ${_git_whole_count})
@ -340,10 +307,7 @@ macro(git_get_versioninfo source_root_directory)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc) RESULT_VARIABLE _rc)
if(_rc OR "${_git_describe}" STREQUAL "") if(_rc OR "${_git_describe}" STREQUAL "")
message( message(FATAL_ERROR "Please install latest version of git (`describe --tags --all --long` failed)")
FATAL_ERROR
"Please install latest version of git (`describe --tags --all --long` failed)"
)
endif() endif()
endif() endif()
else() else()
@ -354,10 +318,7 @@ macro(git_get_versioninfo source_root_directory)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc) RESULT_VARIABLE _rc)
if(_rc OR "${_git_describe}" STREQUAL "") if(_rc OR "${_git_describe}" STREQUAL "")
message( message(FATAL_ERROR "Please install latest version of git (`describe --tags --long --match=v[0-9]*`)")
FATAL_ERROR
"Please install latest version of git (`describe --tags --long --match=v[0-9]*`)"
)
endif() endif()
execute_process( execute_process(
COMMAND ${GIT} rev-list --count "${_git_last_vtag}..HEAD" COMMAND ${GIT} rev-list --count "${_git_last_vtag}..HEAD"
@ -366,16 +327,12 @@ macro(git_get_versioninfo source_root_directory)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc) RESULT_VARIABLE _rc)
if(_rc OR "${_git_trailing_commits}" STREQUAL "") if(_rc OR "${_git_trailing_commits}" STREQUAL "")
message( message(FATAL_ERROR "Please install latest version of git (`rev-list --count ${_git_last_vtag}..HEAD` failed)")
FATAL_ERROR
"Please install latest version of git (`rev-list --count ${_git_last_vtag}..HEAD` failed)"
)
endif() endif()
endif() endif()
endmacro(git_get_versioninfo) endmacro(git_get_versioninfo)
macro(semver_provide name source_root_directory build_directory_for_json_output macro(semver_provide name source_root_directory build_directory_for_json_output build_metadata parent_scope)
build_metadata parent_scope)
set(_semver "") set(_semver "")
set(_git_describe "") set(_git_describe "")
set(_git_timestamp "") set(_git_timestamp "")
@ -395,11 +352,9 @@ macro(semver_provide name source_root_directory build_directory_for_json_output
RESULT_VARIABLE _rc) RESULT_VARIABLE _rc)
if(_rc OR "${_git_root}" STREQUAL "") if(_rc OR "${_git_root}" STREQUAL "")
if(EXISTS "${source_root_directory}/.git") if(EXISTS "${source_root_directory}/.git")
message(ERROR message(ERROR "`git rev-parse --show-toplevel` failed '${_git_root_error}'")
"`git rev-parse --show-toplevel` failed '${_git_root_error}'")
else() else()
message(VERBOSE message(VERBOSE "`git rev-parse --show-toplevel` failed '${_git_root_error}'")
"`git rev-parse --show-toplevel` failed '${_git_root_error}'")
endif() endif()
else() else()
set(_source_root "${source_root_directory}") set(_source_root "${source_root_directory}")
@ -420,8 +375,7 @@ macro(semver_provide name source_root_directory build_directory_for_json_output
set(_version_from "${source_root_directory}/VERSION.json") set(_version_from "${source_root_directory}/VERSION.json")
if(CMAKE_VERSION VERSION_LESS 3.19) if(CMAKE_VERSION VERSION_LESS 3.19)
message( message(FATAL_ERROR "Требуется CMake версии >= 3.19 для чтения VERSION.json")
FATAL_ERROR "Требуется CMake версии >= 3.19 для чтения VERSION.json")
endif() endif()
file( file(
STRINGS "${_version_from}" _versioninfo_json NEWLINE_CONSUME STRINGS "${_version_from}" _versioninfo_json NEWLINE_CONSUME
@ -435,14 +389,11 @@ macro(semver_provide name source_root_directory build_directory_for_json_output
string(JSON _semver GET "${_versioninfo_json}" "semver") string(JSON _semver GET "${_versioninfo_json}" "semver")
unset(_json_object) unset(_json_object)
if(NOT _semver) if(NOT _semver)
message( message(FATAL_ERROR "Unable to retrieve ${name} version from \"${_version_from}\" file.")
FATAL_ERROR
"Unable to retrieve ${name} version from \"${_version_from}\" file.")
endif() endif()
semver_parse("${_semver}") semver_parse("${_semver}")
if(NOT _semver_ok) if(NOT _semver_ok)
message( message(FATAL_ERROR "SemVer `${_semver}` from ${_version_from}: ${_semver_err}")
FATAL_ERROR "SemVer `${_semver}` from ${_version_from}: ${_semver_err}")
endif() endif()
elseif(_git_root AND _source_root STREQUAL _git_root) elseif(_git_root AND _source_root STREQUAL _git_root)
set(_version_from git) set(_version_from git)
@ -551,8 +502,7 @@ macro(semver_provide name source_root_directory build_directory_for_json_output
\"semver\" : \"@_semver@\"\n}" \"semver\" : \"@_semver@\"\n}"
_versioninfo_json _versioninfo_json
@ONLY ESCAPE_QUOTES) @ONLY ESCAPE_QUOTES)
file(WRITE "${build_directory_for_json_output}/VERSION.json" file(WRITE "${build_directory_for_json_output}/VERSION.json" "${_versioninfo_json}")
"${_versioninfo_json}")
endif() endif()
endmacro(semver_provide) endmacro(semver_provide)

View File

@ -1,4 +1,4 @@
# Copyright (c) 2020-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> # Copyright (c) 2020-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> ###############################################
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
enable_language(CXX) enable_language(CXX)
@ -8,14 +8,10 @@ function(add_extra_test name)
set(options DISABLED) set(options DISABLED)
set(oneValueArgs TIMEOUT) set(oneValueArgs TIMEOUT)
set(multiValueArgs SOURCE LIBRARY DEPEND DLLPATH) set(multiValueArgs SOURCE LIBRARY DEPEND DLLPATH)
cmake_parse_arguments(params "${options}" "${oneValueArgs}" cmake_parse_arguments(params "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
"${multiValueArgs}" ${ARGN})
if(params_UNPARSED_ARGUMENTS) if(params_UNPARSED_ARGUMENTS)
message( message(FATAL_ERROR "Unknown keywords given to add_extra_test(): \"${params_UNPARSED_ARGUMENTS}\".")
FATAL_ERROR
"Unknown keywords given to add_extra_test(): \"${params_UNPARSED_ARGUMENTS}\"."
)
endif() endif()
macro(oops) macro(oops)
@ -30,12 +26,10 @@ function(add_extra_test name)
add_executable(${target} ${params_SOURCE}) add_executable(${target} ${params_SOURCE})
target_include_directories(${target} PRIVATE "${PROJECT_SOURCE_DIR}") target_include_directories(${target} PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(${target} ${TOOL_MDBX_LIB}) target_link_libraries(${target} ${TOOL_MDBX_LIB})
set_target_properties(${target} PROPERTIES SKIP_BUILD_RPATH FALSE set_target_properties(${target} PROPERTIES SKIP_BUILD_RPATH FALSE BUILD_WITH_INSTALL_RPATH FALSE)
BUILD_WITH_INSTALL_RPATH FALSE)
if(MDBX_BUILD_CXX AND MDBX_CXX_STANDARD) if(MDBX_BUILD_CXX AND MDBX_CXX_STANDARD)
set_target_properties(${target} PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} set_target_properties(${target} PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
CXX_STANDARD_REQUIRED ON)
endif() endif()
if(params_DEPEND) if(params_DEPEND)
@ -47,32 +41,25 @@ function(add_extra_test name)
foreach(dep IN LISTS params_LIBRARY) foreach(dep IN LISTS params_LIBRARY)
get_target_property(type ${dep} TYPE) get_target_property(type ${dep} TYPE)
if(type STREQUAL SHARED_LIBRARY) if(type STREQUAL SHARED_LIBRARY)
# Windows don't have RPATH feature, therefore we should prepare PATH or # Windows don't have RPATH feature, therefore we should prepare PATH or copy DLL(s)...
# copy DLL(s)...
if(CMAKE_CONFIGURATION_TYPES) if(CMAKE_CONFIGURATION_TYPES)
# Could not provide static ENVIRONMENT property with # Could not provide static ENVIRONMENT property with configuration-depended path
# configuration-depended path
set(dir FALSE) set(dir FALSE)
else(CMAKE_CONFIGURATION_TYPES) else(CMAKE_CONFIGURATION_TYPES)
get_target_property(filename ${dep} get_target_property(filename ${dep} IMPORTED_LOCATION_${CMAKE_BUILD_TYPE_UPPERCASE})
IMPORTED_LOCATION_${CMAKE_BUILD_TYPE_UPPERCASE})
if(NOT filename) if(NOT filename)
get_target_property(filename ${dep} IMPORTED_LOCATION) get_target_property(filename ${dep} IMPORTED_LOCATION)
endif() endif()
get_target_property(filename ${dep} get_target_property(filename ${dep} LOCATION_${CMAKE_BUILD_TYPE_UPPERCASE})
LOCATION_${CMAKE_BUILD_TYPE_UPPERCASE})
if(NOT filename) if(NOT filename)
get_target_property(filename ${dep} LOCATION) get_target_property(filename ${dep} LOCATION)
endif() endif()
if(filename) if(filename)
get_filename_component(dir ${filename} DIRECTORY) get_filename_component(dir ${filename} DIRECTORY)
else(filename) else(filename)
get_target_property( get_target_property(dir ${dep} LIBRARY_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE_UPPERCASE})
dir ${dep} LIBRARY_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE_UPPERCASE})
if(NOT dir) if(NOT dir)
get_target_property( get_target_property(dir ${dep} RUNTIME_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE_UPPERCASE})
dir ${dep}
RUNTIME_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE_UPPERCASE})
endif() endif()
if(NOT dir) if(NOT dir)
get_target_property(dir ${dep} LIBRARY_OUTPUT_DIRECTORY) get_target_property(dir ${dep} LIBRARY_OUTPUT_DIRECTORY)
@ -89,32 +76,25 @@ function(add_extra_test name)
add_custom_command( add_custom_command(
TARGET ${target} TARGET ${target}
POST_BUILD POST_BUILD
COMMAND COMMAND if exist "$<TARGET_PDB_FILE:${dep}>" ${CMAKE_COMMAND} -E copy_if_different
if exist "$<TARGET_PDB_FILE:${dep}>" ${CMAKE_COMMAND} -E "$<TARGET_PDB_FILE:${dep}>" "$<TARGET_FILE_DIR:${target}>")
copy_if_different "$<TARGET_PDB_FILE:${dep}>"
"$<TARGET_FILE_DIR:${target}>")
add_custom_command( add_custom_command(
TARGET ${target} TARGET ${target}
POST_BUILD POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:${dep}>" "$<TARGET_FILE_DIR:${target}>"
"$<TARGET_FILE:${dep}>" "$<TARGET_FILE_DIR:${target}>" COMMENT "${TOOL_MDBX_DLLCRUTCH}: Copy shared library ${dep} for test ${target}")
COMMENT
"${TOOL_MDBX_DLLCRUTCH}: Copy shared library ${dep} for test ${target}"
)
endif(dir) endif(dir)
endif() endif()
endforeach(dep) endforeach(dep)
endif(TOOL_MDBX_DLLCRUTCH) endif(TOOL_MDBX_DLLCRUTCH)
if(NOT params_DISABLED AND NOT (CMAKE_CROSSCOMPILING if(NOT params_DISABLED AND NOT (CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR))
AND NOT CMAKE_CROSSCOMPILING_EMULATOR))
add_test(extra_${name} ${MDBX_OUTPUT_DIR}/${target}) add_test(extra_${name} ${MDBX_OUTPUT_DIR}/${target})
if(params_TIMEOUT) if(params_TIMEOUT)
if(MEMORYCHECK_COMMAND if(MEMORYCHECK_COMMAND
OR CMAKE_MEMORYCHECK_COMMAND OR CMAKE_MEMORYCHECK_COMMAND
OR ENABLE_MEMCHECK) OR ENABLE_MEMCHECK)
# FIXME: unless there are any other ideas how to fix the timeouts # FIXME: unless there are any other ideas how to fix the timeouts problem when testing under Valgrind.
# problem when testing under Valgrind.
math(EXPR params_TIMEOUT "${params_TIMEOUT} * 42") math(EXPR params_TIMEOUT "${params_TIMEOUT} * 42")
endif() endif()
set_tests_properties(extra_${name} PROPERTIES TIMEOUT ${params_TIMEOUT}) set_tests_properties(extra_${name} PROPERTIES TIMEOUT ${params_TIMEOUT})
@ -133,8 +113,7 @@ function(add_extra_test name)
else() else()
string(REPLACE ";" ":" params_DLLPATH_ENV "${params_DLLPATH_ENV}") string(REPLACE ";" ":" params_DLLPATH_ENV "${params_DLLPATH_ENV}")
endif() endif()
set_tests_properties(extra_${name} set_tests_properties(extra_${name} PROPERTIES ENVIRONMENT "PATH=${params_DLLPATH_ENV}")
PROPERTIES ENVIRONMENT "PATH=${params_DLLPATH_ENV}")
endif() endif()
endif() endif()
endfunction(add_extra_test) endfunction(add_extra_test)
@ -179,13 +158,10 @@ add_executable(mdbx_test ${LIBMDBX_TEST_SOURCES})
target_compile_definitions(mdbx_test PRIVATE MDBX_BUILD_TEST=1 MDBX_BUILD_CXX=1) target_compile_definitions(mdbx_test PRIVATE MDBX_BUILD_TEST=1 MDBX_BUILD_CXX=1)
if(MDBX_CXX_STANDARD) if(MDBX_CXX_STANDARD)
set_target_properties(mdbx_test PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} set_target_properties(mdbx_test PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
CXX_STANDARD_REQUIRED ON)
endif() endif()
set_target_properties( set_target_properties(mdbx_test PROPERTIES INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
mdbx_test PROPERTIES INTERPROCEDURAL_OPTIMIZATION
$<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
target_setup_options(mdbx_test) target_setup_options(mdbx_test)
if(NOT MDBX_BUILD_CXX) if(NOT MDBX_BUILD_CXX)
@ -205,8 +181,7 @@ if(NOT MDBX_BUILD_CXX AND LIBCXX_FILESYSTEM)
endif() endif()
if(CMAKE_VERSION VERSION_LESS 3.1) if(CMAKE_VERSION VERSION_LESS 3.1)
target_link_libraries(mdbx_test ${TOOL_MDBX_LIB} ${LIB_MATH} target_link_libraries(mdbx_test ${TOOL_MDBX_LIB} ${LIB_MATH} ${CMAKE_THREAD_LIBS_INIT})
${CMAKE_THREAD_LIBS_INIT})
else() else()
target_link_libraries(mdbx_test ${TOOL_MDBX_LIB} ${LIB_MATH} Threads::Threads) target_link_libraries(mdbx_test ${TOOL_MDBX_LIB} ${LIB_MATH} Threads::Threads)
endif() endif()
@ -222,12 +197,11 @@ if(NOT SUBPROJECT)
endif() endif()
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") message(WARNING "No emulator to run cross-compiled tests")
add_test(NAME fake_since_no_crosscompiling_emulator add_test(NAME fake_since_no_crosscompiling_emulator COMMAND ${CMAKE_COMMAND} -E echo
COMMAND ${CMAKE_COMMAND} -E echo
"No emulator to run cross-compiled tests") "No emulator to run cross-compiled tests")
else() else()
@ -235,16 +209,10 @@ else()
RANDOM RANDOM
LENGTH 9 LENGTH 9
ALPHABET "1234567890" test_seed) ALPHABET "1234567890" test_seed)
message( message(STATUS "The ${test_seed} will be used for seeding tests. Re-run cmake to re-seed it.")
STATUS
"The ${test_seed} will be used for seeding tests. Re-run cmake to re-seed it."
)
add_test( add_test(NAME smoke COMMAND ${MDBX_OUTPUT_DIR}/mdbx_test --loglevel=verbose --prng-seed=${test_seed} --progress
NAME smoke --console=no --pathname=smoke.db --dont-cleanup-after basic)
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) set_tests_properties(smoke PROPERTIES TIMEOUT 600 RUN_SERIAL OFF)
if(MDBX_BUILD_TOOLS) if(MDBX_BUILD_TOOLS)
add_test(NAME smoke_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv smoke.db) add_test(NAME smoke_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv smoke.db)
@ -258,8 +226,7 @@ else()
"cooperative mode" "cooperative mode"
REQUIRED_FILES REQUIRED_FILES
smoke.db) smoke.db)
add_test(NAME smoke_chk_copy COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv add_test(NAME smoke_chk_copy COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv smoke.db-copy)
smoke.db-copy)
set_tests_properties( set_tests_properties(
smoke_chk_copy smoke_chk_copy
PROPERTIES DEPENDS PROPERTIES DEPENDS
@ -275,19 +242,14 @@ else()
add_test( add_test(
NAME dupsort_writemap NAME dupsort_writemap
COMMAND COMMAND
${MDBX_OUTPUT_DIR}/mdbx_test --loglevel=notice --prng-seed=${test_seed} ${MDBX_OUTPUT_DIR}/mdbx_test --loglevel=notice --prng-seed=${test_seed} --table=+data.fixed --keygen.split=29
--table=+data.fixed --keygen.split=29 --datalen=rnd --progress --datalen=rnd --progress --console=no --repeat=2 --pathname=dupsort_writemap.db --dont-cleanup-after basic)
--console=no --repeat=2 --pathname=dupsort_writemap.db
--dont-cleanup-after basic)
set_tests_properties(dupsort_writemap PROPERTIES TIMEOUT 3600 RUN_SERIAL OFF) set_tests_properties(dupsort_writemap PROPERTIES TIMEOUT 3600 RUN_SERIAL OFF)
if(MDBX_BUILD_TOOLS) if(MDBX_BUILD_TOOLS)
add_test(NAME dupsort_writemap_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk add_test(NAME dupsort_writemap_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvvwc dupsort_writemap.db)
-nvvwc dupsort_writemap.db) set_tests_properties(dupsort_writemap_chk PROPERTIES DEPENDS dupsort_writemap TIMEOUT 60 REQUIRED_FILES
set_tests_properties( dupsort_writemap.db)
dupsort_writemap_chk PROPERTIES DEPENDS dupsort_writemap TIMEOUT 60 add_test(NAME dupsort_writemap_chk_copy COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvvc dupsort_writemap.db-copy)
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( set_tests_properties(
dupsort_writemap_chk_copy dupsort_writemap_chk_copy
PROPERTIES DEPENDS PROPERTIES DEPENDS
@ -300,16 +262,12 @@ else()
dupsort_writemap.db-copy) dupsort_writemap.db-copy)
endif() endif()
add_test( add_test(NAME uniq_nested
NAME uniq_nested COMMAND ${MDBX_OUTPUT_DIR}/mdbx_test --loglevel=notice --mode=-writemap,-nosync-safe,-lifo --progress
COMMAND --console=no --repeat=2 --pathname=uniq_nested.db --dont-cleanup-after basic)
${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) set_tests_properties(uniq_nested PROPERTIES TIMEOUT 1800 RUN_SERIAL OFF)
if(MDBX_BUILD_TOOLS) if(MDBX_BUILD_TOOLS)
add_test(NAME uniq_nested_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvvw add_test(NAME uniq_nested_chk COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvvw uniq_nested.db)
uniq_nested.db)
set_tests_properties( set_tests_properties(
uniq_nested_chk uniq_nested_chk
PROPERTIES DEPENDS PROPERTIES DEPENDS
@ -320,8 +278,7 @@ else()
"cooperative mode" "cooperative mode"
REQUIRED_FILES REQUIRED_FILES
uniq_nested.db) uniq_nested.db)
add_test(NAME uniq_nested_chk_copy COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv add_test(NAME uniq_nested_chk_copy COMMAND ${MDBX_OUTPUT_DIR}/mdbx_chk -nvv uniq_nested.db-copy)
uniq_nested.db-copy)
set_tests_properties( set_tests_properties(
uniq_nested_chk_copy uniq_nested_chk_copy
PROPERTIES DEPENDS PROPERTIES DEPENDS