From 062714d80c33ff913d12a38a9756fb0414c08fb6 Mon Sep 17 00:00:00 2001 From: Steven Sloboda Date: Thu, 30 Nov 2017 15:39:35 -0500 Subject: [PATCH 1/3] Make minmea_isfield public. This function is useful when writing libraries that use minmea and support NMEA as well as other sentence types. --- minmea.c | 5 ----- minmea.h | 9 +++++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/minmea.c b/minmea.c index 6bcf0f3..fd1b62a 100644 --- a/minmea.c +++ b/minmea.c @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -85,10 +84,6 @@ bool minmea_check(const char *sentence, bool strict) return true; } -static inline bool minmea_isfield(char c) { - return isprint((unsigned char) c) && c != ',' && c != '*'; -} - bool minmea_scan(const char *sentence, const char *format, ...) { bool result = false; diff --git a/minmea.h b/minmea.h index b80124c..67ebc15 100644 --- a/minmea.h +++ b/minmea.h @@ -13,6 +13,7 @@ extern "C" { #endif +#include #include #include #include @@ -252,6 +253,14 @@ static inline float minmea_tocoord(struct minmea_float *f) return (float) degrees + (float) minutes / (60 * f->scale); } +/** + * Check whether a character belongs to the set of characters allowed in a + * sentence data field. + */ +static inline bool minmea_isfield(char c) { + return isprint((unsigned char) c) && c != ',' && c != '*'; +} + #ifdef __cplusplus } #endif From 5542486aace2984bfc4fea0d18e3de5ded96fbcf Mon Sep 17 00:00:00 2001 From: Steven Sloboda Date: Thu, 30 Nov 2017 16:56:27 -0500 Subject: [PATCH 2/3] Build with meson. --- .gitignore | 1 + README.md | 6 ++++ meson.build | 79 +++++++++++++++++++++++++++++++++++++++++++++++ meson_options.txt | 2 ++ 4 files changed, 88 insertions(+) create mode 100644 meson.build create mode 100644 meson_options.txt diff --git a/.gitignore b/.gitignore index dd53256..beb07f9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ minmea tests example *.exe +build diff --git a/README.md b/README.md index 0bee70a..5ef6710 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,9 @@ while (fgets(line, sizeof(line), stdin) != NULL) { Simply add ``minmea.[ch]`` to your project, ``#include "minmea.h"`` and you're good to go. +Alternatively for projects built with `meson`, add this repository in the +`subprojects` directory and add minmea_dep as a dependency of your project. + ## Running unit tests Building and running the tests requires the following: @@ -133,6 +136,9 @@ Building and running the tests requires the following: If you have both in your ``$PATH``, running the tests should be as simple as typing ``make``. +Alternatively if using `meson` to build minmea, invoke `ninja test` in the +build directory to run the tests. + ## Limitations * Only a handful of frames is supported right now. diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..05b8ef8 --- /dev/null +++ b/meson.build @@ -0,0 +1,79 @@ +project( + 'minmea', + 'c', + default_options: ['c_std=c99', 'buildtype=debug'], +) + +add_project_arguments( + '-Wall', '-Wextra', '-Werror', + '-D_POSIX_C_SOURCE=199309L', '-D_BSD_SOURCE', '-D_DEFAULT_SOURCE', + '-D_DARWIN_C_SOURCE', + language: 'c', +) + +if host_machine.system() == 'windows' + add_project_arguments('DMINMEA_INCLUDE_COMPAT') +endif + +c_args = [] + +if get_option('buildtype') == 'debug' + c_args += '-ggdb' +endif + +minmea_includes = ['minmea.h'] + +minmea_sources = ['minmea.c'] + +minmea_dependencies = [] + +minmea_lib = library( + 'minmea', + minmea_sources, + # include_directories: minmea_includes, + dependencies: minmea_dependencies, + c_args: c_args, +) + +minmea_dep = declare_dependency( + # include_directories: minmea_includes, + dependencies: minmea_dependencies, + link_with: minmea_lib, +) + +if get_option('example') + minmea_example_sources = [ + 'example.c', + ] + + minmea_example_dependencies = [ + minmea_dep, + ] + + minmea_example = executable( + 'example', + minmea_example_sources, + dependencies: minmea_example_dependencies, + ) +endif + +if get_option('tests') + check = dependency('check') + + minmea_test_sources = [ + 'tests.c', + ] + + minmea_test_dependencies = [ + check, + minmea_dep, + ] + + minmea_test = executable( + 'tests', + minmea_test_sources, + dependencies: minmea_test_dependencies, + ) + + test('tests', minmea_test) +endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..b3567ff --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,2 @@ +option('tests', type: 'boolean', value: true) +option('example', type: 'boolean', value: true) From 77e2579162d751f157f1f8fa91b96e0fd3ffcdf7 Mon Sep 17 00:00:00 2001 From: Steven Sloboda Date: Thu, 30 Nov 2017 17:30:59 -0500 Subject: [PATCH 3/3] Reorganize so meson projects can `#include "minmea/minmea.h"`. --- .gitignore | 5 ++--- Makefile | 20 +++++++++++-------- meson.build | 12 +++++------ .../compat}/minmea_compat_windows.h | 0 example.c => minmea/example.c | 0 minmea.c => minmea/minmea.c | 0 minmea.h => minmea/minmea.h | 0 tests.c => minmea/tests.c | 0 8 files changed, 20 insertions(+), 17 deletions(-) rename {compat => minmea/compat}/minmea_compat_windows.h (100%) rename example.c => minmea/example.c (100%) rename minmea.c => minmea/minmea.c (100%) rename minmea.h => minmea/minmea.h (100%) rename tests.c => minmea/tests.c (100%) diff --git a/.gitignore b/.gitignore index beb07f9..fadac96 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,7 @@ *~ *.diff .*.swp -minmea -tests -example +minmea/tests +minmea/example *.exe build diff --git a/Makefile b/Makefile index 4a3688f..1d304a5 100644 --- a/Makefile +++ b/Makefile @@ -9,23 +9,27 @@ CFLAGS += -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_DARWIN_C_ CFLAGS += $(shell pkg-config --cflags check) LDLIBS += $(shell pkg-config --libs check) +SRC_DIR = minmea + all: scan-build test example @echo "+++ All good.""" -test: tests +test: $(SRC_DIR)/tests @echo "+++ Running Check test suite..." - ./tests + ./$(SRC_DIR)/tests + +example: $(SRC_DIR)/example scan-build: clean @echo "+++ Running Clang Static Analyzer..." - scan-build $(MAKE) tests + scan-build $(MAKE) $(SRC_DIR)/tests clean: - $(RM) tests example *.o + $(RM) $(SRC_DIR)/tests $(SRC_DIR)/example $(SRC_DIR)/*.o -tests: tests.o minmea.o -example: example.o minmea.o -tests.o: tests.c minmea.h -minmea.o: minmea.c minmea.h +$(SRC_DIR)/tests: $(SRC_DIR)/tests.o $(SRC_DIR)/minmea.o +$(SRC_DIR)/example: $(SRC_DIR)/example.o $(SRC_DIR)/minmea.o +$(SRC_DIR)/tests.o: $(SRC_DIR)/tests.c $(SRC_DIR)/minmea.h +$(SRC_DIR)/minmea.o: $(SRC_DIR)/minmea.c $(SRC_DIR)/minmea.h .PHONY: all test scan-build clean diff --git a/meson.build b/meson.build index 05b8ef8..0479990 100644 --- a/meson.build +++ b/meson.build @@ -21,29 +21,29 @@ if get_option('buildtype') == 'debug' c_args += '-ggdb' endif -minmea_includes = ['minmea.h'] +minmea_includes = include_directories('.') -minmea_sources = ['minmea.c'] +minmea_sources = ['minmea/minmea.c'] minmea_dependencies = [] minmea_lib = library( 'minmea', minmea_sources, - # include_directories: minmea_includes, + include_directories: minmea_includes, dependencies: minmea_dependencies, c_args: c_args, ) minmea_dep = declare_dependency( - # include_directories: minmea_includes, + include_directories: minmea_includes, dependencies: minmea_dependencies, link_with: minmea_lib, ) if get_option('example') minmea_example_sources = [ - 'example.c', + 'minmea/example.c', ] minmea_example_dependencies = [ @@ -61,7 +61,7 @@ if get_option('tests') check = dependency('check') minmea_test_sources = [ - 'tests.c', + 'minmea/tests.c', ] minmea_test_dependencies = [ diff --git a/compat/minmea_compat_windows.h b/minmea/compat/minmea_compat_windows.h similarity index 100% rename from compat/minmea_compat_windows.h rename to minmea/compat/minmea_compat_windows.h diff --git a/example.c b/minmea/example.c similarity index 100% rename from example.c rename to minmea/example.c diff --git a/minmea.c b/minmea/minmea.c similarity index 100% rename from minmea.c rename to minmea/minmea.c diff --git a/minmea.h b/minmea/minmea.h similarity index 100% rename from minmea.h rename to minmea/minmea.h diff --git a/tests.c b/minmea/tests.c similarity index 100% rename from tests.c rename to minmea/tests.c