configure.ac 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. # Generate configure script for libpqxx. This needs the autoconf archive
  2. # package installed. (The configure script itself does not require it though.)
  3. AC_PREREQ(2.69)
  4. AC_INIT(
  5. libpqxx,
  6. [m4_esyscmd_s([./tools/extract_version])],
  7. [Jeroen T. Vermeulen])
  8. AC_LANG(C++)
  9. AC_CONFIG_SRCDIR([src/connection.cxx])
  10. AC_CONFIG_AUX_DIR(config)
  11. AC_CONFIG_MACRO_DIR([config/m4])
  12. AM_INIT_AUTOMAKE([subdir-objects])
  13. PQXX_ABI=m4_esyscmd_s([./tools/extract_version --abi])
  14. AC_SUBST(PQXXVERSION, $PACKAGE_VERSION)
  15. AC_SUBST(PQXX_ABI)
  16. AC_CONFIG_HEADER([include/pqxx/config.h])
  17. # Default prefix for installs.
  18. AC_PREFIX_DEFAULT(/usr/local)
  19. # Read test programme from config-test.
  20. AC_DEFUN([read_test], [AC_LANG_SOURCE(
  21. esyscmd(tools/m4esc.py --input=config-tests/$1))])
  22. # Checks for programs.
  23. AC_PROG_CXX
  24. AC_PROG_INSTALL
  25. AC_DISABLE_SHARED
  26. AC_PROG_LIBTOOL
  27. AC_PROG_MAKE_SET
  28. AC_PATH_PROG([MKDIR], [mkdir])
  29. # Documentation.
  30. AC_ARG_ENABLE(
  31. documentation,
  32. [AS_HELP_STRING([--enable-documentation], [Generate documentation])],
  33. [],
  34. [enable_documentation=auto])
  35. AC_ARG_VAR([DOXYGEN],
  36. [Path to doxygen needed to build reference documentation])
  37. AC_PATH_TOOL([DOXYGEN], [doxygen], [nodoxygen])
  38. AC_ARG_VAR([HAVE_DOT],
  39. [Variable used by doxygen to declare availibility of dot])
  40. AC_CHECK_TOOL([HAVE_DOT], [dot], [YES], [NO])
  41. AS_IF([test "$enable_documentation" = "yes" && test "$DOXYGEN" = "nodoxygen"],
  42. [AC_MSG_ERROR([could not find tools necessary to build documentation])])
  43. AM_CONDITIONAL([BUILD_REFERENCE],
  44. [test "$enable_documentation" != "no" -a "$DOXYGEN" != "nodoxygen"])
  45. AM_MAINTAINER_MODE
  46. # See if we want stricter compiler warnings.
  47. AC_MSG_CHECKING([maintainer mode])
  48. AC_ARG_ENABLE(maintainer-mode)
  49. AC_MSG_RESULT(${enable_maintainer_mode})
  50. # See if we want runtime debug checking.
  51. AC_MSG_CHECKING([audit])
  52. AC_ARG_ENABLE(audit)
  53. AC_MSG_RESULT(${enable_audit})
  54. # See if we want "suggestions," such as "this class could be final."
  55. # (The suggestions are often useful, but can also easily be wrong.)
  56. AC_MSG_CHECKING([suggest])
  57. AC_ARG_ENABLE(suggest)
  58. AC_MSG_RESULT(${enable_suggest})
  59. AC_ARG_ENABLE(shared)
  60. AS_IF(
  61. [test "${shared}" = "yes" ],
  62. [CPPFLAGS="$CPPFLAGS -DPQXX_SHARED"])
  63. # Add options to compiler command line, if compiler accepts them.
  64. add_compiler_opts_if_ok() {
  65. for option in $*
  66. do
  67. ACO_SAVE_CXXFLAGS="$CXXFLAGS"
  68. CXXFLAGS="$CXXFLAGS $option"
  69. AC_MSG_CHECKING([whether $CXX accepts $option])
  70. AC_COMPILE_IFELSE(
  71. [AC_LANG_PROGRAM([], [])],
  72. has_option=yes,
  73. has_option=no)
  74. AC_MSG_RESULT($has_option)
  75. AS_IF(
  76. [test "$has_option" = "no" ],
  77. [CXXFLAGS="$ACO_SAVE_CXXFLAGS"])
  78. done
  79. }
  80. # Add options to compiler command line, unconditionally.
  81. add_compiler_opts() {
  82. CXXFLAGS="$CXXFLAGS $*"
  83. }
  84. # It's tempting to use Autoconf Archive's AX_CXX_COMPILE_STDCXX_17 for this,
  85. # but it's 2022 and the C++20 equivalent isn't quite ready for use.
  86. # Seems simpler and more reliable for the user to arrange for the desired
  87. # language versions by setting the appropriate option for their compiler.
  88. AC_MSG_CHECKING([for sufficient C++ language/library level])
  89. sufficient_cxx=yes
  90. AC_COMPILE_IFELSE(
  91. [AC_LANG_SOURCE([
  92. #if __cplusplus < 201611L
  93. #error "Need C++17 or better."
  94. #endif
  95. ])],
  96. sufficient_cxx=yes,
  97. sufficient_cxx=no)
  98. AC_MSG_RESULT($sufficient_cxx)
  99. if test "$sufficient_cxx" != "yes"
  100. then
  101. AC_MSG_ERROR([This libpqxx version needs at least C++17.])
  102. fi
  103. # Let's try to get the compiler to be helpful.
  104. #
  105. # (Omit options -Weffc++ and -Wabi because they currently yield too many
  106. # warnings in gcc's standard headers; omit -Wunreachable-code because it isn't
  107. # always right)
  108. if test "$GCC" = "yes"
  109. then
  110. # In maintainer mode, enable all the warning options we can.
  111. if test "$enable_maintainer_mode" = "yes"
  112. then
  113. # "Eternal" (FLW) g++ options. These have been around for
  114. # ages, and both g++ and clang++ support them. Don't bother
  115. # checking for support; just add them to the compiler options.
  116. add_compiler_opts \
  117. -fstrict-enums \
  118. -Werror \
  119. -Wall \
  120. -pedantic \
  121. -Wcast-align \
  122. -Wcast-qual \
  123. -Wconversion \
  124. -Wctor-dtor-privacy \
  125. -Wendif-labels \
  126. -Wextra \
  127. -Wfloat-equal \
  128. -Wformat=2 \
  129. -Wformat-security \
  130. -Wmissing-include-dirs \
  131. -Wno-div-by-zero \
  132. -Wnon-virtual-dtor \
  133. -Wold-style-cast \
  134. -Woverlength-strings \
  135. -Woverloaded-virtual \
  136. -Wpointer-arith \
  137. -Wredundant-decls \
  138. -Wshadow \
  139. -Wsign-promo \
  140. -Wundef \
  141. -Wunused \
  142. -Wwrite-strings
  143. # "Iffy" g++ options. Some reasonably current g++-like
  144. # compilers may not support these.
  145. add_compiler_opts_if_ok \
  146. -fnothrow-opt \
  147. -Wattribute-alias=2 \
  148. -Wextra-semi \
  149. -Wlogical-op \
  150. -Wmismatched-tags \
  151. -Wnoexcept \
  152. -Wredundant-tags \
  153. -Wrestrict \
  154. -Wstringop-overflow \
  155. -Wzero-as-null-pointer-constant \
  156. -Warray-bounds=2 \
  157. -Wduplicated-branches \
  158. -Wduplicated-cond \
  159. -Wsuggest-attribute=noreturn \
  160. -Wsuggest-override \
  161. -Wtrampolines
  162. fi
  163. # In "audit," enable all runtime checks we can.
  164. if test "$enable_audit" = "yes"
  165. then
  166. add_compiler_opts_if_ok \
  167. -D_FORTIFY_SOURCE=2 \
  168. -fsanitize=address \
  169. -fsanitize-address-use-after-scope \
  170. -fsanitize=alignment \
  171. -fsanitize=bool \
  172. -fsanitize=bounds \
  173. -fsanitize=bounds-strict \
  174. -fsanitize=builtin \
  175. -fsanitize=enum \
  176. -fsanitize=float-cast-overflow \
  177. -fsanitize=float-divide-by-zero \
  178. -fsanitize=integer-divide-by-zero \
  179. -fsanitize=leak \
  180. -fsanitize=nonnull-attribute \
  181. -fsanitize=null \
  182. -fsanitize=object-size \
  183. -fsanitize=pointer-compare \
  184. -fsanitize=pointer-overflow \
  185. -fsanitize=pointer-subtract \
  186. -fsanitize=return \
  187. -fsanitize=returns-nonnull-attribute \
  188. -fsanitize=shift \
  189. -fsanitize=shift-base \
  190. -fsanitize=shift-exponent \
  191. -fsanitize=signed-integer-overflow \
  192. -fsanitize=undefined \
  193. -fsanitize=unreachable \
  194. -fsanitize=vla-bound \
  195. -fsanitize=vptr \
  196. -fstack-protector-all
  197. fi
  198. # In "suggest" mode, enable a bunch of code suggestions.
  199. if test "$enable_suggest" = "yes"
  200. then
  201. add_compiler_opts_if_ok \
  202. -Wsuggest-attribute=cold \
  203. -Wsuggest-attribute=const \
  204. -Wsuggest-attribute=malloc \
  205. -Wsuggest-attribute=pure \
  206. -Wsuggest-final-types \
  207. -Wsuggest-final-methods
  208. fi
  209. AC_MSG_CHECKING([g++ visibility attribute])
  210. gcc_visibility=yes
  211. SAVE_CXXFLAGS="$CXXFLAGS"
  212. CXXFLAGS="$CXXFLAGS -Werror"
  213. AC_COMPILE_IFELSE(
  214. [read_test(gcc_visibility.cxx)],
  215. AC_DEFINE(
  216. [PQXX_HAVE_GCC_VISIBILITY],
  217. 1,
  218. [Define if g++ supports visibility attribute.]),
  219. gcc_visibility=no)
  220. AC_MSG_RESULT($gcc_visibility)
  221. CXXFLAGS="$SAVE_CXXFLAGS"
  222. if test "$gcc_visibility" = "yes"
  223. then
  224. # Make internal definitions accessible only to the library itself.
  225. # Only definitions marked PQXX_LIBEXPORT will be accessible.
  226. add_compiler_opts -fvisibility=hidden
  227. add_compiler_opts -fvisibility-inlines-hidden
  228. fi
  229. AC_MSG_CHECKING([g++ pure attribute])
  230. gcc_pure=yes
  231. AC_COMPILE_IFELSE(
  232. [read_test(gcc_pure.cxx)],
  233. AC_DEFINE(
  234. [PQXX_HAVE_GCC_PURE],
  235. 1,
  236. [Define if g++ supports pure attribute]),
  237. gcc_pure=no)
  238. AC_MSG_RESULT($gcc_pure)
  239. fi # End of gcc-specific part.
  240. # Check for __cxa_demangle.
  241. AC_MSG_CHECKING([__cxa_demangle])
  242. cxa_demangle=yes
  243. AC_COMPILE_IFELSE(
  244. [read_test(cxa_demangle.cxx)],
  245. AC_DEFINE(
  246. [PQXX_HAVE_CXA_DEMANGLE],
  247. 1,
  248. [Define if compiler supports __cxa_demangle]),
  249. cxa_demangle=no)
  250. AC_MSG_RESULT($cxa_demangle)
  251. # Check for sufficient Concepts support, introduced with C++20.
  252. AC_MSG_CHECKING([concepts])
  253. concepts=yes
  254. AC_COMPILE_IFELSE(
  255. [read_test(concepts.cxx)],
  256. AC_DEFINE(
  257. [PQXX_HAVE_CONCEPTS],
  258. 1,
  259. [Define if compiler supports Concepts and <ranges> header.]),
  260. concepts=no)
  261. AC_MSG_RESULT($concepts)
  262. # Check for C++20 std::span.
  263. AC_MSG_CHECKING([std::span])
  264. span=yes
  265. AC_COMPILE_IFELSE(
  266. [read_test(span.cxx)],
  267. AC_DEFINE([PQXX_HAVE_SPAN], 1, [Define if compiler has std::span.]),
  268. span=no)
  269. AC_MSG_RESULT($span)
  270. # Check for multidimensional subscript operator support. Proposed for C++23.
  271. AC_MSG_CHECKING([for multidimensional subscript operator support])
  272. multidim_subscript=yes
  273. AC_COMPILE_IFELSE(
  274. [read_test(multidim-subscript.cxx)],
  275. AC_DEFINE(
  276. [PQXX_HAVE_MULTIDIMENSIONAL_SUBSCRIPT], 1,
  277. [Define if operator[] can take multiple arguments.]),
  278. multidim_subscript=no)
  279. AC_MSG_RESULT($multidim_subscript)
  280. AC_MSG_CHECKING([for strerror_r()])
  281. strerror_r=yes
  282. AC_LINK_IFELSE(
  283. [read_test(strerror_r.cxx)],
  284. AC_DEFINE(
  285. [PQXX_HAVE_STRERROR_R],
  286. 1,
  287. [Define if strerror_r() is available.]),
  288. strerror_r=no)
  289. AC_MSG_RESULT($strerror_r)
  290. AC_MSG_CHECKING([for strerror_s()])
  291. strerror_s=yes
  292. AC_LINK_IFELSE(
  293. [read_test(strerror_s.cxx)],
  294. AC_DEFINE(
  295. [PQXX_HAVE_STRERROR_S],
  296. 1,
  297. [Define if strerror_s() is available.]),
  298. strerror_s=no)
  299. AC_MSG_RESULT($strerror_s)
  300. AC_MSG_CHECKING([for std::chrono::year_month_day etc])
  301. year_month_day=yes
  302. AC_LINK_IFELSE(
  303. [read_test(year_month_day.cxx)],
  304. AC_DEFINE(
  305. [PQXX_HAVE_YEAR_MONTH_DAY],
  306. 1,
  307. [Define if std::chrono has year_month_day etc.]),
  308. year_month_day=no)
  309. AC_MSG_RESULT($year_month_day)
  310. # Check for [[likely]] and [[unlikely]] attributes.
  311. AC_MSG_CHECKING([attributes "likely" and "unlikely".])
  312. likely=yes
  313. AC_COMPILE_IFELSE(
  314. [read_test(likely.cxx)],
  315. AC_DEFINE([PQXX_HAVE_LIKELY], 1, [Define if likely & unlikely work.]),
  316. likely=no)
  317. AC_MSG_RESULT($likely)
  318. # It's mid-2019, and gcc's charconv supports integers but not yet floats.
  319. # So for now, we test for int and float conversion... separately.
  320. #
  321. # It's worse for older clang versions, which compile the integer conversions
  322. # but then fail at link time because of a missing symbol "__muloti4" with the
  323. # "long long" version. I couldn't resolve that symbol by adding -lm either.
  324. # So don't just compile these tests; link them as well.
  325. AC_MSG_CHECKING([for C++17 charconv integer conversion])
  326. have_charconv_int=yes
  327. AC_LINK_IFELSE(
  328. [read_test(charconv_int.cxx)],
  329. AC_DEFINE(
  330. [PQXX_HAVE_CHARCONV_INT],
  331. 1,
  332. [Define if <charconv> supports integer conversion.]),
  333. have_charconv_int=no)
  334. AC_MSG_RESULT($have_charconv_int)
  335. AC_MSG_CHECKING([for C++17 charconv floating-point conversion])
  336. have_charconv_float=yes
  337. AC_LINK_IFELSE(
  338. [read_test(charconv_float.cxx)],
  339. AC_DEFINE(
  340. [PQXX_HAVE_CHARCONV_FLOAT],
  341. 1,
  342. [Define if <charconv> supports floating-point conversion.]),
  343. have_charconv_float=no)
  344. AC_MSG_RESULT($have_charconv_float)
  345. # As per #262, clang with libcxxrt does not support thread_local on non-POD
  346. # objects. Luckily we can live without those, it's just less efficient.
  347. AC_MSG_CHECKING([for full thread_local support])
  348. have_thread_local=yes
  349. AC_LINK_IFELSE(
  350. [read_test(thread_local.cxx)],
  351. AC_DEFINE(
  352. [PQXX_HAVE_THREAD_LOCAL],
  353. 1,
  354. [Define if thread_local is fully supported.]),
  355. have_thread_local=no)
  356. AC_MSG_RESULT($have_thread_local)
  357. AC_MSG_CHECKING([for std::this_thread::sleep_for])
  358. have_sleep_for=yes
  359. AC_LINK_IFELSE(
  360. [read_test(sleep_for.cxx)],
  361. AC_DEFINE(
  362. [PQXX_HAVE_SLEEP_FOR],
  363. 1,
  364. [Define if std::this_thread::sleep_for works.]),
  365. have_sleep_for=no)
  366. AC_MSG_RESULT($have_sleep_for)
  367. AC_MSG_CHECKING([for std::cmp_greater, std::cmp_less_equal, etc])
  368. have_cmp=yes
  369. AC_COMPILE_IFELSE(
  370. [read_test(cmp.cxx)],
  371. AC_DEFINE(
  372. [PQXX_HAVE_CMP],
  373. 1,
  374. [Define if compiler has C++20 std::cmp_greater etc.]),
  375. have_cmp=no)
  376. AC_MSG_RESULT($have_cmp)
  377. # Doing my own check for poll(). There's one built into autoconf-archive, but
  378. # it produces warnings in C++ (about unnecessarily using "struct", and using 0
  379. # as a null pointer constant). In maintainer mode, those warnings turn into
  380. # errors.
  381. AC_MSG_CHECKING([for poll()])
  382. ax_cv_have_poll=yes
  383. AC_LINK_IFELSE(
  384. [read_test(poll.cxx)],
  385. AC_DEFINE(
  386. [PQXX_HAVE_POLL],
  387. 1,
  388. [Define if poll() is available.]),
  389. ax_cv_have_poll=no)
  390. AC_MSG_RESULT($ax_cv_have_poll)
  391. if test "$ax_cv_have_poll" != "yes"
  392. then
  393. # No poll(); we'll fall back to select().
  394. # Some systems keep select() in a separate library which is not linked by
  395. # default. See if we need one of those.
  396. socklibok=no
  397. AC_SEARCH_LIBS(select, socket nsl ws2_32 wsock32 winsock, [socklibok=yes])
  398. # Microsoft proprietary libraries do not work with code that is generated with
  399. # autoconf's SEARCH_LIBS macro, so we need to check manually and just use the
  400. # first socket library available.
  401. # We only do this if select() is not available by other means, to avoid picking
  402. # up an unnecessary Windows compatibility library on a non-Windows system.
  403. for l in ws2_32 wsock32 winsock
  404. do
  405. if test "${socklibok}" != "yes"
  406. then
  407. AC_CHECK_LIB($l,main,LIBS="$LIBS -l$l";[socklibok=yes])
  408. fi
  409. done
  410. if test "${socklibok}" != "yes"
  411. then
  412. AC_MSG_ERROR([
  413. Could not figure out how to link a simple sockets-based program. Please read
  414. the config.log file for more clues as to why this failed.
  415. ])
  416. fi
  417. fi # No poll()
  418. # Find PostgreSQL includes and libraries
  419. AC_PATH_PROG([PKG_CONFIG], [pkg-config])
  420. AC_PATH_PROGS(PG_CONFIG, pg_config)
  421. AC_ARG_WITH(
  422. [postgres-include],
  423. [AS_HELP_STRING(
  424. [--with-postgres-include=DIR],
  425. [Use PostgreSQL includes from DIR. Defaults to querying pg_config or pkg-config, whichever is available.])],
  426. AS_IF(
  427. [test "x$with_postgres_include" = "xyes"],
  428. [with_postgres_include=""]))
  429. if test -n "$with_postgres_include"
  430. then
  431. POSTGRES_INCLUDE="-I$with_postgres_include"
  432. else
  433. if test -x "$PKG_CONFIG" || test -x "$PG_CONFIG"
  434. then
  435. # We should prefer pkg-config over pg_config, but there seems to be a
  436. # problem in pkg-config 1.6.3. Until that's been resolved (#291), go
  437. # with pg_config if we can.
  438. if test -x "$PG_CONFIG"
  439. then
  440. # From pg_config we can either get the C compiler options used to
  441. # compile postgres, which isn't quite what we want; or we can get
  442. # the headers directory, without the full option. That's something
  443. # we can work with. The compiler must support the "-I" option for
  444. # that, but both scripts assume that anyway.
  445. POSTGRES_INCLUDE="-I$($PG_CONFIG --includedir)"
  446. else
  447. # From pkg-config we can get the compiler options to extend the
  448. # include path. We use that.
  449. POSTGRES_INCLUDE=$($PKG_CONFIG libpq --cflags-only-I)
  450. fi
  451. AC_MSG_NOTICE([finding PostgreSQL headers using $POSTGRES_INCLUDE])
  452. else
  453. POSTGRES_INCLUDE=""
  454. # We have nothing to tell us where the libpq headers are. That's fine
  455. # if the compiler can find it, but if not, fail here.
  456. AC_CHECK_HEADER(
  457. [libpq-fe.h],
  458. [],
  459. [AC_MSG_ERROR([
  460. Can't find the main PostgreSQL client header, libpq-fe.h. Make sure that it
  461. is installed, and either use the --with-postgres-include option or install
  462. pkg-config.
  463. ])])
  464. fi
  465. fi
  466. AC_SUBST(POSTGRES_INCLUDE)
  467. # Add the compiler option so we can compile configure tests which rely on the
  468. # libpq headers.
  469. CPPFLAGS="$CPPFLAGS $POSTGRES_INCLUDE"
  470. AC_ARG_WITH(
  471. [postgres-lib],
  472. [AS_HELP_STRING(
  473. [--with-postgres-lib=DIR],
  474. [Use PostgreSQL libraries from DIR. Defaults to querying pg_config.])],
  475. AS_IF(
  476. [test "x$with_postgres_lib" = "xyes"],
  477. [with_postgres_lib=""]))
  478. # If no --with-postgres-lib was given, and we have pkg-config, use that.
  479. AS_IF(
  480. [test -z "$with_postgres_lib" -a -x "$PKG_CONFIG"],
  481. [with_postgres_lib=$($PKG_CONFIG libpq --libs-only-L | sed 's/^-L//')])
  482. # pg_config is deprecated, but for some users it may still provide the only
  483. # right answer. For instance, `pkg-config` may not know where `libpq` is
  484. # installed.
  485. AS_IF(
  486. [test -z "$with_postgres_lib" -a -x "$PG_CONFIG"],
  487. [with_postgres_lib=$($PG_CONFIG --libdir)])
  488. AS_IF(
  489. [test -n "$with_postgres_lib"],
  490. [AC_MSG_NOTICE([using PostgreSQL libraries at $with_postgres_lib])],
  491. [AC_MSG_NOTICE([using PostgreSQL libraries in default location])])
  492. AC_SUBST(with_postgres_lib)
  493. AC_CHECK_HEADER(
  494. [libpq-fe.h],
  495. [],
  496. [AC_MSG_ERROR([
  497. Can't find the main PostgreSQL client header, libpq-fe.h. Are you sure the
  498. libpq headers are installed correctly, and that we've got the right path?
  499. ])])
  500. AC_MSG_CHECKING([for ability to compile source files using libpq])
  501. AC_COMPILE_IFELSE(
  502. [AC_LANG_PROGRAM(
  503. [[#include<libpq-fe.h>]],
  504. [[PQexec(nullptr,"")]]
  505. )],
  506. [],
  507. [AC_MSG_ERROR([
  508. Could not compile a call to a basic libpq function. There must be something
  509. seriously wrong with the headers that "pg_config --includedir" or "pkg-config
  510. libpq --cflags" pointed to; the contents of config.log may give you a clue
  511. about the nature of the failure.
  512. Source including the libpq header libpq-fe.h can be compiled, but a call to the
  513. most basic libpq function PQexec() failed to compile successfully. This is the
  514. litmus test for a working libpq.
  515. ])])
  516. AC_MSG_RESULT(yes)
  517. if test "x${with_postgres_lib}" = "x"; then
  518. with_postgres_libpath=""
  519. else
  520. with_postgres_libpath="-L${with_postgres_lib}"
  521. fi
  522. LDFLAGS="$LDFLAGS ${with_postgres_libpath}"
  523. AC_CHECK_LIB(
  524. [pq],
  525. [PQexec],
  526. [],
  527. [AC_MSG_ERROR([
  528. Did not find the PQexec() function in libpq. This is the litmus test for a
  529. working libpq installation.
  530. A source file using the PQexec() function did compile without problems, and the
  531. libpq library is available for linking, but for some reason a call to PQexec()
  532. failed to link properly to the libpq library. This may be because the libpq
  533. library file is damaged, or in some incorrect format, or if your libpq is much
  534. more recent than libpqxx version $PQXX_ABI, perhaps libpq has undergone a
  535. radical ABI change.
  536. The last parts of config.log may give you a clue as to what really went wrong,
  537. but be warned that this is no easy reading. Look for the last error message
  538. occurring in the file.
  539. ])],
  540. ${with_postgres_libpath})
  541. # PQencryptPasswordConn was added in postgres 10.
  542. AC_MSG_CHECKING([for PQencryptPasswordConn])
  543. have_pqencryptpasswordconn=yes
  544. AC_COMPILE_IFELSE(
  545. [AC_LANG_PROGRAM(
  546. [#include<libpq-fe.h>],
  547. [
  548. extern PGconn *conn;
  549. PQencryptPasswordConn(
  550. conn, "pwd", "user", "scram-sha-256")
  551. ]
  552. )],
  553. AC_DEFINE(
  554. [PQXX_HAVE_PQENCRYPTPASSWORDCONN],
  555. 1,
  556. [Define if libpq has PQencryptPasswordConn (since pg 10).]),
  557. [have_pqencryptpasswordconn=no])
  558. AC_MSG_RESULT($have_pqencryptpasswordconn)
  559. # "Pipeline mode" was introduced in libpq 14.
  560. AC_MSG_CHECKING([for libpq pipeline mode])
  561. have_pq_pipeline=yes
  562. AC_COMPILE_IFELSE(
  563. [AC_LANG_PROGRAM(
  564. [#include<libpq-fe.h>],
  565. [
  566. extern PGconn *conn;
  567. PQenterPipelineMode(conn)
  568. ]
  569. )],
  570. AC_DEFINE(
  571. [PQXX_HAVE_PQ_PIPELINE],
  572. 1,
  573. [Define if libpq has pipeline mode (since pg 14).]),
  574. [have_pq_pipeline=no])
  575. AC_MSG_RESULT($have_pq_pipeline)
  576. AC_MSG_CHECKING([for usable std::filesystem::path])
  577. have_path=yes
  578. AC_COMPILE_IFELSE(
  579. [read_test(fs.cxx)],
  580. AC_DEFINE(
  581. [PQXX_HAVE_PATH],
  582. 1,
  583. [Define if compiler has usable std::filesystem::path.]),
  584. have_path=no)
  585. AC_MSG_RESULT($have_path)
  586. AC_MSG_CHECKING([whether we need a link option for <filesystem> support])
  587. LIBS_SAVE="$LIBS"
  588. found_fslib=no
  589. for l in '' '-lstdc++fs' '-lc++fs'
  590. do
  591. if test "$found_fslib" != "yes"
  592. then
  593. LIBS="$LIBS $l"
  594. AC_LINK_IFELSE(
  595. [read_test(need_fslib.cxx)],
  596. [found_fslib=yes],
  597. [LIBS="$LIBS_SAVE"])
  598. if test "$found_fslib" = "yes"
  599. then
  600. result_msg="$l"
  601. # (And keep our current value of $LIBS.)
  602. fi
  603. fi
  604. done
  605. if test "$found_fslib" != "yes"
  606. then
  607. AC_MSG_ERROR([
  608. There seems to be <filesystem> support, but I could not figure out now to make
  609. it work. You'll have to add set your own build options for this.
  610. ])
  611. fi
  612. AC_MSG_RESULT($result_msg)
  613. # Remove redundant occurrances of -lpq
  614. LIBS=[$(echo "$LIBS" | sed -e 's/-lpq * -lpq\>/-lpq/g')]
  615. AC_MSG_CHECKING([that type of libpq's Oid is as expected])
  616. AC_COMPILE_IFELSE(
  617. [AC_LANG_PROGRAM(
  618. [
  619. #include<libpq-fe.h>
  620. #include"${srcdir}/include/pqxx/internal/libpq-forward.hxx"
  621. extern void f(pqxx::oid&);
  622. ],
  623. [Oid o;f(o)],
  624. )],
  625. [],
  626. [AC_MSG_ERROR([
  627. The Oid typedef in libpq has changed. Please notify the libpqxx authors of the
  628. change!
  629. ])])
  630. AC_MSG_RESULT(yes)
  631. AC_PROG_MAKE_SET
  632. AC_CONFIG_FILES([
  633. Makefile config/Makefile doc/Makefile doc/Doxyfile src/Makefile
  634. test/Makefile tools/Makefile include/Makefile include/pqxx/Makefile
  635. libpqxx.pc])
  636. AC_CONFIG_COMMANDS([configitems], ["${srcdir}/tools/splitconfig" "${srcdir}"])
  637. AC_OUTPUT(compile_flags)