Fix a compiler warning in initStringInfo().
[pgsql.git] / src / backend / meson.build
blob2b0db21480470d102f1f12cfd549943c5dfd993c
1 # Copyright (c) 2022-2025, PostgreSQL Global Development Group
3 backend_build_deps = [backend_code]
4 backend_sources = []
5 backend_link_with = [pgport_srv, common_srv]
7 generated_backend_sources = []
8 post_export_backend_sources = []
10 subdir('access')
11 subdir('archive')
12 subdir('backup')
13 subdir('bootstrap')
14 subdir('catalog')
15 subdir('commands')
16 subdir('executor')
17 subdir('foreign')
18 subdir('jit')
19 subdir('lib')
20 subdir('libpq')
21 subdir('main')
22 subdir('nodes')
23 subdir('optimizer')
24 subdir('parser')
25 subdir('partitioning')
26 subdir('port')
27 subdir('postmaster')
28 subdir('regex')
29 subdir('replication')
30 subdir('rewrite')
31 subdir('statistics')
32 subdir('storage')
33 subdir('tcop')
34 subdir('tsearch')
35 subdir('utils')
37 subdir('po', if_found: libintl)
40 backend_link_args = []
41 backend_link_depends = []
44 # On windows when compiling with msvc we need to make postgres export all its
45 # symbols so that extension libraries can use them. For that we need to scan
46 # the constituting objects and generate a file specifying all the functions as
47 # exported (variables need an "import" declaration in the header, hence
48 # PGDLLEXPORT, but functions work without that, due to import libraries
49 # basically being trampolines).
51 # For dtrace probes we need to invoke dtrace on all input files, before
52 # linking the final executable (see more below).
55 # On meson there's currently no easy way to do this that I found. So we build
56 # a static library with all the input objects, run our script to generate
57 # exports, and build the final executable using that static library
59 # We could do that only if either dtrace or msvc is in use, but it seems
60 # easier to just always do so.
62 # Can't name the static library 'postgres', because msbuild ends up with a
63 # conflict for the .pdb file otherwise.
65 postgres_lib = static_library('postgres_lib',
66   backend_sources + timezone_sources + generated_backend_sources,
67   link_whole: backend_link_with,
68   dependencies: backend_build_deps,
69   c_pch: pch_postgres_h,
70   kwargs: internal_lib_args,
73 if cc.get_id() == 'msvc'
74   postgres_def = custom_target('postgres.def',
75     command: [perl, files('../tools/msvc_gendef.pl'),
76               '--arch', host_cpu,
77               '--tempdir', '@PRIVATE_DIR@',
78               '--deffile', '@OUTPUT@',
79               '@INPUT@'],
80     input: [postgres_lib, common_srv, pgport_srv],
81     output: 'postgres.def',
82     depends: [postgres_lib, common_srv, pgport_srv],
83     install: false,
84     build_by_default: false,
85   )
87   backend_link_args += '/DEF:@0@'.format(postgres_def.full_path())
88   backend_link_depends += postgres_def
89   # Due to the way msvc and meson's precompiled headers implementation
90   # interact, we need to have symbols from the full library available. Could
91   # be restricted to b_pch=true.
92   backend_link_with += postgres_lib
94 endif
96 backend_input = []
97 backend_objs = [postgres_lib.extract_all_objects(recursive: false)]
99 # As of 1/2010:
100 # The probes.o file is necessary for dtrace support on Solaris, and on recent
101 # versions of systemtap.  (Older systemtap releases just produce an empty
102 # file, but that's okay.)  However, macOS's dtrace doesn't use it and doesn't
103 # even recognize the -G option.  So, build probes.o except on macOS.
104 # This might need adjustment as other platforms add dtrace support.
106 # On at least linux we don't actually need to pass in all the objects, but
107 # at least on FreeBSD and Solaris we have to.
109 # XXX: The reason we don't use the objects for generated sources is that doing
110 # so is not supported in older meson versions. Luckily we don't have probes in
111 # generated sources...
112 if dtrace.found() and host_system != 'darwin'
113   backend_input += custom_target(
114     'probes.o',
115     input: ['utils/probes.d', postgres_lib.extract_objects(backend_sources, timezone_sources)],
116     output: 'probes.o',
117     command: [dtrace, '-C', '-G', '-o', '@OUTPUT@', '-s', '@INPUT@'],
118     install: false,
119   )
120 endif
122 if host_system == 'windows'
123   post_export_backend_sources += rc_bin_gen.process(win32ver_rc, extra_args: [
124     '--NAME', 'postgres',
125     '--FILEDESC', 'PostgreSQL Server',])
126 endif
128 postgres = executable('postgres',
129   backend_input,
130   sources: post_export_backend_sources,
131   objects: backend_objs,
132   link_args: backend_link_args,
133   link_with: backend_link_with,
134   link_depends: backend_link_depends,
135   export_dynamic: true,
136   implib: 'postgres',
137   dependencies: backend_build_deps,
138   kwargs: default_bin_args,
141 backend_targets += postgres
143 pg_mod_c_args = cflags_mod
144 pg_mod_cpp_args = cxxflags_mod
145 pg_mod_link_args = ldflags_sl + ldflags_mod
146 pg_mod_link_depend = []
148 # A few platforms like MacOS and Windows link shared modules against postgres,
149 # or a [import] library derived from it. Set up the link flags for that.
150 if mod_link_args_fmt.length() > 0
151   # To avoid unnecessary build-time dependencies on other operating systems,
152   # only add the dependency when necessary.
153   pg_mod_link_depend += postgres
155   name = mod_link_with_name.format('postgres')
156   link_with_uninst = meson.current_build_dir() / name
157   link_with_inst = '${@0@}/@1@'.format(mod_link_with_dir, name)
159   foreach el : mod_link_args_fmt
160     pg_mod_link_args += el.format(link_with_uninst)
161   endforeach
162 endif
165 # Note there's intentionally no dependency on pgport/common here - we want the
166 # symbols from the main binary for extension modules, rather than the
167 # extension linking separately to pgport/common.
168 backend_mod_code = declare_dependency(
169   compile_args: pg_mod_c_args,
170   include_directories: postgres_inc,
171   link_args: pg_mod_link_args,
172   sources: generated_headers + generated_backend_headers,
173   dependencies: backend_mod_deps,
176 # normal extension modules
177 pg_mod_args = default_mod_args + {
178   'dependencies': [backend_mod_code],
179   'cpp_args': pg_mod_cpp_args,
180   'link_depends': pg_mod_link_depend,
183 # extension modules that shouldn't be installed by default, as they're only
184 # for testing
185 pg_test_mod_args = pg_mod_args + {
186   'install': false
191 # Shared modules that, on some system, link against the server binary. Only
192 # enter these after we defined the server build.
194 subdir('jit/llvm')
195 subdir('replication/libpqwalreceiver')
196 subdir('replication/pgoutput')
197 subdir('snowball')
198 subdir('utils/mb/conversion_procs')