mirror of
https://github.com/marzer/tomlplusplus.git
synced 2024-10-02 21:12:24 +00:00
build(meson): use system deps when avalable
When building tests, Meson will now look for system dependencies and use them if found. Otherwise, it will check if the submodules are cloned and create a dependency object wrapping the include path of each external dependency (this breaks Meson's sandbox, but the previous approach did too). This also allows passing actual dependencies to the various build targets instead of include paths (a bit more idiomatic). I've also made it possible to skip the tl-optional tests when the lib is not found, so that it is still possible to run tests even from a tarball (i.e. no git checkout)
This commit is contained in:
parent
7306fd2ae5
commit
36030cace8
3
.gitignore
vendored
3
.gitignore
vendored
@ -367,3 +367,6 @@ $RECYCLE.BIN/
|
||||
*.msm
|
||||
*.msp
|
||||
*.lnk
|
||||
|
||||
# Clangd cache
|
||||
/.cache/clangd
|
||||
|
@ -1,4 +1,5 @@
|
||||
example_args = []
|
||||
example_args += universal_args
|
||||
example_args += devel_args
|
||||
example_overrides = []
|
||||
example_overrides += overrides
|
||||
|
@ -4,6 +4,7 @@ project(
|
||||
version: '3.0.1',
|
||||
meson_version: '>=0.54.0',
|
||||
license: 'MIT',
|
||||
subproject_dir: 'external',
|
||||
default_options: [ # https://mesonbuild.com/Builtin-options.html
|
||||
# core options
|
||||
'buildtype=release',
|
||||
@ -42,7 +43,7 @@ is_windows = host_machine.system() == 'windows'
|
||||
is_x64 = host_machine.cpu_family() == 'x86_64'
|
||||
is_subproject = meson.is_subproject()
|
||||
has_exceptions = get_option('cpp_eh') != 'none'
|
||||
include_dirs = include_directories('include', 'external')
|
||||
include_dir = include_directories('include')
|
||||
overrides = []
|
||||
universal_args = [] # args used in tests, examples, lib, everything
|
||||
devel_args = [] # args used in everything *but* the lib
|
||||
@ -446,8 +447,6 @@ endif
|
||||
# subdirectories
|
||||
#######################################################################################################################
|
||||
|
||||
include_dir = include_directories('include')
|
||||
|
||||
# Empty dependency that will be filled either in src/ or include/
|
||||
tomlplusplus_dep = dependency('', required: false)
|
||||
|
||||
@ -459,8 +458,6 @@ endif
|
||||
|
||||
build_tests = get_option('build_tests') and not is_subproject
|
||||
if build_tests
|
||||
run_command('git', 'submodule', 'update', '--init', '--depth', '1', 'external/Catch2')
|
||||
run_command('git', 'submodule', 'update', '--init', '--depth', '1', 'external/tloptional')
|
||||
subdir('tests')
|
||||
endif
|
||||
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
#if __has_include(<Catch2/single_include/catch2/catch.hpp>)
|
||||
#include <Catch2/single_include/catch2/catch.hpp>
|
||||
#elif __has_include(<catch2/catch.hpp>)
|
||||
#include <catch2/catch.hpp>
|
||||
#else
|
||||
#error Catch2 is missing! You probably need to fetch submodules ("git submodule update --init --depth 1 external/Catch2")
|
||||
#endif
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#if __has_include(<tloptional/include/tl/optional.hpp>)
|
||||
#include <tloptional/include/tl/optional.hpp>
|
||||
#elif __has_include(<tl/optional.hpp>)
|
||||
#include <tl/optional.hpp>
|
||||
#else
|
||||
#error TartanLlama/optional is missing! You probably need to fetch submodules ("git submodule update --init --depth 1 external/tloptional")
|
||||
#endif
|
||||
|
@ -26,6 +26,33 @@ test_sources = [
|
||||
'windows_compat.cpp'
|
||||
]
|
||||
|
||||
test_deps = [tomlplusplus_dep]
|
||||
|
||||
fs = import('fs')
|
||||
|
||||
catch2_dep = dependency('catch2', required: false)
|
||||
if catch2_dep.found()
|
||||
test_deps += catch2_dep
|
||||
elif fs.exists('..'/'external'/'Catch2'/'single_include')
|
||||
catch2_dep = declare_dependency(include_directories: '..'/'external'/'Catch2'/'single_include')
|
||||
test_deps += catch2_dep
|
||||
else
|
||||
error('Catch2 is missing! You probably need to fetch submodules ("git submodule update --init --depth 1 external/Catch2"')
|
||||
endif
|
||||
|
||||
has_tl_optional = false
|
||||
tl_optional_dep = dependency('tl-optional', required: false)
|
||||
if tl_optional_dep.found()
|
||||
test_deps += tl_optional_dep
|
||||
has_tl_optional = true
|
||||
elif fs.exists('..'/'external'/'tloptional'/'include')
|
||||
tl_optional_dep = declare_dependency(include_directories: '..'/'external'/'tloptional'/'include')
|
||||
test_deps += tl_optional_dep
|
||||
has_tl_optional = true
|
||||
else
|
||||
warning('tl-optional not found, skipping its tests')
|
||||
endif
|
||||
|
||||
#######################################################################################################################
|
||||
# fast math check
|
||||
#######################################################################################################################
|
||||
@ -87,7 +114,7 @@ foreach cpp20 : cpp20_modes
|
||||
test_args += test_base_args
|
||||
|
||||
single_header = (counter % 2 == 1)
|
||||
tl_optional = (counter % 4 == 2 and exceptions and not get_option('compile_library'))
|
||||
tl_optional = (counter % 4 == 2 and exceptions and not get_option('compile_library') and has_tl_optional)
|
||||
address_sanitizer = (is_clang and not (single_header or tl_optional or fast_math)) and get_option('asan_tests')
|
||||
|
||||
if cpp20
|
||||
@ -161,9 +188,8 @@ foreach cpp20 : cpp20_modes
|
||||
executable(
|
||||
test_name,
|
||||
test_sources,
|
||||
include_directories: include_dirs,
|
||||
cpp_args: test_args,
|
||||
dependencies: tomlplusplus_dep,
|
||||
dependencies: test_deps,
|
||||
override_options: test_overrides
|
||||
)
|
||||
]]
|
||||
@ -203,7 +229,7 @@ endforeach
|
||||
executable(
|
||||
'odr_test',
|
||||
[ 'odr_test_1.cpp', 'odr_test_2.cpp' ],
|
||||
include_directories: include_dirs,
|
||||
cpp_args: test_base_args,
|
||||
dependencies: tomlplusplus_dep,
|
||||
override_options: overrides
|
||||
)
|
||||
|
@ -1,9 +1,14 @@
|
||||
tt_deps = [
|
||||
tomlplusplus_dep,
|
||||
dependency('nlohmann_json', fallback: ['json', 'nlohmann_json_dep'])
|
||||
]
|
||||
|
||||
if get_option('build_tt_encoder')
|
||||
executable(
|
||||
'tt_encoder',
|
||||
'tt_encoder.cpp',
|
||||
cpp_args: devel_args,
|
||||
include_directories: include_dirs
|
||||
dependencies: tt_deps
|
||||
)
|
||||
endif
|
||||
|
||||
@ -12,6 +17,6 @@ if get_option('build_tt_decoder')
|
||||
'tt_decoder',
|
||||
'tt_decoder.cpp',
|
||||
cpp_args: devel_args,
|
||||
include_directories: include_dirs
|
||||
dependencies: tt_deps
|
||||
)
|
||||
endif
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#if __has_include(<json/single_include/nlohmann/json.hpp>)
|
||||
#include <json/single_include/nlohmann/json.hpp>
|
||||
#elif __has_include(<nlohmann/json.hpp>)
|
||||
#include <nlohmann/json.hpp>
|
||||
#else
|
||||
#error nlohmann/json is missing! You probably need to fetch submodules ("git submodule update --init --depth 1 external/json")
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user