libpqxx
The C++ client library for PostgreSQL
header-pre.hxx
Go to the documentation of this file.
1
// NOLINT(llvm-header-guard)
2
/* Compiler settings for compiling libpqxx headers, and workarounds for all.
3
*
4
* Include this before including any other libpqxx headers from within libpqxx.
5
* And to balance it out, also include header-post.hxx at the end of the batch
6
* of headers.
7
*
8
* The public libpqxx headers (e.g. `<pqxx/connection>`) include this already;
9
* there's no need to do this from within an application.
10
*
11
* Include this file at the highest aggregation level possible to avoid nesting
12
* and to keep things simple.
13
*
14
* Copyright (c) 2000-2026, Jeroen T. Vermeulen.
15
*
16
* See COPYING for copyright license. If you did not receive a file called
17
* COPYING with this source code, please notify the distributor of this
18
* mistake, or contact the author.
19
*/
20
21
#if __has_include(<version>)
22
# include <version>
23
#endif
24
25
// NO GUARD HERE! This part should be included every time this file is.
26
#if defined(_MSC_VER)
27
28
// Save compiler's warning state, and set warning level 4 for maximum
29
// sensitivity to warnings.
30
# pragma warning(push, 4)
31
32
// Visual C++ generates some entirely unreasonable warnings. Disable them.
33
# pragma warning(disable : 4061 4251 4275 4275 4511 4512 4514 4623 4625)
34
# pragma warning(disable : 4626 4702 4820 4868 5026 5027 5031 5045 6294)
35
36
#endif
// _MSC_VER
37
38
39
#if defined(PQXX_HEADER_PRE)
40
# error "Avoid nesting #include of pqxx/internal/header-pre.hxx."
41
#endif
42
43
#define PQXX_HEADER_PRE
44
45
46
// Workarounds & definitions that need to be included even in library's headers
47
#include "
pqxx/config-compiler.h
"
48
49
// MSVC has a nonstandard definition of __cplusplus.
50
#if defined(_MSC_VER)
51
# define PQXX_CPLUSPLUS _MSVC_LANG
52
#else
53
# define PQXX_CPLUSPLUS __cplusplus
54
#endif
55
56
#if __has_cpp_attribute(gnu::pure)
58
62
# define PQXX_PURE [[gnu::pure]]
63
#else
64
# define PQXX_PURE
/* pure */
65
#endif
66
67
68
#if __has_cpp_attribute(gnu::cold)
70
# define PQXX_COLD [[gnu::cold]]
71
#else
72
# define PQXX_COLD
/* cold */
73
#endif
74
75
76
#if __has_cpp_attribute(gnu::always_inline)
78
# define PQXX_INLINE_ONLY [[gnu::always_inline]]
79
#elif __has_cpp_attribute(msvc::forceinline)
81
# define PQXX_INLINE_ONLY [[msvc::forceinline]]
82
#else
83
# define PQXX_INLINE_ONLY
/* always inline */
84
#endif
85
86
88
95
#if defined(PQXX_COVERAGE) && __has_cpp_attribute(gnu::always_inline)
96
# define PQXX_INLINE_COV [[gnu::always_inline]]
97
#else
98
# define PQXX_INLINE_COV
/* inline-only on coverage runs */
99
#endif
100
101
103
106
#if __has_cpp_attribute(gnu::noinline)
107
# define PQXX_NOINLINE [[gnu::noinline]]
108
#elif __has_cpp_attribute(msvc::noinline)
109
# define PQXX_NOINLINE [[msvc::noinline]]
110
#else
111
# define PQXX_NOINLINE
/* noinline */
112
#endif
113
114
115
#if __has_cpp_attribute(gnu::returns_nonnull)
117
# define PQXX_RETURNS_NONNULL [[gnu::returns_nonnull]]
118
#else
119
# define PQXX_RETURNS_NONNULL
/* returns nonnull */
120
#endif
121
122
123
#if __has_cpp_attribute(gnu::null_terminated_string_arg)
125
# define PQXX_ZARG(n) [[gnu::null_terminated_string_arg((n))]]
126
#else
127
# define PQXX_ZARG(n)
/* null-terminated string arg */
128
#endif
129
130
131
// Not all gcc versions we're seeing support the argument-less version.
132
#if defined(PQXX_HAVE_ZARGS)
134
# define PQXX_ZARGS [[gnu::null_terminated_string_arg]]
135
#else
136
# define PQXX_ZARGS
/* null-terminated string args */
137
#endif
138
139
140
// Workarounds for Windows
141
#ifdef _WIN32
142
143
/* For now, export DLL symbols if _DLL is defined. This is done automatically
144
* by the compiler when linking to the dynamic version of the runtime library,
145
* according to "gzh"
146
*/
147
# if defined(PQXX_SHARED) && !defined(PQXX_LIBEXPORT)
148
# define PQXX_LIBEXPORT __declspec(dllimport)
149
# endif
// PQXX_SHARED && !PQXX_LIBEXPORT
150
151
152
// Workarounds for Microsoft Visual C++
153
# ifdef _MSC_VER
154
155
// Suppress vtables on abstract classes.
156
# define PQXX_NOVTABLE __declspec(novtable)
157
158
// Automatically link with the appropriate libpq (static or dynamic, debug or
159
// release). The default is to use the release DLL. Define PQXX_PQ_STATIC to
160
// link to a static version of libpq, and _DEBUG to link to a debug version.
161
// The two may be combined.
162
# if defined(PQXX_AUTOLINK)
163
# if defined(PQXX_PQ_STATIC)
164
# ifdef _DEBUG
165
# pragma comment(lib, "libpqd"
)
166
# else
167
# pragma comment(lib, "libpq"
)
168
# endif
169
# else
170
# ifdef _DEBUG
171
# pragma comment(lib, "libpqddll"
)
172
# else
173
# pragma comment(lib, "libpqdll"
)
174
# endif
175
# endif
176
# endif
177
178
// If we're not compiling libpqxx itself, automatically link with the
179
// appropriate libpqxx library. To link with the libpqxx DLL, define
180
// PQXX_SHARED; the default is to link with the static library. A static link
181
// is the recommended practice.
182
//
183
// The preprocessor macro PQXX_INTERNAL is used to detect whether we
184
// are compiling the libpqxx library itself. When you compile the library
185
// yourself using your own project file, make sure to include this macro.
186
# if defined(PQXX_AUTOLINK) && !defined(PQXX_INTERNAL)
187
# ifdef PQXX_SHARED
188
# ifdef _DEBUG
189
# pragma comment(lib, "libpqxxD"
)
190
# else
191
# pragma comment(lib, "libpqxx"
)
192
# endif
193
# else
// !PQXX_SHARED
194
# ifdef _DEBUG
195
# pragma comment(lib, "libpqxx_staticD"
)
196
# else
197
# pragma comment(lib, "libpqxx_static"
)
198
# endif
199
# endif
200
# endif
201
202
# endif
// _MSC_VER
203
204
#elif defined(PQXX_HAVE_GCC_VISIBILITY)
// !_WIN32
205
206
# define PQXX_LIBEXPORT [[gnu::visibility("default"
)]]
207
# define PQXX_PRIVATE [[gnu::visibility("hidden"
)]]
208
209
#endif
// PQXX_HAVE_GCC_VISIBILITY
210
211
212
#ifndef PQXX_LIBEXPORT
213
# define PQXX_LIBEXPORT
/* libexport */
214
#endif
215
216
#ifndef PQXX_PRIVATE
217
# define PQXX_PRIVATE
/* private */
218
#endif
219
220
#ifndef PQXX_NOVTABLE
221
# define PQXX_NOVTABLE
/* novtable */
222
#endif
223
224
// C++23: Assume support.
225
#if defined(PQXX_HAVE_ASSUME)
226
# define PQXX_ASSUME(condition) [[assume(condition)]]
227
#else
228
# define PQXX_ASSUME(condition) while (false)
229
#endif
config-compiler.h
include
pqxx
internal
header-pre.hxx
Generated by
1.9.1