From 304dc47761b94e02be45842935aae317d01a6098 Mon Sep 17 00:00:00 2001 From: Daivik Date: Sat, 8 Jun 2024 12:17:15 +0530 Subject: [PATCH 1/3] major changes in the meson.build and added meson.options --- meson.build | 86 ++++++++++++++++++++++++++++++++++----------------- meson.options | 2 ++ 2 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 meson.options diff --git a/meson.build b/meson.build index c9fd40d..7a8c33c 100644 --- a/meson.build +++ b/meson.build @@ -2,9 +2,12 @@ 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') +deps = [] +cpp_args = ['-Wno-unused-local-typedefs', '-Wno-array-bounds'] +# add_global_arguments(['-Wno-unused-local-typedefs', '-Wno-array-bounds'], language : 'cpp') incdir = include_directories('include') +deps += [dependency('fmt'), dependency('tomlplusplus')] sources_seldon = [ 'src/config_parser.cpp', @@ -16,33 +19,58 @@ 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'], -] +# Static library for bindings +# ----------------------------------- +symbol_visibility = 'default' + +# only generating static library +seldon_lib = static_library('seldon', + sources_seldon, + install:true, + dependencies: deps, + include_directories:incdir, + gnu_symbol_visibility: symbol_visibility, + pic: true, + cpp_args : cpp_args, +) + +seldon_static_dep = declare_dependency(include_directories:incdir, + link_with : seldon_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 : cpp_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 \ No newline at end of file + foreach t : tests + exe = executable(t.get(0), sources_seldon + t.get(1), + dependencies : deps, + include_directories : incdir, + cpp_args : cpp_args + ) + test(t.get(0), exe, workdir : meson.project_source_root()) + endforeach +endif \ No newline at end of file diff --git a/meson.options b/meson.options new file mode 100644 index 0000000..da5c000 --- /dev/null +++ b/meson.options @@ -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') \ No newline at end of file From 26125af84228de402c29edab3e0af9e7e68cfe28 Mon Sep 17 00:00:00 2001 From: Daivik Date: Wed, 19 Jun 2024 17:45:15 +0530 Subject: [PATCH 2/3] ENH:Add subproject lib to the meson build along with meson options --- meson.build | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index 7a8c33c..c230af2 100644 --- a/meson.build +++ b/meson.build @@ -4,7 +4,6 @@ project('seldon', 'cpp', deps = [] cpp_args = ['-Wno-unused-local-typedefs', '-Wno-array-bounds'] -# add_global_arguments(['-Wno-unused-local-typedefs', '-Wno-array-bounds'], language : 'cpp') incdir = include_directories('include') deps += [dependency('fmt'), dependency('tomlplusplus')] @@ -19,12 +18,16 @@ sources_seldon = [ 'src/util/tomlplusplus.cpp', ] -# Static library for bindings +# both static and shared library for bindings # ----------------------------------- -symbol_visibility = 'default' +symbol_visibility = 'default' +if get_option('default_library') == 'static' + # from https://github.com/ERGO-Code/HiGHS/pull/1737/files + symbol_visibility = 'inlineshidden' +endif -# only generating static library -seldon_lib = static_library('seldon', +# both libraries +seldon_lib = both_libraries('seldon', sources_seldon, install:true, dependencies: deps, @@ -35,7 +38,9 @@ seldon_lib = static_library('seldon', ) seldon_static_dep = declare_dependency(include_directories:incdir, - link_with : seldon_lib, dependencies: deps) + 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') From 108ab8586041c3094d4ee6fe4cdf2a10f3114fb7 Mon Sep 17 00:00:00 2001 From: Daivik Date: Thu, 20 Jun 2024 11:18:55 +0530 Subject: [PATCH 3/3] ENH: Added _(underscore) before scoping variables and added compiler arguments in _args list --- meson.build | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/meson.build b/meson.build index c230af2..4de3421 100644 --- a/meson.build +++ b/meson.build @@ -2,11 +2,17 @@ project('seldon', 'cpp', version : '0.1', default_options : ['warning_level=3', 'cpp_std=c++20', 'optimization=3']) -deps = [] -cpp_args = ['-Wno-unused-local-typedefs', '-Wno-array-bounds'] +cppc = meson.get_compiler('cpp') -incdir = include_directories('include') -deps += [dependency('fmt'), dependency('tomlplusplus')] +# 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', @@ -20,35 +26,36 @@ sources_seldon = [ # 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 -# both libraries seldon_lib = both_libraries('seldon', sources_seldon, install:true, - dependencies: deps, - include_directories:incdir, + dependencies: _deps, + include_directories:_incdir, gnu_symbol_visibility: symbol_visibility, pic: true, - cpp_args : cpp_args, + 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) +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 : cpp_args + dependencies : _deps, + include_directories : _incdir, + cpp_args : _args ) endif @@ -68,13 +75,13 @@ if get_option('build_tests') ] Catch2 = dependency('Catch2', method : 'cmake', modules : ['Catch2::Catch2WithMain', 'Catch2::Catch2']) - deps+= Catch2 + _deps+= Catch2 foreach t : tests exe = executable(t.get(0), sources_seldon + t.get(1), - dependencies : deps, - include_directories : incdir, - cpp_args : cpp_args + dependencies : _deps, + include_directories : _incdir, + cpp_args : _args ) test(t.get(0), exe, workdir : meson.project_source_root()) endforeach