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 6088de81523..a083dd1d45a 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 # @@ -121,10 +120,32 @@ INC_GTEST ?= -I $(GTEST)/include -I $(GTEST) CPPFLAGS_BOOST ?= -DBOOST_DISABLE_ASSERTS CPPFLAGS_SUNDIALS ?= -DNO_FPRINTF_OUTPUT $(CPPFLAGS_OPTIM_SUNDIALS) $(CXXFLAGS_FLTO_SUNDIALS) #CPPFLAGS_GTEST ?= +STAN_HAS_CXX17 ?= false +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) + STAN_HAS_CXX17 := true + 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) + STAN_HAS_CXX17 := true + 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) + STAN_HAS_CXX17 := true + endif +endif - -## setup compiler flags -CXXFLAGS_LANG ?= -std=c++1y +ifeq ($(STAN_HAS_CXX17), true) + CXXFLAGS_LANG ?= -std=c++17 + CXXFLAGS_STANDARD ?= c++17 +else + $(warning "Stan cannot detect if your compiler has the C++17 standard. If it does, please set STAN_HAS_CXX17=true in your make/local file. C++17 support is mandatory in the next release of Stan. Defaulting to C++14") + 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