@@ -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
@@ -225,6 +246,10 @@ endif
225246
226247## silence warnings occuring due to the TBB and Eigen libraries
227248CXXFLAGS_WARNINGS += -Wno-ignored-attributes
249+ ## https://github.com/oneapi-src/oneTBB/issues/307
250+ ifeq ($(CXX_TYPE), gcc)
251+ CXXFLAGS_WARNINGS += -Wno-class-memaccess
252+ endif
228253
229254################################################################################
230255# Setup OpenCL
@@ -284,13 +309,19 @@ CXXFLAGS_TBB ?= -I $(TBB_INC)
284309else
285310CXXFLAGS_TBB ?= -I $(TBB)/include
286311endif
287- LDFLAGS_TBB ?= -Wl,-L,"$(TBB_LIB)" -Wl,--disable-new-dtags
312+
313+ # MacOS ld does not support --disable-new-dtags
314+ ifneq ($(OS),Darwin)
315+ LDFLAGS_TBB_DTAGS ?= -Wl,--disable-new-dtags
316+ endif
288317
289318# Windows LLVM/Clang does not support -rpath, but is not needed on Windows anyway
290319ifneq ($(OS), Windows_NT)
291- LDFLAGS_TBB + = -Wl,-rpath,"$(TBB_LIB)"
320+ LDFLAGS_TBB_RPATH ? = -Wl,-rpath,"$(TBB_LIB)"
292321endif
293322
323+ LDFLAGS_TBB ?= -Wl,-L,"$(TBB_LIB)" $(LDFLAGS_TBB_DTAGS) $(LDFLAGS_TBB_RPATH)
324+
294325LDLIBS_TBB ?= -ltbb
295326
296327else
0 commit comments