From e07b096aaf0d229ae074981c3d33515c023a30ee Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 09:43:21 -0700 Subject: [PATCH 1/8] 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 7a9c5ec85..e349362b3 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 cf80e33fd8dd34123a7e7a64adfe96b17f14f92a Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 09:46:21 -0700 Subject: [PATCH 2/8] 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 e349362b3..bdf0fa006 100644 --- a/meson.build +++ b/meson.build @@ -2,6 +2,7 @@ project('nlohmann_json', 'cpp', version : '3.11.3', license : 'MIT', + meson_version : '>= 0.64', ) nlohmann_json_dep = declare_dependency( From ea92dd89a9d9f02561714864e9baebe78d7f9e83 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 09:49:03 -0700 Subject: [PATCH 3/8] 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 bdf0fa006..a373ab509 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 6fede3b3979b90aef2268d49c6bd6ff5412003c5 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:00:25 -0700 Subject: [PATCH 4/8] 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 a373ab509..09b4e24a5 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 df7ec728bdf14885d1e32a77b748bb3fa260f727 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:13:59 -0700 Subject: [PATCH 5/8] 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 09b4e24a5..aff769eb2 100644 --- a/meson.build +++ b/meson.build @@ -3,6 +3,7 @@ project('nlohmann_json', version : '3.11.3', license : 'MIT', meson_version : '>= 0.64', + default_options: ['cpp_std=c++11'], ) nlohmann_json_dep = declare_dependency( From af894c3b9f58192f811f75bf3d330887eb5b18e5 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:07:07 -0700 Subject: [PATCH 6/8] 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 aff769eb2..5b82945d5 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 000000000..8291c1ac4 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,6 @@ +option( + 'MultipleHeaders', + type: 'boolean', + value: true, + description: 'Use non-amalgomated version of the library', +) From a079ed8cde7309aa250cbad7043f00934a15eb59 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:20:00 -0700 Subject: [PATCH 7/8] 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 5b82945d5..699726b9c 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 8291c1ac4..347facca3 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -4,3 +4,9 @@ option( value: true, description: 'Use non-amalgomated version of the library', ) +option( + 'GlobalUDLs', + type: 'boolean', + value: true, + description: 'Place user-defined string literals in the global namespace', +) From e40b32d278cde2c58245a6a4be8a43cb7403b6ed Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:24:51 -0700 Subject: [PATCH 8/8] 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 699726b9c..a8b92f30f 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 347facca3..770fc722f 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', +)