From 7188a4a808f1332ee91e29883504a6b89bb8cdf3 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 09:43:21 -0700 Subject: [PATCH 1/9] meson: Indent code inside an if block for better readability Signed-off-by: Dylan Baker --- meson.build | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index a2d6e31a25..b375b3d1b1 100644 --- a/meson.build +++ b/meson.build @@ -13,12 +13,12 @@ nlohmann_json_multiple_headers = declare_dependency( ) 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_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann') + install_headers('single_include/nlohmann/json_fwd.hpp', subdir: 'nlohmann') -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 From 8c74ccd3ef43dc58b3ebf9fa827757d54f634d18 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 09:46:21 -0700 Subject: [PATCH 2/9] meson: set a minimum Meson version Without a version set meson will give no developer warnings, including deprecations. 0.64 was selected as it's quite old, it's the newest version supported by muon (a pure C Meson implementation), and there's nothing complicated going on here. Signed-off-by: Dylan Baker --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index b375b3d1b1..90bab08243 100644 --- a/meson.build +++ b/meson.build @@ -2,6 +2,7 @@ project('nlohmann_json', 'cpp', version : '3.12.0', license : 'MIT', + meson_version : '>= 0.64', ) nlohmann_json_dep = declare_dependency( From 42f30ff7aa238e1cc13b14fbeecdf33385075728 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 09:49:03 -0700 Subject: [PATCH 3/9] meson: use `override_dependency()` to set dependencies This simplifies the use of json as a subproject. Signed-off-by: Dylan Baker --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index 90bab08243..cecba6c8e0 100644 --- a/meson.build +++ b/meson.build @@ -8,10 +8,12 @@ project('nlohmann_json', nlohmann_json_dep = declare_dependency( include_directories: include_directories('single_include') ) +meson.override_dependency('nlohmann_json', nlohmann_json_dep) nlohmann_json_multiple_headers = declare_dependency( include_directories: include_directories('include') ) +meson.override_dependency('nlohmann_json_multiple_headers', nlohmann_json_multiple_headers) if not meson.is_subproject() install_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann') From 00e48e8b623fd3f2b3319a33c4a2c83991534e2a Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:00:25 -0700 Subject: [PATCH 4/9] meson: use `install_subdir` for headers This makes a single call to install the entire directory, and doesn't need an update if any new headers are added. It also will simplify bringing the Meson and CMake builds into allignment on how they handle the multi-header vs single-header setups. Signed-off-by: Dylan Baker --- meson.build | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index cecba6c8e0..33d0c72464 100644 --- a/meson.build +++ b/meson.build @@ -16,8 +16,11 @@ nlohmann_json_multiple_headers = declare_dependency( meson.override_dependency('nlohmann_json_multiple_headers', nlohmann_json_multiple_headers) 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( + 'single_include/nlohmann', + install_dir: get_option('includedir'), + install_tag: 'devel', + ) pkgc = import('pkgconfig') pkgc.generate(name: 'nlohmann_json', From 76d91cd50f10de2a1fa865e73aa3730189569fb5 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:13:59 -0700 Subject: [PATCH 5/9] meson: set the C++ standard to C++11 Matching the CMake as closely as possible, as Meson doesn't have C++11 feature checks like CMAke does. Signed-off-by: Dylan Baker --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index 33d0c72464..0d551626fd 100644 --- a/meson.build +++ b/meson.build @@ -3,6 +3,7 @@ project('nlohmann_json', version : '3.12.0', license : 'MIT', meson_version : '>= 0.64', + default_options: ['cpp_std=c++11'], ) nlohmann_json_dep = declare_dependency( From da826f1b731b903e85c9c487d3b45e7f45bdcec2 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:07:07 -0700 Subject: [PATCH 6/9] meson: handle single header and multiheader the same way CMake does This uses a meson option (set in `meson_options.txt`) to control whether multi-header or single-header setup is wanted. Signed-off-by: Dylan Baker --- meson.build | 15 ++++++++------- meson_options.txt | 6 ++++++ 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 meson_options.txt diff --git a/meson.build b/meson.build index 0d551626fd..61c0282ae3 100644 --- a/meson.build +++ b/meson.build @@ -6,19 +6,20 @@ project('nlohmann_json', default_options: ['cpp_std=c++11'], ) +if get_option('MultipleHeaders') + incdir = 'include' +else + incdir = 'single_include' +endif + nlohmann_json_dep = declare_dependency( - include_directories: include_directories('single_include') + include_directories: include_directories(incdir) ) meson.override_dependency('nlohmann_json', nlohmann_json_dep) -nlohmann_json_multiple_headers = declare_dependency( - include_directories: include_directories('include') -) -meson.override_dependency('nlohmann_json_multiple_headers', nlohmann_json_multiple_headers) - if not meson.is_subproject() install_subdir( - 'single_include/nlohmann', + incdir / 'nlohmann', install_dir: get_option('includedir'), install_tag: 'devel', ) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000000..0fc9d2e6b3 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,6 @@ +option( + 'MultipleHeaders', + type: 'boolean', + value: true, + description: 'Use non-amalgamated version of the library', +) From 6664d3286c42e6932ab9aa9ec952c019991f9436 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:20:00 -0700 Subject: [PATCH 7/9] meson: add support for the GlobalUDLs option Signed-off-by: Dylan Baker --- meson.build | 6 ++++++ meson_options.txt | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/meson.build b/meson.build index 61c0282ae3..5fbf1d6b08 100644 --- a/meson.build +++ b/meson.build @@ -12,7 +12,13 @@ else incdir = 'single_include' endif +cpp_args = [ + '-DJSON_USE_GLOBAL_UDLS=@0@'.format( + (not get_option('GlobalUDLs')).to_int()), +] + nlohmann_json_dep = declare_dependency( + compile_args: cpp_args, include_directories: include_directories(incdir) ) meson.override_dependency('nlohmann_json', nlohmann_json_dep) diff --git a/meson_options.txt b/meson_options.txt index 0fc9d2e6b3..27d3878abe 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -4,3 +4,9 @@ option( 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', +) From 1836685c3cc6502317afab908b19105dee2f97ad Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:24:51 -0700 Subject: [PATCH 8/9] meson: add support for the ImplictConversions option Signed-off-by: Dylan Baker --- meson.build | 2 ++ meson_options.txt | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/meson.build b/meson.build index 5fbf1d6b08..2d9fa2a9a2 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,8 @@ endif 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( diff --git a/meson_options.txt b/meson_options.txt index 27d3878abe..d22af802ff 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -10,3 +10,9 @@ option( value: true, description: 'Place user-defined string literals in the global namespace', ) +option( + 'ImplicitConversions', + type: 'boolean', + value: true, + description: 'Enable implicit conversions', +) From 30c24bf33928e0121af8d59aa1e7764ab8e70c4c Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 31 Oct 2025 12:10:00 -0700 Subject: [PATCH 9/9] Add meson information to FILES.md Signed-off-by: Dylan Baker --- FILES.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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`