diff --git a/make/compiler_flags b/make/compiler_flags index 33295628e7c..a8c6eed1262 100644 --- a/make/compiler_flags +++ b/make/compiler_flags @@ -161,8 +161,19 @@ ifeq ($(OS),Windows_NT) CXXFLAGS_OS ?= -m64 endif - UCRT_STRING := $(shell echo "\#include " | $(CXX) -E -dM - | grep -i _UCRT) - ifneq (,$(UCRT_STRING)) + ifeq (,$(wildcard $(MATH)make/ucrt)) + UCRT_STRING := $(shell echo "#include " | $(CXX) -E -dM - | findstr _UCRT) + ifneq (,$(UCRT_STRING)) + IS_UCRT ?= true + else + IS_UCRT ?= false + endif + $(shell echo "IS_UCRT ?= $(IS_UCRT)" > $(MATH)make/ucrt) + else + -include $(MATH)make/ucrt + endif + + ifeq ($(IS_UCRT),true) CXXFLAGS_OS += -D_UCRT endif diff --git a/make/libraries b/make/libraries index 1e28b44ea66..7dd5dcbfd45 100644 --- a/make/libraries +++ b/make/libraries @@ -140,7 +140,7 @@ ifeq (Linux, $(OS)) endif ifeq (Windows_NT, $(OS)) - ifneq (,$(UCRT_STRING)) + ifeq ($(IS_UCRT),true) TBB_CXXFLAGS += -D_UCRT endif endif diff --git a/makefile b/makefile index f34da7b164b..f14ab40df4e 100644 --- a/makefile +++ b/makefile @@ -125,6 +125,7 @@ clean-deps: @$(RM) $(call findfiles,test,*.d.*) @$(RM) $(call findfiles,lib,*.d.*) @$(RM) $(call findfiles,stan,*.dSYM) + @$(RM) $(call findfiles,make,ucrt) clean-all: clean clean-doxygen clean-deps clean-libraries