Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson updates #546

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build/
builddir/
test/sandbox
.DS_Store
examples/example_1/subprojects/unity
examples/example_1/test1.exe
examples/example_1/test2.exe
examples/example_2/all_tests.exe
Expand Down
14 changes: 14 additions & 0 deletions auto/extract_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
import re
import sys

ver_re = re.compile(r"^#define\s+UNITY_VERSION_(?:MAJOR|MINOR|BUILD)\s+(\d+)$")
version = []

with open(sys.argv[1], "r") as f:
for line in f:
m = ver_re.match(line)
if m:
version.append(m.group(1))

print(".".join(version))
42 changes: 42 additions & 0 deletions examples/example_1/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
project('Unity Example', 'c',
license: 'MIT',
default_options: [
'c_std=c89',
'warning_level=3',
])

unity_root = 'subprojects' / 'unity'

unity = subproject('unity')
unity_dep = unity.get_variable('unity_dep')

src1 = files('src/ProductionCode.c', 'test/TestProductionCode.c')
src2 = files('src/ProductionCode2.c', 'test/TestProductionCode2.c')

inc = include_directories('src')

ruby = find_program('ruby')
runner_gen = generator(ruby,
arguments: [
'@SOURCE_DIR@' / unity_root / 'auto' / 'generate_test_runner.rb',
'@INPUT@', '@OUTPUT@',
],
output: '@BASENAME@_Runner.c')


test1 = executable('test1', [
src1,
runner_gen.process('test/TestProductionCode.c'),
],
include_directories: inc,
dependencies: unity_dep)
test('test1', test1,
should_fail: true)

test2 = executable('test2', [
src2,
runner_gen.process('test/TestProductionCode2.c'),
],
include_directories: inc,
dependencies: unity_dep)
test('test2', test2)
9 changes: 8 additions & 1 deletion examples/example_1/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ Example 1
=========

Close to the simplest possible example of Unity, using only basic features.
Run make to build & run the example tests.

Build and run with Make
---
Just run `make`.

Build and run with Meson
---
Run `meson setup build` to create the build directory, and then `meson test -C build` to build and run the tests.
3 changes: 3 additions & 0 deletions examples/example_1/subprojects/unity.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[wrap-git]
url = https://github.com/ThrowTheSwitch/Unity.git
revision = head
8 changes: 8 additions & 0 deletions extras/fixture/src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
unity_inc += include_directories('.')
unity_src += files('unity_fixture.c')

install_headers(
'unity_fixture.h',
'unity_fixture_internals.h',
subdir: meson.project_name(),
)
7 changes: 7 additions & 0 deletions extras/memory/src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
unity_inc += include_directories('.')
unity_src += files('unity_memory.c')

install_headers(
'unity_memory.h',
subdir: meson.project_name(),
)
50 changes: 40 additions & 10 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
#
# build script written by : Michael Brockus.
# github repo author: Mike Karlesky, Mark VanderVoord, Greg Williams.
#
# license: MIT
#
project('unity', 'c',
license: 'MIT',
meson_version: '>=0.53.0',
default_options: ['werror=true', 'c_std=c11']
version: run_command(
find_program('python'), 'auto' / 'extract_version.py', 'src/unity.h',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to find python here, because the extract_version.py script is runnable on its own as a regular program (it's executable and has a shebang). On Windows, Meson will scan the shebang and detect that it needs to be run with python.

check: true).stdout(),
license: 'MIT',
meson_version: '>=0.53.0',
default_options: ['werror=true', 'c_std=c11']
)

build_fixture = get_option('extension_fixture').enabled()
build_memory = get_option('extension_memory').enabled()
Comment on lines +10 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're just using these like booleans, it seems misleading to allow people to specify either =auto or =disabled and have auto really just mean disabled.

What about defining the options as type boolean, and just checking the option value directly?


unity_inc = []
unity_src = []

subdir('src')
unity_dep = declare_dependency(link_with: unity_lib, include_directories: unity_dir)

if build_fixture
build_memory = true
subdir('extras/fixture/src')
endif

if build_memory
subdir('extras/memory/src')
endif

unity_lib = static_library(meson.project_name(), unity_src,
include_directories: unity_inc,
install: true)

unity_dep = declare_dependency(
link_with: unity_lib,
include_directories: unity_inc)

pkg = import('pkgconfig')
pkg.generate(unity_lib,
description: 'C Unit testing framework.')

summary({
'Fixture extension': build_fixture,
'Memory extension': build_memory,
},
section: 'Extensions',
bool_yn: true)
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
option('extension_fixture', type: 'feature', value: 'disabled')
option('extension_memory', type: 'feature', value: 'disabled')
17 changes: 7 additions & 10 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#
# build script written by : Michael Brockus.
# github repo author: Mike Karlesky, Mark VanderVoord, Greg Williams.
#
# license: MIT
#
unity_dir = include_directories('.')
unity_inc += include_directories('.')
unity_src += files('unity.c')

unity_lib = static_library(meson.project_name(),
files('unity.c'),
include_directories: unity_dir)
install_headers(
'unity.h',
'unity_internals.h',
subdir: meson.project_name(),
)