From 0ec86110af2825ae7ef3a49f9248201e2553dcbc 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 --- meson.build | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index 7a9c5ec851..e349362b30 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 a24198732511f5d3d7f74264fb9a90a17c0da7cd 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. --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index e349362b30..bdf0fa006e 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 469c61fa6a525264cd91657c8fd70446e9f66311 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. --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index bdf0fa006e..a373ab509c 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 3aa3082df582e4b4aa197c2f908dbf1fa012eb28 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. --- meson.build | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index a373ab509c..09b4e24a5b 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 a29af9c381f3adf0c47e145d094cf875840c9ca0 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. --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index 09b4e24a5b..aff769eb2c 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 16dca3c6dddcaf64c6a4de27466714bac1d23dfd 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. --- 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 aff769eb2c..5b82945d56 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..8291c1ac41 --- /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 b6520e10e92fdb3d06146e33d0fbc527cce29abe Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:20:47 -0700 Subject: [PATCH 7/9] CMake: fix typo in JSON_GlobalUDLs description --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a49dc47ea..967e881d69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ endif() option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${JSON_BuildTests_INIT}) option(JSON_CI "Enable CI build targets." OFF) option(JSON_Diagnostics "Use extended diagnostic messages." OFF) -option(JSON_GlobalUDLs "Place use-defined string literals in the global namespace." ON) +option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON) option(JSON_ImplicitConversions "Enable implicit conversions." ON) option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF) option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF) From a575f8cbdecbf26da49b28fb4f217fb0d2eb4ae0 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:20:00 -0700 Subject: [PATCH 8/9] meson: add support for the GlobalUDLs option --- meson.build | 6 ++++++ meson_options.txt | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/meson.build b/meson.build index 5b82945d56..699726b9c5 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 8291c1ac41..347facca3f 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 b65e362b26159af0e732b998ed0f913aa422c1cd Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 9 Sep 2024 10:24:51 -0700 Subject: [PATCH 9/9] meson: add support for the ImplictConversions option --- meson.build | 2 ++ meson_options.txt | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/meson.build b/meson.build index 699726b9c5..a8b92f30fa 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 347facca3f..770fc722fd 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', +)