1 # Copyright (c) 2022-2024, PostgreSQL Global Development Group
3 common_sources = files(
10 'controldata_utils.c',
44 common_sources += files(
45 'cryptohash_openssl.c',
49 common_sources += files(
58 common_kwlist = custom_target('kwlist',
59 input: files('../include/parser/kwlist.h'),
61 depend_files: gen_kwlist_deps,
62 command: [gen_kwlist_cmd, '--extern'])
63 generated_sources += common_kwlist
64 common_sources += common_kwlist
66 # The code imported from Ryu gets a pass on declaration-after-statement,
67 # in order to keep it more closely aligned with its upstream.
74 ryu_cflags += cflags_no_decl_after_statement
76 config_info_sources = files('config_info.c',)
77 config_info_cflags = [
78 '-DVAL_CC="@0@"'.format(var_cc),
79 '-DVAL_CPPFLAGS="@0@"'.format(var_cppflags),
80 '-DVAL_CFLAGS="@0@"'.format(var_cflags),
81 '-DVAL_CFLAGS_SL="@0@"'.format(var_cflags_sl),
82 '-DVAL_LDFLAGS="@0@"'.format(var_ldflags),
83 '-DVAL_LDFLAGS_EX="@0@"'.format(var_ldflags_ex),
84 '-DVAL_LDFLAGS_SL="@0@"'.format(var_ldflags_sl),
85 '-DVAL_LIBS="@0@"'.format(var_libs),
88 # Some files need to be built with different cflags. The different sets are
92 'config_info': config_info_cflags,
94 common_sources_cflags = {
96 'config_info': config_info_sources
100 # A few files are currently only built for frontend, not server.
101 # logging.c is excluded from OBJS_FRONTEND_SHLIB (shared library) as
102 # a matter of policy, because it is not appropriate for general purpose
103 # libraries such as libpq to report errors directly. fe_memutils.c is
104 # excluded because libpq must not exit() on allocation failure.
106 # The excluded files for _shlib builds are pulled into their own static
107 # library, for the benefit of test programs that need not follow the
110 common_sources_frontend_shlib = common_sources
111 common_sources_frontend_shlib += files(
112 'restricted_token.c',
116 common_sources_excluded_shlib = files(
121 common_sources_frontend_static = [
122 common_sources_frontend_shlib,
123 common_sources_excluded_shlib,
126 # Build pgcommon once for backend, once for use in frontend binaries, and
127 # once for use in shared libraries
129 # XXX: in most environments we could probably link_whole pgcommon_shlib
130 # against pgcommon_static, instead of compiling twice.
132 # For the server build of pgcommon, depend on lwlocknames_h and because at
133 # least cryptohash_openssl.c, hmac_openssl.c depend on it.
134 # controldata_utils.c depends on wait_event_types_h. That's arguably a
135 # layering violation, but ...
137 pgcommon_variants = {
138 '_srv': internal_lib_args + {
139 'sources': common_sources + [lwlocknames_h] + [wait_event_types_h],
140 'dependencies': [backend_common_code],
142 '': default_lib_args + {
143 'sources': common_sources_frontend_static,
144 'dependencies': [frontend_common_code],
145 # Files in libpgcommon.a should use/export the "xxx_private" versions
146 # of pg_char_to_encoding() and friends.
147 'c_args': ['-DUSE_PRIVATE_ENCODING_FUNCS'],
149 '_shlib': default_lib_args + {
151 'sources': common_sources_frontend_shlib,
152 'dependencies': [frontend_common_code],
153 # The JSON API normally exits on out-of-memory; disable that behavior for
154 # shared library builds. This requires libpq's pqexpbuffer.h.
155 'c_args': ['-DJSONAPI_USE_PQEXPBUFFER'],
156 'include_directories': include_directories('../interfaces/libpq'),
160 foreach name, opts : pgcommon_variants
162 # Build internal static libraries for sets of files that need to be built
163 # with different cflags
165 foreach cflagname, sources : common_sources_cflags
166 if sources.length() == 0
169 c_args = opts.get('c_args', []) + common_cflags[cflagname]
170 cflag_libs += static_library('libpgcommon@0@_@1@'.format(name, cflagname),
173 'include_directories': [
174 include_directories('.'),
175 opts.get('include_directories', []),
179 'build_by_default': false,
185 lib = static_library('libpgcommon@0@'.format(name),
186 link_with: cflag_libs,
189 'include_directories': [
190 include_directories('.'),
191 opts.get('include_directories', []),
193 'dependencies': opts['dependencies'] + [ssl],
196 pgcommon += {name: lib}
199 common_srv = pgcommon['_srv']
200 common_shlib = pgcommon['_shlib']
201 common_static = pgcommon['']
203 common_excluded_shlib = static_library('libpgcommon_excluded_shlib',
204 sources: common_sources_excluded_shlib,
205 dependencies: [frontend_common_code],
206 build_by_default: false,
207 kwargs: default_lib_args + {