summaryrefslogtreecommitdiff
path: root/SConstruct
diff options
context:
space:
mode:
authorAndreas Sandberg <Andreas.Sandberg@arm.com>2012-09-25 11:49:40 -0500
committerAndreas Sandberg <Andreas.Sandberg@arm.com>2012-09-25 11:49:40 -0500
commit4544f3def42ae9b8c528223d8762ae3634c7124a (patch)
tree21fa1ea3b3e9e6aa57d44110eec07b712650f6fc /SConstruct
parent6598241f2c188ba6f4ce035d9e1fbdd4619c7e00 (diff)
downloadgem5-4544f3def42ae9b8c528223d8762ae3634c7124a.tar.xz
base: Check for static_assert support and provide fallback
C++11 has support for static_asserts to provide compile-time assertion checking. This is very useful when testing, for example, structure sizes to make sure that the compiler got the right alignment or vector sizes.
Diffstat (limited to 'SConstruct')
-rwxr-xr-xSConstruct21
1 files changed, 19 insertions, 2 deletions
diff --git a/SConstruct b/SConstruct
index 515f6047b..842c4fef5 100755
--- a/SConstruct
+++ b/SConstruct
@@ -684,17 +684,34 @@ def CheckLeading(context):
context.Result(ret)
return ret
+# Test for the presence of C++11 static asserts. If the compiler lacks
+# support for static asserts, base/compiler.hh enables a macro that
+# removes any static asserts in the code.
+def CheckStaticAssert(context):
+ context.Message("Checking for C++11 static_assert support...")
+ ret = context.TryCompile('''
+ static_assert(1, "This assert is always true");
+ ''', extension=".cc")
+ context.env.Append(HAVE_STATIC_ASSERT=ret)
+ context.Result(ret)
+ return ret
+
# Platform-specific configuration. Note again that we assume that all
# builds under a given build root run on the same host platform.
conf = Configure(main,
conf_dir = joinpath(build_root, '.scons_config'),
log_file = joinpath(build_root, 'scons_config.log'),
- custom_tests = { 'CheckLeading' : CheckLeading })
+ custom_tests = { 'CheckLeading' : CheckLeading,
+ 'CheckStaticAssert' : CheckStaticAssert,
+ })
# Check for leading underscores. Don't really need to worry either
# way so don't need to check the return code.
conf.CheckLeading()
+# Check for C++11 features we want to use if they exist
+conf.CheckStaticAssert()
+
# Check if we should compile a 64 bit binary on Mac OS X/Darwin
try:
import platform
@@ -923,7 +940,7 @@ sticky_vars.AddVariables(
# These variables get exported to #defines in config/*.hh (see src/SConscript).
export_vars += ['USE_FENV', 'SS_COMPATIBLE_FP',
'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'PROTOCOL',
- ]
+ 'HAVE_STATIC_ASSERT']
###################################################
#