blob: d7def1af9b55ce975ee227ff68194414b06e96f3 [file] [log] [blame]
liujisi@google.com1fd96c42010-12-07 06:23:55 +00001# We check two things: where the include file is for
2# unordered_map/hash_map (we prefer the first form), and what
3# namespace unordered/hash_map lives in within that include file. We
temporal40ee5512008-07-10 02:12:20 +00004# include AC_TRY_COMPILE for all the combinations we've seen in the
liujisi@google.com1fd96c42010-12-07 06:23:55 +00005# wild. We define HASH_MAP_H to the location of the header file, and
6# HASH_NAMESPACE to the namespace the class (unordered_map or
Peter Newman4af1cc72016-01-09 13:38:42 +00007# hash_map) is in.
temporal40ee5512008-07-10 02:12:20 +00008
liujisi@google.com1fd96c42010-12-07 06:23:55 +00009# This also checks if unordered map exists.
temporal40ee5512008-07-10 02:12:20 +000010AC_DEFUN([AC_CXX_STL_HASH],
liujisi@google.com1fd96c42010-12-07 06:23:55 +000011 [
12 AC_MSG_CHECKING(the location of hash_map)
13 AC_LANG_SAVE
temporal40ee5512008-07-10 02:12:20 +000014 AC_LANG_CPLUSPLUS
liujisi@google.com1fd96c42010-12-07 06:23:55 +000015 ac_cv_cxx_hash_map=""
16 # First try unordered_map, but not on gcc's before 4.2 -- I've
17 # seen unexplainable unordered_map bugs with -O2 on older gcc's.
18 AC_TRY_COMPILE([#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
19 # error GCC too old for unordered_map
20 #endif
21 ],
22 [/* no program body necessary */],
23 [stl_hash_old_gcc=no],
24 [stl_hash_old_gcc=yes])
25 for location in unordered_map tr1/unordered_map; do
26 for namespace in std std::tr1; do
27 if test -z "$ac_cv_cxx_hash_map" -a "$stl_hash_old_gcc" != yes; then
28 # Some older gcc's have a buggy tr1, so test a bit of code.
29 AC_TRY_COMPILE([#include <$location>],
30 [const ${namespace}::unordered_map<int, int> t;
31 return t.find(5) == t.end();],
32 [ac_cv_cxx_hash_map="<$location>";
33 ac_cv_cxx_hash_namespace="$namespace";
34 ac_cv_cxx_hash_map_class="unordered_map";])
35 fi
temporal40ee5512008-07-10 02:12:20 +000036 done
37 done
liujisi@google.com1fd96c42010-12-07 06:23:55 +000038 # Now try hash_map
39 for location in ext/hash_map hash_map; do
40 for namespace in __gnu_cxx "" std stdext; do
41 if test -z "$ac_cv_cxx_hash_map"; then
42 AC_TRY_COMPILE([#include <$location>],
43 [${namespace}::hash_map<int, int> t],
44 [ac_cv_cxx_hash_map="<$location>";
45 ac_cv_cxx_hash_namespace="$namespace";
46 ac_cv_cxx_hash_map_class="hash_map";])
47 fi
48 done
49 done
50 ac_cv_cxx_hash_set=`echo "$ac_cv_cxx_hash_map" | sed s/map/set/`;
kenton@google.comee7e9422009-12-21 18:58:23 +000051 ac_cv_cxx_hash_set_class=`echo "$ac_cv_cxx_hash_map_class" | sed s/map/set/`;
liujisi@google.com1fd96c42010-12-07 06:23:55 +000052 if test -n "$ac_cv_cxx_hash_map"; then
temporal40ee5512008-07-10 02:12:20 +000053 AC_DEFINE(HAVE_HASH_MAP, 1, [define if the compiler has hash_map])
54 AC_DEFINE(HAVE_HASH_SET, 1, [define if the compiler has hash_set])
liujisi@google.com1fd96c42010-12-07 06:23:55 +000055 AC_DEFINE_UNQUOTED(HASH_MAP_H,$ac_cv_cxx_hash_map,
56 [the location of <unordered_map> or <hash_map>])
57 AC_DEFINE_UNQUOTED(HASH_SET_H,$ac_cv_cxx_hash_set,
58 [the location of <unordered_set> or <hash_set>])
temporal40ee5512008-07-10 02:12:20 +000059 AC_DEFINE_UNQUOTED(HASH_NAMESPACE,$ac_cv_cxx_hash_namespace,
60 [the namespace of hash_map/hash_set])
liujisi@google.com1fd96c42010-12-07 06:23:55 +000061 AC_DEFINE_UNQUOTED(HASH_MAP_CLASS,$ac_cv_cxx_hash_map_class,
62 [the name of <hash_map>])
63 AC_DEFINE_UNQUOTED(HASH_SET_CLASS,$ac_cv_cxx_hash_set_class,
64 [the name of <hash_set>])
65 AC_MSG_RESULT([$ac_cv_cxx_hash_map])
temporal40ee5512008-07-10 02:12:20 +000066 else
67 AC_MSG_RESULT()
68 AC_MSG_WARN([could not find an STL hash_map])
69 fi
70])
liujisi@google.com1fd96c42010-12-07 06:23:55 +000071