summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2018-07-18 12:35:06 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2018-07-18 12:35:06 +0200
commitc7e53c7f8fd437819d572aaeb0ad12ac1fdc3187 (patch)
tree007483bd8b5639383467d1c0c91e2b2cc0cfb779
parentc79b12abb7b9cb2adb95b6529061ed1593ae5ee3 (diff)
parent9d8498765ccf188950ccf266ea1fb075a48628ac (diff)
downloadlibnitrokey-c7e53c7f8fd437819d572aaeb0ad12ac1fdc3187.tar.gz
libnitrokey-c7e53c7f8fd437819d572aaeb0ad12ac1fdc3187.tar.bz2
Merge branch 'pr_85'
Support build via Meson and Ninja Fixes #85
-rw-r--r--README.md11
-rw-r--r--build/.gitignore1
-rw-r--r--meson.build139
-rw-r--r--meson_options.txt4
4 files changed, 154 insertions, 1 deletions
diff --git a/README.md b/README.md
index 81b367a..1bc8ef9 100644
--- a/README.md
+++ b/README.md
@@ -76,6 +76,17 @@ Other build options (all take either `ON` or `OFF`):
* NO_LOG (default: OFF) - do not compile LOG statements - will make library smaller, but without any diagnostic messages
+### Meson
+It is possible to use Meson and Ninja to build the project as well (currently available only `master` branch).
+Please run:
+```
+meson builddir
+cd builddir
+meson configure # to show available build flags
+ninja
+```
+
+Tests build with bundled Catch is not supported yet with this method.
# Using libnitrokey with Python
To use libnitrokey with Python a [CFFI](http://cffi.readthedocs.io/en/latest/overview.html) library is required (either 2.7+ or 3.0+). It can be installed with:
diff --git a/build/.gitignore b/build/.gitignore
deleted file mode 100644
index 72e8ffc..0000000
--- a/build/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-*
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..79f9d77
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,139 @@
+project(
+ 'libnitrokey', 'cpp',
+ version : '3.4.1',
+ license : 'LGPL-3.0+',
+ default_options : [
+ 'cpp_std=c++14'
+ ],
+ meson_version : '>= 0.43.0',
+)
+cxx = meson.get_compiler('cpp')
+host_system = host_machine.system()
+pkg = import('pkgconfig')
+
+test_cflags = [
+ '-Wno-unused-function',
+ '-Wcast-qual',
+ '-Woverloaded-virtual',
+]
+add_project_arguments(cxx.get_supported_arguments(test_cflags), language : 'cpp')
+
+dep_hidapi = dependency('hidapi-libusb')
+
+inc_libnitrokey = include_directories('libnitrokey')
+libnitrokey_args = []
+if not get_option('log')
+ libnitrokey_args += ['-DNO_LOG']
+endif
+if get_option('log-volatile-data')
+ libnitrokey_args += ['-DLOG_VOLATILE_DATA']
+endif
+libnitrokey = library(
+ 'nitokey',
+ sources : [
+ 'command_id.cc',
+ 'device.cc',
+ 'log.cc',
+ 'version.cc',
+ 'misc.cc',
+ 'NitrokeyManager.cc',
+ 'NK_C_API.cc',
+ 'DeviceCommunicationExceptions.cpp',
+ ],
+ include_directories : [
+ inc_libnitrokey,
+ ],
+ dependencies : [
+ dep_hidapi,
+ ],
+ cpp_args : libnitrokey_args,
+ version : meson.project_version(),
+ install : true,
+)
+install_headers(
+ 'libnitrokey/CommandFailedException.h',
+ 'libnitrokey/command.h',
+ 'libnitrokey/command_id.h',
+ 'libnitrokey/cxx_semantics.h',
+ 'libnitrokey/DeviceCommunicationExceptions.h',
+ 'libnitrokey/device.h',
+ 'libnitrokey/device_proto.h',
+ 'libnitrokey/dissect.h',
+ 'libnitrokey/LibraryException.h',
+ 'libnitrokey/log.h',
+ 'libnitrokey/LongOperationInProgressException.h',
+ 'libnitrokey/misc.h',
+ 'libnitrokey/version.h',
+ 'libnitrokey/NitrokeyManager.h',
+ 'libnitrokey/stick10_commands_0.8.h',
+ 'libnitrokey/stick10_commands.h',
+ 'libnitrokey/stick20_commands.h',
+ subdir : meson.project_name(),
+)
+
+ext_libnitrokey = declare_dependency(
+ link_with : libnitrokey,
+ include_directories : inc_libnitrokey,
+)
+
+pkg.generate(
+ name : meson.project_name(),
+ filebase : 'libnitrokey-1',
+ libraries : libnitrokey,
+ version : meson.project_version(),
+ requires_private : 'hidapi-libusb',
+ description : 'Library for communicating with Nitrokey in a clean and easy manner',
+ install : true,
+)
+
+if get_option('tests') or get_option('offline-tests')
+ # FIXME
+ _inc_catch = include_directories('/usr/include/catch')
+ if not cxx.has_header('catch.hpp', include_directories : _inc_catch)
+ error('Can\'t find catch.hpp')
+ endif
+ _catch = static_library(
+ 'catch',
+ sources : [
+ 'unittest/catch_main.cpp',
+ ],
+ include_directories : [
+ _inc_catch,
+ ],
+ )
+ _dep_catch = declare_dependency(
+ link_with : _catch,
+ include_directories : _inc_catch,
+ )
+endif
+
+tests = []
+if get_option('offline-tests')
+ tests += [
+ ['test_offline', 'test_offline.cc'],
+ ['test_minimal', 'test_minimal.cc'],
+ ]
+endif
+if get_option('tests')
+ tests += [
+ ['test_C_API', 'test_C_API.cpp'],
+ ['test1', 'test1.cc'],
+ ['test2', 'test2.cc'],
+ ['test3', 'test3.cc'],
+ ['test_HOTP', 'test_HOTP.cc'],
+ ['test_issues', 'test_issues.cc'],
+ ]
+endif
+foreach tst : tests
+ test(
+ tst[0],
+ executable(
+ tst[0],
+ sources : 'unittest/@0@'.format(tst[1]),
+ dependencies : [
+ ext_libnitrokey,
+ _dep_catch,
+ ],
+ )
+ )
+endforeach
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..aaf8195
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,4 @@
+option('log', type : 'boolean', value : true, description : 'Logging functionality')
+option('log-volatile-data', type : 'boolean', value : false, description : 'Log volatile data (debug)')
+option('tests', type : 'boolean', value : false, description : 'Compile tests (needs connected PRO device)')
+option('offline-tests', type : 'boolean', value : false, description : 'Compile offline tests')