scons: Enable build on OSX

This patch changes the SConscript to build gem5 with libc++ on OSX as
the conventional libstdc++ does not have the C++11 constructs that the
current code base makes use of (e.g. std::forward).

Since this was the last use of the transitional TR1, the unordered map
and set header can now be simplified as well.
This commit is contained in:
Andreas Hansson 2013-09-04 13:22:54 -04:00
parent e1b9c8c169
commit fdf6f6c4b6
2 changed files with 9 additions and 35 deletions

View file

@ -630,15 +630,10 @@ elif main['CLANG']:
main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) main.Append(TCMALLOC_CCFLAGS=['-fno-builtin'])
# On Mac OS X/Darwin we need to also use libc++ (part of XCode) as # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as
# opposed to libstdc++ to make the transition from TR1 to # opposed to libstdc++, as the later is dated.
# C++11. See http://libcxx.llvm.org. However, clang has chosen a if sys.platform == "darwin":
# strict implementation of the C++11 standard, and does not allow main.Append(CXXFLAGS=['-stdlib=libc++'])
# incomplete types in template arguments (besides unique_ptr and main.Append(LIBS=['c++'])
# shared_ptr), and the libc++ STL containers create problems in
# combination with the current gem5 code. For now, we stick with
# libstdc++ and use the TR1 namespace.
# if sys.platform == "darwin":
# main.Append(CXXFLAGS=['-stdlib=libc++'])
else: else:
print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal,

View file

@ -44,42 +44,21 @@
#ifndef __HASHMAP_HH__ #ifndef __HASHMAP_HH__
#define __HASHMAP_HH__ #define __HASHMAP_HH__
#if defined(__clang__) // we stick with defines here until gcc >= 4.7 and clang >= 3.2 is
// check if the header is present, which requires -stdlib=libc++, and // adopted as these are the minimum versions to support variadic
// that in turn causes problems with incomplete template parameters // templates and template aliasing
#if (__has_include(<unordered_map>))
#define HAVE_STD_UNORDERED_MAP 1
#endif
#else
// we only support gcc >= 4.4 as the other option
#define HAVE_STD_UNORDERED_MAP 1
#endif
// set a default value of 0 clang with the header in the tr1 namespace
#ifndef HAVE_STD_UNORDERED_MAP
#define HAVE_STD_UNORDERED_MAP 0
#endif
#define hash_map unordered_map #define hash_map unordered_map
#define hash_multimap unordered_multimap #define hash_multimap unordered_multimap
#define hash_set unordered_set #define hash_set unordered_set
#define hash_multiset unordered_multiset #define hash_multiset unordered_multiset
#if HAVE_STD_UNORDERED_MAP // gcc >= 4.4 or clang with libc++ no longer rely on the transitional
// gcc or clang with libc++ // tr1 namespace
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#define __hash_namespace std #define __hash_namespace std
#define __hash_namespace_begin namespace std { #define __hash_namespace_begin namespace std {
#define __hash_namespace_end } #define __hash_namespace_end }
#else
// clang with libstdc++
#include <tr1/unordered_map>
#include <tr1/unordered_set>
#define __hash_namespace std::tr1
#define __hash_namespace_begin namespace std { namespace tr1 {
#define __hash_namespace_end } }
#endif
namespace m5 { namespace m5 {
using ::__hash_namespace::hash_multimap; using ::__hash_namespace::hash_multimap;