You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.5 KiB

  1. dnl Check for the __declspec(dllexport) construct support.
  2. AC_DEFUN([AX_DECLSPEC],
  3. [
  4. AH_TEMPLATE($1[]_IMPORT,
  5. [Defined if the compiler understands __declspec(dllimport)
  6. or __attribute__((visibility("default"))) or __global construct.])
  7. AH_TEMPLATE($1[]_EXPORT,
  8. [Defined if the compiler understands __declspec(dllimport)
  9. or __attribute__((visibility("default"))) or __global construct.])
  10. AH_TEMPLATE($1[]_PRIVATE,
  11. [Defined if the compiler understands __attribute__((visibility("hidden")))
  12. or __hidden construct.])
  13. AS_VAR_SET([continue_checks], [1])
  14. dnl This is for Solaris platforms with Solaris Studio.
  15. AC_CACHE_CHECK([for __global and __hidden], [ac_cv__global],
  16. [
  17. AC_COMPILE_IFELSE(
  18. [AC_LANG_PROGRAM(
  19. [[
  20. __global int x = 0;
  21. __global int foo ();
  22. int foo () { return 0; }
  23. __global int bar () { return x; }
  24. __hidden int baz () { return 1; }
  25. ]],
  26. [[]])],
  27. [ac_cv__global=yes],
  28. [ac_cv__global=no])
  29. ])
  30. AS_IF([test "x$ac_cv__global" = "xyes"],
  31. [AC_DEFINE($1[]_IMPORT, [__global])
  32. AC_DEFINE($1[]_EXPORT, [__global])
  33. AC_DEFINE($1[]_PRIVATE, [__hidden])
  34. AS_UNSET([continue_checks])])
  35. dnl This typically succeeds on Windows/MinGW/Cygwin.
  36. AS_VAR_SET_IF([continue_checks],
  37. [
  38. AC_CACHE_CHECK([for __declspec(dllexport) and __declspec(dllimport)],
  39. [ac_cv_declspec],
  40. [
  41. AC_COMPILE_IFELSE(
  42. [AC_LANG_PROGRAM(
  43. [[
  44. #if defined (__clang__)
  45. // Here the problem is that Clang only warns that it does not support
  46. // __declspec(dllexport) but still compiles the executable.
  47. # error Please fail.
  48. And extra please fail.
  49. #else
  50. __declspec(dllexport) int x = 0;
  51. __declspec(dllexport) int foo ();
  52. int foo () { return 0; }
  53. __declspec(dllexport) int bar () { return x; }
  54. #endif
  55. ]],
  56. [[]])],
  57. [ac_cv_declspec=yes],
  58. [ac_cv_declspec=no])
  59. ])
  60. AS_IF([test "x$ac_cv_declspec" = "xyes"],
  61. [AC_DEFINE($1[]_IMPORT, [__declspec(dllimport)])
  62. AC_DEFINE($1[]_EXPORT, [__declspec(dllexport)])
  63. AC_DEFINE($1[]_PRIVATE, [/* empty */])
  64. AS_UNSET([continue_checks])])
  65. ])
  66. dnl This typically succeeds on *NIX platforms with GCC or Clang.
  67. AS_VAR_SET_IF([continue_checks],
  68. [
  69. AC_CACHE_CHECK([for __attribute__((visibility("default")))dnl
  70. and __attribute__((visibility("hidden")))], [ac_cv__attribute__visibility],
  71. [
  72. AC_COMPILE_IFELSE(
  73. [AC_LANG_PROGRAM(
  74. [[
  75. #if defined (__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 1))
  76. # error Please fail.
  77. And extra please fail.
  78. #else
  79. __attribute__((visibility("default"))) int x = 0;
  80. __attribute__((visibility("default"))) int foo ();
  81. int foo () { return 0; }
  82. __attribute__((visibility("default"))) int bar () { return x; }
  83. __attribute__((visibility("hidden"))) int baz () { return 1; }
  84. #endif
  85. ]],
  86. [[]])],
  87. [ac_cv__attribute__visibility=yes],
  88. [ac_cv__attribute__visibility=no])
  89. ])
  90. AS_IF([test "x$ac_cv__attribute__visibility" = "xyes"],
  91. [AC_DEFINE($1[]_IMPORT, [__attribute__ ((visibility("default")))])
  92. AC_DEFINE($1[]_EXPORT, [__attribute__ ((visibility("default")))])
  93. AC_DEFINE($1[]_PRIVATE, [__attribute__ ((visibility("hidden")))])
  94. AS_UNSET([continue_checks])])
  95. ])
  96. AS_IF([test "x$ac_cv__attribute__visibility" = "xno" dnl
  97. && test "x$ac_cv_declspec" = "xno" dnl
  98. && test "x$ax_cv__global" = "xno"],
  99. [AC_DEFINE($1[]_IMPORT, [/* empty */])
  100. AC_DEFINE($1[]_EXPORT, [/* empty */])
  101. AC_DEFINE($1[]_PRIVATE, [/* empty */])])
  102. AS_UNSET([continue_checks])
  103. ]) dnl AX_DECLSPEC