liujisi@google.com | 1fd96c4 | 2010-12-07 06:23:55 +0000 | [diff] [blame] | 1 | # 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 |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 4 | # include AC_TRY_COMPILE for all the combinations we've seen in the |
liujisi@google.com | 1fd96c4 | 2010-12-07 06:23:55 +0000 | [diff] [blame] | 5 | # 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 Newman | 4af1cc7 | 2016-01-09 13:38:42 +0000 | [diff] [blame^] | 7 | # hash_map) is in. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 8 | |
liujisi@google.com | 1fd96c4 | 2010-12-07 06:23:55 +0000 | [diff] [blame] | 9 | # This also checks if unordered map exists. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 10 | AC_DEFUN([AC_CXX_STL_HASH], |
liujisi@google.com | 1fd96c4 | 2010-12-07 06:23:55 +0000 | [diff] [blame] | 11 | [ |
| 12 | AC_MSG_CHECKING(the location of hash_map) |
| 13 | AC_LANG_SAVE |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 14 | AC_LANG_CPLUSPLUS |
liujisi@google.com | 1fd96c4 | 2010-12-07 06:23:55 +0000 | [diff] [blame] | 15 | 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 |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 36 | done |
| 37 | done |
liujisi@google.com | 1fd96c4 | 2010-12-07 06:23:55 +0000 | [diff] [blame] | 38 | # 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.com | ee7e942 | 2009-12-21 18:58:23 +0000 | [diff] [blame] | 51 | ac_cv_cxx_hash_set_class=`echo "$ac_cv_cxx_hash_map_class" | sed s/map/set/`; |
liujisi@google.com | 1fd96c4 | 2010-12-07 06:23:55 +0000 | [diff] [blame] | 52 | if test -n "$ac_cv_cxx_hash_map"; then |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 53 | 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.com | 1fd96c4 | 2010-12-07 06:23:55 +0000 | [diff] [blame] | 55 | 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>]) |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 59 | AC_DEFINE_UNQUOTED(HASH_NAMESPACE,$ac_cv_cxx_hash_namespace, |
| 60 | [the namespace of hash_map/hash_set]) |
liujisi@google.com | 1fd96c4 | 2010-12-07 06:23:55 +0000 | [diff] [blame] | 61 | 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]) |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 66 | else |
| 67 | AC_MSG_RESULT() |
| 68 | AC_MSG_WARN([could not find an STL hash_map]) |
| 69 | fi |
| 70 | ]) |
liujisi@google.com | 1fd96c4 | 2010-12-07 06:23:55 +0000 | [diff] [blame] | 71 | |