mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-23 08:25:58 +01:00
Update Meson build system
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. This commit is entirely based on existing work by Owen Torres.
This commit is contained in:
15
auto/extract_version.py
Executable file
15
auto/extract_version.py
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
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))
|
||||
|
||||
8
extras/fixture/src/meson.build
Normal file
8
extras/fixture/src/meson.build
Normal file
@@ -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
extras/memory/src/meson.build
Normal file
7
extras/memory/src/meson.build
Normal file
@@ -0,0 +1,7 @@
|
||||
unity_inc += include_directories('.')
|
||||
unity_src += files('unity_memory.c')
|
||||
|
||||
install_headers(
|
||||
'unity_memory.h',
|
||||
subdir: meson.project_name()
|
||||
)
|
||||
56
meson.build
56
meson.build
@@ -6,6 +6,17 @@
|
||||
#
|
||||
project('unity', 'c',
|
||||
license: 'MIT',
|
||||
|
||||
# Set project version to value extracted from unity.h header
|
||||
version: run_command(
|
||||
[
|
||||
find_program('python', 'python3'),
|
||||
'auto' / 'extract_version.py',
|
||||
'src' / 'unity.h'
|
||||
],
|
||||
check: true
|
||||
).stdout().strip(),
|
||||
|
||||
# `meson.project_source_root()` introduced in 0.56.0
|
||||
meson_version: '>=0.56.0',
|
||||
default_options: [
|
||||
@@ -14,8 +25,41 @@ project('unity', 'c',
|
||||
]
|
||||
)
|
||||
|
||||
build_fixture = get_option('extension_fixture').enabled()
|
||||
build_memory = get_option('extension_memory').enabled()
|
||||
|
||||
unity_src = []
|
||||
unity_inc = []
|
||||
|
||||
subdir('src')
|
||||
unity_dep = declare_dependency(link_with: unity_lib, include_directories: unity_dir)
|
||||
|
||||
if build_fixture
|
||||
# Building the fixture extension implies building the memory
|
||||
# extension.
|
||||
build_memory = true
|
||||
subdir('extras/fixture/src')
|
||||
endif
|
||||
|
||||
if build_memory
|
||||
subdir('extras/memory/src')
|
||||
endif
|
||||
|
||||
unity_lib = static_library(meson.project_name(),
|
||||
sources: unity_src,
|
||||
include_directories: unity_inc,
|
||||
install: true
|
||||
)
|
||||
|
||||
unity_dep = declare_dependency(
|
||||
link_with: unity_lib,
|
||||
include_directories: unity_inc
|
||||
)
|
||||
|
||||
# Generate pkg-config file.
|
||||
pkg = import('pkgconfig')
|
||||
pkg.generate(unity_lib,
|
||||
description: 'C Unit testing framework.'
|
||||
)
|
||||
|
||||
# Create a generator that can be used by consumers of our build system to generate
|
||||
# test runners.
|
||||
@@ -24,3 +68,13 @@ gen_test_runner = generator(
|
||||
output: '@BASENAME@_Runner.c',
|
||||
arguments: ['@INPUT@', '@OUTPUT@']
|
||||
)
|
||||
|
||||
# Summarize.
|
||||
summary(
|
||||
{
|
||||
'Fixture extension': build_fixture,
|
||||
'Memory extension': build_memory,
|
||||
},
|
||||
section: 'Extensions',
|
||||
bool_yn: true
|
||||
)
|
||||
|
||||
2
meson_options.txt
Normal file
2
meson_options.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
option('extension_fixture', type: 'feature', value: 'disabled', description: 'Whether to use the fixture extension.')
|
||||
option('extension_memory', type: 'feature', value: 'disabled', description: 'Whether to use the memory extension.')
|
||||
@@ -4,10 +4,12 @@
|
||||
#
|
||||
# license: MIT
|
||||
#
|
||||
unity_dir = include_directories('.')
|
||||
|
||||
unity_lib = static_library(meson.project_name(),
|
||||
'unity.c',
|
||||
include_directories: unity_dir,
|
||||
native: true
|
||||
unity_inc += include_directories('.')
|
||||
unity_src += files('unity.c')
|
||||
|
||||
install_headers(
|
||||
'unity.h',
|
||||
'unity_internals.h',
|
||||
subdir: meson.project_name()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user