meson: simplify use of the common-main library
The "common-main.c" file is used by multiple executables. In order to make it easy to set it up we have created a separate library that these executables can link against. All of these executables also want to link against `libgit.a` though, which makes it necessary to specify both of these as dependencies for every executable. Simplify this a bit by declaring the library as a source dependency: instead of creating a static library, we now instead compile the common set of files into each executable separately. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Feb 26, 2025 at 09:22 UTC
ebb35369f1aea0e829a2e13531316a34d8f2e354
4 files changed
+24
-25
meson.build
+19
-20
@@ -1604,15 +1604,14 @@ if host_machine.system() == 'windows'
1604
error('Unsupported compiler ' + compiler.get_id())
1605
endif
1606
endif
1607
-common_main_library = static_library('common-main',
1608
- sources: common_main_sources,
1609
- c_args: libgit_c_args,
1610
- dependencies: libgit_dependencies,
1611
- include_directories: libgit_include_directories,
1612
-)
1613
-common_main = declare_dependency(
1614
- link_with: common_main_library,
1607
+
1608
+libgit_commonmain = declare_dependency(
1609
+ link_with: static_library('common-main',
1610
+ sources: common_main_sources,
1611
+ dependencies: [ libgit ],
1612
+ ),
1613
link_args: common_main_link_args,
1614
+ dependencies: [ libgit ],
1615
)
1616
1617
bin_wrappers = [ ]
@@ -1620,7 +1619,7 @@ test_dependencies = [ ]
1619
1620
git = executable('git',
1621
sources: builtin_sources + 'git.c',
1623
- dependencies: [libgit, common_main],
1622
+ dependencies: [libgit_commonmain],
1623
install: true,
1624
install_dir: get_option('libexecdir') / 'git-core',
1625
)
@@ -1628,35 +1627,35 @@ bin_wrappers += git
1627
1628
test_dependencies += executable('git-daemon',
1629
sources: 'daemon.c',
1631
- dependencies: [libgit, common_main],
1630
+ dependencies: [libgit_commonmain],
1631
install: true,
1632
install_dir: get_option('libexecdir') / 'git-core',
1633
)
1634
1635
test_dependencies += executable('git-sh-i18n--envsubst',
1636
sources: 'sh-i18n--envsubst.c',
1638
- dependencies: [libgit, common_main],
1637
+ dependencies: [libgit_commonmain],
1638
install: true,
1639
install_dir: get_option('libexecdir') / 'git-core',
1640
)
1641
1642
bin_wrappers += executable('git-shell',
1643
sources: 'shell.c',
1645
- dependencies: [libgit, common_main],
1644
+ dependencies: [libgit_commonmain],
1645
install: true,
1646
install_dir: get_option('libexecdir') / 'git-core',
1647
)
1648
1649
test_dependencies += executable('git-http-backend',
1650
sources: 'http-backend.c',
1652
- dependencies: [libgit, common_main],
1651
+ dependencies: [libgit_commonmain],
1652
install: true,
1653
install_dir: get_option('libexecdir') / 'git-core',
1654
)
1655
1656
bin_wrappers += executable('scalar',
1657
sources: 'scalar.c',
1659
- dependencies: [libgit, common_main],
1658
+ dependencies: [libgit_commonmain],
1659
install: true,
1660
install_dir: get_option('libexecdir') / 'git-core',
1661
)
@@ -1669,7 +1668,7 @@ if get_option('curl').enabled()
1668
1669
git_remote_http = executable('git-remote-http',
1670
sources: curl_sources + 'remote-curl.c',
1672
- dependencies: [libgit, common_main],
1671
+ dependencies: [libgit_commonmain],
1672
install: true,
1673
install_dir: get_option('libexecdir') / 'git-core',
1674
)
@@ -1677,7 +1676,7 @@ if get_option('curl').enabled()
1676
1677
test_dependencies += executable('git-http-fetch',
1678
sources: curl_sources + 'http-fetch.c',
1680
- dependencies: [libgit, common_main],
1679
+ dependencies: [libgit_commonmain],
1680
install: true,
1681
install_dir: get_option('libexecdir') / 'git-core',
1682
)
@@ -1685,7 +1684,7 @@ if get_option('curl').enabled()
1684
if expat.found()
1685
test_dependencies += executable('git-http-push',
1686
sources: curl_sources + 'http-push.c',
1688
- dependencies: [libgit, common_main],
1687
+ dependencies: [libgit_commonmain],
1688
install: true,
1689
install_dir: get_option('libexecdir') / 'git-core',
1690
)
@@ -1694,7 +1693,7 @@ if get_option('curl').enabled()
1693
foreach alias : [ 'git-remote-https', 'git-remote-ftp', 'git-remote-ftps' ]
1694
test_dependencies += executable(alias,
1695
objects: git_remote_http.extract_all_objects(recursive: false),
1697
- dependencies: [libgit, common_main],
1696
+ dependencies: [libgit_commonmain],
1697
)
1698
1699
install_symlink(alias + executable_suffix,
@@ -1711,7 +1710,7 @@ endif
1710
1711
test_dependencies += executable('git-imap-send',
1712
sources: imap_send_sources,
1714
- dependencies: [libgit, common_main],
1713
+ dependencies: [libgit_commonmain],
1714
install: true,
1715
install_dir: get_option('libexecdir') / 'git-core',
1716
)
@@ -1719,7 +1718,7 @@ test_dependencies += executable('git-imap-send',
1718
foreach alias : [ 'git-receive-pack', 'git-upload-archive', 'git-upload-pack' ]
1719
bin_wrappers += executable(alias,
1720
objects: git.extract_all_objects(recursive: false),
1722
- dependencies: [libgit, common_main],
1721
+ dependencies: [libgit_commonmain],
1722
)
1723
1724
install_symlink(alias + executable_suffix,
oss-fuzz/meson.build
+1
-1
@@ -15,6 +15,6 @@ foreach fuzz_program : fuzz_programs
15
'dummy-cmd-main.c',
16
fuzz_program,
17
],
18
- dependencies: [libgit, common_main],
18
+ dependencies: [libgit_commonmain],
19
)
20
endforeach
t/helper/meson.build
+2
-2
@@ -79,14 +79,14 @@ test_tool_sources = [
79
80
test_tool = executable('test-tool',
81
sources: test_tool_sources,
82
- dependencies: [libgit, common_main],
82
+ dependencies: [libgit_commonmain],
83
)
84
bin_wrappers += test_tool
85
test_dependencies += test_tool
86
87
test_fake_ssh = executable('test-fake-ssh',
88
sources: 'test-fake-ssh.c',
89
- dependencies: [libgit, common_main],
89
+ dependencies: [libgit_commonmain],
90
)
91
bin_wrappers += test_fake_ssh
92
test_dependencies += test_fake_ssh
t/meson.build
+2
-2
@@ -39,7 +39,7 @@ clar_sources += custom_target(
39
40
clar_unit_tests = executable('unit-tests',
41
sources: clar_sources + clar_test_suites,
42
- dependencies: [libgit, common_main],
42
+ dependencies: [libgit_commonmain],
43
)
44
test('unit-tests', clar_unit_tests)
45
@@ -72,7 +72,7 @@ foreach unit_test_program : unit_test_programs
72
'unit-tests/lib-reftable.c',
73
unit_test_program,
74
],
75
- dependencies: [libgit, common_main],
75
+ dependencies: [libgit_commonmain],
76
)
77
test(unit_test_name, unit_test,
78
workdir: meson.current_source_dir(),