Skip to content

Commit

Permalink
Added a Meson option to control building of tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
isovic committed Mar 25, 2020
1 parent 532bafc commit 71e3fc8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ clean:

meson: modules
@echo "[Invoking Meson]"
@mkdir -p build-meson && cd build-meson && meson --buildtype=release -Dc_args=-O3 && ninja
@mkdir -p build-meson && cd build-meson && meson --buildtype=release -Dc_args=-O3 -Dtests=true && ninja

rebuild: modules
@echo "[Running Ninja only]"
Expand All @@ -19,7 +19,7 @@ cmake: modules

debug: modules
@echo "[Invoking Meson]"
@mkdir -p build-debug && cd build-debug && (meson --buildtype=debugoptimized -Db_sanitize=address) && ninja
@mkdir -p build-debug && cd build-debug && (meson --buildtype=debugoptimized -Db_sanitize=address -Dtests=true) && ninja

dist: release
cd build && ninja-dist
Expand Down
49 changes: 30 additions & 19 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ project(

cpp = meson.get_compiler('cpp')

opt_compile_with_tests = get_option('tests')

############
# CXXFLAGS #
############
Expand All @@ -29,16 +31,18 @@ racon_thread_dep = dependency('threads', required : true)
racon_zlib_dep = dependency('zlib', required: true, version : '>= 1.2.11', fallback : ['zlib', 'zlib_dep'])

# Google test.
gtest_dep = dependency('gtest', main : true, required : false)
if not gtest_dep.found()
gtest_proj = subproject('gtest')
gtest_inc = gtest_proj.get_variable('gtest_incdir')
gtest_lib = static_library('gtest', gtest_proj.get_variable('gtest_libsources'),
gtest_proj.get_variable('gtest_mainsources'),
include_directories : gtest_inc)

gtest_dep = declare_dependency(include_directories : gtest_inc,
link_with : gtest_lib, dependencies: racon_thread_dep)
if (not meson.is_subproject()) and opt_compile_with_tests
gtest_dep = dependency('gtest', main : true, required : false)
if not gtest_dep.found()
gtest_proj = subproject('gtest')
gtest_inc = gtest_proj.get_variable('gtest_incdir')
gtest_lib = static_library('gtest', gtest_proj.get_variable('gtest_libsources'),
gtest_proj.get_variable('gtest_mainsources'),
include_directories : gtest_inc)

gtest_dep = declare_dependency(include_directories : gtest_inc,
link_with : gtest_lib, dependencies: racon_thread_dep)
endif
endif

#######################
Expand Down Expand Up @@ -80,7 +84,11 @@ racon_include_directories = [include_directories('src'), include_directories('te

subdir('vendor')
subdir('src')
subdir('test')

if (not meson.is_subproject()) and opt_compile_with_tests
subdir('test')
endif


all_sources = racon_cpp_sources + vendor_cpp_sources

Expand Down Expand Up @@ -108,13 +116,16 @@ if not meson.is_subproject()
######################
# Tests #
######################
if gtest_dep.found()
tests_bin = executable(
'racon_test',
racon_test_cpp_sources,
dependencies : [racon_thread_dep, racon_zlib_dep, gtest_dep],
include_directories : racon_include_directories + vendor_include_directories + racon_test_include_directories,
link_with : [racon_lib, vendor_lib],
cpp_args : [racon_warning_flags, racon_cpp_flags, racon_test_extra_flags])
if opt_compile_with_tests
if gtest_dep.found()
tests_bin = executable(
'racon_test',
racon_test_cpp_sources,
dependencies : [racon_thread_dep, racon_zlib_dep, gtest_dep],
include_directories : racon_include_directories + vendor_include_directories + racon_test_include_directories,
link_with : [racon_lib, vendor_lib],
cpp_args : [racon_warning_flags, racon_cpp_flags, racon_test_extra_flags])
endif
endif

endif
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('tests', type : 'boolean', value : true, description : 'Enable dependencies required for testing')

0 comments on commit 71e3fc8

Please sign in to comment.