deps: bump libmdbx to 0.13.6 (#15412)

This commit is contained in:
Alexey Shekhirin
2025-05-12 17:20:14 +01:00
committed by GitHub
parent 3d48dcc8e5
commit 0dee91f6b3
30 changed files with 45907 additions and 49528 deletions

View File

@@ -26,8 +26,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
types: | types: |
fix
feat feat
fix
chore chore
test test
perf perf
@@ -35,6 +35,7 @@ jobs:
docs docs
ci ci
revert revert
deps
continue-on-error: true continue-on-error: true
- name: Add PR Comment for Invalid Title - name: Add PR Comment for Invalid Title
if: steps.lint_pr_title.outcome == 'failure' if: steps.lint_pr_title.outcome == 'failure'
@@ -59,6 +60,7 @@ jobs:
- `docs`: Documentation updates - `docs`: Documentation updates
- `ci`: Changes to CI/CD configurations - `ci`: Changes to CI/CD configurations
- `revert`: Reverts a previously merged PR - `revert`: Reverts a previously merged PR
- `deps`: Updates dependencies
**Breaking Changes** **Breaking Changes**

View File

@@ -884,9 +884,7 @@ mod tests {
// Seek exact // Seek exact
let exact = cursor.seek_exact(missing_key).unwrap(); let exact = cursor.seek_exact(missing_key).unwrap();
assert_eq!(exact, None); assert_eq!(exact, None);
assert_eq!(cursor.current(), Ok(Some((missing_key + 1, B256::ZERO)))); assert_eq!(cursor.current(), Ok(None));
assert_eq!(cursor.prev(), Ok(Some((missing_key - 1, B256::ZERO))));
assert_eq!(cursor.prev(), Ok(Some((missing_key - 2, B256::ZERO))));
} }
#[test] #[test]
@@ -971,11 +969,14 @@ mod tests {
// Seek & delete key2 again // Seek & delete key2 again
assert_eq!(cursor.seek_exact(key2), Ok(None)); assert_eq!(cursor.seek_exact(key2), Ok(None));
assert_eq!(cursor.delete_current(), Ok(())); assert_eq!(
cursor.delete_current(),
Err(DatabaseError::Delete(reth_libmdbx::Error::NoData.into()))
);
// Assert that key1 is still there // Assert that key1 is still there
assert_eq!(cursor.seek_exact(key1), Ok(Some((key1, Account::default())))); assert_eq!(cursor.seek_exact(key1), Ok(Some((key1, Account::default()))));
// Assert that key3 was deleted // Assert that key3 is still there
assert_eq!(cursor.seek_exact(key3), Ok(None)); assert_eq!(cursor.seek_exact(key3), Ok(Some((key3, Account::default()))));
} }
#[test] #[test]
@@ -1343,8 +1344,9 @@ mod tests {
let db: Arc<DatabaseEnv> = create_test_db(DatabaseEnvKind::RW); let db: Arc<DatabaseEnv> = create_test_db(DatabaseEnvKind::RW);
let real_key = address!("0xa2c122be93b0074270ebee7f6b7292c7deb45047"); let real_key = address!("0xa2c122be93b0074270ebee7f6b7292c7deb45047");
for i in 1..5 { let shards = 5;
let key = ShardedKey::new(real_key, i * 100); for i in 1..=shards {
let key = ShardedKey::new(real_key, if i == shards { u64::MAX } else { i * 100 });
let list = IntegerList::new_pre_sorted([i * 100u64]); let list = IntegerList::new_pre_sorted([i * 100u64]);
db.update(|tx| tx.put::<AccountsHistory>(key.clone(), list.clone()).expect("")) db.update(|tx| tx.put::<AccountsHistory>(key.clone(), list.clone()).expect(""))

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
# This makefile is for GNU Make 3.80 or above, and nowadays provided # This makefile is for GNU Make 3.81 or above, and nowadays provided
# just for compatibility and preservation of traditions. # just for compatibility and preservation of traditions.
# #
# Please use CMake in case of any difficulties or # Please use CMake in case of any difficulties or
@@ -16,6 +16,7 @@ ifneq ($(make_lt_3_81),0)
$(error Please use GNU Make 3.81 or above) $(error Please use GNU Make 3.81 or above)
endif endif
make_ge_4_1 := $(shell expr "$(MAKE_VERx3)" ">=" " 4 1") make_ge_4_1 := $(shell expr "$(MAKE_VERx3)" ">=" " 4 1")
make_ge_4_4 := $(shell expr "$(MAKE_VERx3)" ">=" " 4 4")
SRC_PROBE_C := $(shell [ -f mdbx.c ] && echo mdbx.c || echo src/osal.c) SRC_PROBE_C := $(shell [ -f mdbx.c ] && echo mdbx.c || echo src/osal.c)
SRC_PROBE_CXX := $(shell [ -f mdbx.c++ ] && echo mdbx.c++ || echo src/mdbx.c++) SRC_PROBE_CXX := $(shell [ -f mdbx.c++ ] && echo mdbx.c++ || echo src/mdbx.c++)
UNAME := $(shell uname -s 2>/dev/null || echo Unknown) UNAME := $(shell uname -s 2>/dev/null || echo Unknown)
@@ -51,17 +52,24 @@ CC ?= gcc
CXX ?= g++ CXX ?= g++
CFLAGS_EXTRA ?= CFLAGS_EXTRA ?=
LD ?= ld LD ?= ld
CMAKE ?= cmake
CMAKE_OPT ?=
CTEST ?= ctest
CTEST_OPT ?=
# target directory for `make dist`
DIST_DIR ?= dist
# build options # build options
MDBX_BUILD_OPTIONS ?=-DNDEBUG=1 MDBX_BUILD_OPTIONS ?=-DNDEBUG=1
MDBX_BUILD_TIMESTAMP ?=$(shell date +%Y-%m-%dT%H:%M:%S%z) MDBX_BUILD_TIMESTAMP ?=$(if $(SOURCE_DATE_EPOCH),$(SOURCE_DATE_EPOCH),$(shell date +%Y-%m-%dT%H:%M:%S%z))
MDBX_BUILD_CXX ?= YES MDBX_BUILD_CXX ?=YES
MDBX_BUILD_METADATA ?=
# probe and compose common compiler flags with variable expansion trick (seems this work two times per session for GNU Make 3.81) # probe and compose common compiler flags with variable expansion trick (seems this work two times per session for GNU Make 3.81)
CFLAGS ?= $(strip $(eval CFLAGS := -std=gnu11 -O2 -g -Wall -Werror -Wextra -Wpedantic -ffunction-sections -fPIC -fvisibility=hidden -pthread -Wno-error=attributes $$(shell for opt in -fno-semantic-interposition -Wno-unused-command-line-argument -Wno-tautological-compare; do [ -z "$$$$($(CC) '-DMDBX_BUILD_FLAGS="probe"' $$$${opt} -c $(SRC_PROBE_C) -o /dev/null >/dev/null 2>&1 || echo failed)" ] && echo "$$$${opt} "; done)$(CFLAGS_EXTRA))$(CFLAGS)) CFLAGS ?= $(strip $(eval CFLAGS := -std=gnu11 -O2 -g -Wall -Werror -Wextra -Wpedantic -ffunction-sections -fPIC -fvisibility=hidden -pthread -Wno-error=attributes $$(shell for opt in -fno-semantic-interposition -Wno-unused-command-line-argument -Wno-tautological-compare; do [ -z "$$$$($(CC) '-DMDBX_BUILD_FLAGS="probe"' $$$${opt} -c $(SRC_PROBE_C) -o /dev/null >/dev/null 2>&1 || echo failed)" ] && echo "$$$${opt} "; done)$(CFLAGS_EXTRA))$(CFLAGS))
# choosing C++ standard with variable expansion trick (seems this work two times per session for GNU Make 3.81) # choosing C++ standard with variable expansion trick (seems this work two times per session for GNU Make 3.81)
CXXSTD ?= $(eval CXXSTD := $$(shell for std in gnu++23 c++23 gnu++2b c++2b gnu++20 c++20 gnu++2a c++2a gnu++17 c++17 gnu++1z c++1z gnu++14 c++14 gnu++1y c++1y gnu+11 c++11 gnu++0x c++0x; do $(CXX) -std=$$$${std} -c $(SRC_PROBE_CXX) -o /dev/null 2>probe4std-$$$${std}.err >/dev/null && echo "-std=$$$${std}" && exit; done))$(CXXSTD) CXXSTD ?= $(eval CXXSTD := $$(shell for std in gnu++23 c++23 gnu++2b c++2b gnu++20 c++20 gnu++2a c++2a gnu++17 c++17 gnu++1z c++1z gnu++14 c++14 gnu++1y c++1y gnu+11 c++11 gnu++0x c++0x; do $(CXX) -std=$$$${std} -DMDBX_BUILD_CXX=1 -c $(SRC_PROBE_CXX) -o /dev/null 2>probe4std-$$$${std}.err >/dev/null && echo "-std=$$$${std}" && exit; done))$(CXXSTD)
CXXFLAGS ?= $(strip $(CXXSTD) $(filter-out -std=gnu11,$(CFLAGS))) CXXFLAGS ?= $(strip $(CXXSTD) $(filter-out -std=gnu11,$(CFLAGS)))
# libraries and options for linking # libraries and options for linking
@@ -78,6 +86,13 @@ LDFLAGS ?= $(eval LDFLAGS := $$(shell $$(uname2ldflags)))$(LDFLAGS)
LIB_STDCXXFS ?= $(eval LIB_STDCXXFS := $$(shell echo '$$(cxx_filesystem_probe)' | cat mdbx.h++ - | sed $$$$'1s/\xef\xbb\xbf//' | $(CXX) -x c++ $(CXXFLAGS) -Wno-error - -Wl,--allow-multiple-definition -lstdc++fs $(LIBS) $(LDFLAGS) $(EXE_LDFLAGS) -o /dev/null 2>probe4lstdfs.err >/dev/null && echo '-Wl,--allow-multiple-definition -lstdc++fs'))$(LIB_STDCXXFS) LIB_STDCXXFS ?= $(eval LIB_STDCXXFS := $$(shell echo '$$(cxx_filesystem_probe)' | cat mdbx.h++ - | sed $$$$'1s/\xef\xbb\xbf//' | $(CXX) -x c++ $(CXXFLAGS) -Wno-error - -Wl,--allow-multiple-definition -lstdc++fs $(LIBS) $(LDFLAGS) $(EXE_LDFLAGS) -o /dev/null 2>probe4lstdfs.err >/dev/null && echo '-Wl,--allow-multiple-definition -lstdc++fs'))$(LIB_STDCXXFS)
endif endif
ifneq ($(make_ge_4_4),1)
.NOTPARALLEL:
WAIT =
else
WAIT = .WAIT
endif
################################################################################ ################################################################################
define uname2sosuffix define uname2sosuffix
@@ -121,12 +136,13 @@ endef
SO_SUFFIX := $(shell $(uname2sosuffix)) SO_SUFFIX := $(shell $(uname2sosuffix))
HEADERS := mdbx.h mdbx.h++ HEADERS := mdbx.h mdbx.h++
LIBRARIES := libmdbx.a libmdbx.$(SO_SUFFIX) LIBRARIES := libmdbx.a libmdbx.$(SO_SUFFIX)
TOOLS := mdbx_stat mdbx_copy mdbx_dump mdbx_load mdbx_chk mdbx_drop TOOLS := chk copy drop dump load stat
MDBX_TOOLS := $(addprefix mdbx_,$(TOOLS))
MANPAGES := mdbx_stat.1 mdbx_copy.1 mdbx_dump.1 mdbx_load.1 mdbx_chk.1 mdbx_drop.1 MANPAGES := mdbx_stat.1 mdbx_copy.1 mdbx_dump.1 mdbx_load.1 mdbx_chk.1 mdbx_drop.1
TIP := // TIP: TIP := // TIP:
.PHONY: all help options lib libs tools clean install uninstall check_buildflags_tag tools-static .PHONY: all help options lib libs tools clean install uninstall check_buildflags_tag tools-static
.PHONY: install-strip install-no-strip strip libmdbx mdbx show-options lib-static lib-shared .PHONY: install-strip install-no-strip strip libmdbx mdbx show-options lib-static lib-shared cmake-build ninja
boolean = $(if $(findstring $(strip $($1)),YES Yes yes y ON On on 1 true True TRUE),1,$(if $(findstring $(strip $($1)),NO No no n OFF Off off 0 false False FALSE),,$(error Wrong value `$($1)` of $1 for YES/NO option))) boolean = $(if $(findstring $(strip $($1)),YES Yes yes y ON On on 1 true True TRUE),1,$(if $(findstring $(strip $($1)),NO No no n OFF Off off 0 false False FALSE),,$(error Wrong value `$($1)` of $1 for YES/NO option)))
select_by = $(if $(call boolean,$(1)),$(2),$(3)) select_by = $(if $(call boolean,$(1)),$(2),$(3))
@@ -148,7 +164,11 @@ else
$(info $(TIP) Use `make V=1` for verbose.) $(info $(TIP) Use `make V=1` for verbose.)
endif endif
all: show-options $(LIBRARIES) $(TOOLS) ifeq ($(UNAME),Darwin)
$(info $(TIP) Use `brew install gnu-sed gnu-tar` and add ones to the beginning of the PATH.)
endif
all: show-options $(LIBRARIES) $(MDBX_TOOLS)
help: help:
@echo " make all - build libraries and tools" @echo " make all - build libraries and tools"
@@ -160,6 +180,7 @@ help:
@echo " make clean " @echo " make clean "
@echo " make install " @echo " make install "
@echo " make uninstall " @echo " make uninstall "
@echo " make cmake-build | ninja - build by CMake & Ninja"
@echo "" @echo ""
@echo " make strip - strip debug symbols from binaries" @echo " make strip - strip debug symbols from binaries"
@echo " make install-no-strip - install explicitly without strip" @echo " make install-no-strip - install explicitly without strip"
@@ -175,6 +196,7 @@ show-options:
@echo " MDBX_BUILD_OPTIONS = $(MDBX_BUILD_OPTIONS)" @echo " MDBX_BUILD_OPTIONS = $(MDBX_BUILD_OPTIONS)"
@echo " MDBX_BUILD_CXX = $(MDBX_BUILD_CXX)" @echo " MDBX_BUILD_CXX = $(MDBX_BUILD_CXX)"
@echo " MDBX_BUILD_TIMESTAMP = $(MDBX_BUILD_TIMESTAMP)" @echo " MDBX_BUILD_TIMESTAMP = $(MDBX_BUILD_TIMESTAMP)"
@echo " MDBX_BUILD_METADATA = $(MDBX_BUILD_METADATA)"
@echo '$(TIP) Use `make options` to listing available build options.' @echo '$(TIP) Use `make options` to listing available build options.'
@echo $(call select_by,MDBX_BUILD_CXX," CXX =`which $(CXX)` | `$(CXX) --version | head -1`"," CC =`which $(CC)` | `$(CC) --version | head -1`") @echo $(call select_by,MDBX_BUILD_CXX," CXX =`which $(CXX)` | `$(CXX) --version | head -1`"," CC =`which $(CC)` | `$(CC) --version | head -1`")
@echo $(call select_by,MDBX_BUILD_CXX," CXXFLAGS =$(CXXFLAGS)"," CFLAGS =$(CFLAGS)") @echo $(call select_by,MDBX_BUILD_CXX," CXXFLAGS =$(CXXFLAGS)"," CFLAGS =$(CFLAGS)")
@@ -202,38 +224,39 @@ options:
@echo "" @echo ""
@echo " MDBX_BUILD_OPTIONS = $(MDBX_BUILD_OPTIONS)" @echo " MDBX_BUILD_OPTIONS = $(MDBX_BUILD_OPTIONS)"
@echo " MDBX_BUILD_TIMESTAMP = $(MDBX_BUILD_TIMESTAMP)" @echo " MDBX_BUILD_TIMESTAMP = $(MDBX_BUILD_TIMESTAMP)"
@echo " MDBX_BUILD_METADATA = $(MDBX_BUILD_METADATA)"
@echo "" @echo ""
@echo "## Assortment items for MDBX_BUILD_OPTIONS:" @echo "## Assortment items for MDBX_BUILD_OPTIONS:"
@echo "## Note that the defaults should already be correct for most platforms;" @echo "## Note that the defaults should already be correct for most platforms;"
@echo "## you should not need to change any of these. Read their descriptions" @echo "## you should not need to change any of these. Read their descriptions"
@echo "## in README and source code (see mdbx.c) if you do." @echo "## in README and source code (see mdbx.c) if you do."
@grep -h '#ifndef MDBX_' mdbx.c | grep -v BUILD | uniq | sed 's/#ifndef / /' @grep -h '#ifndef MDBX_' mdbx.c | grep -v BUILD | sort -u | sed 's/#ifndef / /'
lib libs libmdbx mdbx: libmdbx.a libmdbx.$(SO_SUFFIX) lib libs libmdbx mdbx: libmdbx.a libmdbx.$(SO_SUFFIX)
tools: $(TOOLS) tools: $(MDBX_TOOLS)
tools-static: $(addsuffix .static,$(TOOLS)) $(addsuffix .static-lto,$(TOOLS)) tools-static: $(addsuffix .static,$(MDBX_TOOLS)) $(addsuffix .static-lto,$(MDBX_TOOLS))
strip: all strip: all
@echo ' STRIP libmdbx.$(SO_SUFFIX) $(TOOLS)' @echo ' STRIP libmdbx.$(SO_SUFFIX) $(MDBX_TOOLS)'
$(TRACE )strip libmdbx.$(SO_SUFFIX) $(TOOLS) $(TRACE )strip libmdbx.$(SO_SUFFIX) $(MDBX_TOOLS)
clean: clean:
@echo ' REMOVE ...' @echo ' REMOVE ...'
$(QUIET)rm -rf $(TOOLS) mdbx_test @* *.[ao] *.[ls]o *.$(SO_SUFFIX) *.dSYM *~ tmp.db/* \ $(QUIET)rm -rf $(MDBX_TOOLS) mdbx_test @* *.[ao] *.[ls]o *.$(SO_SUFFIX) *.dSYM *~ tmp.db/* \
*.gcov *.log *.err src/*.o test/*.o mdbx_example dist \ *.gcov *.log *.err src/*.o test/*.o mdbx_example dist @dist-check \
config.h src/config.h src/version.c *.tar* buildflags.tag \ config.h src/config.h src/version.c *.tar* @buildflags.tag @dist-checked.tag \
mdbx_*.static mdbx_*.static-lto mdbx_*.static mdbx_*.static-lto CMakeFiles
MDBX_BUILD_FLAGS =$(strip MDBX_BUILD_CXX=$(MDBX_BUILD_CXX) $(MDBX_BUILD_OPTIONS) $(call select_by,MDBX_BUILD_CXX,$(CXXFLAGS) $(LDFLAGS) $(LIB_STDCXXFS) $(LIBS),$(CFLAGS) $(LDFLAGS) $(LIBS))) MDBX_BUILD_FLAGS =$(strip MDBX_BUILD_CXX=$(MDBX_BUILD_CXX) $(MDBX_BUILD_OPTIONS) $(call select_by,MDBX_BUILD_CXX,$(CXXFLAGS) $(LDFLAGS) $(LIB_STDCXXFS) $(LIBS),$(CFLAGS) $(LDFLAGS) $(LIBS)))
check_buildflags_tag: check_buildflags_tag:
$(QUIET)if [ "$(MDBX_BUILD_FLAGS)" != "$$(cat buildflags.tag 2>&1)" ]; then \ $(QUIET)if [ "$(MDBX_BUILD_FLAGS)" != "$$(cat @buildflags.tag 2>&1)" ]; then \
echo -n " CLEAN for build with specified flags..." && \ echo -n " CLEAN for build with specified flags..." && \
$(MAKE) IOARENA=false CXXSTD= -s clean >/dev/null && echo " Ok" && \ $(MAKE) IOARENA=false CXXSTD= -s clean >/dev/null && echo " Ok" && \
echo '$(MDBX_BUILD_FLAGS)' > buildflags.tag; \ echo '$(MDBX_BUILD_FLAGS)' > @buildflags.tag; \
fi fi
buildflags.tag: check_buildflags_tag @buildflags.tag: check_buildflags_tag
lib-static libmdbx.a: mdbx-static.o $(call select_by,MDBX_BUILD_CXX,mdbx++-static.o) lib-static libmdbx.a: mdbx-static.o $(call select_by,MDBX_BUILD_CXX,mdbx++-static.o)
@echo ' AR $@' @echo ' AR $@'
@@ -243,32 +266,46 @@ lib-shared libmdbx.$(SO_SUFFIX): mdbx-dylib.o $(call select_by,MDBX_BUILD_CXX,md
@echo ' LD $@' @echo ' LD $@'
$(QUIET)$(call select_by,MDBX_BUILD_CXX,$(CXX) $(CXXFLAGS),$(CC) $(CFLAGS)) $^ -pthread -shared $(LDFLAGS) $(call select_by,MDBX_BUILD_CXX,$(LIB_STDCXXFS)) $(LIBS) -o $@ $(QUIET)$(call select_by,MDBX_BUILD_CXX,$(CXX) $(CXXFLAGS),$(CC) $(CFLAGS)) $^ -pthread -shared $(LDFLAGS) $(call select_by,MDBX_BUILD_CXX,$(LIB_STDCXXFS)) $(LIBS) -o $@
ninja-assertions: CMAKE_OPT += -DMDBX_FORCE_ASSERTIONS=ON
ninja-assertions: cmake-build
ninja-debug: CMAKE_OPT += -DCMAKE_BUILD_TYPE=Debug
ninja-debug: cmake-build
ninja: cmake-build
cmake-build:
@echo " RUN: cmake -G Ninja && cmake --build"
$(QUIET)mkdir -p @cmake-ninja-build && $(CMAKE) $(CMAKE_OPT) -G Ninja -S . -B @cmake-ninja-build && $(CMAKE) --build @cmake-ninja-build
ctest: cmake-build
@echo " RUN: ctest .."
$(QUIET)$(CTEST) --test-dir @cmake-ninja-build --parallel `(nproc | sysctl -n hw.ncpu | echo 2) 2>/dev/null` --schedule-random $(CTEST_OPT)
################################################################################ ################################################################################
# Amalgamated source code, i.e. distributed after `make dist` # Amalgamated source code, i.e. distributed after `make dist`
MAN_SRCDIR := man1/ MAN_SRCDIR := man1/
config.h: buildflags.tag mdbx.c $(lastword $(MAKEFILE_LIST)) config.h: @buildflags.tag $(WAIT) mdbx.c $(lastword $(MAKEFILE_LIST)) LICENSE NOTICE
@echo ' MAKE $@' @echo ' MAKE $@'
$(QUIET)(echo '#define MDBX_BUILD_TIMESTAMP "$(MDBX_BUILD_TIMESTAMP)"' \ $(QUIET)(echo '#define MDBX_BUILD_TIMESTAMP "$(MDBX_BUILD_TIMESTAMP)"' \
&& echo "#define MDBX_BUILD_FLAGS \"$$(cat buildflags.tag)\"" \ && echo "#define MDBX_BUILD_FLAGS \"$$(cat @buildflags.tag)\"" \
&& echo '#define MDBX_BUILD_COMPILER "$(shell (LC_ALL=C $(CC) --version || echo 'Please use GCC or CLANG compatible compiler') | head -1)"' \ && echo '#define MDBX_BUILD_COMPILER "$(shell (LC_ALL=C $(CC) --version || echo 'Please use GCC or CLANG compatible compiler') | head -1)"' \
&& echo '#define MDBX_BUILD_TARGET "$(shell set -o pipefail; (LC_ALL=C $(CC) -v 2>&1 | grep -i '^Target:' | cut -d ' ' -f 2- || (LC_ALL=C $(CC) --version | grep -qi e2k && echo E2K) || echo 'Please use GCC or CLANG compatible compiler') | head -1)"' \ && echo '#define MDBX_BUILD_TARGET "$(shell set -o pipefail; (LC_ALL=C $(CC) -v 2>&1 | grep -i '^Target:' | cut -d ' ' -f 2- || (LC_ALL=C $(CC) --version | grep -qi e2k && echo E2K) || echo 'Please use GCC or CLANG compatible compiler') | head -1)"' \
&& echo '#define MDBX_BUILD_CXX $(call select_by,MDBX_BUILD_CXX,1,0)' \
&& echo '#define MDBX_BUILD_METADATA "$(MDBX_BUILD_METADATA)"' \
) >$@ ) >$@
mdbx-dylib.o: config.h mdbx.c mdbx.h $(lastword $(MAKEFILE_LIST)) mdbx-dylib.o: config.h mdbx.c mdbx.h $(lastword $(MAKEFILE_LIST)) LICENSE NOTICE
@echo ' CC $@' @echo ' CC $@'
$(QUIET)$(CC) $(CFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -DLIBMDBX_EXPORTS=1 -c mdbx.c -o $@ $(QUIET)$(CC) $(CFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -DLIBMDBX_EXPORTS=1 -c mdbx.c -o $@
mdbx-static.o: config.h mdbx.c mdbx.h $(lastword $(MAKEFILE_LIST)) mdbx-static.o: config.h mdbx.c mdbx.h $(lastword $(MAKEFILE_LIST)) LICENSE NOTICE
@echo ' CC $@' @echo ' CC $@'
$(QUIET)$(CC) $(CFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -ULIBMDBX_EXPORTS -c mdbx.c -o $@ $(QUIET)$(CC) $(CFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -ULIBMDBX_EXPORTS -c mdbx.c -o $@
mdbx++-dylib.o: config.h mdbx.c++ mdbx.h mdbx.h++ $(lastword $(MAKEFILE_LIST)) mdbx++-dylib.o: config.h mdbx.c++ mdbx.h mdbx.h++ $(lastword $(MAKEFILE_LIST)) LICENSE NOTICE
@echo ' CC $@' @echo ' CC $@'
$(QUIET)$(CXX) $(CXXFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -DLIBMDBX_EXPORTS=1 -c mdbx.c++ -o $@ $(QUIET)$(CXX) $(CXXFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -DLIBMDBX_EXPORTS=1 -c mdbx.c++ -o $@
mdbx++-static.o: config.h mdbx.c++ mdbx.h mdbx.h++ $(lastword $(MAKEFILE_LIST)) mdbx++-static.o: config.h mdbx.c++ mdbx.h mdbx.h++ $(lastword $(MAKEFILE_LIST)) LICENSE NOTICE
@echo ' CC $@' @echo ' CC $@'
$(QUIET)$(CXX) $(CXXFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -ULIBMDBX_EXPORTS -c mdbx.c++ -o $@ $(QUIET)$(CXX) $(CXXFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -ULIBMDBX_EXPORTS -c mdbx.c++ -o $@
@@ -285,11 +322,10 @@ mdbx_%.static-lto: mdbx_%.c config.h mdbx.c mdbx.h
$(QUIET)$(CC) $(CFLAGS) -Os -flto $(MDBX_BUILD_OPTIONS) '-DLIBMDBX_API=' '-DMDBX_CONFIG_H="config.h"' \ $(QUIET)$(CC) $(CFLAGS) -Os -flto $(MDBX_BUILD_OPTIONS) '-DLIBMDBX_API=' '-DMDBX_CONFIG_H="config.h"' \
$< mdbx.c $(EXE_LDFLAGS) $(LIBS) -static -Wl,--strip-all -o $@ $< mdbx.c $(EXE_LDFLAGS) $(LIBS) -static -Wl,--strip-all -o $@
install: $(LIBRARIES) $(MDBX_TOOLS) $(HEADERS)
install: $(LIBRARIES) $(TOOLS) $(HEADERS)
@echo ' INSTALLING...' @echo ' INSTALLING...'
$(QUIET)mkdir -p $(DESTDIR)$(prefix)/bin$(suffix) && \ $(QUIET)mkdir -p $(DESTDIR)$(prefix)/bin$(suffix) && \
$(INSTALL) -p $(EXE_INSTALL_FLAGS) $(TOOLS) $(DESTDIR)$(prefix)/bin$(suffix)/ && \ $(INSTALL) -p $(EXE_INSTALL_FLAGS) $(MDBX_TOOLS) $(DESTDIR)$(prefix)/bin$(suffix)/ && \
mkdir -p $(DESTDIR)$(prefix)/lib$(suffix)/ && \ mkdir -p $(DESTDIR)$(prefix)/lib$(suffix)/ && \
$(INSTALL) -p $(EXE_INSTALL_FLAGS) $(filter-out libmdbx.a,$(LIBRARIES)) $(DESTDIR)$(prefix)/lib$(suffix)/ && \ $(INSTALL) -p $(EXE_INSTALL_FLAGS) $(filter-out libmdbx.a,$(LIBRARIES)) $(DESTDIR)$(prefix)/lib$(suffix)/ && \
mkdir -p $(DESTDIR)$(prefix)/lib$(suffix)/ && \ mkdir -p $(DESTDIR)$(prefix)/lib$(suffix)/ && \
@@ -307,7 +343,7 @@ install-no-strip: install
uninstall: uninstall:
@echo ' UNINSTALLING/REMOVE...' @echo ' UNINSTALLING/REMOVE...'
$(QUIET)rm -f $(addprefix $(DESTDIR)$(prefix)/bin$(suffix)/,$(TOOLS)) \ $(QUIET)rm -f $(addprefix $(DESTDIR)$(prefix)/bin$(suffix)/,$(MDBX_TOOLS)) \
$(addprefix $(DESTDIR)$(prefix)/lib$(suffix)/,$(LIBRARIES)) \ $(addprefix $(DESTDIR)$(prefix)/lib$(suffix)/,$(LIBRARIES)) \
$(addprefix $(DESTDIR)$(prefix)/include/,$(HEADERS)) \ $(addprefix $(DESTDIR)$(prefix)/include/,$(HEADERS)) \
$(addprefix $(DESTDIR)$(mandir)/man1/,$(MANPAGES)) $(addprefix $(DESTDIR)$(mandir)/man1/,$(MANPAGES))
@@ -347,18 +383,17 @@ bench-$(1)_$(2).txt: $(3) $(IOARENA) $(lastword $(MAKEFILE_LIST))
$(QUIET)(export LD_LIBRARY_PATH="./:$$$${LD_LIBRARY_PATH}"; \ $(QUIET)(export LD_LIBRARY_PATH="./:$$$${LD_LIBRARY_PATH}"; \
ldd $(IOARENA) | grep -i $(1) && \ ldd $(IOARENA) | grep -i $(1) && \
$(IOARENA) -D $(1) -B batch -m $(BENCH_CRUD_MODE) -n $(2) \ $(IOARENA) -D $(1) -B batch -m $(BENCH_CRUD_MODE) -n $(2) \
| tee $$@ | grep throughput | sed 's/throughput/batch×N/' && \ | tee $$@ | grep throughput | $(SED) 's/throughput/batch×N/' && \
$(IOARENA) -D $(1) -B crud -m $(BENCH_CRUD_MODE) -n $(2) \ $(IOARENA) -D $(1) -B crud -m $(BENCH_CRUD_MODE) -n $(2) \
| tee -a $$@ | grep throughput | sed 's/throughput/ crud/' && \ | tee -a $$@ | grep throughput | $(SED) 's/throughput/ crud/' && \
$(IOARENA) -D $(1) -B iterate,get,iterate,get,iterate -m $(BENCH_CRUD_MODE) -r 4 -n $(2) \ $(IOARENA) -D $(1) -B iterate,get,iterate,get,iterate -m $(BENCH_CRUD_MODE) -r 4 -n $(2) \
| tee -a $$@ | grep throughput | sed '0,/throughput/{s/throughput/iterate/};s/throughput/ get/' && \ | tee -a $$@ | grep throughput | $(SED) '0,/throughput/{s/throughput/iterate/};s/throughput/ get/' && \
$(IOARENA) -D $(1) -B delete -m $(BENCH_CRUD_MODE) -n $(2) \ $(IOARENA) -D $(1) -B delete -m $(BENCH_CRUD_MODE) -n $(2) \
| tee -a $$@ | grep throughput | sed 's/throughput/ delete/' && \ | tee -a $$@ | grep throughput | $(SED) 's/throughput/ delete/' && \
true) || mv -f $$@ $$@.error true) || mv -f $$@ $$@.error
endef endef
$(eval $(call bench-rule,mdbx,$(NN),libmdbx.$(SO_SUFFIX))) $(eval $(call bench-rule,mdbx,$(NN),libmdbx.$(SO_SUFFIX)))
$(eval $(call bench-rule,sophia,$(NN))) $(eval $(call bench-rule,sophia,$(NN)))

View File

@@ -1,47 +1,177 @@
The OpenLDAP Public License
Version 2.8, 17 August 2003
Redistribution and use of this software and associated documentation Apache License
("Software"), with or without modification, are permitted provided Version 2.0, January 2004
that the following conditions are met: http://www.apache.org/licenses/
1. Redistributions in source form must retain copyright statements TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
and notices,
2. Redistributions in binary form must reproduce applicable copyright 1. Definitions.
statements and notices, this list of conditions, and the following
disclaimer in the documentation and/or other materials provided
with the distribution, and
3. Redistributions must contain a verbatim copy of this document. "License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
The OpenLDAP Foundation may revise this license from time to time. "Licensor" shall mean the copyright owner or entity authorized by
Each revision is distinguished by a version number. You may use the copyright owner that is granting the License.
this Software under terms of this license revision or under the
terms of any subsequent revision of the license.
THIS SOFTWARE IS PROVIDED BY THE OPENLDAP FOUNDATION AND ITS "Legal Entity" shall mean the union of the acting entity and all
CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, other entities that control, are controlled by, or are under common
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY control with that entity. For the purposes of this definition,
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT "control" means (i) the power, direct or indirect, to cause the
SHALL THE OPENLDAP FOUNDATION, ITS CONTRIBUTORS, OR THE AUTHOR(S) direction or management of such entity, whether by contract or
OR OWNER(S) OF THE SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, otherwise, or (ii) ownership of fifty percent (50%) or more of the
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, outstanding shares, or (iii) beneficial ownership of such entity.
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
The names of the authors and copyright holders must not be used in "You" (or "Your") shall mean an individual or Legal Entity
advertising or otherwise to promote the sale, use or other dealing exercising permissions granted by this License.
in this Software without specific, written prior permission. Title
to copyright in this Software shall at all times remain with copyright
holders.
OpenLDAP is a registered trademark of the OpenLDAP Foundation. "Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
Copyright 1999-2003 The OpenLDAP Foundation, Redwood City, "Object" form shall mean any form resulting from mechanical
California, USA. All Rights Reserved. Permission to copy and transformation or translation of a Source form, including but
distribute verbatim copies of this document is granted. not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

View File

@@ -1,14 +1,15 @@
# This is thunk-Makefile for calling GNU Make 3.80 or above # This is thunk-Makefile for calling GNU Make 3.80 or above
all help options \ all help options cmake-build ninja \
clean install install-no-strip install-strip strip tools uninstall \ clean install install-no-strip install-strip strip tools uninstall \
bench bench-clean bench-couple bench-quartet bench-triplet re-bench \ bench bench-clean bench-couple bench-quartet bench-triplet re-bench \
lib libs lib-static lib-shared tools-static \ lib libs lib-static lib-shared tools-static \
libmdbx mdbx mdbx_chk mdbx_copy mdbx_drop mdbx_dump mdbx_load mdbx_stat \ libmdbx mdbx mdbx_chk mdbx_copy mdbx_drop mdbx_dump mdbx_load mdbx_stat \
check dist memcheck cross-gcc cross-qemu doxygen gcc-analyzer reformat \ check dist memcheck cross-gcc cross-qemu doxygen gcc-analyzer reformat \
release-assets tags test build-test mdbx_test smoke smoke-fault smoke-singleprocess \ release-assets tags build-test mdbx_test \
smoke-assertion test-assertion long-test-assertion \ smoke smoke-fault smoke-singleprocess smoke-assertion smoke-memcheck \
test-asan test-leak test-singleprocess test-ubsan test-valgrind: test test-assertion test-long test-long-assertion test-ci test-ci-extra \
test-asan test-leak test-singleprocess test-ubsan test-memcheck:
@CC=$(CC) \ @CC=$(CC) \
CXX=`if test -n "$(CXX)" && which "$(CXX)" > /dev/null; then echo "$(CXX)"; elif test -n "$(CCC)" && which "$(CCC)" > /dev/null; then echo "$(CCC)"; else echo "c++"; fi` \ CXX=`if test -n "$(CXX)" && which "$(CXX)" > /dev/null; then echo "$(CXX)"; elif test -n "$(CCC)" && which "$(CCC)" > /dev/null; then echo "$(CCC)"; else echo "c++"; fi` \
`which gmake || which gnumake || echo 'echo "GNU Make 3.80 or above is required"; exit 2;'` \ `which gmake || which gnumake || echo 'echo "GNU Make 3.80 or above is required"; exit 2;'` \

View File

@@ -0,0 +1,39 @@
libmdbx (aka MDBX) is an extremely fast, compact, powerful, embeddedable,
transactional key-value storage engine with open-source code. MDBX has a
specific set of properties and capabilities, focused on creating unique
lightweight solutions.
Please visit https://libmdbx.dqdkfa.ru for more information, changelog,
documentation, C++ API description and links to the original git repo
with the source code. Questions, feedback and suggestions are welcome
to the Telegram' group https://t.me/libmdbx.
Donations are welcome to the Ethereum/ERC-20 `0xD104d8f8B2dC312aaD74899F83EBf3EEBDC1EA3A`.
Всё будет хорошо!
Copyright 2015-2025 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru>
SPDX-License-Identifier: Apache-2.0
For notes about the license change, credits and acknowledgments,
please refer to the COPYRIGHT file within libmdbx source.
---
On 2022-04-15, without any warnings or following explanations, the
Github administration deleted _libmdbx_, my account and all other
projects (status 404). A few months later, without any involvement or
notification from/to me, the projects were restored/opened in the "public
read-only archive" status from some kind of incomplete backup. I regard
these actions of Github as malicious sabotage, and I consider the Github
service itself to have lost trust forever.
As a result of what has happened, I will never, under any circumstances,
post the primary sources (aka origins) of my projects on Github, or rely
in any way on the Github infrastructure.
Nevertheless, realizing that it is more convenient for users of
_libmdbx_ and other my projects to access ones on Github, I do not want
to restrict their freedom or create inconvenience, and therefore I place
mirrors (aka mirrors) of such repositories on Github since 2025. At the
same time, I would like to emphasize once again that these are only
mirrors that can be frozen, blocked or deleted at any time, as was the
case in 2022.

View File

@@ -0,0 +1 @@
{ "git_describe": "v0.13.6-0-ga971c76a", "git_timestamp": "2025-04-22T11:53:23+03:00", "git_tree": "4ca2c913e8614a1ed09512353faa227f25245e9f", "git_commit": "a971c76afffbb2ce0aa6151f4683b94fe10dc843", "semver": "0.13.6" }

View File

@@ -1 +0,0 @@
0.12.13.0

View File

@@ -1,17 +1,5 @@
## Copyright (c) 2012-2024 Leonid Yuriev <leo@yuriev.ru>. # Copyright (c) 2010-2025 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> ###############################################
## # SPDX-License-Identifier: Apache-2.0
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
if(CMAKE_VERSION VERSION_LESS 3.8.2) if(CMAKE_VERSION VERSION_LESS 3.8.2)
cmake_minimum_required(VERSION 3.0.2) cmake_minimum_required(VERSION 3.0.2)
@@ -43,9 +31,11 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.9)
cmake_policy(SET CMP0069 NEW) cmake_policy(SET CMP0069 NEW)
endif() endif()
cmake_policy(SET CMP0054 NEW)
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(FATAL_ERROR "CMake from MSVC kit is unfit! " message(FATAL_ERROR "CMake from MSVC kit is unfit! "
"Please use MSVC2019 with modern CMake the original CMake from https://cmake.org/download/") "Please use MSVC-2019 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))
@@ -67,11 +57,11 @@ include(CheckLibraryExists)
include(CheckIncludeFiles) include(CheckIncludeFiles)
# Check if the same compile family is used for both C and CXX # Check if the same compile family is used for both C and CXX
if(CMAKE_C_COMPILER_LOADED AND CMAKE_CXX_COMPILER_LOADED AND if(CMAKE_C_COMPILER_LOADED
NOT (CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID)) AND CMAKE_CXX_COMPILER_LOADED
AND NOT (CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID))
message(WARNING "CMAKE_C_COMPILER_ID (${CMAKE_C_COMPILER_ID}) is different " 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)
@@ -88,27 +78,29 @@ 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 # We support building with Clang and gcc. First check what we're using for build.
# what we're using for 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 ".*[Cc][Ll][Aa][Nn][Gg].*") if(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_ID MATCHES ".*[Cc][Ll][Aa][Nn][Gg].*")
set(CMAKE_COMPILER_IS_CLANG ON) set(CMAKE_COMPILER_IS_CLANG ON)
set(CMAKE_COMPILER_IS_GNUCXX OFF) set(CMAKE_COMPILER_IS_GNUCXX OFF)
endif() endif()
if(CMAKE_C_COMPILER_LOADED) if(CMAKE_C_COMPILER_LOADED)
# Check for Elbrus lcc # Check for Elbrus lcc
execute_process(COMMAND ${CMAKE_C_COMPILER} --version execute_process(
COMMAND ${CMAKE_C_COMPILER} --version
OUTPUT_VARIABLE tmp_lcc_probe_version OUTPUT_VARIABLE tmp_lcc_probe_version
RESULT_VARIABLE tmp_lcc_probe_result ERROR_QUIET) RESULT_VARIABLE tmp_lcc_probe_result
ERROR_QUIET)
if(tmp_lcc_probe_result EQUAL 0) if(tmp_lcc_probe_result EQUAL 0)
string(FIND "${tmp_lcc_probe_version}" "lcc:" tmp_lcc_marker) string(FIND "${tmp_lcc_probe_version}" "lcc:" tmp_lcc_marker)
string(FIND "${tmp_lcc_probe_version}" ":e2k-" tmp_e2k_marker) string(FIND "${tmp_lcc_probe_version}" ":e2k-" tmp_e2k_marker)
if(tmp_lcc_marker GREATER -1 AND tmp_e2k_marker GREATER tmp_lcc_marker) if(tmp_lcc_marker GREATER -1 AND tmp_e2k_marker GREATER tmp_lcc_marker)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-version execute_process(
COMMAND ${CMAKE_C_COMPILER} -print-version
OUTPUT_VARIABLE CMAKE_C_COMPILER_VERSION OUTPUT_VARIABLE CMAKE_C_COMPILER_VERSION
RESULT_VARIABLE tmp_lcc_probe_result RESULT_VARIABLE tmp_lcc_probe_result
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -127,14 +119,17 @@ endif()
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
# Check for Elbrus l++ # Check for Elbrus l++
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version execute_process(
COMMAND ${CMAKE_CXX_COMPILER} --version
OUTPUT_VARIABLE tmp_lxx_probe_version OUTPUT_VARIABLE tmp_lxx_probe_version
RESULT_VARIABLE tmp_lxx_probe_result ERROR_QUIET) RESULT_VARIABLE tmp_lxx_probe_result
ERROR_QUIET)
if(tmp_lxx_probe_result EQUAL 0) if(tmp_lxx_probe_result EQUAL 0)
string(FIND "${tmp_lxx_probe_version}" "lcc:" tmp_lcc_marker) string(FIND "${tmp_lxx_probe_version}" "lcc:" tmp_lcc_marker)
string(FIND "${tmp_lxx_probe_version}" ":e2k-" tmp_e2k_marker) string(FIND "${tmp_lxx_probe_version}" ":e2k-" tmp_e2k_marker)
if(tmp_lcc_marker GREATER -1 AND tmp_e2k_marker GREATER tmp_lcc_marker) if(tmp_lcc_marker GREATER -1 AND tmp_e2k_marker GREATER tmp_lcc_marker)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-version execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -print-version
OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION
RESULT_VARIABLE tmp_lxx_probe_result RESULT_VARIABLE tmp_lxx_probe_result
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -151,20 +146,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 # Hard coding the compiler version is ugly from cmake POV, but at least gives user a friendly error message. The most
# at least gives user a friendly error message. The most critical # critical demand for C++ compiler is support of C++11 lambdas, added only in version 4.5
# demand for C++ compiler is support of C++11 lambdas, added # https://gcc.gnu.org/projects/cxx0x.html
# only in version 4.5 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 if(CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 AND NOT CMAKE_COMPILER_IS_ELBRUSC)
AND NOT 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()
@@ -174,7 +166,8 @@ if(CMAKE_CL_64)
set(MSVC64 1) set(MSVC64 1)
endif() endif()
if(WIN32 AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}) if(WIN32 AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG})
execute_process(COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -dumpmachine execute_process(
COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -dumpmachine
OUTPUT_VARIABLE __GCC_TARGET_MACHINE OUTPUT_VARIABLE __GCC_TARGET_MACHINE
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
if(__GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64") if(__GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64")
@@ -184,9 +177,12 @@ if(WIN32 AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG})
endif() endif()
if(NOT DEFINED IOS) if(NOT DEFINED IOS)
if(APPLE AND (CMAKE_SYSTEM_NAME STREQUAL "iOS" if(APPLE
OR DEFINED CMAKE_IOS_DEVELOPER_ROOT AND (CMAKE_SYSTEM_NAME STREQUAL "iOS"
OR DEFINED IOS_PLATFORM OR DEFINED IOS_ARCH)) OR DEFINED CMAKE_IOS_DEVELOPER_ROOT
OR DEFINED IOS_PLATFORM
OR DEFINED IOS_ARCH
))
set(IOS TRUE) set(IOS TRUE)
else() else()
set(IOS FALSE) set(IOS FALSE)
@@ -194,9 +190,9 @@ if(NOT DEFINED IOS)
endif() endif()
if(NOT DEFINED CMAKE_TARGET_BITNESS) if(NOT DEFINED CMAKE_TARGET_BITNESS)
if (CMAKE_SIZEOF_VOID_P LESS 4) if(CMAKE_SIZEOF_VOID_P LESS 4)
set(CMAKE_TARGET_BITNESS 16) set(CMAKE_TARGET_BITNESS 16)
elseif (CMAKE_SIZEOF_VOID_P LESS 8) elseif(CMAKE_SIZEOF_VOID_P LESS 8)
set(CMAKE_TARGET_BITNESS 32) set(CMAKE_TARGET_BITNESS 32)
else() else()
set(CMAKE_TARGET_BITNESS 64) set(CMAKE_TARGET_BITNESS 64)
@@ -237,12 +233,18 @@ if(NOT CMAKE_SYSTEM_ARCH)
set(MIPS32 TRUE) set(MIPS32 TRUE)
endif() endif()
endif() endif()
elseif(CMAKE_COMPILER_IS_ELBRUSC OR CMAKE_COMPILER_IS_ELBRUSCXX elseif(
OR CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ID STREQUAL "LCC" CMAKE_COMPILER_IS_ELBRUSC
OR CMAKE_SYSTEM_PROCESSOR MATCHES "e2k.*|E2K.*|elbrus.*|ELBRUS.*") OR CMAKE_COMPILER_IS_ELBRUSCXX
OR CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_ID STREQUAL "LCC"
OR CMAKE_SYSTEM_PROCESSOR MATCHES "e2k.*|E2K.*|elbrus.*|ELBRUS.*")
set(E2K TRUE) set(E2K TRUE)
set(CMAKE_SYSTEM_ARCH "Elbrus") set(CMAKE_SYSTEM_ARCH "Elbrus")
elseif(MSVC64 OR MINGW64 OR MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING)) elseif(
MSVC64
OR MINGW64
OR MINGW
OR (MSVC AND NOT CMAKE_CROSSCOMPILING))
if(CMAKE_TARGET_BITNESS EQUAL 64) 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")
@@ -322,15 +324,19 @@ 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)
elseif(CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR) elseif(CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET FALSE) set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET FALSE)
elseif(CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME elseif(
AND ((CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_PROCESSOR) CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME
OR (CMAKE_SYSTEM_ARCH STREQUAL CMAKE_HOST_ARCH) AND ((CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_PROCESSOR)
OR (WIN32 AND CMAKE_HOST_WIN32 AND X86_32 AND CMAKE_HOST_ARCH STREQUAL "x86_64"))) OR (CMAKE_SYSTEM_ARCH STREQUAL CMAKE_HOST_ARCH)
OR (WIN32
AND CMAKE_HOST_WIN32
AND X86_32
AND CMAKE_HOST_ARCH STREQUAL "x86_64"
)
))
set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET TRUE) set(CMAKE_HOST_CAN_RUN_EXECUTABLES_BUILT_FOR_TARGET TRUE)
message(STATUS message(STATUS "Assume СAN RUN A BUILT EXECUTABLES," " since host (${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_ARCH})"
"Assume СAN RUN A BUILT EXECUTABLES," " match target (${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_ARCH})")
" since host (${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_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)
@@ -352,9 +358,8 @@ 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 # GCC started to warn for unused result starting from 4.2, and this is when it introduced -Wno-unused-result GCC can
# this is when it introduced -Wno-unused-result # also be built on top of llvm runtime (on mac).
# GCC can also be built on top of llvm runtime (on mac).
check_compiler_flag("-Wno-unknown-pragmas" CC_HAS_WNO_UNKNOWN_PRAGMAS) check_compiler_flag("-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)
@@ -379,15 +384,21 @@ else()
# Check for an omp support # Check for an omp support
set(CMAKE_REQUIRED_FLAGS "-fopenmp -Werror") set(CMAKE_REQUIRED_FLAGS "-fopenmp -Werror")
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
check_cxx_source_compiles("int main(void) { check_cxx_source_compiles(
#pragma omp parallel "int main(void) {
return 0; #pragma omp for
}" HAVE_OPENMP) for(int i = 0, j = 0; i != 42; i = 1 + i * 12345) j += i % 43;
return j;
}"
HAVE_OPENMP)
else() else()
check_c_source_compiles("int main(void) { check_c_source_compiles(
#pragma omp parallel "int main(void) {
return 0; #pragma omp for
}" HAVE_OPENMP) for(int i = 0, j = 0; i != 42; i = 1 + i * 12345) j += i % 43;
return j;
}"
HAVE_OPENMP)
endif() endif()
set(CMAKE_REQUIRED_FLAGS "") set(CMAKE_REQUIRED_FLAGS "")
endif() endif()
@@ -396,9 +407,13 @@ endif()
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 HAS_CXX11) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 HAS_CXX11)
if(HAS_CXX11 LESS 0) if(HAS_CXX11 LESS 0)
check_cxx_compiler_flag("-std=gnu++11" CXX_FALLBACK_GNU11) if(MSVC)
if(NOT CXX_FALLBACK_GNU11) check_cxx_compiler_flag("/std:c++11" CXX_FALLBACK_11)
check_cxx_compiler_flag("-std=c++11" CXX_FALLBACK_11) else()
check_cxx_compiler_flag("-std=gnu++11" CXX_FALLBACK_GNU11)
if(NOT CXX_FALLBACK_GNU11)
check_cxx_compiler_flag("-std=c++11" CXX_FALLBACK_11)
endif()
endif() endif()
endif() endif()
endif() endif()
@@ -407,7 +422,7 @@ endif()
if(CMAKE_C_COMPILER_LOADED) if(CMAKE_C_COMPILER_LOADED)
list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11) list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11)
if(HAS_C11 LESS 0) if(HAS_C11 LESS 0)
if (MSVC) if(MSVC)
check_c_compiler_flag("/std:c11" C_FALLBACK_11) check_c_compiler_flag("/std:c11" C_FALLBACK_11)
else() else()
check_c_compiler_flag("-std=gnu11" C_FALLBACK_GNU11) check_c_compiler_flag("-std=gnu11" C_FALLBACK_GNU11)
@@ -419,13 +434,17 @@ if(CMAKE_C_COMPILER_LOADED)
endif() endif()
# Check for LTO support by GCC # Check for LTO support by GCC
if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} AND NOT CMAKE_COMPILER_IS_ELBRUSC AND NOT CMAKE_COMPILER_IS_ELBRUSCXX) if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}
AND NOT CMAKE_COMPILER_IS_ELBRUSC
AND NOT CMAKE_COMPILER_IS_ELBRUSCXX)
unset(gcc_collect) unset(gcc_collect)
unset(gcc_lto_wrapper) unset(gcc_lto_wrapper)
if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 4.7) if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 4.7)
execute_process(COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -v execute_process(
OUTPUT_VARIABLE gcc_info_v ERROR_VARIABLE gcc_info_v) COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -v
OUTPUT_VARIABLE gcc_info_v
ERROR_VARIABLE gcc_info_v)
string(REGEX MATCH "^(.+\nCOLLECT_GCC=)([^ \n]+)(\n.+)$" gcc_collect_valid ${gcc_info_v}) string(REGEX MATCH "^(.+\nCOLLECT_GCC=)([^ \n]+)(\n.+)$" gcc_collect_valid ${gcc_info_v})
if(gcc_collect_valid) if(gcc_collect_valid)
@@ -434,7 +453,8 @@ if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} AND NOT CMAKE_COMPILER_IS_ELBRUSC
string(REGEX MATCH "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" gcc_lto_wrapper_valid ${gcc_info_v}) string(REGEX MATCH "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" gcc_lto_wrapper_valid ${gcc_info_v})
if(gcc_lto_wrapper_valid) if(gcc_lto_wrapper_valid)
string(REGEX REPLACE "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" "\\2" gcc_lto_wrapper ${gcc_info_v}) string(REGEX REPLACE "^(.+\nCOLLECT_LTO_WRAPPER=)([^ \n]+/lto-wrapper)(\n.+)$" "\\2" gcc_lto_wrapper
${gcc_info_v})
endif() endif()
set(gcc_suffix "") set(gcc_suffix "")
@@ -447,13 +467,25 @@ if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} AND NOT CMAKE_COMPILER_IS_ELBRUSC
get_filename_component(gcc_dir ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY) get_filename_component(gcc_dir ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} DIRECTORY)
if(NOT CMAKE_GCC_AR) if(NOT CMAKE_GCC_AR)
find_program(CMAKE_GCC_AR NAMES "gcc${gcc_suffix}-ar" "gcc-ar${gcc_suffix}" PATHS "${gcc_dir}" NO_DEFAULT_PATH) find_program(
CMAKE_GCC_AR
NAMES "gcc${gcc_suffix}-ar" "gcc-ar${gcc_suffix}"
PATHS "${gcc_dir}"
NO_DEFAULT_PATH)
endif() endif()
if(NOT CMAKE_GCC_NM) if(NOT CMAKE_GCC_NM)
find_program(CMAKE_GCC_NM NAMES "gcc${gcc_suffix}-nm" "gcc-nm${gcc_suffix}" PATHS "${gcc_dir}" NO_DEFAULT_PATH) find_program(
CMAKE_GCC_NM
NAMES "gcc${gcc_suffix}-nm" "gcc-nm${gcc_suffix}"
PATHS "${gcc_dir}"
NO_DEFAULT_PATH)
endif() endif()
if(NOT CMAKE_GCC_RANLIB) if(NOT CMAKE_GCC_RANLIB)
find_program(CMAKE_GCC_RANLIB NAMES "gcc${gcc_suffix}-ranlib" "gcc-ranlib${gcc_suffix}" PATHS "${gcc_dir}" NO_DEFAULT_PATH) find_program(
CMAKE_GCC_RANLIB
NAMES "gcc${gcc_suffix}-ranlib" "gcc-ranlib${gcc_suffix}"
PATHS "${gcc_dir}"
NO_DEFAULT_PATH)
endif() endif()
unset(gcc_dir) unset(gcc_dir)
@@ -465,9 +497,16 @@ if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} AND NOT CMAKE_COMPILER_IS_ELBRUSC
unset(gcc_info_v) unset(gcc_info_v)
endif() endif()
if(CMAKE_GCC_AR AND CMAKE_GCC_NM AND CMAKE_GCC_RANLIB AND gcc_lto_wrapper) if(CMAKE_GCC_AR
AND CMAKE_GCC_NM
AND CMAKE_GCC_RANLIB
AND gcc_lto_wrapper)
message(STATUS "Found GCC's LTO toolset: ${gcc_lto_wrapper}, ${CMAKE_GCC_AR}, ${CMAKE_GCC_RANLIB}") message(STATUS "Found GCC's LTO toolset: ${gcc_lto_wrapper}, ${CMAKE_GCC_AR}, ${CMAKE_GCC_RANLIB}")
set(GCC_LTO_CFLAGS "-flto -fno-fat-lto-objects -fuse-linker-plugin") if(CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 11.4)
set(GCC_LTO_CFLAGS "-flto -fno-fat-lto-objects -fuse-linker-plugin")
else()
set(GCC_LTO_CFLAGS "-flto=auto -fno-fat-lto-objects -fuse-linker-plugin")
endif()
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")
else() else()
@@ -491,8 +530,11 @@ endif()
# Check for LTO support by CLANG # Check for LTO support by CLANG
if(CMAKE_COMPILER_IS_CLANG) if(CMAKE_COMPILER_IS_CLANG)
if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 3.5) if(NOT CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 3.5)
execute_process(COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -print-search-dirs execute_process(
OUTPUT_VARIABLE clang_search_dirs RESULT_VARIABLE clang_probe_result ERROR_QUIET) COMMAND ${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER} -print-search-dirs
OUTPUT_VARIABLE clang_search_dirs
RESULT_VARIABLE clang_probe_result
ERROR_QUIET)
unset(clang_bindirs) unset(clang_bindirs)
unset(clang_bindirs_x) unset(clang_bindirs_x)
@@ -503,13 +545,21 @@ if(CMAKE_COMPILER_IS_CLANG)
if(regexp_valid) if(regexp_valid)
string(REGEX REPLACE "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" "\\3" list ${clang_search_dirs}) string(REGEX REPLACE "(^|\n.*)(.*programs: =)([^\n]+)((\n.*)|$)" "\\3" list ${clang_search_dirs})
string(REPLACE ":" ";" list "${list}") string(REPLACE ":" ";" list "${list}")
set(libs_extra_subdirs "lib;../lib;lib64;../lib64;lib32;../lib32")
foreach(dir IN LISTS list) foreach(dir IN LISTS list)
get_filename_component(dir "${dir}" REALPATH) get_filename_component(dir "${dir}" REALPATH)
if(dir MATCHES ".*llvm.*" OR dir MATCHES ".*clang.*") if(dir MATCHES ".*llvm.*" OR dir MATCHES ".*clang.*")
list(APPEND clang_bindirs "${dir}") set(list_suffix "")
else() else()
list(APPEND clang_bindirs_x "${dir}") set(list_suffix "_x")
endif() endif()
list(APPEND clang_bindirs${list_suffix} "${dir}")
foreach(subdir IN LISTS libs_extra_subdirs)
get_filename_component(subdir "${dir}/${subdir}" REALPATH)
if(EXISTS "${subdir}")
list(APPEND clang_libdirs${list_suffix} "${subdir}")
endif()
endforeach()
endforeach() endforeach()
list(APPEND clang_bindirs "${clang_bindirs_x}") list(APPEND clang_bindirs "${clang_bindirs_x}")
list(REMOVE_DUPLICATES clang_bindirs) list(REMOVE_DUPLICATES clang_bindirs)
@@ -521,10 +571,11 @@ if(CMAKE_COMPILER_IS_CLANG)
foreach(dir IN LISTS list) foreach(dir IN LISTS list)
get_filename_component(dir "${dir}" REALPATH) get_filename_component(dir "${dir}" REALPATH)
if(dir MATCHES ".*llvm.*" OR dir MATCHES ".*clang.*") if(dir MATCHES ".*llvm.*" OR dir MATCHES ".*clang.*")
list(APPEND clang_libdirs "${dir}") set(list_suffix "")
else() else()
list(APPEND clang_libdirs_x "${dir}") set(list_suffix "_x")
endif() endif()
list(APPEND clang_libdirs${list_suffix} "${dir}")
endforeach() endforeach()
list(APPEND clang_libdirs "${clang_libdirs_x}") list(APPEND clang_libdirs "${clang_libdirs_x}")
list(REMOVE_DUPLICATES clang_libdirs) list(REMOVE_DUPLICATES clang_libdirs)
@@ -545,24 +596,46 @@ if(CMAKE_COMPILER_IS_CLANG)
endif() endif()
if(NOT CMAKE_CLANG_LD AND clang_bindirs) if(NOT CMAKE_CLANG_LD AND clang_bindirs)
find_program(CMAKE_CLANG_LD NAMES lld-link ld.lld "ld${CMAKE_TARGET_BITNESS}.lld" lld llvm-link llvm-ld PATHS ${clang_bindirs} NO_DEFAULT_PATH) find_program(
CMAKE_CLANG_LD
NAMES lld-link ld.lld "ld${CMAKE_TARGET_BITNESS}.lld" lld llvm-link llvm-ld
PATHS ${clang_bindirs}
NO_DEFAULT_PATH)
endif() endif()
if(NOT CMAKE_CLANG_AR AND clang_bindirs) if(NOT CMAKE_CLANG_AR AND clang_bindirs)
find_program(CMAKE_CLANG_AR NAMES llvm-ar ar PATHS ${clang_bindirs} NO_DEFAULT_PATH) find_program(
CMAKE_CLANG_AR
NAMES llvm-ar ar
PATHS ${clang_bindirs}
NO_DEFAULT_PATH)
endif() endif()
if(NOT CMAKE_CLANG_NM AND clang_bindirs) if(NOT CMAKE_CLANG_NM AND clang_bindirs)
find_program(CMAKE_CLANG_NM NAMES llvm-nm nm PATHS ${clang_bindirs} NO_DEFAULT_PATH) find_program(
CMAKE_CLANG_NM
NAMES llvm-nm nm
PATHS ${clang_bindirs}
NO_DEFAULT_PATH)
endif() endif()
if(NOT CMAKE_CLANG_RANLIB AND clang_bindirs) if(NOT CMAKE_CLANG_RANLIB AND clang_bindirs)
find_program(CMAKE_CLANG_RANLIB NAMES llvm-ranlib ranlib PATHS ${clang_bindirs} NO_DEFAULT_PATH) find_program(
CMAKE_CLANG_RANLIB
NAMES llvm-ranlib ranlib
PATHS ${clang_bindirs}
NO_DEFAULT_PATH)
endif() endif()
set(clang_lto_plugin_name "LLVMgold${CMAKE_SHARED_LIBRARY_SUFFIX}") set(clang_lto_plugin_name "LLVMgold${CMAKE_SHARED_LIBRARY_SUFFIX}")
if(NOT CMAKE_LD_GOLD AND clang_bindirs) if(NOT CMAKE_LD_GOLD AND clang_bindirs)
find_program(CMAKE_LD_GOLD NAMES ld.gold PATHS ${clang_bindirs}) find_program(
CMAKE_LD_GOLD
NAMES ld.gold
PATHS ${clang_bindirs})
endif() endif()
if(NOT CLANG_LTO_PLUGIN AND clang_libdirs) if(NOT CLANG_LTO_PLUGIN AND clang_libdirs)
find_file(CLANG_LTO_PLUGIN ${clang_lto_plugin_name} PATHS ${clang_libdirs} NO_DEFAULT_PATH) find_file(
CLANG_LTO_PLUGIN ${clang_lto_plugin_name}
PATHS ${clang_libdirs}
NO_DEFAULT_PATH)
endif() endif()
if(CLANG_LTO_PLUGIN) if(CLANG_LTO_PLUGIN)
@@ -577,7 +650,9 @@ if(CMAKE_COMPILER_IS_CLANG)
message(STATUS "Could NOT find CLANG/LLVM's linker (lld, llvm-ld, llvm-link) for LTO.") message(STATUS "Could NOT find CLANG/LLVM's linker (lld, llvm-ld, llvm-link) for LTO.")
endif() endif()
if(CMAKE_CLANG_AR AND CMAKE_CLANG_RANLIB AND CMAKE_CLANG_NM) if(CMAKE_CLANG_AR
AND CMAKE_CLANG_RANLIB
AND CMAKE_CLANG_NM)
message(STATUS "Found CLANG/LLVM's binutils for LTO: ${CMAKE_CLANG_AR}, ${CMAKE_CLANG_RANLIB}, ${CMAKE_CLANG_NM}") message(STATUS "Found CLANG/LLVM's binutils for LTO: ${CMAKE_CLANG_AR}, ${CMAKE_CLANG_RANLIB}, ${CMAKE_CLANG_NM}")
else() else()
message(STATUS "Could NOT find CLANG/LLVM's binutils (ar, ranlib, nm) for LTO.") message(STATUS "Could NOT find CLANG/LLVM's binutils (ar, ranlib, nm) for LTO.")
@@ -590,15 +665,16 @@ if(CMAKE_COMPILER_IS_CLANG)
unset(clang_search_dirs) unset(clang_search_dirs)
endif() endif()
if(CMAKE_CLANG_AR AND CMAKE_CLANG_NM AND CMAKE_CLANG_RANLIB if(CMAKE_CLANG_AR
AND ((CLANG_LTO_PLUGIN AND CMAKE_LD_GOLD) AND CMAKE_CLANG_NM
OR (CMAKE_CLANG_LD AND CMAKE_CLANG_RANLIB
AND NOT (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND ((CLANG_LTO_PLUGIN AND CMAKE_LD_GOLD)
AND CMAKE_SYSTEM_NAME STREQUAL "Linux")) OR CMAKE_CLANG_LD
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(STATUS "Link-Time Optimization by CLANG/LLVM is available but unusable due https://reviews.llvm.org/D79919") message(
STATUS "Link-Time Optimization by CLANG/LLVM is available but unusable due https://reviews.llvm.org/D79919")
else() 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")
@@ -625,17 +701,22 @@ if(CMAKE_COMPILER_IS_CLANG)
endif() endif()
# Perform build type specific configuration. # Perform build type specific configuration.
option(ENABLE_BACKTRACE "Enable output of fiber backtrace information in 'show option(
ENABLE_BACKTRACE
"Enable output of fiber backtrace information in 'show
fiber' administrative command. Only works on x86 architectures, if compiled fiber' administrative command. Only works on x86 architectures, if compiled
with gcc. If GNU binutils and binutils-dev libraries are installed, backtrace with gcc. If GNU binutils and binutils-dev libraries are installed, backtrace
is output with resolved function (symbol) names. Otherwise only frame is output with resolved function (symbol) names. Otherwise only frame
addresses are printed." OFF) addresses are printed."
OFF)
set(HAVE_BFD FALSE) set(HAVE_BFD FALSE)
if(ENABLE_BACKTRACE) if(ENABLE_BACKTRACE)
if(NOT (X86_32 OR X86_64) OR NOT CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}) if(NOT (X86_32 OR X86_64) OR NOT CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG})
# We only know this option to work with gcc # We only know this option to work with gcc
message(FATAL_ERROR "ENABLE_BACKTRACE option is set but the system message(
FATAL_ERROR
"ENABLE_BACKTRACE option is set but the system
is not x86 based (${CMAKE_SYSTEM_PROCESSOR}) or the compiler is not x86 based (${CMAKE_SYSTEM_PROCESSOR}) or the compiler
is not GNU GCC (${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER}).") is not GNU GCC (${CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER}).")
endif() endif()
@@ -652,11 +733,13 @@ if(ENABLE_BACKTRACE)
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)
if(HAVE_BFD_LIB AND HAVE_BFD_H AND HAVE_IBERTY_LIB AND ZLIB_FOUND) if(HAVE_BFD_LIB
AND HAVE_BFD_H
AND HAVE_IBERTY_LIB
AND ZLIB_FOUND)
set(HAVE_BFD ON) set(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()
@@ -667,16 +750,30 @@ macro(setup_compile_flags)
# save initial C/CXX flags # save initial C/CXX flags
if(NOT INITIAL_CMAKE_FLAGS_SAVED) if(NOT INITIAL_CMAKE_FLAGS_SAVED)
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
set(INITIAL_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) set(INITIAL_CMAKE_CXX_FLAGS
${CMAKE_CXX_FLAGS}
CACHE STRING "Initial CMake's flags" FORCE)
endif() endif()
if(CMAKE_C_COMPILER_LOADED) if(CMAKE_C_COMPILER_LOADED)
set(INITIAL_CMAKE_C_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) set(INITIAL_CMAKE_C_FLAGS
${CMAKE_C_FLAGS}
CACHE STRING "Initial CMake's flags" FORCE)
endif() endif()
set(INITIAL_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) set(INITIAL_CMAKE_EXE_LINKER_FLAGS
set(INITIAL_CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) ${CMAKE_EXE_LINKER_FLAGS}
set(INITIAL_CMAKE_STATIC_LINKER_FLAGS ${CMAKE_STATIC_LINKER_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) CACHE STRING "Initial CMake's flags" FORCE)
set(INITIAL_CMAKE_MODULE_LINKER_FLAGS ${CMAKE_MODULE_LINKER_FLAGS} CACHE STRING "Initial CMake's flags" FORCE) set(INITIAL_CMAKE_SHARED_LINKER_FLAGS
set(INITIAL_CMAKE_FLAGS_SAVED TRUE CACHE INTERNAL "State of initial CMake's flags" FORCE) ${CMAKE_SHARED_LINKER_FLAGS}
CACHE STRING "Initial CMake's flags" FORCE)
set(INITIAL_CMAKE_STATIC_LINKER_FLAGS
${CMAKE_STATIC_LINKER_FLAGS}
CACHE STRING "Initial CMake's flags" FORCE)
set(INITIAL_CMAKE_MODULE_LINKER_FLAGS
${CMAKE_MODULE_LINKER_FLAGS}
CACHE STRING "Initial CMake's flags" FORCE)
set(INITIAL_CMAKE_FLAGS_SAVED
TRUE
CACHE INTERNAL "State of initial CMake's flags" FORCE)
endif() endif()
# reset C/CXX flags # reset C/CXX flags
@@ -717,14 +814,13 @@ 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, # checks for /EHa or /clr options exists, i.e. is enabled structured async WinNT exceptions
# i.e. is enabled structured async WinNT exceptions
string(REGEX MATCH "^(.* )*[-/]EHc*a( .*)*$" msvc_async_eh_enabled "${CXX_FLAGS}" "${C_FLAGS}") string(REGEX MATCH "^(.* )*[-/]EHc*a( .*)*$" msvc_async_eh_enabled "${CXX_FLAGS}" "${C_FLAGS}")
string(REGEX MATCH "^(.* )*[-/]clr( .*)*$" msvc_clr_enabled "${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}")
if (msvc_clr_enabled STREQUAL "") if(msvc_clr_enabled STREQUAL "")
if(NOT msvc_async_eh_enabled STREQUAL "") if(NOT msvc_async_eh_enabled STREQUAL "")
add_compile_flags("C;CXX" "/EHa") add_compile_flags("C;CXX" "/EHa")
else() else()
@@ -733,8 +829,9 @@ macro(setup_compile_flags)
endif() endif()
endif(MSVC) endif(MSVC)
if(CC_HAS_WNO_ATTRIBUTES AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} if(CC_HAS_WNO_ATTRIBUTES
AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 9) AND CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}
AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 9)
# GCC < 9.x generates false-positive warnings for optimization attributes # GCC < 9.x generates false-positive warnings for optimization attributes
add_compile_flags("C;CXX" "-Wno-attributes") add_compile_flags("C;CXX" "-Wno-attributes")
if(LTO_ENABLED) if(LTO_ENABLED)
@@ -742,22 +839,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 # definition. The language permits multiple tentative definitions in the single translation unit; i.e. int foo; int
# language permits multiple tentative definitions in the single # foo; is perfectly ok. GNU toolchain goes even further, allowing multiple tentative definitions in *different*
# translation unit; i.e. int foo; int foo; is perfectly ok. GNU # translation units. Internally, variables introduced via tentative definitions are implemented as common symbols.
# toolchain goes even further, allowing multiple tentative definitions # Linker permits multiple definitions if they are common symbols, and it picks one arbitrarily for inclusion in the
# in *different* translation units. Internally, variables introduced via # binary being linked.
# tentative definitions are implemented as common symbols. Linker
# permits multiple definitions if they are common symbols, and it picks
# one arbitrarily for inclusion in the binary being linked.
# #
# -fno-common forces GNU toolchain to behave in a more # -fno-common forces GNU toolchain to behave in a more standard-conformant way in respect to tentative definitions and
# standard-conformant way in respect to tentative definitions and it # it prevents common symbols generation. Since we are a cross-platform project it really makes sense. There are
# prevents common symbols generation. Since we are a cross-platform # toolchains that dont implement GNU style handling of the tentative definitions and there are platforms lacking
# project it really makes sense. There are toolchains that dont # proper support for common symbols (osx).
# implement GNU style handling of the 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()
@@ -776,10 +868,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 # We must set -fno-omit-frame-pointer here, since we rely on frame pointer when getting a backtrace, and it must be
# on frame pointer when getting a backtrace, and it must # used consistently across all object files. The same reasoning applies to -fno-stack-protector switch.
# be used consistently across all object 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")
@@ -788,7 +878,9 @@ macro(setup_compile_flags)
if(MSVC) if(MSVC)
if(MSVC_VERSION LESS 1900) if(MSVC_VERSION LESS 1900)
message(FATAL_ERROR "At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required.") message(
FATAL_ERROR
"At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required.")
endif() 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")
@@ -809,9 +901,11 @@ 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. # Only add -Werror if it's a debug build, done by developers. Release builds should not cause extra trouble.
# Release builds should not cause extra trouble. if(CC_HAS_WERROR
if(CC_HAS_WERROR AND (CI OR CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE STREQUAL "Debug")) AND (CI
OR CMAKE_CONFIGURATION_TYPES
OR CMAKE_BUILD_TYPE STREQUAL "Debug"))
if(MSVC) if(MSVC)
add_compile_flags("C;CXX" "/WX") add_compile_flags("C;CXX" "/WX")
elseif(CMAKE_COMPILER_IS_CLANG) elseif(CMAKE_COMPILER_IS_CLANG)
@@ -827,17 +921,15 @@ macro(setup_compile_flags)
endif() endif()
endif() endif()
if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG} AND CMAKE_${CMAKE_PRIMARY_LANG}_COMPILER_VERSION VERSION_LESS 5)
if(CMAKE_COMPILER_IS_GNU${CMAKE_PRIMARY_LANG}
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 # Disable junk MINGW's warnings that issued due to incompatibilities and shortcomings of MINGW, since the code is
# and shortcomings of MINGW, # checked by builds with GCC, CLANG and MSVC.
# since the code is checked by builds with GCC, CLANG and MSVC. add_compile_flags("C;CXX" "-Wno-format-extra-args" "-Wno-format" "-Wno-cast-function-type"
add_compile_flags("C;CXX" "-Wno-format-extra-args" "-Wno-format" "-Wno-cast-function-type" "-Wno-implicit-fallthrough") "-Wno-implicit-fallthrough")
endif() endif()
if(ENABLE_ASAN) if(ENABLE_ASAN)
@@ -891,32 +983,46 @@ macro(setup_compile_flags)
endif() endif()
endif() endif()
if(MSVC AND NOT CMAKE_COMPILER_IS_CLANG AND LTO_ENABLED) if(MSVC
AND NOT CMAKE_COMPILER_IS_CLANG
AND LTO_ENABLED)
add_compile_flags("C;CXX" "/GL") 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 REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" ${linkmode}_LINKER_FLAGS "${${linkmode}_LINKER_FLAGS}") string(REGEX REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" ${linkmode}_LINKER_FLAGS
"${${linkmode}_LINKER_FLAGS}")
string(STRIP "${${linkmode}_LINKER_FLAGS}" ${linkmode}_LINKER_FLAGS) string(STRIP "${${linkmode}_LINKER_FLAGS}" ${linkmode}_LINKER_FLAGS)
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES ITEMS Release MinSizeRel RelWithDebInfo Debug) foreach(
config IN
LISTS CMAKE_CONFIGURATION_TYPES
ITEMS Release MinSizeRel RelWithDebInfo Debug)
string(TOUPPER "${config}" config_uppercase) string(TOUPPER "${config}" config_uppercase)
if(DEFINED "CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}") if(DEFINED "CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}")
string(REGEX REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" altered_flags "${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}") string(REGEX REPLACE "^(.*)(/INCREMENTAL)(:YES)?(:NO)?( ?.*)$" "\\1\\2:NO\\5" altered_flags
"${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}")
string(STRIP "${altered_flags}" altered_flags) string(STRIP "${altered_flags}" altered_flags)
if(NOT "${altered_flags}" STREQUAL "${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}") if(NOT "${altered_flags}" STREQUAL "${CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}}")
set(CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase} "${altered_flags}" CACHE STRING "Altered: '/INCREMENTAL' removed for LTO" FORCE) set(CMAKE_${linkmode}_LINKER_FLAGS_${config_uppercase}
"${altered_flags}"
CACHE STRING "Altered: '/INCREMENTAL' removed for LTO" FORCE)
endif() endif()
endif() endif()
endforeach(config) endforeach(config)
endforeach(linkmode) endforeach(linkmode)
unset(linkmode) unset(linkmode)
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES ITEMS Release MinSizeRel RelWithDebInfo) foreach(
config IN
LISTS CMAKE_CONFIGURATION_TYPES
ITEMS Release MinSizeRel RelWithDebInfo)
foreach(lang IN ITEMS C CXX) 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 "${CMAKE_${lang}_FLAGS_${config_uppercase}}") string(REPLACE "/O2" "/Ox" altered_flags "${CMAKE_${lang}_FLAGS_${config_uppercase}}")
if(NOT "${altered_flags}" STREQUAL "${CMAKE_${lang}_FLAGS_${config_uppercase}}") if(NOT "${altered_flags}" STREQUAL "${CMAKE_${lang}_FLAGS_${config_uppercase}}")
set(CMAKE_${lang}_FLAGS_${config_uppercase} "${altered_flags}" CACHE STRING "Altered: '/O2' replaced by '/Ox' for LTO" FORCE) set(CMAKE_${lang}_FLAGS_${config_uppercase}
"${altered_flags}"
CACHE STRING "Altered: '/O2' replaced by '/Ox' for LTO" FORCE)
endif() endif()
endif() endif()
unset(config_uppercase) unset(config_uppercase)
@@ -949,17 +1055,29 @@ macro(setup_compile_flags)
# push C/CXX flags into the cache # push C/CXX flags into the cache
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
set(CMAKE_CXX_FLAGS ${CXX_FLAGS} CACHE STRING "Flags used by the C++ compiler during all build types" FORCE) set(CMAKE_CXX_FLAGS
${CXX_FLAGS}
CACHE STRING "Flags used by the C++ compiler during all build types" FORCE)
unset(CXX_FLAGS) unset(CXX_FLAGS)
endif() endif()
if(CMAKE_C_COMPILER_LOADED) if(CMAKE_C_COMPILER_LOADED)
set(CMAKE_C_FLAGS ${C_FLAGS} CACHE STRING "Flags used by the C compiler during all build types" FORCE) set(CMAKE_C_FLAGS
${C_FLAGS}
CACHE STRING "Flags used by the C compiler during all build types" FORCE)
unset(C_FLAGS) unset(C_FLAGS)
endif() endif()
set(CMAKE_EXE_LINKER_FLAGS ${EXE_LINKER_FLAGS} CACHE STRING "Flags used by the linker" FORCE) set(CMAKE_EXE_LINKER_FLAGS
set(CMAKE_SHARED_LINKER_FLAGS ${SHARED_LINKER_FLAGS} CACHE STRING "Flags used by the linker during the creation of dll's" FORCE) ${EXE_LINKER_FLAGS}
set(CMAKE_STATIC_LINKER_FLAGS ${STATIC_LINKER_FLAGS} CACHE STRING "Flags used by the linker during the creation of static libraries" FORCE) CACHE STRING "Flags used by the linker" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS ${MODULE_LINKER_FLAGS} CACHE STRING "Flags used by the linker during the creation of modules" FORCE) set(CMAKE_SHARED_LINKER_FLAGS
${SHARED_LINKER_FLAGS}
CACHE STRING "Flags used by the linker during the creation of dll's" FORCE)
set(CMAKE_STATIC_LINKER_FLAGS
${STATIC_LINKER_FLAGS}
CACHE STRING "Flags used by the linker during the creation of static libraries" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS
${MODULE_LINKER_FLAGS}
CACHE STRING "Flags used by the linker during the creation of modules" FORCE)
unset(EXE_LINKER_FLAGS) unset(EXE_LINKER_FLAGS)
unset(SHARED_LINKER_FLAGS) unset(SHARED_LINKER_FLAGS)
unset(STATIC_LINKER_FLAGS) unset(STATIC_LINKER_FLAGS)
@@ -969,7 +1087,9 @@ endmacro(setup_compile_flags)
macro(probe_libcxx_filesystem) macro(probe_libcxx_filesystem)
if(CMAKE_CXX_COMPILER_LOADED AND NOT DEFINED LIBCXX_FILESYSTEM) if(CMAKE_CXX_COMPILER_LOADED AND NOT DEFINED LIBCXX_FILESYSTEM)
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 HAS_CXX11) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 HAS_CXX11)
if(NOT HAS_CXX11 LESS 0 OR CXX_FALLBACK_GNU11 OR CXX_FALLBACK_11) if(NOT HAS_CXX11 LESS 0
OR CXX_FALLBACK_GNU11
OR CXX_FALLBACK_11)
include(CMakePushCheckState) include(CMakePushCheckState)
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
cmake_push_check_state() cmake_push_check_state()
@@ -981,8 +1101,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)
@@ -1004,7 +1123,8 @@ macro(probe_libcxx_filesystem)
endif() endif()
set(CMAKE_REQUIRED_FLAGS ${stdfs_probe_flags}) set(CMAKE_REQUIRED_FLAGS ${stdfs_probe_flags})
set(stdfs_probe_code [[ set(stdfs_probe_code
[[
#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4 #if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4
#define __GLIBCXX_BITSIZE_INT_N_0 128 #define __GLIBCXX_BITSIZE_INT_N_0 128
#define __GLIBCXX_TYPE_INT_N_0 __int128 #define __GLIBCXX_TYPE_INT_N_0 __int128

View File

@@ -1,17 +1,5 @@
## Copyright (c) 2012-2024 Leonid Yuriev <leo@yuriev.ru>. # Copyright (c) 2012-2025 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> ###############################################
## # SPDX-License-Identifier: Apache-2.0
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
if(CMAKE_VERSION VERSION_LESS 3.8.2) if(CMAKE_VERSION VERSION_LESS 3.8.2)
cmake_minimum_required(VERSION 3.0.2) cmake_minimum_required(VERSION 3.0.2)
@@ -24,32 +12,47 @@ endif()
cmake_policy(PUSH) cmake_policy(PUSH)
cmake_policy(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION}) cmake_policy(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})
unset(MEMCHECK_OPTION_NAME)
if(NOT DEFINED ENABLE_MEMCHECK)
if(DEFINED MDBX_USE_VALGRIND)
set(MEMCHECK_OPTION_NAME "MDBX_USE_VALGRIND")
elseif(DEFINED ENABLE_VALGRIND)
set(MEMCHECK_OPTION_NAME "ENABLE_VALGRIND")
else()
set(MEMCHECK_OPTION_NAME "ENABLE_MEMCHECK")
endif()
if(MEMCHECK_OPTION_NAME STREQUAL "ENABLE_MEMCHECK")
option(ENABLE_MEMCHECK "Enable integration with valgrind, a memory analyzing tool" OFF)
elseif(${MEMCHECK_OPTION_NAME})
set(ENABLE_MEMCHECK ON)
else()
set(ENABLE_MEMCHECK OFF)
endif()
endif()
include(CheckLibraryExists) include(CheckLibraryExists)
check_library_exists(gcov __gcov_flush "" HAVE_GCOV) check_library_exists(gcov __gcov_flush "" HAVE_GCOV)
option(ENABLE_GCOV option(ENABLE_GCOV "Enable integration with gcov, a code coverage program" OFF)
"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)
if(CMAKE_CXX_COMPILER_LOADED) option(ENABLE_ASAN "Enable AddressSanitizer, a fast memory error detector based on compiler instrumentation" OFF)
include(CheckIncludeFileCXX)
check_include_file_cxx(valgrind/memcheck.h HAVE_VALGRIND_MEMCHECK_H)
else()
include(CheckIncludeFile)
check_include_file(valgrind/memcheck.h HAVE_VALGRIND_MEMCHECK_H)
endif()
option(MDBX_USE_VALGRIND "Enable integration with valgrind, a memory analyzing tool" OFF)
if(MDBX_USE_VALGRIND AND NOT HAVE_VALGRIND_MEMCHECK_H)
message(FATAL_ERROR "MDBX_USE_VALGRIND option is set but valgrind/memcheck.h is not found")
endif()
option(ENABLE_ASAN
"Enable AddressSanitizer, a fast memory error detector based on compiler instrumentation" OFF)
option(ENABLE_UBSAN option(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(CMAKE_CXX_COMPILER_LOADED)
include(CheckIncludeFileCXX)
check_include_file_cxx(valgrind/memcheck.h HAVE_VALGRIND_MEMCHECK_H)
else()
include(CheckIncludeFile)
check_include_file(valgrind/memcheck.h HAVE_VALGRIND_MEMCHECK_H)
endif()
if(NOT HAVE_VALGRIND_MEMCHECK_H)
message(FATAL_ERROR "${MEMCHECK_OPTION_NAME} option is set but valgrind/memcheck.h is not found")
endif()
endif()
cmake_policy(POP) cmake_policy(POP)

View File

@@ -1,17 +1,5 @@
## Copyright (c) 2012-2024 Leonid Yuriev <leo@yuriev.ru>. # Copyright (c) 2012-2025 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> ###############################################
## # SPDX-License-Identifier: Apache-2.0
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
if(CMAKE_VERSION VERSION_LESS 3.8.2) if(CMAKE_VERSION VERSION_LESS 3.8.2)
cmake_minimum_required(VERSION 3.0.2) cmake_minimum_required(VERSION 3.0.2)
@@ -24,6 +12,21 @@ endif()
cmake_policy(PUSH) cmake_policy(PUSH)
cmake_policy(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION}) cmake_policy(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})
macro(add_option HIVE NAME DESCRIPTION DEFAULT)
list(APPEND ${HIVE}_BUILD_OPTIONS ${HIVE}_${NAME})
if(NOT ${DEFAULT} STREQUAL "AUTO")
option(${HIVE}_${NAME} "${DESCRIPTION}" ${DEFAULT})
elseif(NOT DEFINED ${HIVE}_${NAME})
set(${HIVE}_${NAME}_AUTO ON)
endif()
endmacro()
macro(set_if_undefined VARNAME)
if(NOT DEFINED "${VARNAME}")
set("${VARNAME}" ${ARGN})
endif()
endmacro()
macro(add_compile_flags languages) macro(add_compile_flags languages)
foreach(_lang ${languages}) foreach(_lang ${languages})
string(REPLACE ";" " " _flags "${ARGN}") string(REPLACE ";" " " _flags "${ARGN}")
@@ -61,9 +64,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, # CMake believes that Objective C is a flavor of C++, not C, and uses g++ compiler for .m files. LANGUAGE property
# and uses g++ compiler for .m files. # forces CMake to use CC for ${file}
# LANGUAGE property forces CMake to use CC for ${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)
@@ -77,210 +79,446 @@ macro(set_source_files_compile_flags)
set(_flags "${_flags} ${CMAKE_${_lang}_FLAGS}") set(_flags "${_flags} ${CMAKE_${_lang}_FLAGS}")
endif() endif()
# message(STATUS "Set (${file} ${_flags}") # message(STATUS "Set (${file} ${_flags}")
set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "${_flags}")
"${_flags}")
endif() endif()
endforeach() endforeach()
unset(_file_ext) unset(_file_ext)
unset(_lang) unset(_lang)
endmacro(set_source_files_compile_flags) endmacro(set_source_files_compile_flags)
macro(fetch_version name source_root_directory parent_scope) macro(semver_parse str)
set(${name}_VERSION "") set(_semver_ok FALSE)
set(${name}_GIT_DESCRIBE "") set(_semver_err "")
set(${name}_GIT_TIMESTAMP "") set(_semver_major 0)
set(${name}_GIT_TREE "") set(_semver_minor 0)
set(${name}_GIT_COMMIT "") set(_semver_patch 0)
set(${name}_GIT_REVISION 0) set(_semver_tweak_withdot "")
set(${name}_GIT_VERSION "") set(_semver_tweak "")
if(GIT AND EXISTS "${source_root_directory}/.git") set(_semver_extra "")
execute_process(COMMAND ${GIT} show --no-patch --format=%cI HEAD set(_semver_prerelease_withdash "")
OUTPUT_VARIABLE ${name}_GIT_TIMESTAMP set(_semver_prerelease "")
OUTPUT_STRIP_TRAILING_WHITESPACE set(_semver_buildmetadata_withplus "")
WORKING_DIRECTORY ${source_root_directory} set(_semver_buildmetadata "")
RESULT_VARIABLE rc) if("${str}" MATCHES
if(rc OR "${name}_GIT_TIMESTAMP" STREQUAL "%cI") "^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]+.*)?$")
execute_process(COMMAND ${GIT} show --no-patch --format=%ci HEAD set(_semver_major ${CMAKE_MATCH_1})
OUTPUT_VARIABLE ${name}_GIT_TIMESTAMP set(_semver_minor ${CMAKE_MATCH_2})
OUTPUT_STRIP_TRAILING_WHITESPACE set(_semver_patch ${CMAKE_MATCH_3})
WORKING_DIRECTORY ${source_root_directory} set(_semver_tweak_withdot ${CMAKE_MATCH_4})
RESULT_VARIABLE rc) set(_semver_tweak ${CMAKE_MATCH_5})
if(rc OR "${name}_GIT_TIMESTAMP" STREQUAL "%ci") set(_semver_extra "${CMAKE_MATCH_6}")
message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%cI HEAD` failed)") if("${_semver_extra}" STREQUAL "")
set(_semver_ok TRUE)
elseif("${_semver_extra}" MATCHES "^([.-][a-zA-Z0-9-]+)*(\\+[^+]+)?$")
set(_semver_prerelease_withdash "${CMAKE_MATCH_1}")
if(NOT "${_semver_prerelease_withdash}" STREQUAL "")
string(SUBSTRING "${_semver_prerelease_withdash}" 1 -1 _semver_prerelease)
endif() endif()
endif() set(_semver_buildmetadata_withplus "${CMAKE_MATCH_2}")
if(NOT "${_semver_buildmetadata_withplus}" STREQUAL "")
execute_process(COMMAND ${GIT} show --no-patch --format=%T HEAD string(SUBSTRING "${_semver_buildmetadata_withplus}" 1 -1 _semver_buildmetadata)
OUTPUT_VARIABLE ${name}_GIT_TREE
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_TREE" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%T HEAD` failed)")
endif()
execute_process(COMMAND ${GIT} show --no-patch --format=%H HEAD
OUTPUT_VARIABLE ${name}_GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_COMMIT" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%H HEAD` failed)")
endif()
execute_process(COMMAND ${GIT} rev-list --tags --count
OUTPUT_VARIABLE tag_count
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc)
message(FATAL_ERROR "Please install latest version of git (`git rev-list --tags --count` failed)")
endif()
if(tag_count EQUAL 0)
execute_process(COMMAND ${GIT} rev-list --all --count
OUTPUT_VARIABLE whole_count
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc)
message(FATAL_ERROR "Please install latest version of git (`git rev-list --all --count` failed)")
endif() endif()
if(whole_count GREATER 42) set(_semver_ok TRUE)
message(FATAL_ERROR "Please fetch tags (no any tags for ${whole_count} commits)")
endif()
set(${name}_GIT_VERSION "0;0;0")
execute_process(COMMAND ${GIT} rev-list --count --all --no-merges
OUTPUT_VARIABLE ${name}_GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_REVISION" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`rev-list --count --all --no-merges` failed)")
endif()
else(tag_count EQUAL 0)
execute_process(COMMAND ${GIT} describe --tags --long --dirty=-dirty "--match=v[0-9]*"
OUTPUT_VARIABLE ${name}_GIT_DESCRIBE
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_DESCRIBE" STREQUAL "")
if(_whole_count GREATER 42)
message(FATAL_ERROR "Please fetch tags (`describe --tags --long --dirty --match=v[0-9]*` failed)")
else()
execute_process(COMMAND ${GIT} describe --all --long --dirty=-dirty
OUTPUT_VARIABLE ${name}_GIT_DESCRIBE
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_DESCRIBE" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`git rev-list --tags --count` and/or `git rev-list --all --count` failed)")
endif()
endif()
endif()
execute_process(COMMAND ${GIT} describe --tags --abbrev=0 "--match=v[0-9]*"
OUTPUT_VARIABLE last_release_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc)
message(FATAL_ERROR "Please install latest version of git (`describe --tags --abbrev=0 --match=v[0-9]*` failed)")
endif()
if (last_release_tag)
set(git_revlist_arg "${last_release_tag}..HEAD")
else()
execute_process(COMMAND ${GIT} tag --sort=-version:refname
OUTPUT_VARIABLE tag_list
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc)
message(FATAL_ERROR "Please install latest version of git (`tag --sort=-version:refname` failed)")
endif()
string(REGEX REPLACE "\n" ";" tag_list "${tag_list}")
set(git_revlist_arg "HEAD")
foreach(tag IN LISTS tag_list)
if(NOT last_release_tag)
string(REGEX MATCH "^v[0-9]+(\.[0-9]+)+" last_release_tag "${tag}")
set(git_revlist_arg "${tag}..HEAD")
endif()
endforeach(tag)
endif()
execute_process(COMMAND ${GIT} rev-list --count "${git_revlist_arg}"
OUTPUT_VARIABLE ${name}_GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_REVISION" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`rev-list --count ${git_revlist_arg}` failed)")
endif()
string(REGEX MATCH "^(v)?([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" git_version_valid "${${name}_GIT_DESCRIBE}")
if(git_version_valid)
string(REGEX REPLACE "^(v)?([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" "\\2;\\3;\\4" ${name}_GIT_VERSION ${${name}_GIT_DESCRIBE})
else()
string(REGEX MATCH "^(v)?([0-9]+)\\.([0-9]+)(.*)?" git_version_valid "${${name}_GIT_DESCRIBE}")
if(git_version_valid)
string(REGEX REPLACE "^(v)?([0-9]+)\\.([0-9]+)(.*)?" "\\2;\\3;0" ${name}_GIT_VERSION ${${name}_GIT_DESCRIBE})
else()
message(AUTHOR_WARNING "Bad ${name} version \"${${name}_GIT_DESCRIBE}\"; falling back to 0.0.0 (have you made an initial release?)")
set(${name}_GIT_VERSION "0;0;0")
endif()
endif()
endif(tag_count EQUAL 0)
endif()
if(NOT ${name}_GIT_VERSION OR NOT ${name}_GIT_TIMESTAMP OR ${name}_GIT_REVISION STREQUAL "")
if(GIT AND EXISTS "${source_root_directory}/.git")
message(WARNING "Unable to retrieve ${name} version from git.")
endif()
set(${name}_GIT_VERSION "0;0;0;0")
set(${name}_GIT_TIMESTAMP "")
set(${name}_GIT_REVISION 0)
# Try to get version from VERSION file
set(version_file "${source_root_directory}/VERSION.txt")
if(NOT EXISTS "${version_file}")
set(version_file "${source_root_directory}/VERSION")
endif()
if(EXISTS "${version_file}")
file(STRINGS "${version_file}" ${name}_VERSION LIMIT_COUNT 1 LIMIT_INPUT 42)
endif()
if(NOT ${name}_VERSION)
message(WARNING "Unable to retrieve ${name} version from \"${version_file}\" file.")
set(${name}_VERSION_LIST ${${name}_GIT_VERSION})
string(REPLACE ";" "." ${name}_VERSION "${${name}_GIT_VERSION}")
else() else()
string(REPLACE "." ";" ${name}_VERSION_LIST ${${name}_VERSION}) set(_semver_err
"Поля prerelease и/или buildmetadata (строка `-foo+bar` в составе `0.0.0[.0][-foo][+bar]`) не соответствуют SemVer-спецификации"
)
endif() endif()
else() else()
list(APPEND ${name}_GIT_VERSION ${${name}_GIT_REVISION}) set(_semver_err "Версионная отметка в целом не соответствует шаблону `0.0.0[.0][-foo][+bar]` SemVer-спецификации")
set(${name}_VERSION_LIST ${${name}_GIT_VERSION}) endif()
string(REPLACE ";" "." ${name}_VERSION "${${name}_GIT_VERSION}") endmacro(semver_parse)
function(_semver_parse_probe str expect)
semver_parse(${str})
if(expect AND NOT _semver_ok)
message(FATAL_ERROR "semver_parse(${str}) expect SUCCESS, got ${_semver_ok}: ${_semver_err}")
elseif(NOT expect AND _semver_ok)
message(FATAL_ERROR "semver_parse(${str}) expect FAIL, got ${_semver_ok}")
endif()
endfunction()
function(semver_parse_selfcheck)
_semver_parse_probe("0.0.4" TRUE)
_semver_parse_probe("v1.2.3" TRUE)
_semver_parse_probe("10.20.30" TRUE)
_semver_parse_probe("10.20.30.42" TRUE)
_semver_parse_probe("1.1.2-prerelease+meta" TRUE)
_semver_parse_probe("1.1.2+meta" TRUE)
_semver_parse_probe("1.1.2+meta-valid" TRUE)
_semver_parse_probe("1.0.0-alpha" TRUE)
_semver_parse_probe("1.0.0-beta" TRUE)
_semver_parse_probe("1.0.0-alpha.beta" TRUE)
_semver_parse_probe("1.0.0-alpha.beta.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-alpha.0valid" TRUE)
_semver_parse_probe("1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay" 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("1.2.3-beta" TRUE)
_semver_parse_probe("10.2.3-DEV-SNAPSHOT" TRUE)
_semver_parse_probe("1.2.3-SNAPSHOT-123" TRUE)
_semver_parse_probe("1.0.0" TRUE)
_semver_parse_probe("2.0.0" TRUE)
_semver_parse_probe("1.1.7" TRUE)
_semver_parse_probe("2.0.0+build.1848" TRUE)
_semver_parse_probe("2.0.1-alpha.1227" TRUE)
_semver_parse_probe("1.0.0-alpha+beta" TRUE)
_semver_parse_probe("1.2.3----RC-SNAPSHOT.12.9.1--.12+788" 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.0.0+0.build.1-rc.10000aaa-kk-0.1" TRUE)
_semver_parse_probe("99999999999999999999999.999999999999999999.99999999999999999" TRUE)
_semver_parse_probe("v1.0.0-0A.is.legal" TRUE)
_semver_parse_probe("1" FALSE)
_semver_parse_probe("1.2" FALSE)
# _semver_parse_probe("1.2.3-0123" FALSE) _semver_parse_probe("1.2.3-0123.0123" FALSE)
_semver_parse_probe("1.1.2+.123" FALSE)
_semver_parse_probe("+invalid" FALSE)
_semver_parse_probe("-invalid" FALSE)
_semver_parse_probe("-invalid+invalid" FALSE)
_semver_parse_probe("-invalid.01" FALSE)
_semver_parse_probe("alpha" FALSE)
_semver_parse_probe("alpha.beta" FALSE)
_semver_parse_probe("alpha.beta.1" FALSE)
_semver_parse_probe("alpha.1" FALSE)
_semver_parse_probe("alpha+beta" FALSE)
_semver_parse_probe("alpha_beta" FALSE)
_semver_parse_probe("alpha." FALSE)
_semver_parse_probe("alpha.." FALSE)
_semver_parse_probe("beta" FALSE)
_semver_parse_probe("1.0.0-alpha_beta" FALSE)
_semver_parse_probe("-alpha." FALSE)
_semver_parse_probe("1.0.0-alpha.." FALSE)
_semver_parse_probe("1.0.0-alpha..1" FALSE)
_semver_parse_probe("1.0.0-alpha...1" FALSE)
_semver_parse_probe("1.0.0-alpha....1" FALSE)
_semver_parse_probe("1.0.0-alpha.....1" FALSE)
_semver_parse_probe("1.0.0-alpha......1" FALSE)
_semver_parse_probe("1.0.0-alpha.......1" FALSE)
_semver_parse_probe("01.1.1" FALSE)
_semver_parse_probe("1.01.1" FALSE)
_semver_parse_probe("1.1.01" FALSE)
_semver_parse_probe("1.2" FALSE)
_semver_parse_probe("1.2.3.DEV" FALSE)
_semver_parse_probe("1.2-SNAPSHOT" FALSE)
_semver_parse_probe("1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788" FALSE)
_semver_parse_probe("1.2-RC-SNAPSHOT" FALSE)
_semver_parse_probe("-1.0.3-gamma+b7718" FALSE)
_semver_parse_probe("+justmeta" FALSE)
_semver_parse_probe("9.8.7+meta+meta" FALSE)
_semver_parse_probe("9.8.7-whatever+meta+meta" FALSE)
_semver_parse_probe(
"99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12"
FALSE)
endfunction()
macro(git_get_versioninfo source_root_directory)
set(_git_describe "")
set(_git_timestamp "")
set(_git_tree "")
set(_git_commit "")
set(_git_last_vtag "")
set(_git_trailing_commits 0)
set(_git_is_dirty FALSE)
execute_process(
COMMAND ${GIT} show --no-patch --format=%cI HEAD
OUTPUT_VARIABLE _git_timestamp
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc OR "${_git_timestamp}" STREQUAL "%cI")
execute_process(
COMMAND ${GIT} show --no-patch --format=%ci HEAD
OUTPUT_VARIABLE _git_timestamp
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc OR "${_git_timestamp}" STREQUAL "%ci")
message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%cI HEAD` failed)")
endif()
endif() endif()
list(GET ${name}_VERSION_LIST 0 "${name}_VERSION_MAJOR") execute_process(
list(GET ${name}_VERSION_LIST 1 "${name}_VERSION_MINOR") COMMAND ${GIT} show --no-patch --format=%T HEAD
list(GET ${name}_VERSION_LIST 2 "${name}_VERSION_RELEASE") OUTPUT_VARIABLE _git_tree
list(GET ${name}_VERSION_LIST 3 "${name}_VERSION_REVISION") OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc OR "${_git_tree}" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%T HEAD` failed)")
endif()
execute_process(
COMMAND ${GIT} show --no-patch --format=%H HEAD
OUTPUT_VARIABLE _git_commit
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc OR "${_git_commit}" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%H HEAD` failed)")
endif()
execute_process(
COMMAND ${GIT} status --untracked-files=no --porcelain
OUTPUT_VARIABLE _git_status
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc)
message(FATAL_ERROR "Please install latest version of git (`status --untracked-files=no --porcelain` failed)")
endif()
if(NOT "${_git_status}" STREQUAL "")
set(_git_commit "DIRTY-${_git_commit}")
set(_git_is_dirty TRUE)
endif()
unset(_git_status)
execute_process(
COMMAND ${GIT} describe --tags --abbrev=0 "--match=v[0-9]*"
OUTPUT_VARIABLE _git_last_vtag
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc OR "${_git_last_vtag}" STREQUAL "")
execute_process(
COMMAND ${GIT} tag
OUTPUT_VARIABLE _git_tags_dump
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
execute_process(
COMMAND ${GIT} rev-list --count --no-merges --remove-empty HEAD
OUTPUT_VARIABLE _git_whole_count
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc)
message(
FATAL_ERROR
"Please install latest version of git (`git rev-list --count --no-merges --remove-empty HEAD` failed)")
endif()
if(_git_whole_count GREATER 42 AND "${_git_tags_dump}" STREQUAL "")
message(FATAL_ERROR "Please fetch tags (`describe --tags --abbrev=0 --match=v[0-9]*` failed)")
else()
message(NOTICE "Falling back to version `0.0.0` (have you made an initial release?")
endif()
set(_git_last_vtag "0.0.0")
set(_git_trailing_commits ${_git_whole_count})
execute_process(
COMMAND ${GIT} describe --tags --dirty --long --always
OUTPUT_VARIABLE _git_describe
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc OR "${_git_describe}" STREQUAL "")
execute_process(
COMMAND ${GIT} describe --tags --all --dirty --long --always
OUTPUT_VARIABLE _git_describe
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc OR "${_git_describe}" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`describe --tags --all --long` failed)")
endif()
endif()
else()
execute_process(
COMMAND ${GIT} describe --tags --dirty --long "--match=v[0-9]*"
OUTPUT_VARIABLE _git_describe
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc OR "${_git_describe}" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`describe --tags --long --match=v[0-9]*`)")
endif()
execute_process(
COMMAND ${GIT} rev-list --count "${_git_last_vtag}..HEAD"
OUTPUT_VARIABLE _git_trailing_commits
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc OR "${_git_trailing_commits}" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`rev-list --count ${_git_last_vtag}..HEAD` failed)")
endif()
endif()
endmacro(git_get_versioninfo)
macro(semver_provide name source_root_directory build_directory_for_json_output build_metadata parent_scope)
set(_semver "")
set(_git_describe "")
set(_git_timestamp "")
set(_git_tree "")
set(_git_commit "")
set(_version_from "")
set(_git_root FALSE)
find_program(GIT git)
if(GIT)
execute_process(
COMMAND ${GIT} rev-parse --show-toplevel
OUTPUT_VARIABLE _git_root
ERROR_VARIABLE _git_root_error
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE _rc)
if(_rc OR "${_git_root}" STREQUAL "")
if(EXISTS "${source_root_directory}/.git")
message(ERROR "`git rev-parse --show-toplevel` failed '${_git_root_error}'")
else()
message(VERBOSE "`git rev-parse --show-toplevel` failed '${_git_root_error}'")
endif()
else()
set(_source_root "${source_root_directory}")
if(NOT CMAKE_VERSION VERSION_LESS 3.19)
file(REAL_PATH "${_git_root}" _git_root)
file(REAL_PATH "${_source_root}" _source_root)
endif()
if(_source_root STREQUAL _git_root AND EXISTS "${_git_root}/VERSION.json")
message(
FATAL_ERROR
"Несколько источников информации о версии, допустим только один из: репозиторий git, либо файл VERSION.json"
)
endif()
endif()
endif()
if(EXISTS "${source_root_directory}/VERSION.json")
set(_version_from "${source_root_directory}/VERSION.json")
if(CMAKE_VERSION VERSION_LESS 3.19)
message(FATAL_ERROR "Требуется CMake версии >= 3.19 для чтения VERSION.json")
endif()
file(
STRINGS "${_version_from}" _versioninfo_json NEWLINE_CONSUME
LIMIT_COUNT 9
LIMIT_INPUT 999
ENCODING UTF-8)
string(JSON _git_describe GET ${_versioninfo_json} git_describe)
string(JSON _git_timestamp GET "${_versioninfo_json}" "git_timestamp")
string(JSON _git_tree GET "${_versioninfo_json}" "git_tree")
string(JSON _git_commit GET "${_versioninfo_json}" "git_commit")
string(JSON _semver GET "${_versioninfo_json}" "semver")
unset(_json_object)
if(NOT _semver)
message(FATAL_ERROR "Unable to retrieve ${name} version from \"${_version_from}\" file.")
endif()
semver_parse("${_semver}")
if(NOT _semver_ok)
message(FATAL_ERROR "SemVer `${_semver}` from ${_version_from}: ${_semver_err}")
endif()
elseif(_git_root AND _source_root STREQUAL _git_root)
set(_version_from git)
git_get_versioninfo(${source_root_directory})
semver_parse(${_git_last_vtag})
if(NOT _semver_ok)
message(FATAL_ERROR "Git tag `${_git_last_vtag}`: ${_semver_err}")
endif()
if(_git_trailing_commits GREATER 0 AND "${_semver_tweak}" STREQUAL "")
set(_semver_tweak ${_git_trailing_commits})
endif()
elseif(GIT)
message(
FATAL_ERROR
"Нет источника информации о версии (${source_root_directory}), требуется один из: репозиторий git, либо VERSION.json"
)
else()
message(FATAL_ERROR "Требуется git для получения информации о версии")
endif()
if(NOT _git_describe
OR NOT _git_timestamp
OR NOT _git_tree
OR NOT _git_commit
OR "${_semver_major}" STREQUAL ""
OR "${_semver_minor}" STREQUAL ""
OR "${_semver_patch}" STREQUAL "")
message(ERROR "Unable to retrieve ${name} version from ${_version_from}.")
endif()
set(_semver "${_semver_major}.${_semver_minor}.${_semver_patch}")
if("${_semver_tweak}" STREQUAL "")
set(_semver_tweak 0)
elseif(_semver_tweak GREATER 0)
string(APPEND _semver ".${_semver_tweak}")
endif()
if(NOT "${_semver_prerelease}" STREQUAL "")
string(APPEND _semver "-${_semver_prerelease}")
endif()
if(_git_is_dirty)
string(APPEND _semver "-DIRTY")
endif()
set(_semver_complete "${_semver}")
if(NOT "${build_metadata}" STREQUAL "")
string(APPEND _semver_complete "+${build_metadata}")
endif()
set(${name}_VERSION "${_semver_complete}")
set(${name}_VERSION_PURE "${_semver}")
set(${name}_VERSION_MAJOR ${_semver_major})
set(${name}_VERSION_MINOR ${_semver_minor})
set(${name}_VERSION_PATCH ${_semver_patch})
set(${name}_VERSION_TWEAK ${_semver_tweak})
set(${name}_VERSION_PRERELEASE "${_semver_prerelease}")
set(${name}_GIT_DESCRIBE "${_git_describe}")
set(${name}_GIT_TIMESTAMP "${_git_timestamp}")
set(${name}_GIT_TREE "${_git_tree}")
set(${name}_GIT_COMMIT "${_git_commit}")
if(${parent_scope}) if(${parent_scope})
set(${name}_VERSION_MAJOR "${${name}_VERSION_MAJOR}" PARENT_SCOPE) set(${name}_VERSION
set(${name}_VERSION_MINOR "${${name}_VERSION_MINOR}" PARENT_SCOPE) "${_semver_complete}"
set(${name}_VERSION_RELEASE "${${name}_VERSION_RELEASE}" PARENT_SCOPE) PARENT_SCOPE)
set(${name}_VERSION_REVISION "${${name}_VERSION_REVISION}" PARENT_SCOPE) set(${name}_VERSION_PURE
set(${name}_VERSION "${${name}_VERSION}" PARENT_SCOPE) "${_semver}"
PARENT_SCOPE)
set(${name}_GIT_DESCRIBE "${${name}_GIT_DESCRIBE}" PARENT_SCOPE) set(${name}_VERSION_MAJOR
set(${name}_GIT_TIMESTAMP "${${name}_GIT_TIMESTAMP}" PARENT_SCOPE) ${_semver_major}
set(${name}_GIT_TREE "${${name}_GIT_TREE}" PARENT_SCOPE) PARENT_SCOPE)
set(${name}_GIT_COMMIT "${${name}_GIT_COMMIT}" PARENT_SCOPE) set(${name}_VERSION_MINOR
set(${name}_GIT_REVISION "${${name}_GIT_REVISION}" PARENT_SCOPE) ${_semver_minor}
set(${name}_GIT_VERSION "${${name}_GIT_VERSION}" PARENT_SCOPE) PARENT_SCOPE)
set(${name}_VERSION_PATCH
${_semver_patch}
PARENT_SCOPE)
set(${name}_VERSION_TWEAK
"${_semver_tweak}"
PARENT_SCOPE)
set(${name}_VERSION_PRERELEASE
"${_semver_prerelease}"
PARENT_SCOPE)
set(${name}_GIT_DESCRIBE
"${_git_describe}"
PARENT_SCOPE)
set(${name}_GIT_TIMESTAMP
"${_git_timestamp}"
PARENT_SCOPE)
set(${name}_GIT_TREE
"${_git_tree}"
PARENT_SCOPE)
set(${name}_GIT_COMMIT
"${_git_commit}"
PARENT_SCOPE)
endif() endif()
endmacro(fetch_version)
if(_version_from STREQUAL "git")
string(
CONFIGURE
"{
\"git_describe\" : \"@_git_describe@\",
\"git_timestamp\" : \"@_git_timestamp@\",
\"git_tree\" : \"@_git_tree@\",
\"git_commit\" : \"@_git_commit@\",
\"semver\" : \"@_semver@\"\n}"
_versioninfo_json
@ONLY ESCAPE_QUOTES)
file(WRITE "${build_directory_for_json_output}/VERSION.json" "${_versioninfo_json}")
endif()
endmacro(semver_provide)
cmake_policy(POP) cmake_policy(POP)

View File

@@ -5,12 +5,15 @@
/* clang-format off */ /* clang-format off */
#cmakedefine LTO_ENABLED #cmakedefine LTO_ENABLED
#cmakedefine MDBX_USE_VALGRIND #cmakedefine ENABLE_MEMCHECK
#cmakedefine ENABLE_GPROF #cmakedefine ENABLE_GPROF
#cmakedefine ENABLE_GCOV #cmakedefine ENABLE_GCOV
#cmakedefine ENABLE_ASAN #cmakedefine ENABLE_ASAN
#cmakedefine ENABLE_UBSAN #cmakedefine ENABLE_UBSAN
#cmakedefine01 MDBX_FORCE_ASSERTIONS #cmakedefine01 MDBX_FORCE_ASSERTIONS
#if !defined(MDBX_BUILD_TEST) && !defined(MDBX_BUILD_CXX)
#cmakedefine01 MDBX_BUILD_CXX
#endif
/* Common */ /* Common */
#cmakedefine01 MDBX_TXN_CHECKOWNER #cmakedefine01 MDBX_TXN_CHECKOWNER
@@ -29,23 +32,36 @@
#cmakedefine01 MDBX_DISABLE_VALIDATION #cmakedefine01 MDBX_DISABLE_VALIDATION
#cmakedefine01 MDBX_AVOID_MSYNC #cmakedefine01 MDBX_AVOID_MSYNC
#cmakedefine01 MDBX_ENABLE_REFUND #cmakedefine01 MDBX_ENABLE_REFUND
#cmakedefine01 MDBX_ENABLE_MADVISE
#cmakedefine01 MDBX_ENABLE_BIGFOOT #cmakedefine01 MDBX_ENABLE_BIGFOOT
#cmakedefine01 MDBX_ENABLE_PGOP_STAT #cmakedefine01 MDBX_ENABLE_PGOP_STAT
#cmakedefine01 MDBX_ENABLE_PROFGC #cmakedefine01 MDBX_ENABLE_PROFGC
#cmakedefine01 MDBX_ENABLE_DBI_SPARSE
#cmakedefine01 MDBX_ENABLE_DBI_LOCKFREE
/* Windows */ /* Windows */
#if defined(MDBX_BUILD_TEST) || !defined(MDBX_BUILD_CXX) || MDBX_BUILD_CXX
#define MDBX_WITHOUT_MSVC_CRT 0
#else
#cmakedefine01 MDBX_WITHOUT_MSVC_CRT #cmakedefine01 MDBX_WITHOUT_MSVC_CRT
#endif /* MDBX_WITHOUT_MSVC_CRT */
/* MacOS & iOS */ /* MacOS & iOS */
#cmakedefine01 MDBX_OSX_SPEED_INSTEADOF_DURABILITY #cmakedefine01 MDBX_APPLE_SPEED_INSTEADOF_DURABILITY
/* POSIX */ /* POSIX */
#cmakedefine01 MDBX_DISABLE_GNU_SOURCE #cmakedefine01 MDBX_DISABLE_GNU_SOURCE
#cmakedefine MDBX_USE_OFDLOCKS_AUTO #cmakedefine MDBX_USE_OFDLOCKS_AUTO
#ifndef MDBX_USE_OFDLOCKS_AUTO #ifndef MDBX_USE_OFDLOCKS_AUTO
#cmakedefine01 MDBX_USE_OFDLOCKS #cmakedefine01 MDBX_USE_OFDLOCKS
#endif #endif /* MDBX_USE_OFDLOCKS */
#cmakedefine MDBX_MMAP_NEEDS_JOLT_AUTO
#ifndef MDBX_MMAP_NEEDS_JOLT_AUTO
#cmakedefine01 MDBX_MMAP_NEEDS_JOLT
#endif /* MDBX_MMAP_NEEDS_JOLT */
#cmakedefine01 MDBX_USE_MINCORE
/* Build Info */ /* Build Info */
#ifndef MDBX_BUILD_TIMESTAMP #ifndef MDBX_BUILD_TIMESTAMP
@@ -63,6 +79,9 @@
#ifndef MDBX_BUILD_FLAGS #ifndef MDBX_BUILD_FLAGS
#cmakedefine MDBX_BUILD_FLAGS "@MDBX_BUILD_FLAGS@" #cmakedefine MDBX_BUILD_FLAGS "@MDBX_BUILD_FLAGS@"
#endif #endif
#ifndef MDBX_BUILD_METADATA
#cmakedefine MDBX_BUILD_METADATA "@MDBX_BUILD_METADATA@"
#endif
#cmakedefine MDBX_BUILD_SOURCERY @MDBX_BUILD_SOURCERY@ #cmakedefine MDBX_BUILD_SOURCERY @MDBX_BUILD_SOURCERY@
/* *INDENT-ON* */ /* *INDENT-ON* */

View File

@@ -1,6 +1,6 @@
.\" Copyright 2015-2024 Leonid Yuriev <leo@yuriev.ru>. .\" Copyright 2015-2025 Leonid Yuriev <leo@yuriev.ru>.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.TH MDBX_CHK 1 "2024-03-13" "MDBX 0.12.10" .TH MDBX_CHK 1 "2024-08-29" "MDBX 0.13"
.SH NAME .SH NAME
mdbx_chk \- MDBX checking tool mdbx_chk \- MDBX checking tool
.SH SYNOPSIS .SH SYNOPSIS
@@ -22,7 +22,7 @@ mdbx_chk \- MDBX checking tool
[\c [\c
.BR \-i ] .BR \-i ]
[\c [\c
.BI \-s \ subdb\fR] .BI \-s \ table\fR]
.BR \ dbpath .BR \ dbpath
.SH DESCRIPTION .SH DESCRIPTION
The The
@@ -69,8 +69,8 @@ pages.
Ignore wrong order errors, which will likely false-positive if custom Ignore wrong order errors, which will likely false-positive if custom
comparator(s) was used. comparator(s) was used.
.TP .TP
.BR \-s \ subdb .BR \-s \ table
Verify and show info only for a specific subdatabase. Verify and show info only for a specific table.
.TP .TP
.BR \-0 | \-1 | \-2 .BR \-0 | \-1 | \-2
Using specific meta-page 0, or 2 for checking. Using specific meta-page 0, or 2 for checking.

View File

@@ -1,8 +1,8 @@
.\" Copyright 2015-2024 Leonid Yuriev <leo@yuriev.ru>. .\" Copyright 2015-2025 Leonid Yuriev <leo@yuriev.ru>.
.\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>. .\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>.
.\" Copyright 2012-2015 Howard Chu, Symas Corp. All Rights Reserved. .\" Copyright 2012-2015 Howard Chu, Symas Corp. All Rights Reserved.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.TH MDBX_COPY 1 "2024-03-13" "MDBX 0.12.10" .TH MDBX_COPY 1 "2024-08-29" "MDBX 0.13"
.SH NAME .SH NAME
mdbx_copy \- MDBX environment copy tool mdbx_copy \- MDBX environment copy tool
.SH SYNOPSIS .SH SYNOPSIS
@@ -14,6 +14,10 @@ mdbx_copy \- MDBX environment copy tool
[\c [\c
.BR \-c ] .BR \-c ]
[\c [\c
.BR \-d ]
[\c
.BR \-p ]
[\c
.BR \-n ] .BR \-n ]
.B src_path .B src_path
[\c [\c
@@ -45,6 +49,22 @@ or unused pages will be omitted from the copy. This option will
slow down the backup process as it is more CPU-intensive. slow down the backup process as it is more CPU-intensive.
Currently it fails if the environment has suffered a page leak. Currently it fails if the environment has suffered a page leak.
.TP .TP
.BR \-d
Alters geometry to enforce the copy to be a dynamic size DB,
which could be growth and shrink by reasonable steps on the fly.
.TP
.BR \-p
Use read transaction parking/ousting during copying MVCC-snapshot.
This allows the writing transaction to oust the read
transaction used to copy the database if copying takes so long
that it will interfere with the recycling old MVCC snapshots
and may lead to an overflow of the database.
However, if the reading transaction is ousted the copy will
be aborted until successful completion. Thus, this option
allows copy the database without interfering with write
transactions and a threat of database overflow, but at the cost
that copying will be aborted to prevent such conditions.
.TP
.BR \-u .BR \-u
Warms up the DB before copying via notifying OS kernel of subsequent access to the database pages. Warms up the DB before copying via notifying OS kernel of subsequent access to the database pages.
.TP .TP

View File

@@ -1,7 +1,7 @@
.\" Copyright 2021-2024 Leonid Yuriev <leo@yuriev.ru>. .\" Copyright 2021-2025 Leonid Yuriev <leo@yuriev.ru>.
.\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved. .\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.TH MDBX_DROP 1 "2024-03-13" "MDBX 0.12.10" .TH MDBX_DROP 1 "2024-08-29" "MDBX 0.13"
.SH NAME .SH NAME
mdbx_drop \- MDBX database delete tool mdbx_drop \- MDBX database delete tool
.SH SYNOPSIS .SH SYNOPSIS
@@ -11,7 +11,7 @@ mdbx_drop \- MDBX database delete tool
[\c [\c
.BR \-d ] .BR \-d ]
[\c [\c
.BI \-s \ subdb\fR] .BI \-s \ table\fR]
[\c [\c
.BR \-n ] .BR \-n ]
.BR \ dbpath .BR \ dbpath
@@ -28,8 +28,8 @@ Write the library version number to the standard output, and exit.
.BR \-d .BR \-d
Delete the specified database, don't just empty it. Delete the specified database, don't just empty it.
.TP .TP
.BR \-s \ subdb .BR \-s \ table
Operate on a specific subdatabase. If no database is specified, only the main database is dropped. Operate on a specific table. If no table is specified, only the main table is dropped.
.TP .TP
.BR \-n .BR \-n
Dump an MDBX database which does not use subdirectories. Dump an MDBX database which does not use subdirectories.

View File

@@ -1,8 +1,8 @@
.\" Copyright 2015-2024 Leonid Yuriev <leo@yuriev.ru>. .\" Copyright 2015-2025 Leonid Yuriev <leo@yuriev.ru>.
.\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>. .\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>.
.\" Copyright 2014-2015 Howard Chu, Symas Corp. All Rights Reserved. .\" Copyright 2014-2015 Howard Chu, Symas Corp. All Rights Reserved.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.TH MDBX_DUMP 1 "2024-03-13" "MDBX 0.12.10" .TH MDBX_DUMP 1 "2024-08-29" "MDBX 0.13"
.SH NAME .SH NAME
mdbx_dump \- MDBX environment export tool mdbx_dump \- MDBX environment export tool
.SH SYNOPSIS .SH SYNOPSIS
@@ -19,7 +19,7 @@ mdbx_dump \- MDBX environment export tool
.BR \-p ] .BR \-p ]
[\c [\c
.BR \-a \ | .BR \-a \ |
.BI \-s \ subdb\fR] .BI \-s \ table\fR]
[\c [\c
.BR \-r ] .BR \-r ]
[\c [\c
@@ -58,10 +58,10 @@ are considered printing characters, and databases dumped in this manner may
be less portable to external systems. be less portable to external systems.
.TP .TP
.BR \-a .BR \-a
Dump all of the subdatabases in the environment. Dump all of the tables in the environment.
.TP .TP
.BR \-s \ subdb .BR \-s \ table
Dump a specific subdatabase. If no database is specified, only the main database is dumped. Dump a specific table. If no database is specified, only the main table is dumped.
.TP .TP
.BR \-r .BR \-r
Rescure mode. Ignore some errors to dump corrupted DB. Rescure mode. Ignore some errors to dump corrupted DB.

View File

@@ -1,8 +1,8 @@
.\" Copyright 2015-2024 Leonid Yuriev <leo@yuriev.ru>. .\" Copyright 2015-2025 Leonid Yuriev <leo@yuriev.ru>.
.\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>. .\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>.
.\" Copyright 2014-2015 Howard Chu, Symas Corp. All Rights Reserved. .\" Copyright 2014-2015 Howard Chu, Symas Corp. All Rights Reserved.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.TH MDBX_LOAD 1 "2024-03-13" "MDBX 0.12.10" .TH MDBX_LOAD 1 "2024-08-29" "MDBX 0.13"
.SH NAME .SH NAME
mdbx_load \- MDBX environment import tool mdbx_load \- MDBX environment import tool
.SH SYNOPSIS .SH SYNOPSIS
@@ -16,7 +16,7 @@ mdbx_load \- MDBX environment import tool
[\c [\c
.BI \-f \ file\fR] .BI \-f \ file\fR]
[\c [\c
.BI \-s \ subdb\fR] .BI \-s \ table\fR]
[\c [\c
.BR \-N ] .BR \-N ]
[\c [\c
@@ -71,11 +71,11 @@ on a database that uses custom compare functions.
.BR \-f \ file .BR \-f \ file
Read from the specified file instead of from the standard input. Read from the specified file instead of from the standard input.
.TP .TP
.BR \-s \ subdb .BR \-s \ table
Load a specific subdatabase. If no database is specified, data is loaded into the main database. Load a specific table. If no table is specified, data is loaded into the main table.
.TP .TP
.BR \-N .BR \-N
Don't overwrite existing records when loading into an already existing database; just skip them. Don't overwrite existing records when loading into an already existing table; just skip them.
.TP .TP
.BR \-T .BR \-T
Load data from simple text files. The input must be paired lines of text, where the first Load data from simple text files. The input must be paired lines of text, where the first

View File

@@ -1,8 +1,8 @@
.\" Copyright 2015-2024 Leonid Yuriev <leo@yuriev.ru>. .\" Copyright 2015-2025 Leonid Yuriev <leo@yuriev.ru>.
.\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>. .\" Copyright 2015,2016 Peter-Service R&D LLC <http://billing.ru/>.
.\" Copyright 2012-2015 Howard Chu, Symas Corp. All Rights Reserved. .\" Copyright 2012-2015 Howard Chu, Symas Corp. All Rights Reserved.
.\" Copying restrictions apply. See COPYRIGHT/LICENSE. .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
.TH MDBX_STAT 1 "2024-03-13" "MDBX 0.12.10" .TH MDBX_STAT 1 "2024-08-29" "MDBX 0.13"
.SH NAME .SH NAME
mdbx_stat \- MDBX environment status tool mdbx_stat \- MDBX environment status tool
.SH SYNOPSIS .SH SYNOPSIS
@@ -21,7 +21,7 @@ mdbx_stat \- MDBX environment status tool
.BR \-r [ r ]] .BR \-r [ r ]]
[\c [\c
.BR \-a \ | .BR \-a \ |
.BI \-s \ subdb\fR] .BI \-s \ table\fR]
.BR \ dbpath .BR \ dbpath
[\c [\c
.BR \-n ] .BR \-n ]
@@ -61,10 +61,10 @@ table and clear them. The reader table will be printed again
after the check is performed. after the check is performed.
.TP .TP
.BR \-a .BR \-a
Display the status of all of the subdatabases in the environment. Display the status of all of the tables in the environment.
.TP .TP
.BR \-s \ subdb .BR \-s \ table
Display the status of a specific subdatabase. Display the status of a specific table.
.TP .TP
.BR \-n .BR \-n
Display the status of an MDBX database which does not use subdirectories. Display the status of an MDBX database which does not use subdirectories.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -324,14 +324,21 @@ fn test_put_del() {
cursor.put(b"key3", b"val3", WriteFlags::empty()).unwrap(); cursor.put(b"key3", b"val3", WriteFlags::empty()).unwrap();
assert_eq!( assert_eq!(
cursor.get_current().unwrap().unwrap(), cursor.set_key(b"key2").unwrap(),
(Cow::Borrowed(b"key3" as &[u8]), Cow::Borrowed(b"val3" as &[u8])) Some((Cow::Borrowed(b"key2" as &[u8]), Cow::Borrowed(b"val2" as &[u8])))
);
assert_eq!(
cursor.get_current().unwrap(),
Some((Cow::Borrowed(b"key2" as &[u8]), Cow::Borrowed(b"val2" as &[u8])))
); );
cursor.del(WriteFlags::empty()).unwrap(); cursor.del(WriteFlags::empty()).unwrap();
assert_eq!(cursor.get_current::<Vec<u8>, Vec<u8>>().unwrap(), None);
assert_eq!( assert_eq!(
cursor.last().unwrap().unwrap(), cursor.get_current().unwrap(),
(Cow::Borrowed(b"key2" as &[u8]), Cow::Borrowed(b"val2" as &[u8])) Some((Cow::Borrowed(b"key3" as &[u8]), Cow::Borrowed(b"val3" as &[u8])))
);
assert_eq!(
cursor.last().unwrap(),
Some((Cow::Borrowed(b"key3" as &[u8]), Cow::Borrowed(b"val3" as &[u8])))
); );
} }