build(meson): add compile_library option

This commit is contained in:
Andrea Pappacoda 2022-02-12 14:25:20 +01:00 committed by Mark Gillard
parent 5e6008329f
commit 029160c280
27 changed files with 529 additions and 685 deletions

View File

@ -228,7 +228,7 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[
- **[@sneves](https://github.com/sneves)** - Helped fix a number of parser bugs - **[@sneves](https://github.com/sneves)** - Helped fix a number of parser bugs
- **[@sobczyk](https://github.com/sobczyk)** - Reported some bugs - **[@sobczyk](https://github.com/sobczyk)** - Reported some bugs
- **[@std-any-emplace](https://github.com/std-any-emplace)** - Reported some bugs - **[@std-any-emplace](https://github.com/std-any-emplace)** - Reported some bugs
- **[@Tachi107](https://github.com/Tachi107)** - Made some tweaks to meson.build - **[@Tachi107](https://github.com/Tachi107)** - Made some tweaks to meson.build, added compile_library build option
- **[@traversaro](https://github.com/traversaro)** - Added vcpkg support and reported a bunch of bugs - **[@traversaro](https://github.com/traversaro)** - Added vcpkg support and reported a bunch of bugs
- **[@whiterabbit963](https://github.com/whiterabbit963)** - Fixed a bug with value_or conversions - **[@whiterabbit963](https://github.com/whiterabbit963)** - Fixed a bug with value_or conversions
- **[@ximion](https://github.com/ximion)** - Added support for installation with meson - **[@ximion](https://github.com/ximion)** - Added support for installation with meson

View File

@ -1,14 +0,0 @@
@PACKAGE_INIT@
# If tomlplusplus::tomlplusplus target is not defined it will be included
if(NOT TARGET tomlplusplus::tomlplusplus)
# Import tomlplusplus interface library
add_library(tomlplusplus::tomlplusplus INTERFACE IMPORTED)
set_target_properties(tomlplusplus::tomlplusplus PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/@includedir@")
# Require C++17
target_compile_features(tomlplusplus::tomlplusplus INTERFACE cxx_std_17)
endif()

View File

@ -0,0 +1,29 @@
@PACKAGE_INIT@
# If tomlplusplus::tomlplusplus target is not defined it will be included
if(NOT TARGET tomlplusplus::tomlplusplus)
if (@compile_library@)
set(imported_type UNKNOWN)
else()
set(imported_type INTERFACE)
endif()
# Import tomlplusplus interface library
add_library(tomlplusplus::tomlplusplus ${imported_type} IMPORTED)
set_target_properties(tomlplusplus::tomlplusplus PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/@includedir@")
# Require C++17
target_compile_features(tomlplusplus::tomlplusplus INTERFACE cxx_std_17)
# Set the path to the installed library so that users can link to it
if (@compile_library@)
set_target_properties(tomlplusplus::tomlplusplus PROPERTIES
IMPORTED_LOCATION "${PACKAGE_PREFIX_DIR}/@libdir@/@lib_name@"
)
# compile_options not quoted on purpose
target_compile_options(tomlplusplus::tomlplusplus INTERFACE @compile_options@)
endif()
endif()

View File

@ -7,9 +7,6 @@
// failures and printing their results. // failures and printing their results.
#include "examples.h" #include "examples.h"
#define TOML_EXCEPTIONS 0
#define TOML_ENABLE_UNRELEASED_FEATURES 0
#include <toml++/toml.h> #include <toml++/toml.h>
using namespace std::string_view_literals; using namespace std::string_view_literals;
@ -110,6 +107,24 @@ namespace
int main() int main()
{ {
const auto parse_and_print_if_error = [](std::string_view str)
{
#if TOML_EXCEPTIONS
try
{
auto result = toml::parse(str);
static_cast<void>(result);
}
catch (const toml::parse_error& err)
{
std::cout << err << "\n\n"sv;
}
#else
if (auto result = toml::parse(str); !result)
std::cout << result.error() << "\n\n"sv;
#endif
};
for (auto str : invalid_parses) for (auto str : invalid_parses)
{ {
if (str.empty()) if (str.empty())
@ -133,13 +148,10 @@ int main()
std::string s(1000u, '['); std::string s(1000u, '[');
constexpr auto start = "array = "sv; constexpr auto start = "array = "sv;
memcpy(s.data(), start.data(), start.length()); memcpy(s.data(), start.data(), start.length());
result = toml::parse(s); parse_and_print_if_error(s);
} }
else else
result = toml::parse(str); parse_and_print_if_error(str);
if (!result)
std::cout << result.error() << "\n\n"sv;
} }
} }
return 0; return 0;

View File

@ -25,6 +25,7 @@
#include <vector> #include <vector>
#include <array> #include <array>
#include <chrono> #include <chrono>
#include <fstream>
#ifdef _WIN32 #ifdef _WIN32
#ifdef _MSC_VER #ifdef _MSC_VER
extern "C" __declspec(dllimport) int __stdcall SetConsoleOutputCP(unsigned int); extern "C" __declspec(dllimport) int __stdcall SetConsoleOutputCP(unsigned int);

View File

@ -1,5 +1,5 @@
example_args = [] example_args = []
example_args += additional_arguments example_args += devel_args
example_overrides = [] example_overrides = []
example_overrides += overrides example_overrides += overrides
if is_gcc or is_clang if is_gcc or is_clang
@ -25,8 +25,8 @@ foreach example : examples
executable( executable(
example, example,
[ example+'.cpp' ], [ example+'.cpp' ],
include_directories: include_dirs,
cpp_args: example_args, cpp_args: example_args,
dependencies: tomlplusplus_dep,
override_options: example_overrides override_options: example_overrides
) )
]] ]]

View File

@ -6,8 +6,6 @@
// This example demonstrates how to parse TOML from a file or stdin and re-serialize it (print it out) to stdout. // This example demonstrates how to parse TOML from a file or stdin and re-serialize it (print it out) to stdout.
#include "examples.h" #include "examples.h"
#define TOML_ENABLE_UNRELEASED_FEATURES 1
#include <toml++/toml.h> #include <toml++/toml.h>
using namespace std::string_view_literals; using namespace std::string_view_literals;

View File

@ -6,8 +6,6 @@
// This example demonstrates the use of some more advanced features to generate a tree of random TOML data. // This example demonstrates the use of some more advanced features to generate a tree of random TOML data.
#include "examples.h" #include "examples.h"
#define TOML_ENABLE_PARSER 0
#include <toml++/toml.h> #include <toml++/toml.h>
using namespace std::string_view_literals; using namespace std::string_view_literals;

View File

@ -6,8 +6,6 @@
// This example demonstrates how to use the toml::json_formatter to re-serialize TOML data as JSON. // This example demonstrates how to use the toml::json_formatter to re-serialize TOML data as JSON.
#include "examples.h" #include "examples.h"
#define TOML_ENABLE_UNRELEASED_FEATURES 1
#include <toml++/toml.h> #include <toml++/toml.h>
using namespace std::string_view_literals; using namespace std::string_view_literals;

39
include/meson.build Normal file
View File

@ -0,0 +1,39 @@
# Header-only
tomlplusplus_dep = declare_dependency(include_directories: include_dir)
if not is_subproject
import('pkgconfig').generate(
name: meson.project_name(),
description: 'Header-only TOML config file parser and serializer for C++',
install_dir: get_option('datadir')/'pkgconfig',
url: 'https://marzer.github.io/tomlplusplus'
)
endif
# cmake
if get_option('generate_cmake_config') and not is_subproject
cmake = import('cmake')
# Can't use until Meson 0.62.0, see https://github.com/mesonbuild/meson/pull/9916
# and https://github.com/marzer/tomlplusplus/issues/140
#cmake.write_basic_package_version_file(
# name: meson.project_name(),
# version: meson.project_version(),
# install_dir: get_option('datadir')/'cmake'/meson.project_name(),
# arch_independent: true
#)
# In the meantime, install a pre-generated Package Version file
configure_file(
configuration: {'version': meson.project_version()},
input: '..'/'cmake'/'tomlplusplusConfigVersion.cmake.meson.in',
output: 'tomlplusplusConfigVersion.cmake',
install_dir: get_option('datadir')/'cmake'/meson.project_name()
)
cmake.configure_package_config_file(
name: meson.project_name(),
input: '..'/'cmake'/'tomlplusplusConfig.cmake.meson.in',
configuration: configuration_data({'includedir': get_option('includedir')}),
install_dir: get_option('datadir')/'cmake'/meson.project_name(),
)
endif

View File

@ -88,6 +88,7 @@
_Pragma("clang diagnostic ignored \"-Wchar-subscripts\"") \ _Pragma("clang diagnostic ignored \"-Wchar-subscripts\"") \
_Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") \ _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") \
_Pragma("clang diagnostic ignored \"-Wpadded\"") \ _Pragma("clang diagnostic ignored \"-Wpadded\"") \
_Pragma("clang diagnostic ignored \"-Wsuggest-destructor-override\"") \
static_assert(true) static_assert(true)
#define TOML_POP_WARNINGS \ #define TOML_POP_WARNINGS \
@ -366,6 +367,11 @@
#ifdef TOML_CONFIG_HEADER #ifdef TOML_CONFIG_HEADER
#include TOML_CONFIG_HEADER #include TOML_CONFIG_HEADER
#endif #endif
// is the library being built as a shared lib/dll using meson and friends?
#ifndef TOML_SHARED_LIB
#define TOML_SHARED_LIB 0
#endif
// header-only mode // header-only mode
#if !defined(TOML_HEADER_ONLY) && defined(TOML_ALL_INLINE) // was TOML_ALL_INLINE pre-2.0 #if !defined(TOML_HEADER_ONLY) && defined(TOML_ALL_INLINE) // was TOML_ALL_INLINE pre-2.0
@ -375,7 +381,7 @@
#undef TOML_HEADER_ONLY #undef TOML_HEADER_ONLY
#define TOML_HEADER_ONLY 1 #define TOML_HEADER_ONLY 1
#endif #endif
#ifdef DOXYGEN #if defined(DOXYGEN) || TOML_SHARED_LIB
#undef TOML_HEADER_ONLY #undef TOML_HEADER_ONLY
#define TOML_HEADER_ONLY 0 #define TOML_HEADER_ONLY 0
#endif #endif
@ -398,6 +404,28 @@
#define TOML_EXPORTED_FREE_FUNCTION TOML_API #define TOML_EXPORTED_FREE_FUNCTION TOML_API
#endif #endif
// dll/shared lib exports
#if TOML_SHARED_LIB
#undef TOML_API
#undef TOML_EXPORTED_CLASS
#undef TOML_EXPORTED_MEMBER_FUNCTION
#undef TOML_EXPORTED_STATIC_FUNCTION
#undef TOML_EXPORTED_FREE_FUNCTION
#if defined(_WIN32) || defined(__CYGWIN__)
#if TOML_IMPLEMENTATION
#define TOML_EXPORTED_CLASS __declspec(dllexport)
#define TOML_EXPORTED_FREE_FUNCTION __declspec(dllexport)
#else
#define TOML_EXPORTED_CLASS __declspec(dllimport)
#define TOML_EXPORTED_FREE_FUNCTION __declspec(dllimport)
#endif
#elif defined(__GNUC__) && __GNUC__ >= 4
#define TOML_EXPORTED_CLASS __attribute__((visibility("default")))
#define TOML_EXPORTED_MEMBER_FUNCTION __attribute__((visibility("default")))
#define TOML_EXPORTED_STATIC_FUNCTION __attribute__((visibility("default")))
#define TOML_EXPORTED_FREE_FUNCTION __attribute__((visibility("default")))
#endif
#endif
#ifndef TOML_EXPORTED_CLASS #ifndef TOML_EXPORTED_CLASS
#define TOML_EXPORTED_CLASS #define TOML_EXPORTED_CLASS
#endif #endif

View File

@ -20,6 +20,9 @@ TOML_DISABLE_SUGGEST_ATTR_WARNINGS;
// misc warning false-positives // misc warning false-positives
#if TOML_MSVC #if TOML_MSVC
#pragma warning(disable : 5031) // #pragma warning(pop): likely mismatch #pragma warning(disable : 5031) // #pragma warning(pop): likely mismatch
#if TOML_SHARED_LIB
#pragma warning(disable : 4251) // dll exports for std lib types
#endif
#elif TOML_CLANG #elif TOML_CLANG
#pragma clang diagnostic ignored "-Wheader-hygiene" #pragma clang diagnostic ignored "-Wheader-hygiene"
#if TOML_CLANG >= 12 #if TOML_CLANG >= 12

View File

@ -44,7 +44,8 @@ is_subproject = meson.is_subproject()
has_exceptions = get_option('cpp_eh') != 'none' has_exceptions = get_option('cpp_eh') != 'none'
include_dirs = include_directories('include', 'external') include_dirs = include_directories('include', 'external')
overrides = [] overrides = []
additional_arguments = [] universal_args = [] # args used in tests, examples, lib, everything
devel_args = [] # args used in everything *but* the lib
message('is_release: @0@'.format(is_release)) message('is_release: @0@'.format(is_release))
message('is_windows: @0@'.format(is_windows)) message('is_windows: @0@'.format(is_windows))
@ -59,34 +60,17 @@ message('has_exceptions: @0@'.format(has_exceptions))
# GCC or Clang # GCC or Clang
if is_gcc or is_clang if is_gcc or is_clang
add_project_arguments( devel_args += '-march=native'
'-march=native',
'-fvisibility=hidden',
'-fvisibility-inlines-hidden',
language: 'cpp'
)
if is_release
add_project_arguments(
'-fdata-sections',
'-ffunction-sections',
'-Wl,--gc-sections',
'-Wl,-s',
'-mfma',
language: 'cpp'
)
endif
endif endif
# GCC # GCC
if is_gcc if is_gcc
add_project_arguments( universal_args += [
'-fmax-errors=5', '-fmax-errors=5',
'-Wno-init-list-lifetime', '-Wno-init-list-lifetime',
language: 'cpp' ]
)
if is_pedantic if is_pedantic
add_project_arguments( universal_args += [
'-Wcast-align', '-Wcast-align',
'-Wcast-qual', '-Wcast-qual',
'-Wctor-dtor-privacy', '-Wctor-dtor-privacy',
@ -122,25 +106,22 @@ if is_gcc
'-Wvariadic-macros', '-Wvariadic-macros',
'-Wwrite-strings', '-Wwrite-strings',
'-Wmissing-noreturn', '-Wmissing-noreturn',
language: 'cpp' ]
)
endif endif
if is_release if is_release and is_pedantic
add_project_arguments( universal_args += [
'-fmerge-constants',
'-Wsuggest-attribute=const', '-Wsuggest-attribute=const',
'-Wsuggest-attribute=pure', '-Wsuggest-attribute=pure',
language: 'cpp' ]
)
endif endif
endif endif
# Clang # Clang
if is_clang if is_clang
if is_pedantic if is_pedantic
add_project_arguments('-Weverything', language: 'cpp') universal_args += '-Weverything'
endif endif
add_project_arguments( universal_args += [
'-ferror-limit=5', '-ferror-limit=5',
'-Wno-unused-command-line-argument', '-Wno-unused-command-line-argument',
@ -151,54 +132,45 @@ if is_clang
'-Wno-documentation-unknown-command', '-Wno-documentation-unknown-command',
'-Wno-switch-enum', '-Wno-switch-enum',
'-Wno-covered-switch-default', '-Wno-covered-switch-default',
language: 'cpp' ]
)
if get_option('time_trace') if get_option('time_trace')
add_project_arguments('-ftime-trace', language: 'cpp') universal_args += ['-ftime-trace']
endif endif
endif endif
# MSVC or icc-cl # MSVC or icc-cl
if is_msvc or is_icc_cl if is_msvc or is_icc_cl
add_project_arguments( universal_args += [
'/bigobj', '/bigobj',
'/fp:except-', # disable floating-point exceptions '/fp:except-', # disable floating-point exceptions
'/Gy', # function-level linking '/Gy', # function-level linking
'/GF', # string pooling '/GF', # string pooling
'/openmp-', '/openmp-',
'/permissive-', '/permissive-',
'/sdl-',
'/utf-8', '/utf-8',
'/volatile:iso', '/Zc:inline'
'/Zc:__cplusplus', ]
'/Zc:inline', if has_exceptions
'/Zc:throwingNew', universal_args += '/Zc:throwingNew'
'/Zi', # generate debug info (doesn't affect optimization) endif
language: 'cpp'
)
add_project_link_arguments('/DEBUG', language: 'cpp') # generate PDB (doesn't affect optimization)
if is_release if is_release
add_project_arguments( universal_args += [
'/GL', # whole program optimization '/GL', # whole program optimization
'/Gw', # Optimize Global Data '/Gw', # Optimize Global Data
'/Ob3', # aggressive inlining '/Ob3', # aggressive inlining
'/Oy', # omit frame pointers '/Oy', # omit frame pointers
'/Oi', # generate intrinsics '/Oi', # generate intrinsics
language: 'cpp' ]
)
add_project_link_arguments('/ltcg', language: 'cpp') add_project_link_arguments('/ltcg', language: 'cpp')
endif endif
if is_pedantic if is_pedantic
add_project_arguments('/W4', language: 'cpp') universal_args += '/W4'
endif
if is_x64
add_project_arguments('/arch:AVX', language: 'cpp')
endif endif
endif endif
# icc-cl # icc-cl
if is_icc_cl if is_icc_cl
add_project_arguments( universal_args += [
'/wd82', # storage class is not first '/wd82', # storage class is not first
'/wd177', # unreferenced var '/wd177', # unreferenced var
'/wd280', # selector expression is constant (why the fuck is that a warning?) '/wd280', # selector expression is constant (why the fuck is that a warning?)
@ -209,37 +181,27 @@ if is_icc_cl
'/wd2261', # assume with side effects discarded '/wd2261', # assume with side effects discarded
'/wd2557', # mismatched sign compare '/wd2557', # mismatched sign compare
'/wd3280', # declaration hides member (triggered in Catch2) '/wd3280', # declaration hides member (triggered in Catch2)
language: 'cpp' ]
)
endif endif
# icc (any) # icc (any)
if is_icc if is_icc
add_project_arguments( universal_args += [
'/Qdiag-error-limit:5', '/Qdiag-error-limit:5',
'/Qoption,cpp,--unicode_source_kind,UTF-8', '/Qoption,cpp,--unicode_source_kind,UTF-8',
'/D__builtin_bit_cast(T, v)=([&]()noexcept{ T val; memcpy(&val, &v, sizeof(T)); return val; })()', # __builtin_bit_cast workaround '/D__builtin_bit_cast(T, v)=([&]()noexcept{ T val; memcpy(&val, &v, sizeof(T)); return val; })()', # __builtin_bit_cast workaround
language: 'cpp' ]
)
endif endif
# windows stuff # windows stuff
if is_windows if is_windows
add_project_arguments( universal_args += has_exceptions ? '-D_HAS_EXCEPTIONS=1' : '-D_HAS_EXCEPTIONS=0'
'-D_ITERATOR_DEBUG_LEVEL=0',
'-D_WINSOCK_DEPRECATED_NO_WARNINGS',
'-D_SCL_SECURE_NO_WARNINGS',
'-D_CRT_SECURE_NO_WARNINGS',
language: 'cpp'
)
add_project_arguments(has_exceptions ? '-D_HAS_EXCEPTIONS=1' : '-D_HAS_EXCEPTIONS=0', language: 'cpp')
elif is_release elif is_release
overrides += 'strip=true' overrides += 'strip=true'
endif endif
# LTO # LTO
if is_lld or is_debug if is_lld or is_debug or (is_windows and is_clang)
overrides += 'b_lto=false' overrides += 'b_lto=false'
endif endif
@ -418,7 +380,7 @@ compiler_supports_float16 = compiler.links('''
args: compiler_supports_float16_args args: compiler_supports_float16_args
) )
if compiler_supports_fp16 or compiler_supports_float16 if compiler_supports_fp16 or compiler_supports_float16
additional_arguments += compiler_supports_float16_args devel_args += compiler_supports_float16_args
endif endif
####################################################################################################################### #######################################################################################################################
@ -484,6 +446,17 @@ endif
# subdirectories # subdirectories
####################################################################################################################### #######################################################################################################################
include_dir = include_directories('include')
# Empty dependency that will be filled either in src/ or include/
tomlplusplus_dep = dependency('', required: false)
if get_option('compile_library')
subdir('src')
else
subdir('include')
endif
build_tests = get_option('build_tests') and not is_subproject build_tests = get_option('build_tests') and not is_subproject
if build_tests if build_tests
run_command('git', 'submodule', 'update', '--init', '--depth', '1', 'external/Catch2') run_command('git', 'submodule', 'update', '--init', '--depth', '1', 'external/Catch2')
@ -502,51 +475,8 @@ if build_tt
endif endif
if not is_subproject if not is_subproject
install_subdir('include'/'toml++', install_subdir('include'/'toml++', install_dir: get_option('includedir'))
strip_directory: true,
install_dir: get_option('includedir')/'toml++'
)
endif endif
####################################################################################################################### # Allow subproject usage
# dependencies, cmake etc.
#######################################################################################################################
tomlplusplus_dep = declare_dependency(include_directories: 'include')
meson.override_dependency(meson.project_name(), tomlplusplus_dep) meson.override_dependency(meson.project_name(), tomlplusplus_dep)
if not is_subproject
import('pkgconfig').generate(
name: meson.project_name(),
description: 'Header-only TOML config file parser and serializer for C++',
install_dir: get_option('datadir')/'pkgconfig',
)
endif
# cmake
if get_option('generate_cmake_config') and not is_subproject
cmake = import('cmake')
# Can't use until Meson 0.62.0, see https://github.com/mesonbuild/meson/pull/9916
# and https://github.com/marzer/tomlplusplus/issues/140
#cmake.write_basic_package_version_file(
# name: meson.project_name(),
# version: meson.project_version(),
# install_dir: get_option('datadir')/'cmake'/meson.project_name(),
# arch_independent: true
#)
# In the meantime, install a pre-generated Package Version file
configure_file(
configuration: {'version': meson.project_version()},
input: 'cmake'/'tomlplusplusConfigVersion.cmake.in',
output: 'tomlplusplusConfigVersion.cmake',
install_dir: get_option('datadir')/'cmake'/meson.project_name()
)
cmake.configure_package_config_file(
name: meson.project_name(),
input: 'cmake'/'tomlplusplus.cmake.in',
configuration: configuration_data({'includedir': get_option('includedir')}),
install_dir: get_option('datadir')/'cmake'/meson.project_name(),
)
endif

View File

@ -1,4 +1,4 @@
option('build_tests', type: 'boolean', value: false, description: 'Build tests (default: false - no effect when included as a subproject)') option('build_tests', type: 'boolean', value: false, description: 'Build tests (default: false - no effect when included as a subproject)')
option('build_examples', type: 'boolean', value: false, description: 'Build examples (default: false - no effect when included as a subproject)') option('build_examples', type: 'boolean', value: false, description: 'Build examples (default: false - no effect when included as a subproject)')
option('generate_cmake_config', type: 'boolean', value: true, description: 'Generate a cmake package config file (default: true - no effect when included as a subproject)') option('generate_cmake_config', type: 'boolean', value: true, description: 'Generate a cmake package config file (default: true - no effect when included as a subproject)')
option('pedantic', type: 'boolean', value: false, description: 'Enable as many compiler warnings as possible (default: false)') option('pedantic', type: 'boolean', value: false, description: 'Enable as many compiler warnings as possible (default: false)')
@ -7,4 +7,4 @@ option('asan_examples', type: 'boolean', value: false)
option('asan_tests', type: 'boolean', value: false) option('asan_tests', type: 'boolean', value: false)
option('build_tt_encoder', type: 'boolean', value: false, description: 'Enable to build the toml-test encoder.') 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('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')

72
src/meson.build Normal file
View File

@ -0,0 +1,72 @@
# Compiled library
# These are the arguments needed to compile and consume the library, and
# are exposed to users with the `compile_args` kwarg of declare_dependency()
lib_args = ['-DTOML_HEADER_ONLY=0']
if get_option('default_library') != 'static'
lib_args += '-DTOML_SHARED_LIB=1'
endif
lib = library(
meson.project_name(),
'toml++'/'toml.cpp',
cpp_args: [universal_args, lib_args],
gnu_symbol_visibility: 'hidden',
include_directories: include_dir,
install: not is_subproject,
version: meson.project_version(),
override_options: overrides
)
tomlplusplus_dep = declare_dependency(
compile_args: lib_args,
include_directories: include_dir,
link_with: lib
)
if not is_subproject
import('pkgconfig').generate(
lib,
description: 'TOML config file parser and serializer for C++',
extra_cflags: lib_args,
url: 'https://marzer.github.io/tomlplusplus'
)
endif
# cmake
if get_option('generate_cmake_config') and not is_subproject
cmake = import('cmake')
cmake.write_basic_package_version_file(
name: meson.project_name(),
version: meson.project_version(),
)
# This gets the full path of the library, then considers just the last
# component (i.e. the actual file name), and finally removes the
# version suffix from it, because users _should_ link against the .so
# file, as opposed to the .so.x.y.z one. This last step is only doable
# with str.replace(), introduced in Meson 0.58.0, but it isn't essential
lib_name = lib.full_path().split('/')[-1]
if meson.version().version_compare('>=0.58.0')
lib_name = lib_name.replace('.' + meson.project_version(), '')
endif
# CMake needs space-separated values since it doesn't have types
cmake_compile_options = ''
foreach arg : lib_args
cmake_compile_options += arg + ' '
endforeach
cmake_compile_options = cmake_compile_options.strip()
cmake.configure_package_config_file(
name: meson.project_name(),
input: '..'/'cmake'/'tomlplusplusConfig.cmake.meson.in',
configuration: configuration_data({
'compile_library': true,
'compile_options': cmake_compile_options,
'includedir': get_option('includedir'),
'libdir': get_option('libdir'),
'lib_name': lib_name
})
)
endif

5
src/toml++/toml.cpp Normal file
View File

@ -0,0 +1,5 @@
#ifndef TOML_IMPLEMENTATION
#define TOML_IMPLEMENTATION
#endif
#include <toml++/toml.h>

View File

@ -4,7 +4,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "settings.h" #include "settings.h"
#if !TOML_HEADER_ONLY #if !TOML_HEADER_ONLY && !TOML_SHARED_LIB
#define TOML_IMPLEMENTATION #define TOML_IMPLEMENTATION
#endif #endif

View File

@ -60,26 +60,34 @@ unreleased_feature_modes = [ false, true ]
cpp20_modes = [ false, true ] cpp20_modes = [ false, true ]
test_executables = [] test_executables = []
counter = 0 counter = 0
test_base_args = []
test_base_args += universal_args
test_base_args += devel_args
foreach cpp20 : cpp20_modes foreach cpp20 : cpp20_modes
if cpp20 and not compiler_supports_cpp20 if cpp20 and (not compiler_supports_cpp20 or get_option('compile_library'))
continue continue
endif endif
foreach unrel : unreleased_feature_modes foreach unrel : unreleased_feature_modes
if unrel and get_option('compile_library')
continue
endif
foreach fast_math : fast_math_modes foreach fast_math : fast_math_modes
if fast_math and not compiler_supports_fast_math if fast_math and (not compiler_supports_fast_math or get_option('compile_library'))
continue continue
endif endif
foreach exceptions : exception_modes foreach exceptions : exception_modes
if (not exceptions) and get_option('compile_library')
continue
endif
test_name = '' test_name = ''
test_overrides = [] test_overrides = []
test_overrides += overrides test_overrides += overrides
test_args = [] test_args = []
test_args += additional_arguments test_args += test_base_args
single_header = (counter % 2 == 1) single_header = (counter % 2 == 1)
tl_optional = (counter % 4 == 2 and exceptions) tl_optional = (counter % 4 == 2 and exceptions and not get_option('compile_library'))
address_sanitizer = (is_clang and not (single_header or tl_optional or fast_math)) and get_option('asan_tests') address_sanitizer = (is_clang and not (single_header or tl_optional or fast_math)) and get_option('asan_tests')
if cpp20 if cpp20
@ -155,6 +163,7 @@ foreach cpp20 : cpp20_modes
test_sources, test_sources,
include_directories: include_dirs, include_directories: include_dirs,
cpp_args: test_args, cpp_args: test_args,
dependencies: tomlplusplus_dep,
override_options: test_overrides override_options: test_overrides
) )
]] ]]
@ -195,6 +204,6 @@ executable(
'odr_test', 'odr_test',
[ 'odr_test_1.cpp', 'odr_test_2.cpp' ], [ 'odr_test_1.cpp', 'odr_test_2.cpp' ],
include_directories: include_dirs, include_directories: include_dirs,
cpp_args: additional_arguments, cpp_args: test_base_args,
override_options: overrides override_options: overrides
) )

View File

@ -1,6 +1,4 @@
#define TOML_ENABLE_UNRELEASED_FEATURES 1 #define TOML_UNDEF_MACROS 0
#define TOML_HEADER_ONLY 1
#define TOML_UNDEF_MACROS 0
#include "../toml.hpp" #include "../toml.hpp"
TOML_DISABLE_WARNINGS; TOML_DISABLE_WARNINGS;

View File

@ -1,3 +1,2 @@
#define TOML_ENABLE_UNRELEASED_FEATURES 1
#define TOML_HEADER_ONLY 1
#include "../toml.hpp" #include "../toml.hpp"
#include "../toml.hpp" // make sure it behaves if included more than once

View File

@ -6,7 +6,12 @@
// toml++ config // toml++ config
#define TOML_UNDEF_MACROS 0 #define TOML_UNDEF_MACROS 0
#define TOML_HEADER_ONLY 0 #ifndef TOML_HEADER_ONLY
#define TOML_HEADER_ONLY 0
#endif
#ifndef TOML_SHARED_LIB
#define TOML_SHARED_LIB 0
#endif
#ifndef USE_SINGLE_HEADER #ifndef USE_SINGLE_HEADER
#define USE_SINGLE_HEADER 0 #define USE_SINGLE_HEADER 0
#endif #endif

View File

@ -94,6 +94,7 @@
<None Include="CHANGELOG.md" /> <None Include="CHANGELOG.md" />
<None Include="CODE_OF_CONDUCT.md" /> <None Include="CODE_OF_CONDUCT.md" />
<None Include="CONTRIBUTING.md" /> <None Include="CONTRIBUTING.md" />
<None Include="include\meson.build" />
<None Include="include\toml++\impl\at_path.inl" /> <None Include="include\toml++\impl\at_path.inl" />
<None Include="include\toml++\impl\unicode.inl" /> <None Include="include\toml++\impl\unicode.inl" />
<None Include="include\toml++\impl\yaml_formatter.inl" /> <None Include="include\toml++\impl\yaml_formatter.inl" />
@ -108,6 +109,7 @@
<None Include="docs\pages\main_page.dox" /> <None Include="docs\pages\main_page.dox" />
<None Include="docs\poxy.toml" /> <None Include="docs\poxy.toml" />
<None Include="meson.build" /> <None Include="meson.build" />
<None Include="src\meson.build" />
<None Include="toml++.props" /> <None Include="toml++.props" />
<None Include="tools\ci_single_header_check.py" /> <None Include="tools\ci_single_header_check.py" />
<None Include="tools\clang_format.bat" /> <None Include="tools\clang_format.bat" />

View File

@ -112,18 +112,9 @@
<ClInclude Include="include\toml++\impl\formatter.inl"> <ClInclude Include="include\toml++\impl\formatter.inl">
<Filter>include\impl</Filter> <Filter>include\impl</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="include\toml++\impl\node_view.inl">
<Filter>include\impl</Filter>
</ClInclude>
<ClInclude Include="include\toml++\impl\value.inl">
<Filter>include\impl</Filter>
</ClInclude>
<ClInclude Include="include\toml++\impl\std_initializer_list.h"> <ClInclude Include="include\toml++\impl\std_initializer_list.h">
<Filter>include\impl</Filter> <Filter>include\impl</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="include\toml++\impl\value_extern.inl">
<Filter>include\impl</Filter>
</ClInclude>
<ClInclude Include="include\toml++\impl\yaml_formatter.h"> <ClInclude Include="include\toml++\impl\yaml_formatter.h">
<Filter>include\impl</Filter> <Filter>include\impl</Filter>
</ClInclude> </ClInclude>
@ -195,9 +186,6 @@
<None Include="tools\clang_format.bat"> <None Include="tools\clang_format.bat">
<Filter>tools</Filter> <Filter>tools</Filter>
</None> </None>
<None Include="include\toml++\impl\node_view_extern.inl">
<Filter>include\impl</Filter>
</None>
<None Include=".github\pull_request_template.md"> <None Include=".github\pull_request_template.md">
<Filter>.github</Filter> <Filter>.github</Filter>
</None> </None>
@ -226,6 +214,12 @@
<None Include="include\toml++\impl\at_path.inl"> <None Include="include\toml++\impl\at_path.inl">
<Filter>include\impl</Filter> <Filter>include\impl</Filter>
</None> </None>
<None Include="src\meson.build">
<Filter>src</Filter>
</None>
<None Include="include\meson.build">
<Filter>include</Filter>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include=".circleci"> <Filter Include=".circleci">
@ -252,6 +246,9 @@
<Filter Include=".github"> <Filter Include=".github">
<UniqueIdentifier>{e3ab5e86-e053-48a6-9fee-f6442a63aaa6}</UniqueIdentifier> <UniqueIdentifier>{e3ab5e86-e053-48a6-9fee-f6442a63aaa6}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="src">
<UniqueIdentifier>{5ae94dae-1dce-4522-a33a-230bdb075921}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Natvis Include="toml++.natvis" /> <Natvis Include="toml++.natvis" />

View File

@ -2,6 +2,7 @@ if get_option('build_tt_encoder')
executable( executable(
'tt_encoder', 'tt_encoder',
'tt_encoder.cpp', 'tt_encoder.cpp',
cpp_args: devel_args,
include_directories: include_dirs include_directories: include_dirs
) )
endif endif
@ -10,6 +11,7 @@ if get_option('build_tt_decoder')
executable( executable(
'tt_decoder', 'tt_decoder',
'tt_decoder.cpp', 'tt_decoder.cpp',
cpp_args: devel_args,
include_directories: include_dirs include_directories: include_dirs
) )
endif endif

758
toml.hpp

File diff suppressed because it is too large Load Diff

View File

@ -217,6 +217,7 @@ def main():
r'TOML_SMALL_INT_TYPE', r'TOML_SMALL_INT_TYPE',
r'TOML_UNDEF_MACROS', r'TOML_UNDEF_MACROS',
r'TOMLPLUSPLUS_H', r'TOMLPLUSPLUS_H',
r'TOML_SHARED_LIB'
) )
set_defines = [] set_defines = []
for define, currently_set in defines.items(): for define, currently_set in defines.items():