2020-01-04 14:21:38 +00:00
project (
2020-02-29 20:34:08 +00:00
'tomlplusplus' ,
'cpp' ,
2022-04-24 17:21:59 +00:00
version : '3.1.0' ,
2021-10-25 21:49:17 +00:00
meson_version : '>=0.54.0' ,
2021-09-22 06:47:15 +00:00
license : 'MIT' ,
default_options : [ # https://mesonbuild.com/Builtin-options.html
2020-09-05 10:26:12 +00:00
# core options
'buildtype=release' ,
2020-01-04 14:21:38 +00:00
'warning_level=3' ,
2020-02-29 20:34:08 +00:00
'werror=true' ,
2020-09-05 10:26:12 +00:00
# base options
'b_lto=true' ,
'b_ndebug=if-release' ,
# compiler options
'cpp_std=c++17'
2020-01-04 14:21:38 +00:00
]
)
2020-02-29 20:34:08 +00:00
2020-09-05 10:26:12 +00:00
#######################################################################################################################
# compiler management
#######################################################################################################################
2020-03-04 11:01:46 +00:00
2020-09-05 10:26:12 +00:00
compiler = meson . get_compiler ( 'cpp' )
2021-10-25 19:15:23 +00:00
message ( 'target cpu_family: @0@' . format ( host_machine . cpu_family ( ) ) )
message ( 'target cpu: @0@' . format ( host_machine . cpu ( ) ) )
message ( 'target system: @0@' . format ( host_machine . system ( ) ) )
message ( 'target endian: @0@' . format ( host_machine . endian ( ) ) )
2020-03-18 13:28:00 +00:00
2020-09-05 10:26:12 +00:00
is_gcc = compiler . get_id ( ) == 'gcc'
is_clang = compiler . get_id ( ) == 'clang'
is_msvc = compiler . get_id ( ) == 'msvc'
is_icc_cl = compiler . get_id ( ) == 'intel-cl'
is_icc = is_icc_cl or compiler . get_id ( ) == 'intel'
2020-10-09 05:50:15 +00:00
is_lld = compiler . get_linker_id ( ) == 'ld.lld'
2020-09-05 10:26:12 +00:00
is_debug = get_option ( 'debug' )
is_release = not is_debug
is_pedantic = get_option ( 'pedantic' )
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'
2022-02-14 17:41:52 +00:00
include_dir = include_directories ( 'include' )
2020-09-05 10:26:12 +00:00
overrides = [ ]
2022-02-12 13:25:20 +00:00
universal_args = [ ] # args used in tests, examples, lib, everything
devel_args = [ ] # args used in everything *but* the lib
2020-03-18 13:28:00 +00:00
2021-10-25 19:15:23 +00:00
message ( 'is_release: @0@' . format ( is_release ) )
message ( 'is_windows: @0@' . format ( is_windows ) )
message ( 'is_x64: @0@' . format ( is_x64 ) )
message ( 'has_exceptions: @0@' . format ( has_exceptions ) )
2020-08-08 17:51:33 +00:00
2020-09-05 10:26:12 +00:00
# compiler argument references:
# msvc: https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically?view=vs-2019
# intel and intel-cl: https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-oneapi-dev-guide-and-reference/top/compiler-reference/compiler-options/alphabetical-list-of-compiler-options.html
# gcc:
# clang:
2020-04-08 13:33:57 +00:00
2020-09-05 10:26:12 +00:00
# GCC or Clang
if is_gcc or is_clang
2022-02-12 13:25:20 +00:00
devel_args + = '-march=native'
2020-09-05 10:26:12 +00:00
endif
2020-03-18 13:28:00 +00:00
2020-09-05 10:26:12 +00:00
# GCC
if is_gcc
2022-02-12 13:25:20 +00:00
universal_args + = [
2020-09-05 10:26:12 +00:00
'-fmax-errors=5' ,
'-Wno-init-list-lifetime' ,
2022-02-12 13:25:20 +00:00
]
2020-09-05 10:26:12 +00:00
if is_pedantic
2022-02-12 13:25:20 +00:00
universal_args + = [
2020-10-09 05:50:15 +00:00
'-Wcast-align' ,
'-Wcast-qual' ,
'-Wctor-dtor-privacy' ,
'-Wdisabled-optimization' ,
'-Wfloat-equal' ,
'-Wimport' ,
'-Winit-self' ,
'-Wlogical-op' ,
'-Wmissing-declarations' ,
'-Wmissing-field-initializers' ,
'-Wmissing-format-attribute' ,
'-Wmissing-include-dirs' ,
'-Wmissing-noreturn' ,
'-Wold-style-cast' ,
'-Woverloaded-virtual' ,
'-Wpacked' ,
'-Wpadded' ,
'-Wpointer-arith' ,
'-Wredundant-decls' ,
'-Wshadow' ,
'-Wsign-conversion' ,
'-Wsign-promo' ,
'-Wstack-protector' ,
'-Wstrict-null-sentinel' ,
'-Wswitch-default' ,
'-Wswitch-enum' ,
'-Wundef' ,
'-Wunreachable-code' ,
'-Wunused' ,
'-Wunused-parameter' ,
2020-12-15 11:39:58 +00:00
'-Wuseless-cast' ,
2020-10-09 05:50:15 +00:00
'-Wvariadic-macros' ,
'-Wwrite-strings' ,
'-Wmissing-noreturn' ,
2022-02-12 13:25:20 +00:00
]
2020-03-18 13:28:00 +00:00
endif
2022-02-12 13:25:20 +00:00
if is_release and is_pedantic
universal_args + = [
2021-11-02 20:13:09 +00:00
'-Wsuggest-attribute=const' ,
'-Wsuggest-attribute=pure' ,
2022-02-12 13:25:20 +00:00
]
2020-09-05 10:26:12 +00:00
endif
endif
2020-03-18 13:28:00 +00:00
2020-09-05 10:26:12 +00:00
# Clang
if is_clang
if is_pedantic
2022-02-12 13:25:20 +00:00
universal_args + = '-Weverything'
2020-08-08 17:51:33 +00:00
endif
2022-02-12 13:25:20 +00:00
universal_args + = [
2020-09-05 10:26:12 +00:00
'-ferror-limit=5' ,
'-Wno-unused-command-line-argument' ,
2020-08-08 17:51:33 +00:00
2020-09-05 10:26:12 +00:00
# flags from here down are disabling stupidly pedantic warnings that only appear with -Weverything
'-Wno-c++98-compat' ,
'-Wno-c++98-compat-pedantic' ,
'-Wno-documentation' ,
'-Wno-documentation-unknown-command' ,
'-Wno-switch-enum' ,
'-Wno-covered-switch-default' ,
2022-02-12 13:25:20 +00:00
]
2020-09-05 10:26:12 +00:00
if get_option ( 'time_trace' )
2022-02-12 13:25:20 +00:00
universal_args + = [ '-ftime-trace' ]
2020-09-05 10:26:12 +00:00
endif
endif
# MSVC or icc-cl
if is_msvc or is_icc_cl
2022-02-12 13:25:20 +00:00
universal_args + = [
2020-09-05 10:26:12 +00:00
'/bigobj' ,
'/fp:except-' , # disable floating-point exceptions
'/Gy' , # function-level linking
'/GF' , # string pooling
'/openmp-' ,
'/permissive-' ,
'/utf-8' ,
2022-02-12 13:25:20 +00:00
'/Zc:inline'
]
if has_exceptions
universal_args + = '/Zc:throwingNew'
endif
2020-09-05 10:26:12 +00:00
if is_release
2022-02-12 13:25:20 +00:00
universal_args + = [
2020-09-05 10:26:12 +00:00
'/GL' , # whole program optimization
'/Gw' , # Optimize Global Data
'/Ob3' , # aggressive inlining
'/Oy' , # omit frame pointers
'/Oi' , # generate intrinsics
2022-02-12 13:25:20 +00:00
]
2021-09-22 06:47:15 +00:00
add_project_link_arguments ( '/ltcg' , language : 'cpp' )
2020-09-05 10:26:12 +00:00
endif
if is_pedantic
2022-02-12 13:25:20 +00:00
universal_args + = '/W4'
2020-09-05 10:26:12 +00:00
endif
endif
2020-03-18 13:28:00 +00:00
2020-09-05 10:26:12 +00:00
# icc-cl
if is_icc_cl
2022-02-12 13:25:20 +00:00
universal_args + = [
2020-09-05 10:26:12 +00:00
'/wd82' , # storage class is not first
'/wd177' , # unreferenced var
'/wd280' , # selector expression is constant (why the fuck is that a warning?)
'/wd411' , # class provides no constructor (duh, it's an aggregate)
'/wd869' , # parameter "blah" was never referenced
'/wd1011' , # missing return statement (false negative)
'/wd1628' , # function marked [[noreturn]] returns (false positive)
'/wd2261' , # assume with side effects discarded
'/wd2557' , # mismatched sign compare
'/wd3280' , # declaration hides member (triggered in Catch2)
2022-02-12 13:25:20 +00:00
]
2020-09-05 10:26:12 +00:00
endif
2020-03-18 13:28:00 +00:00
2020-09-05 10:26:12 +00:00
# icc (any)
if is_icc
2022-02-12 13:25:20 +00:00
universal_args + = [
2020-09-05 10:26:12 +00:00
'/Qdiag-error-limit:5' ,
'/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
2022-02-12 13:25:20 +00:00
]
2020-09-05 10:26:12 +00:00
endif
# windows stuff
if is_windows
2022-02-12 13:25:20 +00:00
universal_args + = has_exceptions ? '-D_HAS_EXCEPTIONS=1' : '-D_HAS_EXCEPTIONS=0'
2020-09-05 10:26:12 +00:00
elif is_release
overrides + = 'strip=true'
endif
2020-10-09 05:50:15 +00:00
# LTO
2022-02-12 13:25:20 +00:00
if is_lld or is_debug or ( is_windows and is_clang )
2020-10-09 05:50:15 +00:00
overrides + = 'b_lto=false'
endif
2020-09-05 10:26:12 +00:00
#######################################################################################################################
# c++ 20 check
#######################################################################################################################
compiler_supports_cpp20_args = [ ]
if is_gcc or is_clang
compiler_supports_cpp20_args + = '-std=c++2a'
elif is_icc
compiler_supports_cpp20_args + = '/Qstd=c++2a'
elif is_msvc
compiler_supports_cpp20_args + = '/std:c++latest'
endif
compiler_supports_cpp20 = compiler_supports_cpp20_args . length ( ) > 0 and compiler . links ( '' '
#include <version>
#include <string>
#include <iostream>
2021-10-30 14:26:05 +00:00
#include <cstdint>
#include <cstddef>
#include <cstring>
#include <cfloat>
#include <climits>
#include <cmath>
#include <limits>
#include <memory>
#include <iosfwd>
#include <type_traits>
2020-09-05 10:26:12 +00:00
int main ( )
{
std : : string s = " kek " ;
std : : cout < < s < < std : : endl ;
return 0 ;
}
'' ' ,
2021-09-22 06:47:15 +00:00
name : 'supports c++20' ,
args : compiler_supports_cpp20_args
2020-09-05 10:26:12 +00:00
)
2020-03-18 13:28:00 +00:00
2020-09-05 10:26:12 +00:00
#######################################################################################################################
# char8_t check
#######################################################################################################################
compiler_supports_char8_args = [ ]
if is_gcc or is_clang
compiler_supports_char8_args + = '-fchar8_t'
endif
compiler_supports_char8_args_private = [ ]
compiler_supports_char8_args_private + = compiler_supports_cpp20_args
compiler_supports_char8_args_private + = compiler_supports_char8_args
compiler_supports_char8 = compiler_supports_cpp20 and compiler . links ( '' '
#include <version>
#include <string_view>
#include <string>
#include <type_traits>
using namespace std : : string_view_literals ;
2021-05-19 11:36:25 +00:00
#if !defined(__cpp_char8_t) || __cpp_char8_t < 201811 || !defined(__cpp_lib_char8_t) || __cpp_lib_char8_t < 201907
2020-09-05 10:26:12 +00:00
#error oh noes
#endif
static_assert ( ! std : : is_same_v < char , char8_t > ) ;
static_assert ( ! std : : is_same_v < std : : string , std : : u8string > ) ;
std : : u8string func ( )
{
return std : : u8string { u8 " this is a test . " sv } ;
}
int main ( )
{
return 0 ;
}
'' ' ,
2021-09-22 06:47:15 +00:00
name : 'supports char8_t' ,
args : compiler_supports_char8_args_private
2020-09-05 10:26:12 +00:00
)
#######################################################################################################################
# consteval check
2020-10-30 13:09:28 +00:00
# (this doesn't inform the build in any way; it's just so i can see who supports it properly)
2020-09-05 10:26:12 +00:00
#######################################################################################################################
compiler_supports_consteval = compiler_supports_cpp20 and compiler . compiles ( '' '
2020-10-09 05:50:15 +00:00
consteval int test ( ) noexcept
2020-09-05 10:26:12 +00:00
{
return 42 ;
}
int main ( )
{
2020-10-09 05:50:15 +00:00
constexpr auto val = test ( ) ; / / test ( ) should be compiletime - callable
return val ;
2020-09-05 10:26:12 +00:00
}
'' ' ,
2021-09-22 06:47:15 +00:00
name : 'supports consteval keyword' ,
args : compiler_supports_cpp20_args
2020-09-05 10:26:12 +00:00
)
2020-10-30 13:09:28 +00:00
compiler_supports_consteval_properly = compiler_supports_consteval and not compiler . compiles ( '' '
consteval int test ( int i ) noexcept
{
return 42 + i ;
}
int get_value ( ) noexcept ;
int main ( )
{
return test ( get_value ( ) ) ; / / test ( ) should not be runtime - callable
}
'' ' ,
2021-09-22 06:47:15 +00:00
name : 'consteval is just renamed constexpr' ,
args : compiler_supports_cpp20_args
2020-10-30 13:09:28 +00:00
)
2020-09-05 10:26:12 +00:00
#######################################################################################################################
# __fp16 and _Float16 checks
#######################################################################################################################
float_16_preprocessor_single_check_template = '' '
#ifndef @0@
#error @0@ wasn't defined!
#else
#pragma message("@0@: " MAKE_STRING(@0@))
#endif
#if @0@ != @1@
#error @0@ was not @1@!
#endif
'' '
float_16_preprocessor_checks = '' '
#define MAKE_STRING(s) MAKE_STRING_1(s)
#define MAKE_STRING_1(s) #s
2020-10-09 05:50:15 +00:00
'' ' + float_16_preprocessor_single_check_template.format(' __FLT_RADIX__ ', ' 2 ' ) \
+ float_16_preprocessor_single_check_template . format ( '__FLT16_MANT_DIG__' , '11' ) \
+ float_16_preprocessor_single_check_template . format ( '__FLT16_DIG__' , '3' ) \
+ float_16_preprocessor_single_check_template . format ( '__FLT16_MIN_EXP__' , '-13' ) \
+ float_16_preprocessor_single_check_template . format ( '__FLT16_MIN_10_EXP__' , '-4' ) \
+ float_16_preprocessor_single_check_template . format ( '__FLT16_MAX_EXP__' , '16' ) \
2020-09-05 10:26:12 +00:00
+ float_16_preprocessor_single_check_template . format ( '__FLT16_MAX_10_EXP__' , '4' )
compiler_supports_float16_args = [ ]
if is_gcc
compiler_supports_float16_args + = '-mfp16-format=ieee'
endif
compiler_supports_fp16 = compiler . links ( '' '
int main ( )
{
static_assert ( sizeof ( __fp16 ) == 2 ) ;
__fp16 f = static_cast < __fp16 > ( 1 ) ;
const auto f2 = static_cast < float > ( f ) ;
const auto f3 = static_cast < __fp16 > ( 0 . 2 L ) ;
return 0 ;
}
2020-10-09 05:50:15 +00:00
'' ' ,
2021-09-22 06:47:15 +00:00
name : 'supports __fp16' ,
args : compiler_supports_float16_args
2020-09-05 10:26:12 +00:00
)
compiler_supports_float16 = compiler . links ( '' '
@ 0 @
int main ( )
{
static_assert ( sizeof ( _Float16 ) == 2 ) ;
_Float16 f = static_cast < _Float16 > ( 1 ) ;
const auto f2 = static_cast < float > ( f ) ;
const auto f3 = static_cast < _Float16 > ( 0 . 2 L ) ;
return 0 ;
}
'' ' . format ( float_16_preprocessor_checks ) ,
2021-09-22 06:47:15 +00:00
name : 'supports _Float16' ,
args : compiler_supports_float16_args
2020-09-05 10:26:12 +00:00
)
if compiler_supports_fp16 or compiler_supports_float16
2022-02-12 13:25:20 +00:00
devel_args + = compiler_supports_float16_args
2020-09-05 10:26:12 +00:00
endif
#######################################################################################################################
# int128 check
#######################################################################################################################
compiler_supports_int128 = compiler . links ( '' '
#ifndef __SIZEOF_INT128__
#error __SIZEOF_INT128__ wasn't defined!
#endif
#include <cstdint>
int main ( )
{
static_assert ( __SIZEOF_INT128__ == 16 ) ;
static_assert ( sizeof ( __int128_t ) == 16 ) ;
static_assert ( sizeof ( __uint128_t ) == 16 ) ;
__int128_t i = static_cast < __int128_t > ( 1 ) ;
const auto i2 = static_cast < int64_t > ( i ) ;
const auto i3 = static_cast < int32_t > ( i ) ;
return 0 ;
}
'' ' ,
2021-09-22 06:47:15 +00:00
name : 'supports __int128_t'
2020-09-05 10:26:12 +00:00
)
#######################################################################################################################
# float128 check
#######################################################################################################################
compiler_supports_float128 = compiler . links ( '' '
#ifndef __SIZEOF_FLOAT128__
#error __SIZEOF_FLOAT128__ wasn't defined!
#endif
#ifndef __FLT128_MANT_DIG__
#error __FLT128_MANT_DIG__ wasn't defined!
#endif
#ifndef __LDBL_MANT_DIG__
#error __LDBL_MANT_DIG__ wasn't defined!
#endif
#if __FLT128_MANT_DIG__ <= __LDBL_MANT_DIG__
#error __FLT128_MANT_DIG__ was <= __LDBL_MANT_DIG__
#endif
int main ( )
{
static_assert ( __SIZEOF_FLOAT128__ == 16 ) ;
static_assert ( sizeof ( __float128 ) == 16 ) ;
__float128 f = static_cast < __float128 > ( 1 ) ;
const auto f2 = static_cast < long double > ( f ) ;
const auto f3 = static_cast < double > ( f ) ;
return 0 ;
}
'' ' ,
2021-09-22 06:47:15 +00:00
name : 'supports __float128'
2020-09-05 10:26:12 +00:00
)
2020-12-09 07:48:02 +00:00
if compiler_supports_float128 and is_gcc and not is_subproject
2021-09-22 06:47:15 +00:00
add_global_arguments ( '-fext-numeric-literals' , language : 'cpp' )
2020-09-05 10:26:12 +00:00
endif
2020-03-18 13:28:00 +00:00
2020-09-05 10:26:12 +00:00
#######################################################################################################################
# subdirectories
#######################################################################################################################
2022-02-12 13:25:20 +00:00
# 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
2020-09-05 10:26:12 +00:00
build_tests = get_option ( 'build_tests' ) and not is_subproject
if build_tests
subdir ( 'tests' )
2020-03-04 11:01:46 +00:00
endif
2020-01-04 14:21:38 +00:00
2020-09-05 10:26:12 +00:00
build_examples = get_option ( 'build_examples' ) and not is_subproject
if build_examples
subdir ( 'examples' )
endif
2022-01-03 18:51:03 +00:00
build_tt = ( get_option ( 'build_tt_encoder' ) or get_option ( 'build_tt_encoder' ) ) and not is_subproject
if build_tt
subdir ( 'toml-test' )
endif
2021-09-21 13:57:05 +00:00
if not is_subproject
2022-02-12 13:25:20 +00:00
install_subdir ( 'include' / 'toml++' , install_dir : get_option ( 'includedir' ) )
2021-09-21 13:57:05 +00:00
endif
2020-04-03 08:03:15 +00:00
2022-02-12 13:25:20 +00:00
# Allow subproject usage
2022-02-02 14:01:52 +00:00
meson . override_dependency ( meson . project_name ( ) , tomlplusplus_dep )