From 9b7155865768f7987be2bbae93978bfbc689555a Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Thu, 16 May 2024 12:50:19 -0400 Subject: [PATCH] update to use logic to check compiler version for c++17 compatability --- .../contributor_help_pages/developer_doc.md | 2 +- make/compiler_flags | 26 ++++++++++++++++--- make/libraries | 4 +-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/doxygen/contributor_help_pages/developer_doc.md b/doxygen/contributor_help_pages/developer_doc.md index 0961a5ba9c3..687eb1b157d 100644 --- a/doxygen/contributor_help_pages/developer_doc.md +++ b/doxygen/contributor_help_pages/developer_doc.md @@ -184,7 +184,7 @@ These are the more common make flags that could be set: These are the rest of the variables that can be set: - C++ compiler flags - - `CXXFLAGS_LANG`: sets the language. Currently defaults to `-std=c++1y` + - `CXXFLAGS_LANG`: sets the language. Currently defaults to `-std=c++17` - `CXXFLAGS_WARNINGS`: compiler options to squash compiler warnings - `CXXFLAGS_BOOST`: Boost-specific compiler flags - `CXXFLAGS_EIGEN`: Eigen-specific compiler flags diff --git a/make/compiler_flags b/make/compiler_flags index 407d5932082..73268a95204 100644 --- a/make/compiler_flags +++ b/make/compiler_flags @@ -70,7 +70,6 @@ CXX_VERSION := $(shell $(CXX) -dumpfullversion -dumpversion 2>&1) CXX_MAJOR := $(word 1,$(subst ., ,$(CXX_VERSION))) CXX_MINOR := $(word 2,$(subst ., ,$(CXX_VERSION))) - ################################################################################ # Set optional compiler flags for performance # @@ -122,13 +121,34 @@ CPPFLAGS_BOOST ?= -DBOOST_DISABLE_ASSERTS CPPFLAGS_SUNDIALS ?= -DNO_FPRINTF_OUTPUT $(CPPFLAGS_OPTIM_SUNDIALS) $(CXXFLAGS_FLTO_SUNDIALS) #CPPFLAGS_GTEST ?= - -ifeq ($(STAN_USE_CPP14),) +ifeq ($(CXX_TYPE), gcc) + GCC_GE_73 := $(shell [ $(CXX_MAJOR) -gt 7 -o \( $(CXX_MAJOR) -eq 7 -a $(CXX_MINOR) -ge 1 \) ] && echo true) + ifeq ($(GCC_GE_73),true) + CXXFLAGS_LANG ?= -std=c++17 + CXXFLAGS_STANDARD ?= c++17 + endif +else ifeq ($(CXX_TYPE), clang) + CLANG_GE_5 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true) + ifeq ($(CLANG_GE_5),true) + CXXFLAGS_LANG ?= -std=c++17 + CXXFLAGS_STANDARD ?= c++17 + endif +else ifeq ($(CXX_TYPE), mingw32-gcc) + MINGW_GE_50 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true) + ifeq ($(MINGW_GE_50),true) + CXXFLAGS_LANG ?= -std=c++17 + CXXFLAGS_STANDARD ?= c++17 + endif +else ifeq ($(STAN_USE_CPP14),) CXXFLAGS_LANG ?= -std=c++17 + CXXFLAGS_STANDARD ?= c++17 else $(warning "Because STAN_USE_CPP14 is set C++14 standard is requested. This will not be possible in the next release!") CXXFLAGS_LANG ?= -std=c++1y + CXXFLAGS_STANDARD ?= c++1y endif + + #CXXFLAGS_BOOST ?= CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS) #CXXFLAGS_GTEST diff --git a/make/libraries b/make/libraries index f6beafcda46..e2b347d8388 100644 --- a/make/libraries +++ b/make/libraries @@ -176,11 +176,11 @@ endif $(TBB_BIN)/tbb.def: $(TBB_BIN)/tbb-make-check @mkdir -p $(TBB_BIN) touch $(TBB_BIN)/version_$(notdir $(TBB)) - tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbb" compiler=$(TBB_CXX_TYPE) cfg=release stdver=c++1y CXXFLAGS="$(TBB_CXXFLAGS)" + tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbb" compiler=$(TBB_CXX_TYPE) cfg=release stdver=$(CXXFLAGS_STANDARD) CXXFLAGS="$(TBB_CXXFLAGS)" $(TBB_BIN)/tbbmalloc.def: $(TBB_BIN)/tbb-make-check @mkdir -p $(TBB_BIN) - tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbbmalloc" compiler=$(TBB_CXX_TYPE) cfg=release stdver=c++1y malloc CXXFLAGS="$(TBB_CXXFLAGS)" + tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbbmalloc" compiler=$(TBB_CXX_TYPE) cfg=release stdver=$(CXXFLAGS_STANDARD) malloc CXXFLAGS="$(TBB_CXXFLAGS)" $(TBB_BIN)/libtbb.dylib: $(TBB_BIN)/tbb.def $(TBB_BIN)/libtbbmalloc.dylib: $(TBB_BIN)/tbbmalloc.def