pandora_stl_hash.m4 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_COMPILE_IFELSE 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. AC_DEFUN([PANDORA_CXX_STL_HASH],
  13. [AC_MSG_CHECKING(the location of hash_map)
  14. save_CXXFLAGS="${CXXFLAGS}"
  15. CXXFLAGS="${AM_CXXFLAGS} ${CXXFLAGS}"
  16. AC_LANG_PUSH(C++)
  17. ac_cv_cxx_hash_map=""
  18. for location in "" "ext/" "tr1/" ; do
  19. for namespace in __gnu_cxx "" std stdext; do
  20. for classprefix in unordered hash; do
  21. if test -z "$ac_cv_cxx_hash_map"; then
  22. AC_COMPILE_IFELSE(
  23. [AC_LANG_PROGRAM([[#include <${location}${classprefix}_map>]],
  24. [[${namespace}::${classprefix}_map<int, int> t]])],
  25. [ac_cv_cxx_hash_map="<${location}${classprefix}_map>";
  26. ac_cv_cxx_hash_set="<${location}${classprefix}_set>";
  27. ac_cv_cxx_hash_namespace="$namespace";
  28. ac_cv_cxx_hash_map_class="${classprefix}_map";
  29. ac_cv_cxx_hash_set_class="${classprefix}_set"])
  30. fi
  31. done
  32. done
  33. done
  34. if test -n "$ac_cv_cxx_hash_map"; then
  35. AC_DEFINE(HAVE_HASH_MAP, 1, [define if the compiler has hash_map])
  36. AC_DEFINE(HAVE_HASH_SET, 1, [define if the compiler has hash_set])
  37. AC_DEFINE_UNQUOTED(HASH_MAP_H,$ac_cv_cxx_hash_map,
  38. [the location of <hash_map>])
  39. AC_DEFINE_UNQUOTED(HASH_SET_H,$ac_cv_cxx_hash_set,
  40. [the location of <hash_set>])
  41. AC_DEFINE_UNQUOTED(HASH_NAMESPACE,$ac_cv_cxx_hash_namespace,
  42. [the namespace of hash_map/hash_set])
  43. AC_DEFINE_UNQUOTED(HASH_MAP_CLASS,$ac_cv_cxx_hash_map_class,
  44. [the classname of hash_map])
  45. AC_DEFINE_UNQUOTED(HASH_SET_CLASS,$ac_cv_cxx_hash_set_class,
  46. [the classname of hash_set])
  47. AC_MSG_RESULT([$ac_cv_cxx_hash_map])
  48. else
  49. AC_MSG_RESULT()
  50. AC_MSG_WARN([could not find an STL hash_map])
  51. fi
  52. AC_CACHE_CHECK(
  53. [whether hash_map has rehash method],
  54. [ac_cv_hash_map_has_rehash],
  55. [AC_COMPILE_IFELSE(
  56. [AC_LANG_PROGRAM([[
  57. #include HASH_MAP_H
  58. using namespace HASH_NAMESPACE;
  59. ]],[[
  60. HASH_MAP_CLASS<int, int> test_hash;
  61. test_hash.rehash(100);
  62. ]])],
  63. [ac_cv_hash_map_has_rehash=yes],
  64. [ac_cv_hash_map_has_rehash=no])])
  65. AS_IF([test $ac_cv_hash_map_has_rehash = yes],[
  66. AC_DEFINE(HASH_MAP_HAS_REHASH, 1, [if hash_map<> hash rehash method])
  67. ])
  68. AC_CACHE_CHECK(
  69. [whether hash_map has resize method],
  70. [ac_cv_hash_map_has_resize],
  71. [AC_COMPILE_IFELSE(
  72. [AC_LANG_PROGRAM([[
  73. #include HASH_MAP_H
  74. using namespace HASH_NAMESPACE;
  75. ]],[[
  76. HASH_MAP_CLASS<int, int> test_hash;
  77. test_hash.resize(100);
  78. ]])],
  79. [ac_cv_hash_map_has_resize=yes],
  80. [ac_cv_hash_map_has_resize=no])])
  81. AS_IF([test $ac_cv_hash_map_has_resize = yes],[
  82. AC_DEFINE(HASH_MAP_HAS_RESIZE, 1, [if hash_map<> hash resize method])
  83. ])
  84. AC_CACHE_CHECK(
  85. [whether to redefine hash<string>],
  86. [ac_cv_redefine_hash_string],
  87. [AC_COMPILE_IFELSE(
  88. [AC_LANG_PROGRAM([[
  89. #include HASH_SET_H
  90. #include <string>
  91. using namespace HASH_NAMESPACE;
  92. using namespace std;
  93. ]],[[
  94. string teststr("test");
  95. HASH_SET_CLASS<string> test_hash;
  96. HASH_SET_CLASS<string>::iterator iter= test_hash.find(teststr);
  97. if (iter != test_hash.end())
  98. return 1;
  99. ]])],
  100. [ac_cv_redefine_hash_string=no],
  101. [ac_cv_redefine_hash_string=yes])])
  102. AS_IF([test $ac_cv_redefine_hash_string = yes],[
  103. AC_DEFINE(REDEFINE_HASH_STRING, 1, [if hash<string> needs to be defined])
  104. ])
  105. CXXFLAGS="${save_CXXFLAGS}"
  106. AC_LANG_POP()
  107. ])