1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
project(
'libnitrokey', 'cpp',
version : '3.5.0',
license : 'LGPL-3.0+',
default_options : [
'cpp_std=c++14'
],
meson_version : '>= 0.44.0',
)
cxx = meson.get_compiler('cpp')
host_system = host_machine.system()
pkg = import('pkgconfig')
common_flags = [
'-Wno-unused-function',
'-Wcast-qual',
]
test_cxxflags = common_flags + [
'-Woverloaded-virtual',
]
test_cflags = common_flags
add_project_arguments(cxx.get_supported_arguments(test_cxxflags), language : 'cpp')
if get_option('offline-tests')
add_languages('c', required: get_option('offline-tests'))
c = meson.get_compiler('c')
add_project_arguments(c.get_supported_arguments(test_cflags), language : 'c')
endif
if target_machine.system() == 'freebsd'
dep_hidapi = dependency('hidapi')
else
dep_hidapi = dependency('hidapi-libusb')
endif
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
version_array = meson.project_version().split('.')
version_major = version_array[0].to_int()
version_minor = version_array[1].to_int()
version_data = configuration_data()
version_data.set('PROJECT_VERSION_MAJOR', version_major)
version_data.set('PROJECT_VERSION_MINOR', version_minor)
# We don't want to substitute it by noop
version_data.set('PROJECT_VERSION_GIT', '@VCS_TAG@')
version_cc_in = configure_file(
input : 'version.cc.in',
output : 'version.cc.in',
configuration : version_data,
)
version_cc = vcs_tag(
input : version_cc_in,
output : 'version.cc',
fallback : 'v@0@'.format(meson.project_version()),
)
libnitrokey = library(
'nitrokey',
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,
)
if meson.version().version_compare('>= 0.48.0')
dep_hidapi_name = dep_hidapi.name()
else
if target_machine.system() == 'freebsd'
dep_hidapi_name = 'hidapi'
else
dep_hidapi_name = 'hidapi-libusb'
endif
endif
pkg.generate(
name : meson.project_name(),
filebase : 'libnitrokey-1',
libraries : libnitrokey,
version : meson.project_version(),
requires_private : dep_hidapi_name,
description : 'Library for communicating with Nitrokey in a clean and easy manner',
install : true,
)
if target_machine.system() == 'freebsd'
dep_udev = dependency('libudev')
else
dep_udev = dependency('udev')
endif
install_data(
'data/41-nitrokey.rules',
install_dir : '@0@/rules.d'.format(dep_udev.get_pkgconfig_variable('udevdir')),
)
if get_option('tests') or get_option('offline-tests')
dep_catch = dependency('catch2', version : '>=2.3.0', required : false)
if not dep_catch.found()
dep_catch = declare_dependency(
include_directories : include_directories('unittest/Catch/single_include')
)
endif
_catch = static_library(
'catch',
sources : [
'unittest/catch_main.cpp',
],
dependencies : [
dep_catch,
],
)
_dep_catch = declare_dependency(
link_with : _catch,
dependencies : dep_catch,
)
endif
tests = []
if get_option('offline-tests')
tests += [
['test_offline', 'test_offline.cc'],
['test_minimal', 'test_minimal.c'],
]
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_memory', 'test_memory.c'],
['test_issues', 'test_issues.cc'],
['test_multiple_devices', 'test_multiple_devices.cc'],
['test_strdup', 'test_strdup.cpp'],
['test_safe', 'test_safe.cpp'],
]
endif
foreach tst : tests
test(
tst[0],
executable(
tst[0],
sources : 'unittest/@0@'.format(tst[1]),
dependencies : [
ext_libnitrokey,
_dep_catch,
],
)
)
endforeach
|