Skip to content

Commit 0854f3d

Browse files
authored
Merge pull request #658 from amcnulty-fermat/meson-update
Meson update
2 parents 5204c1b + fba6be1 commit 0854f3d

File tree

10 files changed

+157
-18
lines changed

10 files changed

+157
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ build/
22
builddir/
33
test/sandbox
44
.DS_Store
5+
examples/example_1/subprojects/unity
56
examples/example_1/test1.exe
67
examples/example_1/test2.exe
78
examples/example_2/all_tests.exe

auto/extract_version.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python3
2+
import re
3+
import sys
4+
5+
ver_re = re.compile(r"^#define\s+UNITY_VERSION_(?:MAJOR|MINOR|BUILD)\s+(\d+)$")
6+
version = []
7+
8+
with open(sys.argv[1], "r") as f:
9+
for line in f:
10+
m = ver_re.match(line)
11+
if m:
12+
version.append(m.group(1))
13+
14+
print(".".join(version))
15+

examples/example_1/meson.build

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
project('Unity example', 'c',
2+
license: 'MIT',
3+
default_options: [
4+
'c_std=c99',
5+
'warning_level=3',
6+
],
7+
meson_version: '>= 0.49.0'
8+
)
9+
10+
unity_subproject = subproject('unity')
11+
unity_dependency = unity_subproject.get_variable('unity_dep')
12+
unity_gen_runner = unity_subproject.get_variable('gen_test_runner')
13+
14+
src1 = files([
15+
'src' / 'ProductionCode.c',
16+
'test' / 'TestProductionCode.c',
17+
])
18+
19+
src2 = files([
20+
'src' / 'ProductionCode2.c',
21+
'test' / 'TestProductionCode2.c',
22+
])
23+
24+
inc = include_directories('src')
25+
26+
test1 = executable('test1',
27+
sources: [
28+
src1,
29+
unity_gen_runner.process('test' / 'TestProductionCode.c')
30+
],
31+
include_directories: [ inc ],
32+
dependencies: [ unity_dependency ],
33+
)
34+
35+
test('test1', test1,
36+
should_fail: true)
37+
38+
test2 = executable('test2',
39+
sources: [
40+
src2,
41+
unity_gen_runner.process('test' / 'TestProductionCode2.c')
42+
],
43+
include_directories: [ inc ],
44+
dependencies: [ unity_dependency ],
45+
)
46+
47+
test('test2', test2)
48+

examples/example_1/readme.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@ Example 1
22
=========
33

44
Close to the simplest possible example of Unity, using only basic features.
5-
Run make to build & run the example tests.
5+
6+
Build and run with Make
7+
---
8+
Just run `make`.
9+
10+
Build and run with Meson
11+
---
12+
Run `meson setup build` to create the build directory, and then `meson test -C build` to build and run the tests.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[wrap-git]
2+
url = https://github.com/ThrowTheSwitch/Unity.git
3+
revision = head

extras/fixture/src/meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
unity_inc += include_directories('.')
2+
unity_src += files('unity_fixture.c')
3+
4+
install_headers(
5+
'unity_fixture.h',
6+
'unity_fixture_internals.h',
7+
subdir: meson.project_name()
8+
)

extras/memory/src/meson.build

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
unity_inc += include_directories('.')
2+
unity_src += files('unity_memory.c')
3+
4+
install_headers(
5+
'unity_memory.h',
6+
subdir: meson.project_name()
7+
)

meson.build

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,67 @@
55
# license: MIT
66
#
77
project('unity', 'c',
8-
license: 'MIT',
9-
meson_version: '>=0.37.0',
10-
default_options: ['werror=true', 'c_std=c11'])
8+
license: 'MIT',
9+
10+
# Set project version to value extracted from unity.h header
11+
version: run_command(
12+
[
13+
'auto/extract_version.py',
14+
'src/unity.h'
15+
],
16+
check: true
17+
).stdout().strip(),
18+
19+
meson_version: '>=0.47.0',
20+
default_options: [
21+
'werror=true',
22+
'c_std=c11'
23+
]
24+
)
25+
26+
build_fixture = get_option('extension_fixture')
27+
build_memory = get_option('extension_memory')
28+
29+
unity_src = []
30+
unity_inc = []
1131

1232
subdir('src')
13-
unity_dep = declare_dependency(link_with: unity_lib, include_directories: unity_dir)
1433

34+
if build_fixture
35+
# Building the fixture extension implies building the memory
36+
# extension.
37+
build_memory = true
38+
subdir('extras/fixture/src')
39+
endif
1540

16-
# Get the generate_test_runner script relative to itself or the parent project if it is being used as a subproject
17-
# NOTE: This could be (and probably is) a complete hack - but I haven't yet been able to find a better way....
18-
if meson.is_subproject()
19-
gen_test_runner_path = find_program(meson.source_root() / 'subprojects/unity/auto/generate_test_runner.rb')
20-
else
21-
gen_test_runner_path = find_program('subprojects/unity/auto/generate_test_runner.rb')
41+
if build_memory
42+
subdir('extras/memory/src')
2243
endif
2344

24-
# Create a generator that we can access from the parent project
25-
gen_test_runner = generator(gen_test_runner_path, output: '@BASENAME@_Runner.c', arguments: ['@INPUT@', '@OUTPUT@'] )
45+
unity_lib = static_library(meson.project_name(),
46+
sources: unity_src,
47+
include_directories: unity_inc,
48+
install: true
49+
)
50+
51+
unity_dep = declare_dependency(
52+
link_with: unity_lib,
53+
include_directories: unity_inc
54+
)
55+
56+
# Generate pkg-config file.
57+
pkg = import('pkgconfig')
58+
pkg.generate(
59+
name: meson.project_name(),
60+
version: meson.project_version(),
61+
libraries: [ unity_lib ],
62+
description: 'C Unit testing framework.'
63+
)
64+
65+
# Create a generator that can be used by consumers of our build system to generate
66+
# test runners.
67+
gen_test_runner = generator(
68+
find_program('auto/generate_test_runner.rb'),
69+
output: '@BASENAME@_Runner.c',
70+
arguments: ['@INPUT@', '@OUTPUT@']
71+
)

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
option('extension_fixture', type: 'boolean', value: 'false', description: 'Whether to enable the fixture extension.')
2+
option('extension_memory', type: 'boolean', value: 'false', description: 'Whether to enable the memory extension.')

src/meson.build

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#
55
# license: MIT
66
#
7-
unity_dir = include_directories('.')
87

9-
unity_lib = static_library(meson.project_name(),
10-
'unity.c',
11-
include_directories: unity_dir,
12-
native: true
8+
unity_inc += include_directories('.')
9+
unity_src += files('unity.c')
10+
11+
install_headers(
12+
'unity.h',
13+
'unity_internals.h',
14+
subdir: meson.project_name()
1315
)

0 commit comments

Comments
 (0)