Skip to content

Commit daa56fb

Browse files
pks-tgitster
authored andcommitted
meson: compile compatibility sources separately
In the next commit we're about to introduce a precompiled header for "git-compat-util.h". The consequence of this change is that we'll implicitly include that header for every compilation unit that uses the precompiled headers. This is okay for our "normal" library sources and our builtins. But some of our compatibility sources do not include the header on purpose, and doing so would cause compilation errors. Prepare for this change by splitting out compatibility sources into their static library. Like this, we can selectively enable precompiled headers for the library sources. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent baa61e4 commit daa56fb

1 file changed

Lines changed: 45 additions & 34 deletions

File tree

meson.build

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ version_gen_environment.set('GIT_VERSION', get_option('version'))
271271

272272
compiler = meson.get_compiler('c')
273273

274+
compat_sources = [
275+
'compat/nonblock.c',
276+
'compat/obstack.c',
277+
'compat/open.c',
278+
'compat/terminal.c',
279+
]
280+
274281
libgit_sources = [
275282
'abspath.c',
276283
'add-interactive.c',
@@ -304,10 +311,6 @@ libgit_sources = [
304311
'commit.c',
305312
'common-exit.c',
306313
'common-init.c',
307-
'compat/nonblock.c',
308-
'compat/obstack.c',
309-
'compat/open.c',
310-
'compat/terminal.c',
311314
'compiler-tricks/not-constant.c',
312315
'config.c',
313316
'connect.c',
@@ -1163,7 +1166,7 @@ endif
11631166

11641167
if not has_poll_h and not has_sys_poll_h
11651168
libgit_c_args += '-DNO_POLL'
1166-
libgit_sources += 'compat/poll/poll.c'
1169+
compat_sources += 'compat/poll/poll.c'
11671170
libgit_include_directories += 'compat/poll'
11681171
endif
11691172

@@ -1179,7 +1182,7 @@ endif
11791182
# implementation to threat things like drive prefixes specially.
11801183
if host_machine.system() == 'windows' or not compiler.has_header('libgen.h')
11811184
libgit_c_args += '-DNO_LIBGEN_H'
1182-
libgit_sources += 'compat/basename.c'
1185+
compat_sources += 'compat/basename.c'
11831186
endif
11841187

11851188
if compiler.has_header('paths.h')
@@ -1209,7 +1212,7 @@ if host_machine.system() != 'windows'
12091212
foreach symbol : ['inet_ntop', 'inet_pton', 'hstrerror']
12101213
if not compiler.has_function(symbol, dependencies: networking_dependencies)
12111214
libgit_c_args += '-DNO_' + symbol.to_upper()
1212-
libgit_sources += 'compat/' + symbol + '.c'
1215+
compat_sources += 'compat/' + symbol + '.c'
12131216
endif
12141217
endforeach
12151218
endif
@@ -1251,18 +1254,18 @@ else
12511254
endif
12521255

12531256
if host_machine.system() == 'darwin'
1254-
libgit_sources += 'compat/precompose_utf8.c'
1257+
compat_sources += 'compat/precompose_utf8.c'
12551258
libgit_c_args += '-DPRECOMPOSE_UNICODE'
12561259
libgit_c_args += '-DPROTECT_HFS_DEFAULT'
12571260
endif
12581261

12591262
# Configure general compatibility wrappers.
12601263
if host_machine.system() == 'cygwin'
1261-
libgit_sources += [
1264+
compat_sources += [
12621265
'compat/win32/path-utils.c',
12631266
]
12641267
elif host_machine.system() == 'windows'
1265-
libgit_sources += [
1268+
compat_sources += [
12661269
'compat/winansi.c',
12671270
'compat/win32/dirent.c',
12681271
'compat/win32/flush.c',
@@ -1289,20 +1292,20 @@ elif host_machine.system() == 'windows'
12891292
libgit_include_directories += 'compat/win32'
12901293
if compiler.get_id() == 'msvc'
12911294
libgit_include_directories += 'compat/vcbuild/include'
1292-
libgit_sources += 'compat/msvc.c'
1295+
compat_sources += 'compat/msvc.c'
12931296
else
1294-
libgit_sources += 'compat/mingw.c'
1297+
compat_sources += 'compat/mingw.c'
12951298
endif
12961299
endif
12971300

12981301
if host_machine.system() == 'linux'
1299-
libgit_sources += 'compat/linux/procinfo.c'
1302+
compat_sources += 'compat/linux/procinfo.c'
13001303
elif host_machine.system() == 'windows'
1301-
libgit_sources += 'compat/win32/trace2_win32_process_info.c'
1304+
compat_sources += 'compat/win32/trace2_win32_process_info.c'
13021305
elif host_machine.system() == 'darwin'
1303-
libgit_sources += 'compat/darwin/procinfo.c'
1306+
compat_sources += 'compat/darwin/procinfo.c'
13041307
else
1305-
libgit_sources += 'compat/stub/procinfo.c'
1308+
compat_sources += 'compat/stub/procinfo.c'
13061309
endif
13071310

13081311
if host_machine.system() == 'cygwin' or host_machine.system() == 'windows'
@@ -1315,13 +1318,13 @@ endif
13151318

13161319
# Configure the simple-ipc subsystem required fro the fsmonitor.
13171320
if host_machine.system() == 'windows'
1318-
libgit_sources += [
1321+
compat_sources += [
13191322
'compat/simple-ipc/ipc-shared.c',
13201323
'compat/simple-ipc/ipc-win32.c',
13211324
]
13221325
libgit_c_args += '-DSUPPORTS_SIMPLE_IPC'
13231326
else
1324-
libgit_sources += [
1327+
compat_sources += [
13251328
'compat/simple-ipc/ipc-shared.c',
13261329
'compat/simple-ipc/ipc-unix-socket.c',
13271330
]
@@ -1339,7 +1342,7 @@ if fsmonitor_backend != ''
13391342
libgit_c_args += '-DHAVE_FSMONITOR_DAEMON_BACKEND'
13401343
libgit_c_args += '-DHAVE_FSMONITOR_OS_SETTINGS'
13411344

1342-
libgit_sources += [
1345+
compat_sources += [
13431346
'compat/fsmonitor/fsm-health-' + fsmonitor_backend + '.c',
13441347
'compat/fsmonitor/fsm-ipc-' + fsmonitor_backend + '.c',
13451348
'compat/fsmonitor/fsm-listen-' + fsmonitor_backend + '.c',
@@ -1355,7 +1358,7 @@ if not get_option('b_sanitize').contains('address') and get_option('regex').allo
13551358

13561359
if compiler.get_define('REG_ENHANCED', prefix: '#include <regex.h>') != ''
13571360
libgit_c_args += '-DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS'
1358-
libgit_sources += 'compat/regcomp_enhanced.c'
1361+
compat_sources += 'compat/regcomp_enhanced.c'
13591362
endif
13601363
elif not get_option('regex').enabled()
13611364
libgit_c_args += [
@@ -1364,7 +1367,7 @@ elif not get_option('regex').enabled()
13641367
'-DNO_MBSUPPORT',
13651368
]
13661369
build_options_config.set('NO_REGEX', '1')
1367-
libgit_sources += 'compat/regex/regex.c'
1370+
compat_sources += 'compat/regex/regex.c'
13681371
libgit_include_directories += 'compat/regex'
13691372
else
13701373
error('Native regex support requested but not found')
@@ -1428,7 +1431,7 @@ else
14281431

14291432
if get_option('b_sanitize').contains('address')
14301433
libgit_c_args += '-DNO_MMAP'
1431-
libgit_sources += 'compat/mmap.c'
1434+
compat_sources += 'compat/mmap.c'
14321435
else
14331436
checkfuncs += { 'mmap': ['mmap.c'] }
14341437
endif
@@ -1438,7 +1441,7 @@ foreach func, impls : checkfuncs
14381441
if not compiler.has_function(func)
14391442
libgit_c_args += '-DNO_' + func.to_upper()
14401443
foreach impl : impls
1441-
libgit_sources += 'compat/' + impl
1444+
compat_sources += 'compat/' + impl
14421445
endforeach
14431446
endif
14441447
endforeach
@@ -1449,13 +1452,13 @@ endif
14491452

14501453
if not compiler.has_function('strdup')
14511454
libgit_c_args += '-DOVERRIDE_STRDUP'
1452-
libgit_sources += 'compat/strdup.c'
1455+
compat_sources += 'compat/strdup.c'
14531456
endif
14541457

14551458
if not compiler.has_function('qsort')
14561459
libgit_c_args += '-DINTERNAL_QSORT'
14571460
endif
1458-
libgit_sources += 'compat/qsort_s.c'
1461+
compat_sources += 'compat/qsort_s.c'
14591462

14601463
if compiler.has_function('getdelim')
14611464
libgit_c_args += '-DHAVE_GETDELIM'
@@ -1511,7 +1514,7 @@ if meson.can_run_host_binaries() and compiler.run('''
15111514
}
15121515
''', name: 'fread reads directories').returncode() == 0
15131516
libgit_c_args += '-DFREAD_READS_DIRECTORIES'
1514-
libgit_sources += 'compat/fopen.c'
1517+
compat_sources += 'compat/fopen.c'
15151518
endif
15161519

15171520
if not meson.is_cross_build() and fs.exists('/dev/tty')
@@ -1745,14 +1748,22 @@ else
17451748
endif
17461749

17471750
libgit = declare_dependency(
1748-
link_with: static_library('git',
1749-
sources: libgit_sources,
1750-
c_args: libgit_c_args + [
1751-
'-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1752-
],
1753-
dependencies: libgit_dependencies,
1754-
include_directories: libgit_include_directories,
1755-
),
1751+
link_with: [
1752+
static_library('compat',
1753+
sources: compat_sources,
1754+
c_args: libgit_c_args,
1755+
dependencies: libgit_dependencies,
1756+
include_directories: libgit_include_directories,
1757+
),
1758+
static_library('git',
1759+
sources: libgit_sources,
1760+
c_args: libgit_c_args + [
1761+
'-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1762+
],
1763+
dependencies: libgit_dependencies,
1764+
include_directories: libgit_include_directories,
1765+
),
1766+
],
17561767
compile_args: libgit_c_args,
17571768
dependencies: libgit_dependencies,
17581769
include_directories: libgit_include_directories,

0 commit comments

Comments
 (0)