From 8cdebcff1d1e8321b070c7e675f9a9709a2b0b81 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Mon, 14 Mar 2016 12:27:29 +0100 Subject: Build all Swift projects as C++11 Added a SCons compiler test so that the build process fails early if C++11 is not supported. Remove C++11 checks as we now default to C++11 and they are not needed anymore. Ignore a Clang warning if building 3rdParty Boost. Test-Information: Tested build and unit tests on OS X 10.11.3. Change-Id: Icbecbd1e25e8d8bbe5f402f75355373a86b5f8a1 diff --git a/3rdParty/Boost/SConscript b/3rdParty/Boost/SConscript index d56f5e3..b3ed153 100644 --- a/3rdParty/Boost/SConscript +++ b/3rdParty/Boost/SConscript @@ -1,3 +1,5 @@ +import os + Import("env") # FIXME: Remove this when Boost UUID is present on most distros @@ -54,6 +56,10 @@ elif env.get("BOOST_BUNDLED", False) : if env["SCONS_STAGE"] == "build" : myenv = env.Clone() myenv.Replace(CXXFLAGS = [flag for flag in env["CXXFLAGS"] if not flag.startswith("-W")]) + if os.path.basename(env["CXX"]) in ["clang", "clang++"] : + myenv.Append(CXXFLAGS = [ + "-Wno-deprecated-register", # The register keyword will be reserved in C++17, we only use C++11 though. + ]) sources = [ "src/libs/atomic/src/lockpool.cpp", diff --git a/BuildTools/SCons/SConscript.boot b/BuildTools/SCons/SConscript.boot index 10b0daf..1811b28 100644 --- a/BuildTools/SCons/SConscript.boot +++ b/BuildTools/SCons/SConscript.boot @@ -174,11 +174,9 @@ if env["PLATFORM"] == "darwin" and env["target"] == "native" : env["CCFLAGS"] = ["-arch", "x86_64"] if "cxx" not in env : env["CXX"] = "clang++" - # Compiling Qt5 in C++0x mode includes headers that we don't have - if not env["qt5"] : - env["CXXFLAGS"] = ["-std=c++11"] if "link" not in env : - env["LINK"] = "clang" + # Use clang++ instead of clang, otherwise XCode's clang will cause linking errors due to missing C++ standard lib. + env["LINK"] = "clang++" if platform.machine() == "x86_64" : env.Append(LINKFLAGS = ["-arch", "x86_64"]) @@ -201,6 +199,8 @@ if "ar" in env : if "link" in env : env["SHLINK"] = env["link"] env["LINK"] = env["link"] + +# Process user-defined external flags for flags_type in ["ccflags", "cxxflags", "linkflags"] : if flags_type in env : if isinstance(env[flags_type], str) : @@ -212,6 +212,10 @@ for flags_type in ["ccflags", "cxxflags", "linkflags"] : # where you need it env["OBJCCFLAGS"] = [] +# Compile code as C++11 +if env["PLATFORM"] != "win32" : + env.Append(CXXFLAGS = ["-std=c++11"]) + if env["optimize"] : if env["PLATFORM"] == "win32" : env.Append(CCFLAGS = ["/O2"]) @@ -303,7 +307,7 @@ elif env["PLATFORM"] == "sunos" : #env.Append(CXXFLAGS = ["-z verbose"]) pass else : - if "clang" in env["CXX"] : + if os.path.basename(env["CXX"]) in ["clang", "clang++"] : env.Append(CXXFLAGS = [ "-Weverything", "-Wno-unknown-warning-option", # To stay compatible between CLang versions @@ -316,7 +320,6 @@ else : "-Wno-c++98-compat-pedantic", # We do different things that violate this, but they could be fixed "-Wno-global-constructors", # We depend on this for e.g. string constants "-Wno-disabled-macro-expansion", # Caused due to system headers - "-Wno-c++11-extensions", # We use C++11; turn this off when we use -std=c++11 "-Wno-long-long", # We use long long "-Wno-padded", "-Wno-missing-variable-declarations", # Getting rid of CPPUnit warnings diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct index 3305fd3..173380e 100644 --- a/BuildTools/SCons/SConstruct +++ b/BuildTools/SCons/SConstruct @@ -68,6 +68,35 @@ def checkObjCHeader(context, header) : context.Result(ret) return ret +def checkForCpp11Support(context) : + context.Message('Checking whether the C++ compiler supports C++11... ') + result = context.TryLink( + """ +#include + +int main(int, char **) { + // shared_ptr test + std::shared_ptr intPtr = std::make_shared(); + + // unique_ptr test + std::unique_ptr intPtrUnique = std::unique_ptr(new int(1)); + + // auto test + auto otherIntPtr = intPtr; + std::shared_ptr fooIntPtr = otherIntPtr; + + // lambda test + auto someFunction = [](int i){ i = i * i; }; + + // nullptr test + double* fooDouble = nullptr; + return 0; +} +""", '.cpp') + context.Result(result) + return result + + ################################################################################ # Platform configuration ################################################################################ @@ -103,13 +132,19 @@ int main(int argc, char* argv[]) { else : return -1 - -conf = Configure(conf_env) +conf = Configure(conf_env, custom_tests = { + 'CheckCpp11Support' : checkForCpp11Support, + }) if not conf.CheckCXX() or not conf.CheckCC() : print "Error: You need a working compiler" Exit(1) +if not conf.CheckCpp11Support() : + print "Error: You need a compiler with support for the C++11 standard" + Exit(1) + + env["HAVE_ZLIB"] = True zlib_flags = {} zlib_okay = False diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript index 5d27b70..f3cb0d7 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript @@ -13,24 +13,5 @@ example_env.UseFlags(example_env["SWIFTEN_DEP_FLAGS"]) for i in range(1,7) : example_env.Program("EchoBot" + str(i), ["EchoBot" + str(i) + ".cpp"]) +example_env.Program("EchoBot0x", "EchoBot0x.cpp") example_env.Program("EchoComponent", "EchoComponent.cpp") - -# C++0x -cpp0x = False -cpp0x_env = example_env.Clone() -if env["PLATFORM"] == "win32" : - if int(env["MSVS_VERSION"].split(".")[0]) >= 10 : - cpp0x = True -elif env["PLATFORM"] == "hpux" : - pass -elif env["PLATFORM"] == "sunos" : - pass -else : - if env["CCVERSION"].split(".") >= ["4", "5", "0"] : - # Temporarily disabling c++0x mode because of problems with boost::thread - # on some platforms - #cpp0x = True - cpp0x_env.Replace(CXXFLAGS = [flag for flag in env["CXXFLAGS"] if flag != "-Werror"]) - cpp0x_env.Append(CXXFLAGS = ["-std=c++0x"]) -if cpp0x : - cpp0x_env.Program("EchoBot0x", "EchoBot0x.cpp") -- cgit v0.10.2-6-g49f6