c++ - Can I have my Makefile automatically make GCC use the most recent standard it supports? -


my c++03 project needs upgrade c++11, , can guarantee @ least experimental support available in gccs want use.

however, may -std=c++0x or may actual -std=c++11 newer gcc. 1 day it'll -std=c++14 (when centos catches up…).

how can form gnu makefile adds "best" flag cxxflags depending on succeed?

i could "okay, earliest gcc in use still doesn't have production-ready c++11 support should stick c++03", meh.

this select best option supported $(cxx) compiler:

cxx_mode.42 := -std=c++98 cxx_mode.43 := $(cxx_mode.42) cxx_mode.44 := $(cxx_mode.43) cxx_mode.45 := $(cxx_mode.44) cxx_mode.46 := -std=c++0x # unnecessary, since -std=c++0x still works, hey why not: cxx_mode.47 := -std=c++11 cxx_mode.48 := $(cxx_mode.47) cxx_mode.49 := $(cxx_mode.48) cxx_mode.5 := -std=c++14 cxx_mode.6 := $(cxx_mode.5) gxx_version := $(shell $(cxx) -dumpversion | awk -f. '$$1<5{print $$1$$2} $$1>=5{print $$1}') cxx_mode := $(cxx_mode.$(gxx_version)) cxxflags += $(cxx_mode) 

for fun choose between c++ , gnu++ modes based on other variable:

cxx_mode.42 := 98 cxx_mode.43 := $(cxx_mode.42) cxx_mode.44 := $(cxx_mode.43) cxx_mode.45 := $(cxx_mode.44) cxx_mode.46 := 0x # unnecessary, since -std=c++0x still works, hey why not: cxx_mode.47 := 11 cxx_mode.48 := $(cxx_mode.47) cxx_mode.49 := $(cxx_mode.48) cxx_mode.5 := 14 cxx_mode.6 := $(cxx_mode.5) gxx_version := $(shell $(cxx) -dumpversion | awk -f. '$$1<5{print $$1$$2} $$1>=5{print $$1}') cxx_mode := $(cxx_mode.$(gxx_version)) ifneq($(strict),) cxxflags += -std=c++$(cxx_mode) -pedantic -pedantic-errors else cxxflags += -std=gnu++$(cxx_mode) endif 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -