postgresql/src/include/meson.build
Andres Freund e5555657ba meson: Add support for building with precompiled headers
This substantially speeds up building for windows, due to the vast amount of
headers included via windows.h. A cross build from linux targetting mingw goes
from

994.11user 136.43system 0:31.58elapsed 3579%CPU
to
422.41user 89.05system 0:14.35elapsed 3562%CPU

The wins on windows are similar-ish (but I don't have a system at hand just
now for actual numbers). Targetting other operating systems the wins are far
smaller (tested linux, macOS, FreeBSD).

For now precompiled headers are disabled by default, it's not clear how well
they work on all platforms. E.g. on FreeBSD gcc doesn't seem to have working
support, but clang does.

When doing a full build precompiled headers are only beneficial for targets
with multiple .c files, as meson builds a separate precompiled header for each
target (so that different compilation options take effect). This commit
therefore only changes target with at least two .c files to use precompiled
headers.

Because this commit adds b_pch=false to the default_options new build
directories will have precompiled headers disabled by default, however
existing build directories will continue use the default value of b_pch, which
is true.

Note that using precompiled headers with ccache requires setting
CCACHE_SLOPPINESS=pch_defines,time_macros to get hits.

Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/CA+hUKG+50eOUbN++ocDc0Qnp9Pvmou23DSXu=ZA6fepOcftKqA@mail.gmail.com
Discussion: https://postgr.es/m/c5736f70-bb6d-8d25-e35c-e3d886e4e905@enterprisedb.com
Discussion: https://postgr.es/m/20190826054000.GE7005%40paquier.xyz
2022-10-06 17:19:30 -07:00

178 lines
4.1 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 + get_option('c_args'))
if llvm.found()
var_cxxflags = ' '.join(cxxflags + cxxflags_warn + get_option('cpp_args'))
else
var_cxxflags = ''
endif
var_cppflags = ' '.join(cppflags)
var_cflags_sl = '-fPIC' #FIXME
var_ldflags = ' '.join(ldflags + get_option('c_link_args'))
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('pch')
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']}