-
Notifications
You must be signed in to change notification settings - Fork 2
/
meson.build
528 lines (465 loc) · 11.9 KB
/
meson.build
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
project(
'demo_web_server',
'cpp',
version: '0.1',
default_options: ['warning_level=3', 'cpp_std=c++20'],
)
cpp_args = [
'-Wall',
'-Wextra',
'-Wpedantic',
'-Wshadow',
'-Wformat=2',
'-Wconversion',
'-Wnull-dereference',
'-Wsign-conversion',
'-D_FORTIFY_SOURCE=2',
'-D__STDC_LIMIT_MACROS',
'-std=c++20',
]
cpp_args_debug = [
cpp_args,
'-g3',
'-ggdb',
]
os = host_machine.system()
# change this to your own vcgpkg triplet
# more info: vcpkg help triplet
triplet = 'x64-linux'
if os == 'windows'
triplet = 'x64-mingw-static'
endif
src_root = 'src'
test_root = 'test'
# change to your vcpkg root
vcpkg_root = '/home/username/vcpkg'
if os == 'windows'
vcpkg_root = 'C:/Users/Administrator/projects/vcpkg'
endif
# vendor sources (htmx, bootstrap)
vendor_dir = 'vendor'
# gifs
videos_dir = 'videos'
# favicon
favicon_path = 'cpp_favicon.ico'
# config files
drogon_config = 'config.json'
server_config = 'server_config.json'
db_dir = src_root / 'database'
controllers_dir = src_root / 'controllers'
models_dir = src_root / 'models'
server_dir = src_root / 'server'
dtos_dir = src_root / 'dtos'
views_dir = src_root / 'views'
view_templates_dir = src_root / 'templates'
main_cpp = src_root / 'demo_web_server.cpp'
test_main_cpp = test_root / 'test_demo_web_server.cpp'
controllers_src = [
controllers_dir / 'home/home.cpp',
controllers_dir / 'contacts/contacts.cpp',
]
db_src = db_dir / 'db_mgr.cpp'
server_src = [server_dir / 'server_config.cpp']
dtos_src = [dtos_dir / 'contact_dto.cpp']
views_src = [
views_dir / 'contact.cc',
views_dir / 'contact_edit.cc',
views_dir / 'contact_new.cc',
views_dir / 'contacts.cc',
]
# ------------------------------
# For Windows compilations only
# ------------------------------
# put your local paths in here
drogon_root = 'C:/bin/drogon'
mingw_root = 'C:/bin/msys64/mingw64'
mingw_includes = join_paths(mingw_root, 'include')
drogon_includes = join_paths(drogon_root, 'include')
trantor_includes = join_paths(drogon_root, 'include')
project_includes = join_paths(meson.source_root(), 'include')
jsoncpp_includes = join_paths(mingw_root, 'include')
mingw_libs = join_paths(mingw_root, 'lib')
drogon_libs = join_paths(drogon_root, 'lib')
#--------------------------
# Criterion test framework
#--------------------------
# Windows notice:
# Build it locally with:
# > meson -Dprefix=c:/bin/criterion build
# > ninja -C build install
#
# macOs & Linux users can install it with:
# $ brew install criterion
criterion_root = '/usr/local/opt/criterion'
if os == 'windows'
criterion_root = 'C:/bin/criterion'
endif
if os == 'linux'
criterion_root = '/usr/include/criterion'
endif
criterion_includes = join_paths(criterion_root, 'include')
# A conditional when installing criterion with apt in Ubuntu
# dpkg -L libcriterion-dev finds where package is installed by default
if os == 'linux'
criterion_includes = '/usr/include/criterion'
endif
criterion_libs = join_paths(criterion_root, 'lib')
# A conditional when installing criterion with apt in Ubuntu
# dpkg -L libcriterion-dev finds where package is installed by default
if os == 'linux'
criterion_libs = '/usr/lib/x86_64-linux-gnu/'
endif
if os != 'windows'
drogon_root = '/usr/local/bin'
mingw_root = ''
mingw_includes = ''
drogon_includes = vcpkg_root / 'packages/drogon_' + triplet + '/include'
trantor_includes = vcpkg_root / 'packages/trantor_' + triplet + '/include'
jsoncpp_includes = vcpkg_root / 'packages/jsoncpp_' + triplet + '/include'
project_includes = ''
mingw_libs = ''
drogon_libs = vcpkg_root / 'packages/drogon_' + triplet + '/lib'
endif
# ------------------------------------------
# Generate Drogon views from CSP templates
# ------------------------------------------
# For every new CSP file you must add a new
# run_command, so that drogon_ctl can generate
# the corresponding C++ files.
drogon_ctl = find_program('drogon_ctl', dirs: [join_paths(drogon_root, 'bin')])
r = run_command(
drogon_ctl,
'create',
'view',
join_paths(
meson.source_root(),
view_templates_dir / 'contact.csp',
),
'-o',
join_paths(
meson.source_root(),
views_dir,
),
)
message('[Contact] ' + r.stdout().strip())
r = run_command(
drogon_ctl,
'create',
'view',
join_paths(
meson.source_root(),
view_templates_dir / 'contacts.csp',
),
'-o',
join_paths(
meson.source_root(),
views_dir,
),
)
message('[Contacts] ' + r.stdout().strip())
r = run_command(
drogon_ctl,
'create',
'view',
join_paths(
meson.source_root(),
view_templates_dir / 'contact_new.csp',
),
'-o',
join_paths(
meson.source_root(),
views_dir,
),
)
message('[ContactNew] ' + r.stdout().strip())
r = run_command(
drogon_ctl,
'create',
'view',
join_paths(
meson.source_root(),
view_templates_dir / 'contact_edit.csp',
),
'-o',
join_paths(
meson.source_root(),
views_dir,
),
)
message('[ContactEdit] ' + r.stdout().strip())
# sources
sources = [main_cpp]
sources += controllers_src
sources += db_src
sources += server_src
sources += views_src
sources += dtos_src
#--------------
# test sources
#--------------
# Include those sources that need to be tested.
# Alternatively, create multiple partial tests
# to keep binaries smaller.
test_sources = [test_main_cpp]
#test_sources += controllers_src
#test_sources += db_src
test_sources += server_src
#test_sources += views_src
#test_sources += dtos_src
# includes
incdir = include_directories(
[
project_includes,
db_dir,
server_dir,
models_dir,
views_dir,
dtos_dir,
drogon_includes,
mingw_includes,
trantor_includes,
jsoncpp_includes,
vcpkg_root / 'packages/argparse_' + triplet + '/include',
vcpkg_root / 'packages/fmt_' + triplet + '/include',
vcpkg_root / 'packages/sqlite3_' + triplet + '/include',
vcpkg_root / 'packages/soci_' + triplet + '/include',
],
)
test_incdir = [incdir, criterion_includes]
# find libraries
cpp = meson.get_compiler('cpp')
libdrogon = cpp.find_library(
'drogon',
dirs: [drogon_libs],
)
libtrantor_path = vcpkg_root / 'packages/trantor_' + triplet + '/lib'
if os == 'windows'
libtrantor_path = drogon_libs
endif
libtrantor = cpp.find_library(
'trantor',
dirs: [libtrantor_path],
)
libjsoncpp_path = vcpkg_root / 'packages/jsoncpp_' + triplet + '/lib'
if os == 'windows'
libjsoncpp_path = mingw_libs
endif
libjsoncpp = cpp.find_library(
'jsoncpp',
dirs: [libjsoncpp_path],
)
libopenssl_path = vcpkg_root / 'packages/openssl_' + triplet + '/lib'
if os == 'windows'
libopenssl_path = mingw_libs
endif
libopenssl = cpp.find_library(
'ssl',
dirs: [libopenssl_path],
)
libcrypto_path = vcpkg_root / 'packages/openssl_' + triplet + '/lib'
if os == 'windows'
libcrypto_path = mingw_libs
endif
libcrypto = cpp.find_library(
'crypto',
dirs: [libcrypto_path],
)
brotlicommon_static_name = 'brotlicommon-static'
if os == 'windows'
brotlicommon_static_name = 'brotlicommon'
endif
brotlicommon_path = vcpkg_root / 'packages/brotli_' + triplet + '/lib/'
if os == 'windows'
brotlicommon_path = mingw_libs
endif
libbrotli_common = cpp.find_library(
brotlicommon_static_name,
dirs: [brotlicommon_path],
)
brotlienc_static_name = 'brotlienc-static'
if os == 'windows'
brotlienc_static_name = 'brotlienc'
endif
brotlienc_path = vcpkg_root / 'packages/brotli_' + triplet + '/lib/'
if os == 'windows'
brotlienc_path = mingw_libs
endif
libbrotli_enc = cpp.find_library(
brotlienc_static_name,
dirs: [brotlienc_path],
)
brotlidec_static_name = 'brotlidec-static'
if os == 'windows'
brotlidec_static_name = 'brotlidec'
endif
brotlidec_path = vcpkg_root / 'packages/brotli_' + triplet + '/lib/'
if os == 'windows'
brotlidec_path = mingw_libs
endif
libbrotli_dec = cpp.find_library(
brotlidec_static_name,
dirs: [brotlidec_path],
)
cares_path = vcpkg_root / 'packages/c-ares_' + triplet + '/lib'
if os == 'windows'
cares_path = mingw_libs
endif
libcares = cpp.find_library(
'cares',
dirs: [cares_path],
)
zlib_name = 'z'
zlib_path = vcpkg_root / 'packages/zlib_' + triplet + '/lib'
if os == 'windows'
zlib_path = mingw_libs
endif
libz = cpp.find_library(
zlib_name,
dirs: [zlib_path],
)
libfmt = cpp.find_library(
'fmt',
dirs: [vcpkg_root / 'packages/fmt_' + triplet + '/lib'],
)
libsqlite3 = cpp.find_library(
'sqlite3',
dirs: [vcpkg_root / 'packages/sqlite3_' + triplet + '/lib'],
)
soci_core_name = 'soci_core'
if os == 'windows'
soci_core_name = 'soci_core_4_0'
endif
libsoci_core = cpp.find_library(
soci_core_name,
dirs: [vcpkg_root / 'packages/soci_' + triplet + '/lib'],
)
soci_sqlite3_name = 'soci_sqlite3'
if os == 'windows'
soci_sqlite3_name = 'soci_sqlite3_4_0'
endif
libsoci_sqlite3 = cpp.find_library(
soci_sqlite3_name,
dirs: [vcpkg_root / 'packages/soci_' + triplet + '/lib'],
)
libresolv = ''
if os != 'windows'
libresolv = cpp.find_library('resolv')
endif
librpcrt4 = ''
if os == 'windows'
librpcrt4 = cpp.find_library('rpcrt4', dirs: [mingw_libs])
endif
libcrypt32 = ''
if os == 'windows'
libcrypt32 = cpp.find_library('crypt32', dirs: [mingw_libs])
endif
# Criterion test library
libcriterion_name = 'criterion'
libcriterion = cpp.find_library(
libcriterion_name,
dirs: [criterion_libs],
)
# Will be done only in POSIX systems. On Windows, the files will be
# copied by the powershell script itself.
if os != 'windows'
copy = find_program('cp')
# copy index.html to build directory
run_command(
copy,
join_paths(meson.source_root(), 'index.html'),
join_paths(meson.build_root(), 'index.html'),
)
# copy styles.css to build directory
run_command(
copy,
join_paths(meson.source_root(), 'styles.css'),
join_paths(meson.build_root(), 'styles.css'),
)
# copy vendor sources to build directory
run_command(
copy,
'-r',
join_paths(meson.source_root(), vendor_dir),
join_paths(meson.build_root(), vendor_dir),
)
# copy gifs to build directory
run_command(
copy,
'-r',
join_paths(meson.source_root(), videos_dir),
join_paths(meson.build_root(), videos_dir),
)
# copy favicon to build directory
run_command(
copy,
'-r',
join_paths(meson.source_root(), favicon_path),
join_paths(meson.build_root(), favicon_path),
)
# copy Drogon's config.json to build directory
run_command(
copy,
'-r',
join_paths(meson.source_root(), drogon_config),
join_paths(meson.build_root(), drogon_config),
)
# copy server_config.json to build directory
run_command(
copy,
'-r',
join_paths(meson.source_root(), server_config),
join_paths(meson.build_root(), server_config),
)
endif
deps = [
libdrogon,
libtrantor,
libjsoncpp,
libopenssl,
libcrypto,
libbrotli_common,
libbrotli_enc,
libbrotli_dec,
libcares,
libz,
libfmt,
libsqlite3,
libsoci_core,
libsoci_sqlite3,
]
if os == 'windows'
deps += [
librpcrt4,
libcrypt32,
]
endif
if os != 'windows'
deps += libresolv
endif
link_args = ''
if os == 'windows'
link_args = ['-lws2_32', '-lssl', '-lcrypto', '-lrpcrt4', '-lcrypt32']
endif
if os == 'linux'
link_args = ['-luuid']
endif
executable(
'demo_web_server',
sources,
cpp_args: cpp_args,
link_args: link_args,
install: true,
include_directories: incdir,
dependencies: deps,
)
test_deps = [deps, libcriterion]
test_exe = executable(
'test_demo_web_server',
test_sources,
cpp_args: cpp_args_debug,
link_args: link_args,
install: true,
include_directories: test_incdir,
dependencies: test_deps,
)
test('basic', test_exe)