1# --------------------------------------------------------------
2# Test for compiler which does not support namespace-wrapped inclusion
3# of errno.h.  This is currently only known to affect GCC 5.2.0 on OSX
4# Yosemite and above.  One can work around the issue by simply
5# including errno.h separately, outside of any namespace.
6# --------------------------------------------------------------
7AC_DEFUN([CHECK_FOR_BROKEN_ERRNO_T],
8[
9  dnl Try to compile a test program that exhibits the error.
10  AC_LANG_PUSH([C++])
11
12  AC_MSG_CHECKING([if errno.h can be wrapped in namespace])
13
14  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
15  namespace Foo {
16  @%:@include <errno.h>
17  }
18  @%:@include <cstring>
19  ]], [[
20  ]])],[
21    AC_MSG_RESULT(yes)
22  ],[
23    errno_t_works=no
24    AC_MSG_RESULT(no)
25  ])
26
27  dnl If that test failed, verify that including the header outside of any namespace fixes the issue.
28  AS_IF([test "x$errno_t_works" = "xno"],
29        [
30          AC_MSG_CHECKING([if workaround fixes the issue])
31          AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
32          @%:@include <errno.h> // the fix
33          namespace Foo {
34          @%:@include <errno.h>
35          }
36          @%:@include <cstring>
37          ]], [[
38          ]])],[
39            typedef_errno_t_fixes_issue=yes
40            AC_MSG_RESULT(yes)
41          ],[
42            AC_MSG_RESULT(no)
43          ])
44        ])
45
46  AC_LANG_POP([C++])
47
48  dnl If the compiler has the issue and the workaround fixes it, set the #define
49  AS_IF([test "x$errno_t_works" = "xno" && test "x$typedef_errno_t_fixes_issue" = "xyes"],
50        [AC_DEFINE(COMPILER_HAS_BROKEN_ERRNO_T, 1, [define if errno.h cannot be included in a namespace])])
51
52  dnl On the other hand, if the compiler has the issue and the workaround *doesn't* fix it, error out.
53  AS_IF([test "x$errno_t_works" = "xno" && test "x$typedef_errno_t_fixes_issue" = "x"],
54        [AC_MSG_ERROR([Cannot work around errno.h inclusion issue.  This compiler will most likely not be able to build libmesh correctly.])])
55])
56