stl_hash.m4 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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
  4. # include AC_TRY_COMPILE for all the combinations we've seen in the
  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
  7. # hash_map) is in.
  8. # This also checks if unordered map exists.
  9. AC_DEFUN([AC_CXX_STL_HASH],
  10. [
  11. AC_MSG_CHECKING(the location of hash_map)
  12. AC_LANG_SAVE
  13. AC_LANG_CPLUSPLUS
  14. ac_cv_cxx_hash_map=""
  15. # First try unordered_map, but not on gcc's before 4.2 -- I've
  16. # seen unexplainable unordered_map bugs with -O2 on older gcc's.
  17. AC_TRY_COMPILE([#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
  18. # error GCC too old for unordered_map
  19. #endif
  20. ],
  21. [/* no program body necessary */],
  22. [stl_hash_old_gcc=no],
  23. [stl_hash_old_gcc=yes])
  24. for location in unordered_map tr1/unordered_map; do
  25. for namespace in std std::tr1; do
  26. if test -z "$ac_cv_cxx_hash_map" -a "$stl_hash_old_gcc" != yes; then
  27. # Some older gcc's have a buggy tr1, so test a bit of code.
  28. AC_TRY_COMPILE([#include <$location>],
  29. [const ${namespace}::unordered_map<int, int> t;
  30. return t.find(5) == t.end();],
  31. [ac_cv_cxx_hash_map="<$location>";
  32. ac_cv_cxx_hash_namespace="$namespace";
  33. ac_cv_cxx_hash_map_class="unordered_map";])
  34. fi
  35. done
  36. done
  37. # Now try hash_map
  38. for location in ext/hash_map hash_map; do
  39. for namespace in __gnu_cxx "" std stdext; do
  40. if test -z "$ac_cv_cxx_hash_map"; then
  41. AC_TRY_COMPILE([#include <$location>],
  42. [${namespace}::hash_map<int, int> t],
  43. [ac_cv_cxx_hash_map="<$location>";
  44. ac_cv_cxx_hash_namespace="$namespace";
  45. ac_cv_cxx_hash_map_class="hash_map";])
  46. fi
  47. done
  48. done
  49. ac_cv_cxx_hash_set=`echo "$ac_cv_cxx_hash_map" | sed s/map/set/`;
  50. ac_cv_cxx_hash_set_class=`echo "$ac_cv_cxx_hash_map_class" | sed s/map/set/`;
  51. if test -n "$ac_cv_cxx_hash_map"; then
  52. AC_DEFINE(HAVE_HASH_MAP, 1, [define if the compiler has hash_map])
  53. AC_DEFINE(HAVE_HASH_SET, 1, [define if the compiler has hash_set])
  54. AC_DEFINE_UNQUOTED(HASH_MAP_H,$ac_cv_cxx_hash_map,
  55. [the location of <unordered_map> or <hash_map>])
  56. AC_DEFINE_UNQUOTED(HASH_SET_H,$ac_cv_cxx_hash_set,
  57. [the location of <unordered_set> or <hash_set>])
  58. AC_DEFINE_UNQUOTED(HASH_NAMESPACE,$ac_cv_cxx_hash_namespace,
  59. [the namespace of hash_map/hash_set])
  60. AC_DEFINE_UNQUOTED(HASH_MAP_CLASS,$ac_cv_cxx_hash_map_class,
  61. [the name of <hash_map>])
  62. AC_DEFINE_UNQUOTED(HASH_SET_CLASS,$ac_cv_cxx_hash_set_class,
  63. [the name of <hash_set>])
  64. AC_MSG_RESULT([$ac_cv_cxx_hash_map])
  65. else
  66. AC_MSG_RESULT()
  67. AC_MSG_WARN([could not find an STL hash_map])
  68. fi
  69. ])