1dnl Checks whether system's pugixml library exists and is usable.
2
3AC_DEFUN([FZ_CHECK_PUGIXML], [
4  AC_ARG_WITH(pugixml, AC_HELP_STRING([--with-pugixml=type], [Selects which version of pugixml to use. Type has to be either system or builtin]),
5    [
6      if test "x$with_pugixml" != "xbuiltin"; then
7        if test "x$with_pugixml" != "xsystem"; then
8          if test "x$with_pugixml" != "xauto"; then
9            AC_MSG_ERROR([--with-pugixml has to be set to either system (the default), builtin or auto])
10          fi
11        fi
12      fi
13    ],
14    [
15      with_pugixml=system
16    ])
17
18
19  AC_LANG_PUSH(C++)
20
21  if test "x$with_pugixml" != "xbuiltin"; then
22
23    dnl Check pugixml.hpp header
24    AC_CHECK_HEADER(
25      [pugixml.hpp],
26      [],
27      [
28        if test "x$with_pugixml" = "xsystem"; then
29          AC_MSG_ERROR([pugixml.hpp not found. If you do not have pugixml installed as system library, you can use the copy of pugixml distributed with FileZilla by passing --with-pugixml=builtin as argument to configure.])
30        else
31          with_pugixml=builtin
32        fi
33      ])
34
35  fi
36
37  if test "x$with_pugixml" != "xbuiltin"; then
38    dnl Check for shared library
39    dnl Oddity: in AC_CHECK_HEADER I can leave the true case empty, but not in AC_HAVE_LIBRARY
40    AC_HAVE_LIBRARY(pugixml,
41      [true],
42      [
43        if test "x$with_pugixml" = "xsystem"; then
44          AC_MSG_ERROR([pugixml sytem library not found but requested. If you do not have pugixml installed as system library, you can use the copy of pugixml distributed with FileZilla by passing --with-pugixml=builtin as argument to configure.])
45        else
46          with_pugixml=builtin
47        fi
48      ])
49  fi
50
51  if test "x$with_pugixml" != "xbuiltin"; then
52    dnl Check for at least version 1.9
53    AC_MSG_CHECKING([for pugixml >= 1.9])
54    AC_COMPILE_IFELSE([
55      AC_LANG_PROGRAM([
56        #include <pugixml.hpp>
57      ],[
58          static_assert(PUGIXML_VERSION >= 190, "Need at least pugixml 1.9");
59      ])
60    ],[
61      AC_MSG_RESULT([yes])
62    ],[
63      AC_MSG_RESULT([no])
64        if test "x$with_pugixml" = "xsystem"; then
65          AC_MSG_ERROR([pugixml system library is too old, you need at least version 1.9])
66        else
67          with_pugixml=builtin
68        fi
69    ])
70  fi
71
72  if test "x$with_pugixml" != "xbuiltin"; then
73    AC_MSG_CHECKING([whether pugixml has been compiled with long long support])
74    old_libs="$LIBS"
75    LIBS="$LIBS -lpugixml"
76    AC_LINK_IFELSE([
77      AC_LANG_PROGRAM([
78        #include <pugixml.hpp>
79      ],[
80        long long v{};
81        pugi::xml_text t;
82        t.set(v);
83        v = t.as_llong();
84        return v;
85      ])
86    ],[
87      AC_MSG_RESULT([yes])
88    ],[
89      AC_MSG_RESULT([no])
90      if test "x$with_pugixml" = "xsystem"; then
91        AC_MSG_ERROR([pugixml system library has been compiled without long long support])
92      else
93        with_pugixml=builtin
94      fi
95    ])
96    LIBS="$old_libs"
97  fi
98
99  AC_LANG_POP
100
101  if test "x$with_pugixml" != "xbuiltin"; then
102    AC_MSG_NOTICE([Using system pugixml])
103    AC_DEFINE(HAVE_LIBPUGIXML, 1, [Define to 1 if your system has the `pugixml' library (-lpugixml).])
104    PUGIXML_LIBS="-lpugixml"
105  else
106    AC_MSG_NOTICE([Using builtin pugixml])
107  fi
108
109  AC_SUBST(PUGIXML_LIBS)
110])
111