postgresql/src/include/meson.build
Andres Freund e6927270cd meson: Add initial version of meson based build system
Autoconf is showing its age, fewer and fewer contributors know how to wrangle
it. Recursive make has a lot of hard to resolve dependency issues and slow
incremental rebuilds. Our home-grown MSVC build system is hard to maintain for
developers not using Windows and runs tests serially. While these and other
issues could individually be addressed with incremental improvements, together
they seem best addressed by moving to a more modern build system.

After evaluating different build system choices, we chose to use meson, to a
good degree based on the adoption by other open source projects.

We decided that it's more realistic to commit a relatively early version of
the new build system and mature it in tree.

This commit adds an initial version of a meson based build system. It supports
building postgres on at least AIX, FreeBSD, Linux, macOS, NetBSD, OpenBSD,
Solaris and Windows (however only gcc is supported on aix, solaris). For
Windows/MSVC postgres can now be built with ninja (faster, particularly for
incremental builds) and msbuild (supporting the visual studio GUI, but
building slower).

Several aspects (e.g. Windows rc file generation, PGXS compatibility, LLVM
bitcode generation, documentation adjustments) are done in subsequent commits
requiring further review. Other aspects (e.g. not installing test-only
extensions) are not yet addressed.

When building on Windows with msbuild, builds are slower when using a visual
studio version older than 2019, because those versions do not support
MultiToolTask, required by meson for intra-target parallelism.

The plan is to remove the MSVC specific build system in src/tools/msvc soon
after reaching feature parity. However, we're not planning to remove the
autoconf/make build system in the near future. Likely we're going to keep at
least the parts required for PGXS to keep working around until all supported
versions build with meson.

Some initial help for postgres developers is at
https://wiki.postgresql.org/wiki/Meson

With contributions from Thomas Munro, John Naylor, Stone Tickle and others.

Author: Andres Freund <andres@anarazel.de>
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Author: Peter Eisentraut <peter@eisentraut.org>
Reviewed-By: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/20211012083721.hvixq4pnh2pixr3j@alap3.anarazel.de
2022-09-21 22:37:17 -07:00

174 lines
4.0 KiB
Meson

pg_config_ext = configure_file(
input: 'pg_config_ext.h.meson',
output: 'pg_config_ext.h',
configuration: cdata,
install: true,
install_dir: dir_include,
)
configure_files += pg_config_ext
pg_config_os = configure_file(
output: 'pg_config_os.h',
input: files('port/@0@.h'.format(portname)),
install: true,
install_dir: dir_include,
copy: true,
)
configure_files += pg_config_os
pg_config = configure_file(
output: 'pg_config.h',
install: true,
install_dir: dir_include,
configuration: cdata,
)
configure_files += pg_config
config_paths_data = configuration_data()
config_paths_data.set_quoted('PGBINDIR', dir_prefix / dir_bin)
config_paths_data.set_quoted('PGSHAREDIR', dir_prefix / dir_data)
config_paths_data.set_quoted('SYSCONFDIR', dir_prefix / dir_sysconf)
config_paths_data.set_quoted('INCLUDEDIR', dir_prefix / dir_include)
config_paths_data.set_quoted('PKGINCLUDEDIR', dir_prefix / dir_include_pkg)
config_paths_data.set_quoted('INCLUDEDIRSERVER', dir_prefix / dir_include_server)
config_paths_data.set_quoted('LIBDIR', dir_prefix / dir_lib)
config_paths_data.set_quoted('PKGLIBDIR', dir_prefix / dir_lib_pkg)
config_paths_data.set_quoted('LOCALEDIR', dir_prefix / dir_locale)
config_paths_data.set_quoted('DOCDIR', dir_prefix / dir_doc)
config_paths_data.set_quoted('HTMLDIR', dir_prefix / dir_doc_html)
config_paths_data.set_quoted('MANDIR', dir_prefix / dir_man)
var_cc = ' '.join(cc.cmd_array())
var_cpp = ' '.join(cc.cmd_array() + ['-E'])
var_cflags = ' '.join(cflags + cflags_warn)
var_cxxflags = ' '.join(cxxflags + cxxflags_warn)
var_cppflags = ' '.join(cppflags)
var_cflags_sl = '-fPIC' #FIXME
var_ldflags = ' '.join(ldflags)
var_ldflags_sl = ''.join(ldflags_sl)
var_ldflags_ex = '' # FIXME
# FIXME - some extensions might directly use symbols from one of libs. If
# that symbol isn't used by postgres, and statically linked, it'll cause an
# undefined symbol at runtime. And obviously it'll cause problems for
# executables, although those are probably less common.
var_libs = ''
pg_config_paths = configure_file(
output: 'pg_config_paths.h',
configuration: config_paths_data,
install: false,
)
configure_files += pg_config_paths
install_headers(
'pg_config_manual.h',
'postgres_ext.h',
)
install_headers(
'libpq/libpq-fs.h',
install_dir: dir_include / 'libpq',
)
install_headers(
'c.h',
'port.h',
'postgres_fe.h',
install_dir: dir_include_internal
)
install_headers(
'libpq/pqcomm.h',
install_dir: dir_include_internal / 'libpq',
)
install_headers(
'c.h',
'fmgr.h',
'funcapi.h',
'getopt_long.h',
'miscadmin.h',
'pg_config_manual.h',
'pg_getopt.h',
'pg_trace.h',
'pgstat.h',
'pgtar.h',
'pgtime.h',
'port.h',
'postgres.h',
'postgres_ext.h',
'postgres_fe.h',
'windowapi.h',
pg_config_ext,
pg_config_os,
pg_config,
install_dir: dir_include_server,
)
subdir('catalog')
subdir('nodes')
subdir('storage')
subdir('utils')
header_subdirs = [
'access',
'catalog',
'bootstrap',
'commands',
'common',
'datatype',
'executor',
'fe_utils',
'foreign',
'jit',
'lib',
'libpq',
'mb',
'nodes',
'optimizer',
'parser',
'partitioning',
'postmaster',
'regex',
'replication',
'rewrite',
'statistics',
'storage',
'tcop',
'snowball',
'tsearch',
'utils',
'port',
'portability',
]
# XXX: installing headers this way has the danger of installing editor files
# etc, unfortunately install_subdir() doesn't allow including / excluding by
# pattern currently.
foreach d : header_subdirs
if d == 'catalog'
continue
endif
install_subdir(d, install_dir: dir_include_server,
exclude_files: ['.gitignore', 'meson.build'])
endforeach
install_subdir('catalog',
install_dir: dir_include_server,
exclude_files: [
'.gitignore',
'Makefile',
'duplicate_oids',
'meson.build',
'reformat_dat_file.pl',
'renumber_oids.pl',
'unused_oids',
] + bki_data,
)
# autoconf generates the file there, ensure we get a conflict
generated_sources_ac += {'src/include': ['stamp-h', 'stamp-ext-h']}