diff --git a/FILES.md b/FILES.md index 91326ab6ad..1d54e19303 100644 --- a/FILES.md +++ b/FILES.md @@ -232,7 +232,22 @@ The file can be updated by calling make BUILD.bazel ``` -### `meson.build` +### `meson.build` and `meson_options.txt` + +Meson build definitions suitable for use as a subproject ("wrap" in Meson terminology). + +Projects wishing to use the wrap can execute: +```sh +meson wrap install nlohmann_json +``` + +Which allows Meson to build from source when a system provided dependency isn't available. + +To build directly: +```sh +meson setup builddir +ninja -C builddir +``` ### `Package.swift` diff --git a/meson.build b/meson.build index a2d6e31a25..2d9fa2a9a2 100644 --- a/meson.build +++ b/meson.build @@ -2,23 +2,39 @@ project('nlohmann_json', 'cpp', version : '3.12.0', license : 'MIT', + meson_version : '>= 0.64', + default_options: ['cpp_std=c++11'], ) -nlohmann_json_dep = declare_dependency( - include_directories: include_directories('single_include') -) +if get_option('MultipleHeaders') + incdir = 'include' +else + incdir = 'single_include' +endif -nlohmann_json_multiple_headers = declare_dependency( - include_directories: include_directories('include') +cpp_args = [ + '-DJSON_USE_GLOBAL_UDLS=@0@'.format( + (not get_option('GlobalUDLs')).to_int()), + '-DJSON_USE_IMPLICIT_CONVERSIONS=@0@'.format( + (not get_option('ImplicitConversions')).to_int()), +] + +nlohmann_json_dep = declare_dependency( + compile_args: cpp_args, + include_directories: include_directories(incdir) ) +meson.override_dependency('nlohmann_json', nlohmann_json_dep) if not meson.is_subproject() -install_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann') -install_headers('single_include/nlohmann/json_fwd.hpp', subdir: 'nlohmann') + install_subdir( + incdir / 'nlohmann', + install_dir: get_option('includedir'), + install_tag: 'devel', + ) -pkgc = import('pkgconfig') -pkgc.generate(name: 'nlohmann_json', - version: meson.project_version(), - description: 'JSON for Modern C++' -) + pkgc = import('pkgconfig') + pkgc.generate(name: 'nlohmann_json', + version: meson.project_version(), + description: 'JSON for Modern C++' + ) endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000000..d22af802ff --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,18 @@ +option( + 'MultipleHeaders', + type: 'boolean', + value: true, + description: 'Use non-amalgamated version of the library', +) +option( + 'GlobalUDLs', + type: 'boolean', + value: true, + description: 'Place user-defined string literals in the global namespace', +) +option( + 'ImplicitConversions', + type: 'boolean', + value: true, + description: 'Enable implicit conversions', +)