Skip to content

Commit

Permalink
Merge pull request #47 from User-DK/main
Browse files Browse the repository at this point in the history
ENH: Added subproject support(lib) to the meson.build and also added meson.options
  • Loading branch information
HaoZeke authored Jun 29, 2024
2 parents 16a8d32 + 108ab85 commit 3ba2520
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 30 deletions.
100 changes: 70 additions & 30 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ project('seldon', 'cpp',
version : '0.1',
default_options : ['warning_level=3', 'cpp_std=c++20', 'optimization=3'])

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

incdir = include_directories('include')
# Add C++ compiler options
_incdir = [] # Include directories
_deps = [] # Dependencies
_args = [] # Extra arguments


_incdir += include_directories('include')
_deps += [dependency('fmt'), dependency('tomlplusplus')]
_args += cppc.get_supported_arguments(['-Wno-unused-local-typedefs', '-Wno-array-bounds'])

sources_seldon = [
'src/config_parser.cpp',
Expand All @@ -16,33 +24,65 @@ sources_seldon = [
'src/util/tomlplusplus.cpp',
]

exe = executable('seldon', sources_seldon + 'src/main.cpp',
install : true,
dependencies : [dependency('fmt'), dependency('tomlplusplus')],
include_directories : incdir
)


tests = [
['Test_Tarjan', 'test/test_tarjan.cpp'],
['Test_DeGroot', 'test/test_deGroot.cpp'],
['Test_Activity_Driven', 'test/test_activity.cpp'],
['Test_Activity_Driven_Inertial', 'test/test_activity_inertial.cpp'],
['Test_Deffuant', 'test/test_deffuant.cpp'],
['Test_Network', 'test/test_network.cpp'],
['Test_Network_Generation', 'test/test_network_generation.cpp'],
['Test_Sampling', 'test/test_sampling.cpp'],
['Test_IO', 'test/test_io.cpp'],
['Test_Util', 'test/test_util.cpp'],
['Test_Prob', 'test/test_probability_distributions.cpp'],
]
# both static and shared library for bindings
# -----------------------------------

symbol_visibility = 'default'
if get_option('default_library') == 'static'
# from https://github.com/ERGO-Code/HiGHS/pull/1737/files
symbol_visibility = 'inlineshidden'
endif

seldon_lib = both_libraries('seldon',
sources_seldon,
install:true,
dependencies: _deps,
include_directories:_incdir,
gnu_symbol_visibility: symbol_visibility,
pic: true,
cpp_args : _args,
)

seldon_static_dep = declare_dependency(include_directories:_incdir,
link_with : seldon_lib.get_static_lib(), dependencies: _deps)
seldon_shared_dep = declare_dependency(include_directories : _incdir,
link_with : seldon_lib.get_shared_lib(), dependencies: _deps)

# ------------------------------------

if get_option('build_exe')
exe = executable('seldon', sources_seldon + 'src/main.cpp',
install : true,
dependencies : _deps,
include_directories : _incdir,
cpp_args : _args
)
endif

if get_option('build_tests')
tests = [
['Test_Tarjan', 'test/test_tarjan.cpp'],
['Test_DeGroot', 'test/test_deGroot.cpp'],
['Test_Activity_Driven', 'test/test_activity.cpp'],
['Test_Activity_Driven_Inertial', 'test/test_activity_inertial.cpp'],
['Test_Deffuant', 'test/test_deffuant.cpp'],
['Test_Network', 'test/test_network.cpp'],
['Test_Network_Generation', 'test/test_network_generation.cpp'],
['Test_Sampling', 'test/test_sampling.cpp'],
['Test_IO', 'test/test_io.cpp'],
['Test_Util', 'test/test_util.cpp'],
['Test_Prob', 'test/test_probability_distributions.cpp'],
]

Catch2 = dependency('Catch2', method : 'cmake', modules : ['Catch2::Catch2WithMain', 'Catch2::Catch2'])
Catch2 = dependency('Catch2', method : 'cmake', modules : ['Catch2::Catch2WithMain', 'Catch2::Catch2'])
_deps+= Catch2

foreach t : tests
exe = executable(t.get(0), sources_seldon + t.get(1),
dependencies : [dependency('fmt'), dependency('tomlplusplus'), Catch2],
include_directories : incdir
)
test(t.get(0), exe, workdir : meson.project_source_root())
endforeach
foreach t : tests
exe = executable(t.get(0), sources_seldon + t.get(1),
dependencies : _deps,
include_directories : _incdir,
cpp_args : _args
)
test(t.get(0), exe, workdir : meson.project_source_root())
endforeach
endif
2 changes: 2 additions & 0 deletions meson.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
option('build_tests', type : 'boolean', value : true, description : 'Enable building of the tests')
option('build_exe', type : 'boolean', value : true, description : 'Enable building of the executable')

0 comments on commit 3ba2520

Please sign in to comment.