Skip to content

Commit 3ba2520

Browse files
authored
Merge pull request #47 from User-DK/main
ENH: Added subproject support(lib) to the meson.build and also added meson.options
2 parents 16a8d32 + 108ab85 commit 3ba2520

2 files changed

Lines changed: 72 additions & 30 deletions

File tree

meson.build

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ project('seldon', 'cpp',
22
version : '0.1',
33
default_options : ['warning_level=3', 'cpp_std=c++20', 'optimization=3'])
44

5-
add_global_arguments(['-Wno-unused-local-typedefs', '-Wno-array-bounds'], language : 'cpp')
5+
cppc = meson.get_compiler('cpp')
66

7-
incdir = include_directories('include')
7+
# Add C++ compiler options
8+
_incdir = [] # Include directories
9+
_deps = [] # Dependencies
10+
_args = [] # Extra arguments
11+
12+
13+
_incdir += include_directories('include')
14+
_deps += [dependency('fmt'), dependency('tomlplusplus')]
15+
_args += cppc.get_supported_arguments(['-Wno-unused-local-typedefs', '-Wno-array-bounds'])
816

917
sources_seldon = [
1018
'src/config_parser.cpp',
@@ -16,33 +24,65 @@ sources_seldon = [
1624
'src/util/tomlplusplus.cpp',
1725
]
1826

19-
exe = executable('seldon', sources_seldon + 'src/main.cpp',
20-
install : true,
21-
dependencies : [dependency('fmt'), dependency('tomlplusplus')],
22-
include_directories : incdir
23-
)
24-
25-
26-
tests = [
27-
['Test_Tarjan', 'test/test_tarjan.cpp'],
28-
['Test_DeGroot', 'test/test_deGroot.cpp'],
29-
['Test_Activity_Driven', 'test/test_activity.cpp'],
30-
['Test_Activity_Driven_Inertial', 'test/test_activity_inertial.cpp'],
31-
['Test_Deffuant', 'test/test_deffuant.cpp'],
32-
['Test_Network', 'test/test_network.cpp'],
33-
['Test_Network_Generation', 'test/test_network_generation.cpp'],
34-
['Test_Sampling', 'test/test_sampling.cpp'],
35-
['Test_IO', 'test/test_io.cpp'],
36-
['Test_Util', 'test/test_util.cpp'],
37-
['Test_Prob', 'test/test_probability_distributions.cpp'],
38-
]
27+
# both static and shared library for bindings
28+
# -----------------------------------
29+
30+
symbol_visibility = 'default'
31+
if get_option('default_library') == 'static'
32+
# from https://github.com/ERGO-Code/HiGHS/pull/1737/files
33+
symbol_visibility = 'inlineshidden'
34+
endif
35+
36+
seldon_lib = both_libraries('seldon',
37+
sources_seldon,
38+
install:true,
39+
dependencies: _deps,
40+
include_directories:_incdir,
41+
gnu_symbol_visibility: symbol_visibility,
42+
pic: true,
43+
cpp_args : _args,
44+
)
45+
46+
seldon_static_dep = declare_dependency(include_directories:_incdir,
47+
link_with : seldon_lib.get_static_lib(), dependencies: _deps)
48+
seldon_shared_dep = declare_dependency(include_directories : _incdir,
49+
link_with : seldon_lib.get_shared_lib(), dependencies: _deps)
50+
51+
# ------------------------------------
52+
53+
if get_option('build_exe')
54+
exe = executable('seldon', sources_seldon + 'src/main.cpp',
55+
install : true,
56+
dependencies : _deps,
57+
include_directories : _incdir,
58+
cpp_args : _args
59+
)
60+
endif
61+
62+
if get_option('build_tests')
63+
tests = [
64+
['Test_Tarjan', 'test/test_tarjan.cpp'],
65+
['Test_DeGroot', 'test/test_deGroot.cpp'],
66+
['Test_Activity_Driven', 'test/test_activity.cpp'],
67+
['Test_Activity_Driven_Inertial', 'test/test_activity_inertial.cpp'],
68+
['Test_Deffuant', 'test/test_deffuant.cpp'],
69+
['Test_Network', 'test/test_network.cpp'],
70+
['Test_Network_Generation', 'test/test_network_generation.cpp'],
71+
['Test_Sampling', 'test/test_sampling.cpp'],
72+
['Test_IO', 'test/test_io.cpp'],
73+
['Test_Util', 'test/test_util.cpp'],
74+
['Test_Prob', 'test/test_probability_distributions.cpp'],
75+
]
3976

40-
Catch2 = dependency('Catch2', method : 'cmake', modules : ['Catch2::Catch2WithMain', 'Catch2::Catch2'])
77+
Catch2 = dependency('Catch2', method : 'cmake', modules : ['Catch2::Catch2WithMain', 'Catch2::Catch2'])
78+
_deps+= Catch2
4179

42-
foreach t : tests
43-
exe = executable(t.get(0), sources_seldon + t.get(1),
44-
dependencies : [dependency('fmt'), dependency('tomlplusplus'), Catch2],
45-
include_directories : incdir
46-
)
47-
test(t.get(0), exe, workdir : meson.project_source_root())
48-
endforeach
80+
foreach t : tests
81+
exe = executable(t.get(0), sources_seldon + t.get(1),
82+
dependencies : _deps,
83+
include_directories : _incdir,
84+
cpp_args : _args
85+
)
86+
test(t.get(0), exe, workdir : meson.project_source_root())
87+
endforeach
88+
endif

meson.options

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
option('build_tests', type : 'boolean', value : true, description : 'Enable building of the tests')
2+
option('build_exe', type : 'boolean', value : true, description : 'Enable building of the executable')

0 commit comments

Comments
 (0)