• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# We check two things: where the include file is for hash_map, and
2# what namespace hash_map lives in within that include file.  We
3# include AC_TRY_COMPILE for all the combinations we've seen in the
4# wild.  We define one of HAVE_HASH_MAP or HAVE_EXT_HASH_MAP depending
5# on location, and HASH_NAMESPACE to be the namespace hash_map is
6# defined in.
7#
8# Ideally we'd use AC_CACHE_CHECK, but that only lets us store one value
9# at a time, and we need to store two (filename and namespace).
10# prints messages itself, so we have to do the message-printing ourselves
11# via AC_MSG_CHECKING + AC_MSG_RESULT.  (TODO(csilvers): can we cache?)
12
13AC_DEFUN([AC_CXX_STL_HASH],
14  [AC_MSG_CHECKING(the location of hash_map)
15  AC_LANG_SAVE
16   AC_LANG_CPLUSPLUS
17   ac_cv_cxx_hash_map_header=""
18   ac_cv_cxx_hash_map_class=""
19   for location in [tr1/unordered_map ext/hash_map hash_map]; do
20     for namespace in [std::tr1 __gnu_cxx "" std stdext]; do
21       for name in [unordered_map hash_map]; do
22
23         if test -z "$ac_cv_cxx_hash_map_header"; then
24
25           # On OSX 1.5 / GCC 4.0.1 (the standard compiler on that platform),
26           # calling find() on a const unordered_map does not compile.  So, we
27           # include a call to find() in our test to detect this broken
28           # implementation and avoid using it.  Note that ext/hash_map works
29           # fine on this platform, so we'll end up using that.
30           AC_TRY_COMPILE([#include <$location>],
31                          [const ${namespace}::$name<int, int> t;
32                           t.find(1);],
33                          [ac_cv_cxx_hash_map_header="<$location>";
34                           ac_cv_cxx_hash_namespace="$namespace";
35                           ac_cv_cxx_hash_map_class="$name";])
36         fi
37       done
38     done
39   done
40   ac_cv_cxx_hash_set_header=`echo "$ac_cv_cxx_hash_map_header" | sed s/map/set/`;
41   ac_cv_cxx_hash_set_class=`echo "$ac_cv_cxx_hash_map_class" | sed s/map/set/`;
42   if test -n "$ac_cv_cxx_hash_map_header"; then
43      AC_DEFINE(HAVE_HASH_MAP, 1, [define if the compiler has hash_map])
44      AC_DEFINE(HAVE_HASH_SET, 1, [define if the compiler has hash_set])
45      AC_DEFINE_UNQUOTED(HASH_MAP_H,$ac_cv_cxx_hash_map_header,
46                         [the location of <hash_map>])
47      AC_DEFINE_UNQUOTED(HASH_SET_H,$ac_cv_cxx_hash_set_header,
48                         [the location of <hash_set>])
49      AC_DEFINE_UNQUOTED(HASH_MAP_CLASS,$ac_cv_cxx_hash_map_class,
50                         [the name of <hash_set>])
51      AC_DEFINE_UNQUOTED(HASH_SET_CLASS,$ac_cv_cxx_hash_set_class,
52                         [the name of <hash_set>])
53      AC_DEFINE_UNQUOTED(HASH_NAMESPACE,$ac_cv_cxx_hash_namespace,
54                         [the namespace of hash_map/hash_set])
55      AC_MSG_RESULT([$ac_cv_cxx_hash_map_header])
56   else
57      AC_MSG_RESULT()
58      AC_MSG_WARN([could not find an STL hash_map])
59   fi
60])
61