libpqxx
The C++ client library for PostgreSQL
Loading...
Searching...
No Matches
header-pre.hxx
1/* Compiler settings for compiling libpqxx headers, and workarounds for all.
2 *
3 * Include this before including any other libpqxx headers from within libpqxx.
4 * And to balance it out, also include header-post.hxx at the end of the batch
5 * of headers.
6 *
7 * The public libpqxx headers (e.g. `<pqxx/connection>`) include this already;
8 * there's no need to do this from within an application.
9 *
10 * Include this file at the highest aggregation level possible to avoid nesting
11 * and to keep things simple.
12 *
13 * Copyright (c) 2000-2024, Jeroen T. Vermeulen.
14 *
15 * See COPYING for copyright license. If you did not receive a file called
16 * COPYING with this source code, please notify the distributor of this
17 * mistake, or contact the author.
18 */
19
20#if __has_include(<version>)
21# include <version>
22#endif
23
24// NO GUARD HERE! This part should be included every time this file is.
25#if defined(_MSC_VER)
26
27// Save compiler's warning state, and set warning level 4 for maximum
28// sensitivity to warnings.
29# pragma warning(push, 4)
30
31// Visual C++ generates some entirely unreasonable warnings. Disable them.
32// Copy constructor could not be generated.
33# pragma warning(disable : 4511)
34// Assignment operator could not be generated.
35# pragma warning(disable : 4512)
36// Can't expose outside classes without exporting them. Except the MSVC docs
37// say please ignore the warning if it's a standard library class.
38# pragma warning(disable : 4251)
39// Can't derive library classes from outside classes without exporting them.
40// Except the MSVC docs say please ignore the warning if the parent class is
41// in the standard library.
42# pragma warning(disable : 4275)
43// Can't inherit from non-exported class.
44# pragma warning(disable : 4275)
45
46#endif // _MSC_VER
47
48
49#if defined(PQXX_HEADER_PRE)
50# error "Avoid nesting #include of pqxx/internal/header-pre.hxx."
51#endif
52
53#define PQXX_HEADER_PRE
54
55
56// Workarounds & definitions that need to be included even in library's headers
57#include "pqxx/config-public-compiler.h"
58
59// MSVC has a nonstandard definition of __cplusplus.
60#if defined(_MSC_VER)
61# define PQXX_CPLUSPLUS _MSVC_LANG
62#else
63# define PQXX_CPLUSPLUS __cplusplus
64#endif
65
66// C++20: No longer needed.
67// Enable ISO-646 alternative operaotr representations: "and" instead of "&&"
68// etc. on older compilers. C++20 removes this header.
69#if PQXX_CPLUSPLUS <= 201703L && __has_include(<ciso646>)
70# include <ciso646>
71#endif
72
73#if defined(PQXX_HAVE_GCC_PURE)
75# define PQXX_PURE __attribute__((pure))
76#else
77# define PQXX_PURE /* pure */
78#endif
79
80
81#if defined(__GNUC__)
83# define PQXX_COLD __attribute__((cold))
84#else
85# define PQXX_COLD /* cold */
86#endif
87
88
89// Workarounds for Windows
90#ifdef _WIN32
91
92/* For now, export DLL symbols if _DLL is defined. This is done automatically
93 * by the compiler when linking to the dynamic version of the runtime library,
94 * according to "gzh"
95 */
96# if defined(PQXX_SHARED) && !defined(PQXX_LIBEXPORT)
97# define PQXX_LIBEXPORT __declspec(dllimport)
98# endif // PQXX_SHARED && !PQXX_LIBEXPORT
99
100
101// Workarounds for Microsoft Visual C++
102# ifdef _MSC_VER
103
104// Suppress vtables on abstract classes.
105# define PQXX_NOVTABLE __declspec(novtable)
106
107// Automatically link with the appropriate libpq (static or dynamic, debug or
108// release). The default is to use the release DLL. Define PQXX_PQ_STATIC to
109// link to a static version of libpq, and _DEBUG to link to a debug version.
110// The two may be combined.
111# if defined(PQXX_AUTOLINK)
112# if defined(PQXX_PQ_STATIC)
113# ifdef _DEBUG
114# pragma comment(lib, "libpqd")
115# else
116# pragma comment(lib, "libpq")
117# endif
118# else
119# ifdef _DEBUG
120# pragma comment(lib, "libpqddll")
121# else
122# pragma comment(lib, "libpqdll")
123# endif
124# endif
125# endif
126
127// If we're not compiling libpqxx itself, automatically link with the
128// appropriate libpqxx library. To link with the libpqxx DLL, define
129// PQXX_SHARED; the default is to link with the static library. A static link
130// is the recommended practice.
131//
132// The preprocessor macro PQXX_INTERNAL is used to detect whether we
133// are compiling the libpqxx library itself. When you compile the library
134// yourself using your own project file, make sure to include this macro.
135# if defined(PQXX_AUTOLINK) && !defined(PQXX_INTERNAL)
136# ifdef PQXX_SHARED
137# ifdef _DEBUG
138# pragma comment(lib, "libpqxxD")
139# else
140# pragma comment(lib, "libpqxx")
141# endif
142# else // !PQXX_SHARED
143# ifdef _DEBUG
144# pragma comment(lib, "libpqxx_staticD")
145# else
146# pragma comment(lib, "libpqxx_static")
147# endif
148# endif
149# endif
150
151# endif // _MSC_VER
152
153#elif defined(PQXX_HAVE_GCC_VISIBILITY) // !_WIN32
154
155# define PQXX_LIBEXPORT __attribute__((visibility("default")))
156# define PQXX_PRIVATE __attribute__((visibility("hidden")))
157
158#endif // PQXX_HAVE_GCC_VISIBILITY
159
160
161#ifndef PQXX_LIBEXPORT
162# define PQXX_LIBEXPORT /* libexport */
163#endif
164
165#ifndef PQXX_PRIVATE
166# define PQXX_PRIVATE /* private */
167#endif
168
169#ifndef PQXX_NOVTABLE
170# define PQXX_NOVTABLE /* novtable */
171#endif
172
173// C++20: Assume support.
174#if defined(PQXX_HAVE_LIKELY)
175# define PQXX_LIKELY [[likely]]
176# define PQXX_UNLIKELY [[unlikely]]
177#else
178# define PQXX_LIKELY /* [[likely]] */
179# define PQXX_UNLIKELY /* [[unlikely]] */
180#endif
181
182
183// C++23: Assume support.
184// C++20: Assume __has_cpp_attribute is defined.
185// XXX: Find places to apply [[assume(...)]].
186#if !defined(__has_cpp_attribute)
187# define PQXX_ASSUME(condition) while (false)
188#elif !__has_cpp_attribute(assume)
189# define PQXX_ASSUME(condition) while (false)
190#else
191# define PQXX_ASSUME(condition) [[assume(condition)]]
192#endif