From 3576898a20cd60976910894e069bb0da19ce4d57 Mon Sep 17 00:00:00 2001 From: Owen Torres <55297187+optorres@users.noreply.github.com> Date: Sat, 13 Mar 2021 22:04:30 -0500 Subject: [PATCH 1/2] Add Meson example --- .gitignore | 1 + examples/example_1/meson.build | 42 +++++++++++++++++++++++ examples/example_1/readme.txt | 9 ++++- examples/example_1/subprojects/unity.wrap | 3 ++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 examples/example_1/meson.build create mode 100644 examples/example_1/subprojects/unity.wrap diff --git a/.gitignore b/.gitignore index e4bb017b1..6832136a6 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/examples/example_1/meson.build b/examples/example_1/meson.build new file mode 100644 index 000000000..138d79c33 --- /dev/null +++ b/examples/example_1/meson.build @@ -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) diff --git a/examples/example_1/readme.txt b/examples/example_1/readme.txt index dfed81502..ddddd369e 100644 --- a/examples/example_1/readme.txt +++ b/examples/example_1/readme.txt @@ -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. \ No newline at end of file + +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. diff --git a/examples/example_1/subprojects/unity.wrap b/examples/example_1/subprojects/unity.wrap new file mode 100644 index 000000000..6df241bdd --- /dev/null +++ b/examples/example_1/subprojects/unity.wrap @@ -0,0 +1,3 @@ +[wrap-git] +url = https://github.com/ThrowTheSwitch/Unity.git +revision = head From 682495a2d3f34ffe3de1121f48d402e809ff23a4 Mon Sep 17 00:00:00 2001 From: Owen Torres <55297187+optorres@users.noreply.github.com> Date: Sat, 13 Mar 2021 22:03:10 -0500 Subject: [PATCH 2/2] Update Meson build The following features from the CMake build have been implemented: * Library version retrieved from unity.h. * Extension support. * Library, header, and package configuration file installation. --- auto/extract_version.py | 14 ++++++++++ extras/fixture/src/meson.build | 8 ++++++ extras/memory/src/meson.build | 7 +++++ meson.build | 50 +++++++++++++++++++++++++++------- meson_options.txt | 2 ++ src/meson.build | 17 +++++------- 6 files changed, 78 insertions(+), 20 deletions(-) create mode 100755 auto/extract_version.py create mode 100644 extras/fixture/src/meson.build create mode 100644 extras/memory/src/meson.build create mode 100644 meson_options.txt diff --git a/auto/extract_version.py b/auto/extract_version.py new file mode 100755 index 000000000..e1d448f68 --- /dev/null +++ b/auto/extract_version.py @@ -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)) diff --git a/extras/fixture/src/meson.build b/extras/fixture/src/meson.build new file mode 100644 index 000000000..7c3cd3391 --- /dev/null +++ b/extras/fixture/src/meson.build @@ -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(), +) diff --git a/extras/memory/src/meson.build b/extras/memory/src/meson.build new file mode 100644 index 000000000..2bf2421a0 --- /dev/null +++ b/extras/memory/src/meson.build @@ -0,0 +1,7 @@ +unity_inc += include_directories('.') +unity_src += files('unity_memory.c') + +install_headers( + 'unity_memory.h', + subdir: meson.project_name(), +) diff --git a/meson.build b/meson.build index f5c5cfaa7..cd5f1bfee 100644 --- a/meson.build +++ b/meson.build @@ -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', + 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() + +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) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 000000000..5edcff180 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,2 @@ +option('extension_fixture', type: 'feature', value: 'disabled') +option('extension_memory', type: 'feature', value: 'disabled') diff --git a/src/meson.build b/src/meson.build index 1c7b426ff..ac3d4752f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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(), +)