From 6eb98cbd5e20fd23a99a5726a767445b702c8ffb Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Sun, 23 Apr 2023 14:53:07 +0800 Subject: [PATCH 1/3] Initial Meson build support --- meson.build | 77 ++++++++++++++++++++++++++++++++++++++++++ meson_options.txt | 1 + subprojects/gtest.wrap | 15 ++++++++ 3 files changed, 93 insertions(+) create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 subprojects/gtest.wrap diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..deb1aec --- /dev/null +++ b/meson.build @@ -0,0 +1,77 @@ +project('capnp-c', ['c','cpp'], meson_version: '>=1.0.0', default_options : ['c_std=c99', 'cpp_std=c++14']) + +cc = meson.get_compiler('c') + +common_c_args = [] +common_cpp_args = ['-std=c++14'] +libcapnp_c_args = [] +libcapnp_src = [ + 'lib' / 'capn-malloc.c', + 'lib' / 'capn-stream.c', + 'lib' / 'capn.c', +] + +libcapnp = library('capnp', libcapnp_src, + c_args : common_c_args + libcapnp_c_args, + dependencies: [], + implicit_include_directories: false, + include_directories: include_directories(['compiler', 'lib']) +) + +libcapnp_dep = declare_dependency( + link_with: libcapnp, + dependencies: [], + include_directories: include_directories(['compiler', 'lib']) +) + +capnpc_src = [ + 'compiler' / 'capnpc-c.c', + 'compiler' / 'schema.capnp.c', + 'compiler' / 'str.c' +] + +capnpc_c = executable('capnpc-c', capnpc_src, + include_directories: include_directories(['lib']), + dependencies: [libcapnp_dep], + c_args : common_c_args, +) + +capn_test_src = [ + 'tests' / 'capn-test.cpp', + 'tests' / 'capn-stream-test.cpp', + 'tests' / 'example-test.cpp', + 'tests' / 'addressbook.capnp.c', + 'compiler' / 'test.capnp.c', + 'compiler' / 'schema-test.cpp', + 'compiler' / 'schema.capnp.c' +] + +if get_option('enable_tests') and not meson.is_subproject() + + thread_dep = dependency('threads') + + gtest_proj = subproject('gtest') + gtest_dep = gtest_proj.get_variable('gtest_dep') + gmock_dep = gtest_proj.get_variable('gmock_dep') + + test_dependencies = [libcapnp_dep, gtest_dep, gmock_dep, thread_dep] + + if get_option('b_sanitize').contains('address') + test_dependencies += cc.find_library('asan') + endif + if get_option('b_sanitize').contains('undefined') + test_dependencies += cc.find_library('ubsan') + endif + + exe = executable('capn-test', capn_test_src, + include_directories: include_directories(['lib', 'tests', 'compiler']), + dependencies: test_dependencies, + c_args : common_c_args, + cpp_args : common_cpp_args, + install: false, + install_rpath: '', + implicit_include_directories: false + ) + test('capn-test', exe) + +endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..ae5c8a4 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +option('enable_tests', type: 'boolean', value: true, description: 'Build unit tests in test/ and compiler/') diff --git a/subprojects/gtest.wrap b/subprojects/gtest.wrap new file mode 100644 index 0000000..195aaca --- /dev/null +++ b/subprojects/gtest.wrap @@ -0,0 +1,15 @@ +[wrap-file] +directory = googletest-1.13.0 +source_url = https://github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz +source_filename = gtest-1.13.0.tar.gz +source_hash = ad7fdba11ea011c1d925b3289cf4af2c66a352e18d4c7264392fead75e919363 +patch_filename = gtest_1.13.0-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.13.0-1/get_patch +patch_hash = 6d82a02c3a45071cea989983bf6becde801cbbfd29196ba30dada0215393b082 +wrapdb_version = 1.13.0-1 + +[provide] +gtest = gtest_dep +gtest_main = gtest_main_dep +gmock = gmock_dep +gmock_main = gmock_main_dep From 6b8e3caed3c323090d73653db4feba1e731939d3 Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Sun, 23 Apr 2023 17:19:46 +0800 Subject: [PATCH 2/3] Ignore subprojects in git --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index c3a9d9d..8d57551 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ capnpc-c c-capnproto.pc *.tar.gz + +subprojects/googletest-* +subprojects/packagecache From 53f6def21b7d4028519656b73f95f72849daac59 Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Sun, 23 Apr 2023 17:08:26 +0800 Subject: [PATCH 3/3] Add Meson building instructions in README --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6142a1a..8a36575 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,24 @@ capnpc compiler/test.capnp -oc ## Building on Linux ```sh -git clone https://github.com/opensourcerouting/c-capnproto +git clone --recurse-submodules https://github.com/opensourcerouting/c-capnproto cd c-capnproto -git submodule update --init --recursive autoreconf -f -i -s ./configure make make check ``` +## Building with Meson + +```sh +git clone --recurse-submodules https://github.com/opensourcerouting/c-capnproto +cd c-capnproto +meson setup build +meson compile -C build +build/capn-test +``` + ## Usage ### Generating C code from a `.capnp` schema file