@@ -70,7 +70,6 @@ CXX_VERSION := $(shell $(CXX) -dumpfullversion -dumpversion 2>&1)
7070CXX_MAJOR := $(word 1,$(subst ., ,$(CXX_VERSION)))
7171CXX_MINOR := $(word 2,$(subst ., ,$(CXX_VERSION)))
7272
73-
7473################################################################################
7574# Set optional compiler flags for performance
7675#
@@ -121,10 +120,32 @@ INC_GTEST ?= -I $(GTEST)/include -I $(GTEST)
121120CPPFLAGS_BOOST ?= -DBOOST_DISABLE_ASSERTS
122121CPPFLAGS_SUNDIALS ?= -DNO_FPRINTF_OUTPUT $(CPPFLAGS_OPTIM_SUNDIALS) $(CXXFLAGS_FLTO_SUNDIALS)
123122#CPPFLAGS_GTEST ?=
123+ STAN_HAS_CXX17 ?= false
124+ ifeq ($(CXX_TYPE), gcc)
125+ GCC_GE_73 := $(shell [ $(CXX_MAJOR) -gt 7 -o \( $(CXX_MAJOR) -eq 7 -a $(CXX_MINOR) -ge 1 \) ] && echo true)
126+ ifeq ($(GCC_GE_73),true)
127+ STAN_HAS_CXX17 := true
128+ endif
129+ else ifeq ($(CXX_TYPE), clang)
130+ CLANG_GE_5 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true)
131+ ifeq ($(CLANG_GE_5),true)
132+ STAN_HAS_CXX17 := true
133+ endif
134+ else ifeq ($(CXX_TYPE), mingw32-gcc)
135+ MINGW_GE_50 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true)
136+ ifeq ($(MINGW_GE_50),true)
137+ STAN_HAS_CXX17 := true
138+ endif
139+ endif
124140
125-
126- ## setup compiler flags
127- CXXFLAGS_LANG ?= -std=c++1y
141+ ifeq ($(STAN_HAS_CXX17), true)
142+ CXXFLAGS_LANG ?= -std=c++17
143+ CXXFLAGS_STANDARD ?= c++17
144+ else
145+ $(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")
146+ CXXFLAGS_LANG ?= -std=c++1y
147+ CXXFLAGS_STANDARD ?= c++1y
148+ endif
128149#CXXFLAGS_BOOST ?=
129150CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS)
130151#CXXFLAGS_GTEST
0 commit comments