From: W. Felix Handte Date: Mon, 27 Mar 2023 15:24:47 +0000 (-0400) Subject: [contrib/pzstd] Detect and Select Maximum Available C++ Standard X-Git-Tag: v1.5.5~2^2~13^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b8bddc41ea721d1ff8056280bbf62d3bb0da344;p=thirdparty%2Fzstd.git [contrib/pzstd] Detect and Select Maximum Available C++ Standard Rather than remove the flag entirely, as proposed in #3499, this commit uses the newest C++ standard the compiler supports. This retains the selection of using only standardized features (excluding GNU extensions) and keeps the recency requirements of the codebase explicit. Tested with various versions of `g++` and `clang++`. --- diff --git a/contrib/pzstd/Makefile b/contrib/pzstd/Makefile index 830053cd7..423be59d2 100644 --- a/contrib/pzstd/Makefile +++ b/contrib/pzstd/Makefile @@ -37,10 +37,29 @@ CFLAGS += -Wno-deprecated-declarations PZSTD_INC = -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(PROGDIR) -I. GTEST_INC = -isystem googletest/googletest/include +# Select newest C++ standard available, minimum C++11 +ifeq ($(shell echo | $(CXX) -x c++ -Werror -std=c++23 -c - -o /dev/null 2>/dev/null && echo 1 || echo 0),1) +PZSTD_CXX_STD := -std=c++23 +else +ifeq ($(shell echo | $(CXX) -x c++ -Werror -std=c++20 -c - -o /dev/null 2>/dev/null && echo 1 || echo 0),1) +PZSTD_CXX_STD := -std=c++20 +else +ifeq ($(shell echo | $(CXX) -x c++ -Werror -std=c++17 -c - -o /dev/null 2>/dev/null && echo 1 || echo 0),1) +PZSTD_CXX_STD := -std=c++17 +else +ifeq ($(shell echo | $(CXX) -x c++ -Werror -std=c++14 -c - -o /dev/null 2>/dev/null && echo 1 || echo 0),1) +PZSTD_CXX_STD := -std=c++14 +else +PZSTD_CXX_STD := -std=c++11 +endif +endif +endif +endif + PZSTD_CPPFLAGS = $(PZSTD_INC) PZSTD_CCXXFLAGS = PZSTD_CFLAGS = $(PZSTD_CCXXFLAGS) -PZSTD_CXXFLAGS = $(PZSTD_CCXXFLAGS) -std=c++11 +PZSTD_CXXFLAGS = $(PZSTD_CCXXFLAGS) $(PZSTD_CXX_STD) PZSTD_LDFLAGS = EXTRA_FLAGS = ALL_CFLAGS = $(EXTRA_FLAGS) $(CPPFLAGS) $(PZSTD_CPPFLAGS) $(CFLAGS) $(PZSTD_CFLAGS)