From 27816dbbd168a84a0a7a252d7d75b0ca4dc1e073 Mon Sep 17 00:00:00 2001 From: Mark Gillard Date: Sun, 1 May 2022 15:09:09 +0300 Subject: [PATCH] added meson option `use_vendored_libs` --- CONTRIBUTING.md | 7 +++++-- meson_options.txt | 1 + tests/lib_catch2.h | 8 ++++++++ tests/meson.build | 11 ++++++++--- toml-test/README.md | 3 +++ toml-test/meson.build | 17 ++++++++++++----- toml-test/tt.h | 11 ++++++++++- vendor/README.md | 5 ++--- 8 files changed, 49 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b33f712..67c7f1b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,7 +21,7 @@ If you wish to submit a PR, please be aware that:
## Building and running the tests -Testing is done using [Catch2], vendored in the respository at `vendor/catch.hpp`. +Testing is done using [Catch2]. ### Testing on Windows with Visual Studio @@ -60,9 +60,12 @@ cd build-gcc-debug && ninja && ninja test \ && cd .. ``` -> ℹ️ Note: To ensure parity between single-header and regular versions of the library, 50% of the tests +> ℹ️ To ensure parity between single-header and regular versions of the library, 50% of the tests will be compiled using one, and 50% with the other. Ensure you've regenerated toml.hpp before running tests. +> ℹ️ Pass `-Duse_vendored_libs=false` to meson if you wish to use the system-installed version +of Catch2 rather than the vendored one. +
## Testing with the [toml-test] suite diff --git a/meson_options.txt b/meson_options.txt index db4d088..885040c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -10,3 +10,4 @@ option('ubsan_tests', type: 'boolean', value: false) option('build_tt_encoder', type: 'boolean', value: false, description: 'Enable to build the toml-test encoder.') option('build_tt_decoder', type: 'boolean', value: false, description: 'Enable to build the toml-test decoder.') option('compile_library', type: 'boolean', value: false, description: 'Compile as a library') +option('use_vendored_libs', type: 'boolean', value: true, description: 'Use the libs from the vendor dir when building tests.') diff --git a/tests/lib_catch2.h b/tests/lib_catch2.h index e70283a..9a04913 100644 --- a/tests/lib_catch2.h +++ b/tests/lib_catch2.h @@ -22,7 +22,15 @@ #pragma warning(disable : 5105) #endif +#if !defined(USE_VENDORED_LIBS) || USE_VENDORED_LIBS #include "../vendor/catch.hpp" +#elif __has_include() +#include +#elif __has_include() +#include +#else +#error Catch2 is missing! +#endif #ifdef __clang__ #pragma clang diagnostic pop diff --git a/tests/meson.build b/tests/meson.build index 3278fe0..a3f7d23 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -29,9 +29,10 @@ test_sources = [ 'windows_compat.cpp' ] -test_deps = [tomlplusplus_dep] - -fs = import('fs') +test_deps = [ tomlplusplus_dep ] +if not get_option('use_vendored_libs') + test_deps += dependency('catch2') +endif ####################################################################################################################### # fast math check @@ -210,6 +211,10 @@ foreach cpp20 : cpp20_modes test_args += '-DUSE_SINGLE_HEADER=1' endif + if not get_option('use_vendored_libs') + test_args += '-DUSE_VENDORED_LIBS=0' + endif + test_executables += [[ test_name, executable( diff --git a/toml-test/README.md b/toml-test/README.md index d2247d5..9c399ef 100644 --- a/toml-test/README.md +++ b/toml-test/README.md @@ -38,6 +38,9 @@ cd build_tt ninja && toml-test ./toml-test/tt_decoder && toml-test ./toml-test/tt_encoder --encoder ``` +> ℹ️ Pass `-Duse_vendored_libs=false` to meson if you wish to use the system-installed version +of nlohmann/json rather than the vendored one. + [toml-test]: https://github.com/BurntSushi/toml-test diff --git a/toml-test/meson.build b/toml-test/meson.build index 4e79e4d..8979e26 100644 --- a/toml-test/meson.build +++ b/toml-test/meson.build @@ -1,12 +1,19 @@ -tt_deps = [ - tomlplusplus_dep -] +tt_deps = [ tomlplusplus_dep ] +if not get_option('use_vendored_libs') + tt_deps += dependency('nlohmann_json', fallback: ['json', 'nlohmann_json_dep']) +endif + +tt_args = [] +tt_args += devel_args +if not get_option('use_vendored_libs') + tt_args += '-DUSE_VENDORED_LIBS=0' +endif if get_option('build_tt_encoder') executable( 'tt_encoder', 'tt_encoder.cpp', - cpp_args: devel_args, + cpp_args: tt_args, dependencies: tt_deps ) endif @@ -15,7 +22,7 @@ if get_option('build_tt_decoder') executable( 'tt_decoder', 'tt_decoder.cpp', - cpp_args: devel_args, + cpp_args: tt_args, dependencies: tt_deps ) endif diff --git a/toml-test/tt.h b/toml-test/tt.h index c7a0cee..58596cc 100644 --- a/toml-test/tt.h +++ b/toml-test/tt.h @@ -15,8 +15,17 @@ #pragma warning(push, 0) #endif -#define JSON_HAS_FILESYSTEM 0 +#define JSON_HAS_FILESYSTEM 0 +#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0 +#if !defined(USE_VENDORED_LIBS) || USE_VENDORED_LIBS #include "../vendor/json.hpp" +#elif __has_include() +#include +#elif __has_include() +#include +#else +#error nlohmann/json is missing! +#endif #include #include diff --git a/vendor/README.md b/vendor/README.md index a38255e..7576fb3 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -2,7 +2,6 @@ The code files in this directory are third-party 'vendor' dependencies used by the various test applications. -⚠️ They are **not** required for regular use of toml++. ⚠️ - -⚠️ They are not **not** `#included` anywhere in toml++. ⚠️ +⚠️ They are **not** required for regular use of toml++. +⚠️ They are **not** `#included` anywhere in toml++.