From 5e37c325034c851512a8a6a3b10a15e80bdb7dd9 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Mon, 8 Jan 2018 14:12:00 +0100 Subject: add meson buildsystem definitions References: https://github.com/Nitrokey/nitrokey-app/issues/306 Signed-off-by: Igor Gnatenko --- build/.gitignore | 1 - meson.build | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ meson_options.txt | 4 ++ 3 files changed, 141 insertions(+), 1 deletion(-) delete mode 100644 build/.gitignore create mode 100644 meson.build create mode 100644 meson_options.txt 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..d13b1f4 --- /dev/null +++ b/meson.build @@ -0,0 +1,137 @@ +project( + 'libnitrokey', 'cpp', + version : '3.1.0', + 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('include') +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', + '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( + 'include/CommandFailedException.h', + 'include/command.h', + 'include/command_id.h', + 'include/cxx_semantics.h', + 'include/DeviceCommunicationExceptions.h', + 'include/device.h', + 'include/device_proto.h', + 'include/dissect.h', + 'include/inttypes.h', + 'include/LibraryException.h', + 'include/log.h', + 'include/LongOperationInProgressException.h', + 'include/misc.h', + 'include/NitrokeyManager.h', + 'include/stick10_commands_0.8.h', + 'include/stick10_commands.h', + 'include/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'], + ] +endif +if get_option('tests') + tests += [ + ['test_C_API', 'test_C_API.cpp'], + ['test1', 'test.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') -- cgit v1.2.3 From 734859fa2a960d16db0d3526c44d759b7756f915 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 18 Jul 2018 12:24:31 +0200 Subject: Update meson definition to v3.4.1 Signed-off-by: Szczepan Zalega --- meson.build | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/meson.build b/meson.build index d13b1f4..79f9d77 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project( 'libnitrokey', 'cpp', - version : '3.1.0', + version : '3.4.1', license : 'LGPL-3.0+', default_options : [ 'cpp_std=c++14' @@ -20,7 +20,7 @@ add_project_arguments(cxx.get_supported_arguments(test_cflags), language : 'cpp' dep_hidapi = dependency('hidapi-libusb') -inc_libnitrokey = include_directories('include') +inc_libnitrokey = include_directories('libnitrokey') libnitrokey_args = [] if not get_option('log') libnitrokey_args += ['-DNO_LOG'] @@ -34,6 +34,7 @@ libnitrokey = library( 'command_id.cc', 'device.cc', 'log.cc', + 'version.cc', 'misc.cc', 'NitrokeyManager.cc', 'NK_C_API.cc', @@ -50,23 +51,23 @@ libnitrokey = library( install : true, ) install_headers( - 'include/CommandFailedException.h', - 'include/command.h', - 'include/command_id.h', - 'include/cxx_semantics.h', - 'include/DeviceCommunicationExceptions.h', - 'include/device.h', - 'include/device_proto.h', - 'include/dissect.h', - 'include/inttypes.h', - 'include/LibraryException.h', - 'include/log.h', - 'include/LongOperationInProgressException.h', - 'include/misc.h', - 'include/NitrokeyManager.h', - 'include/stick10_commands_0.8.h', - 'include/stick10_commands.h', - 'include/stick20_commands.h', + '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(), ) @@ -110,12 +111,13 @@ 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', 'test.cc'], + ['test1', 'test1.cc'], ['test2', 'test2.cc'], ['test3', 'test3.cc'], ['test_HOTP', 'test_HOTP.cc'], -- cgit v1.2.3 From 9d8498765ccf188950ccf266ea1fb075a48628ac Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 18 Jul 2018 12:32:22 +0200 Subject: Mention build with meson in the Readme Signed-off-by: Szczepan Zalega --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) 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: -- cgit v1.2.3