forked from jtv/libpqxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
426 lines (367 loc) · 11.7 KB
/
configure.ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# Generate configure script for libpqxx. This needs the autoconf archive
# package installed. (The configure script itself does not require it though.)
AC_PREREQ(2.69)
AC_INIT(
libpqxx,
[m4_esyscmd_s([./tools/extract_version])],
[Jeroen T. Vermeulen])
AC_LANG(C++)
# Require C++11 at minimum.
AX_CXX_COMPILE_STDCXX_11([noext])
AC_CONFIG_SRCDIR([src/connection.cxx])
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_MACRO_DIR([config/m4])
AM_INIT_AUTOMAKE
PQXX_ABI=m4_esyscmd_s([./tools/extract_version --abi])
AC_SUBST(PQXXVERSION)
AC_SUBST(PQXX_ABI)
AC_CONFIG_HEADER([include/pqxx/config.h])
# Default prefix for installs.
AC_PREFIX_DEFAULT(/usr/local)
# Checks for programs.
AC_PROG_CXX
AC_PROG_INSTALL
AC_DISABLE_SHARED
AC_PROG_LIBTOOL
AC_PROG_MAKE_SET
AC_PATH_PROG([MKDIR], [mkdir])
AC_PATH_PROG([PKG_CONFIG], [pkg-config])
# Documentation.
AC_ARG_ENABLE(
documentation,
[AS_HELP_STRING([--enable-documentation], [Generate documentation])],
[],
[enable_documentation=auto])
AC_ARG_VAR([DOXYGEN],
[Path to doxygen needed to build reference documentation])
AC_PATH_TOOL([DOXYGEN], [doxygen], [nodoxygen])
AC_ARG_VAR([HAVE_DOT],
[Variable used by doxygen to declare availibility of dot])
AC_CHECK_TOOL([HAVE_DOT], [dot], [YES], [NO])
AC_ARG_VAR([XMLTO], [Path to xmlto needed to build tutorial documentation])
AC_PATH_TOOL([XMLTO], [xmlto], [noxmlto])
AS_IF([test "$enable_documentation" = "yes" && test "$DOXYGEN" = "nodoxygen" -o "$XMLTO" = "noxmlto"],
[AC_MSG_ERROR([could not files tools necessary to build documentation])])
AM_CONDITIONAL([BUILD_REFERENCE],
[test "$enable_documentation" != "no" -a "$DOXYGEN" != "nodoxygen"])
AM_CONDITIONAL([BUILD_TUTORIAL],
[test "$enable_documentation" != "no" -a "$XMLTO" != "xmlto"])
AM_MAINTAINER_MODE
# See if we want verbose compiler warnings.
AC_MSG_CHECKING([maintainer mode])
AC_ARG_ENABLE(maintainer-mode)
AC_MSG_RESULT(${enable_maintainer_mode})
AC_ARG_ENABLE(shared)
AS_IF(
[test "${shared}" = "yes" ],
[CPPFLAGS="$CPPFLAGS -DPQXX_SHARED"])
# Add options to compiler command line, if compiler accepts them.
add_compiler_opts_if_ok() {
for option in $*
do
ACO_SAVE_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $option"
AC_MSG_CHECKING([whether $CXX accepts $option])
AC_TRY_COMPILE([], [], has_option=yes, has_option=no,)
AC_MSG_RESULT($has_option)
AS_IF(
[test "$has_option" = "no" ],
[CXXFLAGS="$ACO_SAVE_CXXFLAGS"])
done
}
# Add options to compiler command line, unconditionally.
add_compiler_opts() {
CXXFLAGS="$CXXFLAGS $*"
}
# Let's try to get the compiler to be helpful.
#
# (Omit options -Weffc++ and -Wabi because they currently yield too many
# warnings in gcc's standard headers; omit -Wunreachable-code because it isn't
# always right)
if test "$GCC" = "yes"
then
# In maintainer mode, enable all the warning options we can.
if test "$enable_maintainer_mode" = "yes"
then
# "Eternal" (FLW) g++ options. These have been around for
# ages, and both g++ and clang++ support them. Don't bother
# checking for support; just add them to the compiler options.
add_compiler_opts \
-fstrict-enums \
-Werror \
-Wall \
-pedantic \
-Wcast-align \
-Wcast-qual \
-Wconversion \
-Wctor-dtor-privacy \
-Wendif-labels \
-Wextra \
-Wfloat-equal \
-Wformat=2 \
-Wformat-security \
-Wmissing-include-dirs \
-Wno-div-by-zero \
-Wnon-virtual-dtor \
-Wold-style-cast \
-Woverlength-strings \
-Woverloaded-virtual \
-Wpointer-arith \
-Wredundant-decls \
-Wshadow \
-Wsign-promo \
-Wwrite-strings \
-Wundef \
-Wunused
# "Iffy" g++ options. Some reasonably current g++-like
# compilers may not support these.
add_compiler_opts_if_ok \
-fnothrow-opt \
-Wattribute-alias \
-Wextra-semi \
-Wlogical-op \
-Wrestrict \
-Wstringop-overflow \
-Wsuggest-override \
-Wzero-as-null-pointer-constant
fi
AC_MSG_CHECKING([g++ visibility attribute])
gcc_visibility=yes
SAVE_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -Werror"
AC_TRY_COMPILE(
[
struct __attribute__ ((visibility("hidden"))) d
{
d() {}
void f() {}
};
],
[d D; D.f()],
AC_DEFINE(
[PQXX_HAVE_GCC_VISIBILITY],
1,
[Define if g++ supports visibility attribute, as in g++ 4.0]),
gcc_visibility=no)
AC_MSG_RESULT($gcc_visibility)
CXXFLAGS="$SAVE_CXXFLAGS"
if test "$gcc_visibility" = "yes"
then
# Make internal definitions accessible only to the library itself.
# Only definitions marked PQXX_LIBEXPORT will be accessible.
add_compiler_opts -fvisibility=hidden
add_compiler_opts -fvisibility-inlines-hidden
fi
# Check gcc "const" attribute. (More like a stricter version of "pure").
AX_GCC_CONST_CALL
if test "$ax_cv_gcc_const_call"
then
AC_DEFINE(
[PQXX_HAVE_GCC_CONST],
1,
[Define if g++ supports const attribute.])
fi
if test "$deprecated" != "yes"
then
AC_MSG_CHECKING([g++ deprecation attribute])
gcc_deprecated=yes
AC_TRY_COMPILE(
[__attribute__ ((deprecated)) void f();],
[],
AC_DEFINE(
[PQXX_HAVE_GCC_DEPRECATED],
1,
[Define if g++ supports deprecated attribute, as in g++ 4.0]),
gcc_deprecated=no)
AC_MSG_RESULT($gcc_deprecated)
fi
AC_MSG_CHECKING([g++ pure attribute])
gcc_pure=yes
AC_TRY_COMPILE(
[void __attribute__ ((pure)) f();],
[],
AC_DEFINE(
[PQXX_HAVE_GCC_PURE],
1,
[Define if g++ supports pure attribute]),
gcc_pure=yes)
AC_MSG_RESULT($gcc_pure)
fi # End of gcc-specific part.
AC_MSG_CHECKING([C++14 deprecation attribute])
deprecated=yes
AC_TRY_COMPILE(
[[[deprecated]] void f();],
[],
AC_DEFINE(
[PQXX_HAVE_DEPRECATED],
1,
[Define if compiler supports [[deprecated]] attribute]),
deprecated=no)
AC_MSG_RESULT($deprecated)
AC_MSG_CHECKING([for C++17 std::optional support])
have_optional=yes
AC_TRY_COMPILE(
[#include <optional>],
[return std::optional<int>(0).value()],
AC_DEFINE(
[PQXX_HAVE_OPTIONAL],
1,
[Define if the compiler supports std::optional.]),
have_optional=no)
AC_MSG_RESULT($have_optional)
if test "$have_optional" != "yes"
then
AC_MSG_CHECKING([for experimental C++17 std::optional support])
have_exp_optional=yes
AC_TRY_COMPILE(
[#include <experimental/optional>],
[return std::experimental::optional<int>(0).value()],
AC_DEFINE(
[PQXX_HAVE_EXP_OPTIONAL],
1,
[Define if the compiler supports std::experimental::optional.]),
have_exp_optional=no)
AC_MSG_RESULT($have_exp_optional)
fi
AX_HAVE_POLL(
[AX_CONFIG_FEATURE_ENABLE(poll)],
[AX_CONFIG_FEATURE_DISABLE(poll)])
AX_CONFIG_FEATURE([poll], [System supports poll().], [HAVE_POLL], [System supports poll().])
if test "$ax_cv_have_poll" != "yes"
then
# No poll(); try for select() instead.
select_h=no
AC_CHECK_HEADERS([sys/select.h], [select_h=yes])
# Some systems keep select() in a separate library which is not linked by
# default. See if we need one of those.
socklibok=no
AC_SEARCH_LIBS(select, socket nsl ws2_32 wsock32 winsock, [socklibok=yes])
# Microsoft proprietary libraries do not work with code that is generated with
# autoconf's SEARCH_LIBS macro, so we need to check manually and just use the
# first socket library available.
# We only do this if select() is not available by other means, to avoid picking
# up an unnecessary Windows compatibility library on a non-Windows system.
for l in ws2_32 wsock32 winsock
do
if test "${socklibok}" != "yes"
then
AC_CHECK_LIB($l,main,LIBS="$LIBS -l$l";[socklibok=yes])
fi
done
if test "${socklibok}" != "yes"
then
AC_MSG_ERROR([
Could not figure out how to link a simple sockets-based program. Please read
the config.log file for more clues as to why this failed.
])
fi
fi # No poll()
AC_CHECK_HEADERS([sys/time.h])
# Find PostgreSQL includes and libraries
AC_PATH_PROGS(PG_CONFIG, pg_config)
if test -z "$PG_CONFIG" || test ! -r "$PG_CONFIG"
then
AC_MSG_ERROR([
PostgreSQL configuration script pg_config not found. Make sure this is in your
command path before configuring. Without it, the configure script has no way to
find the right location for the libpq library and its headers.
])
fi
AC_ARG_WITH(
[postgres-include],
[AS_HELP_STRING(
[--with-postgres-include=DIR],
[Use PostgreSQL includes from DIR. Defaults to querying pg_config.])],
AS_IF(
[test "x$with_postgres_include" = "xyes"],
[with_postgres_include=""]))
AS_IF(
[test -z "$with_postgres_include"],
[with_postgres_include=$($PG_CONFIG --includedir)])
AC_MSG_NOTICE([using PostgreSQL headers at $with_postgres_include])
AC_SUBST(with_postgres_include)
POSTGRES_INCLUDE="-I${with_postgres_include}"
AC_SUBST(POSTGRES_INCLUDE)
AC_ARG_WITH(
[postgres-lib],
[AS_HELP_STRING(
[--with-postgres-lib=DIR],
[Use PostgreSQL libraries from DIR. Defaults to querying pg_config.])],
AS_IF(
[test "x$with_postgres_lib" = "xyes"],
[with_postgres_lib=""]))
AS_IF(
[test -z "$with_postgres_lib"],
[with_postgres_lib=$($PG_CONFIG --libdir)])
AC_MSG_NOTICE([using PostgreSQL libraries at $with_postgres_lib])
AC_SUBST(with_postgres_lib)
#POSTGRES_LIB="-R${with_postgres_lib}"
AC_SUBST(POSTGRES_LIB)
AC_CHECK_HEADER(
[${with_postgres_include}/libpq-fe.h],
[],
[AC_MSG_ERROR([
Can't find libpq-fe.h in ${with_postgres_include}. Are you sure the libpq
headers are installed correctly? They should be in the directory returned by
"pg_config --includedir".
If you do have libpq (the C-language client library for PostgreSQL) installed,
make sure you have the related development materials--mainly its header files--
as well as the library binary. Some system distributions keep the two in
seperate packages with names like "alibrary" and "alibrary-dev", respectively.
In that case, make sure you have the latter installed as well.
])])
AC_MSG_CHECKING([for ability to compile source files using libpq])
AC_TRY_COMPILE(
[#include<${with_postgres_include}/libpq-fe.h>],[PQexec(nullptr,"")],
[],
[AC_MSG_ERROR([
Could not compile a call to a basic libpq function. There must be something
seriously wrong with the headers that "pg_config --includedir" pointed to; the
contents of config.log may give you a clue about the nature of the failure.
Source including the libpq header libpq-fe.h can be compiled, but a call to the
most basic libpq function PQexec() failed to compile successfully. This is the
litmus test for a working libpq.
])])
AC_MSG_RESULT(yes)
LDFLAGS="$LDFLAGS -L${with_postgres_lib}"
AC_CHECK_LIB(
[pq],
[PQexec],
[],
[AC_MSG_ERROR([
Did not find the PQexec() function in libpq. This is the litmus test for a
working libpq installation.
A source file using the PQexec() function did compile without problems, and the
libpq library is available for linking, but for some reason a call to PQexec()
failed to link properly to the libpq library. This may be because the libpq
library file is damaged, or in some incorrect format, or if your libpq is much
more recent than libpqxx version $PQXX_ABI, perhaps libpq has undergone a
radical ABI change.
The last parts of config.log may give you a clue as to what really went wrong,
but be warned that this is no easy reading. Look for the last error message
occurring in the file.
])],
-L${with_postgres_lib})
# Remove redundant occurrances of -lpq
LIBS=[$(echo "$LIBS" | sed -e 's/-lpq * -lpq\>/-lpq/g')]
AC_MSG_CHECKING([that type of libpq's Oid is as expected])
AC_TRY_COMPILE(
[
#include<${with_postgres_include}/libpq-fe.h>
#include"${srcdir}/include/pqxx/internal/libpq-forward.hxx"
extern void f(pqxx::oid&);
],
[Oid o;f(o)],
[],
[AC_MSG_ERROR([
The Oid typedef in libpq has changed. Please notify the libpqxx authors of the
change!
])])
AC_MSG_RESULT(yes)
AC_PROG_MAKE_SET
AC_CONFIG_FILES([
Makefile config/Makefile doc/Makefile doc/Doxyfile src/Makefile
test/Makefile test/unit/Makefile tools/Makefile win32/Makefile
include/Makefile include/pqxx/Makefile libpqxx.pc])
AC_CONFIG_COMMANDS([configitems], ["${srcdir}/tools/splitconfig" "${srcdir}"])
AC_OUTPUT