Skip to content

Commit 8e76f01

Browse files
authored
Merge pull request #3063 from stan-dev/cpp17-smoke-test
Request C++17 by default, add fallback flag for now
2 parents b12cfbd + 16337a1 commit 8e76f01

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

doxygen/contributor_help_pages/developer_doc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ These are the more common make flags that could be set:
184184
These are the rest of the variables that can be set:
185185

186186
- C++ compiler flags
187-
- `CXXFLAGS_LANG`: sets the language. Currently defaults to `-std=c++1y`
187+
- `CXXFLAGS_LANG`: sets the language. Currently defaults to `-std=c++17`
188188
- `CXXFLAGS_WARNINGS`: compiler options to squash compiler warnings
189189
- `CXXFLAGS_BOOST`: Boost-specific compiler flags
190190
- `CXXFLAGS_EIGEN`: Eigen-specific compiler flags

make/compiler_flags

+25-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ CXX_VERSION := $(shell $(CXX) -dumpfullversion -dumpversion 2>&1)
7070
CXX_MAJOR := $(word 1,$(subst ., ,$(CXX_VERSION)))
7171
CXX_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)
121120
CPPFLAGS_BOOST ?= -DBOOST_DISABLE_ASSERTS
122121
CPPFLAGS_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 ?=
129150
CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS)
130151
#CXXFLAGS_GTEST

make/libraries

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ endif
176176
$(TBB_BIN)/tbb.def: $(TBB_BIN)/tbb-make-check
177177
@mkdir -p $(TBB_BIN)
178178
touch $(TBB_BIN)/version_$(notdir $(TBB))
179-
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)"
179+
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)"
180180

181181
$(TBB_BIN)/tbbmalloc.def: $(TBB_BIN)/tbb-make-check
182182
@mkdir -p $(TBB_BIN)
183-
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)"
183+
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)"
184184

185185
$(TBB_BIN)/libtbb.dylib: $(TBB_BIN)/tbb.def
186186
$(TBB_BIN)/libtbbmalloc.dylib: $(TBB_BIN)/tbbmalloc.def

0 commit comments

Comments
 (0)