pg_regress: Disable autoruns for cmd.exe on Windows
[pgsql.git] / src / port / meson.build
blob69b30ab21b4caa3760713bcc6ce328d2cae91292
1 # Copyright (c) 2022-2024, PostgreSQL Global Development Group
3 pgport_sources = [
4   'bsearch_arg.c',
5   'chklocale.c',
6   'inet_net_ntop.c',
7   'noblock.c',
8   'path.c',
9   'pg_bitutils.c',
10   'pg_strong_random.c',
11   'pgcheckdir.c',
12   'pgmkdirp.c',
13   'pgsleep.c',
14   'pgstrcasecmp.c',
15   'pgstrsignal.c',
16   'pqsignal.c',
17   'qsort.c',
18   'qsort_arg.c',
19   'quotes.c',
20   'snprintf.c',
21   'strerror.c',
22   'tar.c',
23   'user.c',
26 if host_system == 'windows'
27   pgport_sources += files(
28     'dirmod.c',
29     'kill.c',
30     'open.c',
31     'system.c',
32     'win32common.c',
33     'win32dlopen.c',
34     'win32env.c',
35     'win32error.c',
36     'win32fdatasync.c',
37     'win32fseek.c',
38     'win32getrusage.c',
39     'win32link.c',
40     'win32ntdll.c',
41     'win32pread.c',
42     'win32pwrite.c',
43     'win32security.c',
44     'win32setlocale.c',
45     'win32stat.c',
46   )
47 elif host_system == 'cygwin'
48   pgport_sources += files(
49     'dirmod.c',
50   )
51 endif
53 if cc.get_id() == 'msvc'
54   pgport_sources += files(
55     'dirent.c',
56     'win32gettimeofday.c',
57   )
58 endif
60 # Replacement functionality to be built if corresponding configure symbol
61 # is false
62 replace_funcs_neg = [
63   ['explicit_bzero'],
64   ['getopt'],
65   ['getopt_long'],
66   ['getpeereid'],
67   ['inet_aton'],
68   ['mkdtemp'],
69   ['strlcat'],
70   ['strlcpy'],
71   ['strnlen'],
74 if host_system != 'windows'
75   replace_funcs_neg += [['pthread_barrier_wait']]
76 endif
78 # Replacement functionality to be built if corresponding configure symbol
79 # is true
80 replace_funcs_pos = [
81   # x86/x64
82   ['pg_crc32c_sse42', 'USE_SSE42_CRC32C'],
83   ['pg_crc32c_sse42', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK', 'crc'],
84   ['pg_crc32c_sse42_choose', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK'],
85   ['pg_crc32c_sb8', 'USE_SSE42_CRC32C_WITH_RUNTIME_CHECK'],
87   # arm / aarch64
88   ['pg_crc32c_armv8', 'USE_ARMV8_CRC32C'],
89   ['pg_crc32c_armv8', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK', 'crc'],
90   ['pg_crc32c_armv8_choose', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK'],
91   ['pg_crc32c_sb8', 'USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK'],
93   # loongarch
94   ['pg_crc32c_loongarch', 'USE_LOONGARCH_CRC32C'],
96   # generic fallback
97   ['pg_crc32c_sb8', 'USE_SLICING_BY_8_CRC32C'],
100 pgport_cflags = {'crc': cflags_crc}
101 pgport_sources_cflags = {'crc': []}
103 foreach f : replace_funcs_neg
104   func = f.get(0)
105   varname = f.get(1, 'HAVE_@0@'.format(func.to_upper()))
106   filename = '@0@.c'.format(func)
108   val = '@0@'.format(cdata.get(varname, 'false'))
109   if val == 'false' or val == '0'
110     pgport_sources += files(filename)
111   endif
112 endforeach
114 foreach f : replace_funcs_pos
115   func = f.get(0)
116   varname = f.get(1, 'HAVE_@0@'.format(func.to_upper()))
117   filename = '@0@.c'.format(func)
119   val = '@0@'.format(cdata.get(varname, 'false'))
120   if val == 'true' or val == '1'
121     src = files(filename)
122     if f.length() > 2
123       pgport_sources_cflags += {f[2]: pgport_sources_cflags[f[2]] + src}
124     else
125       pgport_sources += src
126     endif
127   endif
128 endforeach
131 if (host_system == 'windows' or host_system == 'cygwin') and \
132   (cc.get_id() != 'msvc' or cc.version().version_compare('<14.0'))
134   # Cygwin and (apparently, based on test results) Mingw both
135   # have a broken strtof(), so substitute its implementation.
136   # That's not a perfect fix, since it doesn't avoid double-rounding,
137   # but we have no better options.
138   pgport_sources += files('strtof.c')
139   message('On @0@ with compiler @1@ @2@ we will use our strtof wrapper.'.format(
140     host_system, cc.get_id(), cc.version()))
141 endif
145 # Build pgport once for backend, once for use in frontend binaries, and once
146 # for use in shared libraries
147 pgport = {}
148 pgport_variants = {
149   '_srv': internal_lib_args + {
150     'dependencies': [backend_port_code],
151   },
152   '': default_lib_args + {
153     'dependencies': [frontend_port_code],
154   },
155   '_shlib': default_lib_args + {
156     'pic': true,
157     'dependencies': [frontend_port_code],
158   },
161 foreach name, opts : pgport_variants
163   # Build internal static libraries for sets of files that need to be built
164   # with different cflags
165   cflag_libs = []
166   foreach cflagname, sources : pgport_sources_cflags
167     if sources.length() == 0
168       continue
169     endif
170     c_args = opts.get('c_args', []) + pgport_cflags[cflagname]
171     cflag_libs += static_library('libpgport@0@_@1@'.format(name, cflagname),
172       sources,
173       c_pch: pch_c_h,
174       kwargs: opts + {
175         'c_args': c_args,
176         'build_by_default': false,
177         'install': false,
178       },
179     )
180   endforeach
182   lib = static_library('libpgport@0@'.format(name),
183       pgport_sources,
184       link_with: cflag_libs,
185       c_pch: pch_c_h,
186       kwargs: opts + {
187         'dependencies': opts['dependencies'] + [ssl],
188       }
189     )
190   pgport += {name: lib}
191 endforeach
193 pgport_srv = pgport['_srv']
194 pgport_static = pgport['']
195 pgport_shlib = pgport['_shlib']
197 # autoconf generates the file there, ensure we get a conflict
198 generated_sources_ac += {'src/port': ['pg_config_paths.h']}