Meson C++ standard with fallback
Meson can set a default C++ (or C) langauge standard level with fallback to older versions. This allows recent compilers to support the full functionality of the project code, while falling back for older compilers.
get_option('cpp_std')
can be used for logic within meson.build if desired.
project('ffilesystem', ['cpp'],
default_options: ['c_std=c99', 'cpp_std=c++23,c++20,c++17', 'buildtype=release', 'b_ndebug=if-release'])
cpp_std = get_option('cpp_std')
message('C++ standard: ' + cpp_std)
The C / C++ code can use macro feature checks that detect compiler C++ / C standard support.
#if __cplusplus >= 201703L
// C++17 features
#endif
For C code likewise:
#if __STDC_VERSION__ >= 201112L
// C11 features
#endif
Related: CMake C++ standard with fallback