diff --git a/Makefile b/Makefile index 871ea7995..c5e541f93 100644 --- a/Makefile +++ b/Makefile @@ -213,7 +213,7 @@ json.tar.xz: # We use `-X` to make the resulting ZIP file reproducible, see # . include.zip: BUILD.bazel - zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) BUILD.bazel MODULE.bazel meson.build LICENSE.MIT + zip -9 --recurse-paths -X include.zip $(SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) BUILD.bazel MODULE.bazel meson.build meson_options.txt LICENSE.MIT # Create the files for a release and add signatures and hashes. release: include.zip json.tar.xz diff --git a/cmake/nlohmann_jsonTargets.cmake.in b/cmake/nlohmann_jsonTargets.cmake.in index adbefbf82..8149eff9e 100644 --- a/cmake/nlohmann_jsonTargets.cmake.in +++ b/cmake/nlohmann_jsonTargets.cmake.in @@ -2,8 +2,9 @@ # # CMake installations generate this file with install(EXPORT ...). Meson cannot # do that, but as the library is header-only, the target only needs an include -# directory and the C++ standard. Paths are computed relative to this file so -# that the installation can be relocated (e.g., into a sysroot). +# directory, the C++ standard, and the compile definitions of the options that +# differ from their defaults. Paths are computed relative to this file so that +# the installation can be relocated (e.g., into a sysroot). if(TARGET @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@) return() @@ -25,4 +26,12 @@ else() ) endif() +set(_NLOHMANN_JSON_COMPILE_DEFINITIONS "@NLOHMANN_JSON_COMPILE_DEFINITIONS@") +if(_NLOHMANN_JSON_COMPILE_DEFINITIONS) + set_target_properties(@PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@ PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "${_NLOHMANN_JSON_COMPILE_DEFINITIONS}" + ) +endif() + +unset(_NLOHMANN_JSON_COMPILE_DEFINITIONS) unset(_IMPORT_PREFIX) diff --git a/meson.build b/meson.build index 059095f2d..4f93c17d1 100644 --- a/meson.build +++ b/meson.build @@ -12,12 +12,35 @@ else incdir = 'single_include' 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()), -] +# The same compile definitions as the CMake target (see target_compile_definitions +# in CMakeLists.txt): only an option that differs from its default adds one. +json_defines = [] +if not get_option('GlobalUDLs') + json_defines += 'JSON_USE_GLOBAL_UDLS=0' +endif +if not get_option('ImplicitConversions') + json_defines += 'JSON_USE_IMPLICIT_CONVERSIONS=0' +endif +if get_option('DisableEnumSerialization') + json_defines += 'JSON_DISABLE_ENUM_SERIALIZATION=1' +endif +if get_option('Diagnostics') + json_defines += 'JSON_DIAGNOSTICS=1' +endif +if get_option('Diagnostic_Positions') + json_defines += 'JSON_DIAGNOSTIC_POSITIONS=1' +endif +if get_option('LegacyDiscardedValueComparison') + json_defines += 'JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1' +endif +if get_option('StrictNulHandling') + json_defines += 'JSON_STRICT_NUL_HANDLING=1' +endif + +cpp_args = [] +foreach define : json_defines + cpp_args += '-D' + define +endforeach nlohmann_json_dep = declare_dependency( compile_args: cpp_args, @@ -25,6 +48,12 @@ nlohmann_json_dep = declare_dependency( ) meson.override_dependency('nlohmann_json', nlohmann_json_dep) +# The multi-header version under the name earlier versions of this file used +nlohmann_json_multiple_headers = declare_dependency( + compile_args: cpp_args, + include_directories: include_directories('include') +) + if not meson.is_subproject() install_subdir( incdir / 'nlohmann', @@ -35,7 +64,9 @@ if not meson.is_subproject() pkgc = import('pkgconfig') pkgc.generate(name: 'nlohmann_json', version: meson.project_version(), - description: 'JSON for Modern C++' + description: 'JSON for Modern C++', + extra_cflags: cpp_args, + install_dir: get_option('datadir') / 'pkgconfig', ) # CMake package config files, so that find_package(nlohmann_json) works @@ -53,6 +84,7 @@ if not meson.is_subproject() cmake_conf.set('NLOHMANN_JSON_TARGETS_EXPORT_NAME', meson.project_name() + 'Targets') cmake_conf.set('NLOHMANN_JSON_INCLUDE_INSTALL_DIR', get_option('includedir')) cmake_conf.set('NLOHMANN_JSON_CONFIG_TO_PREFIX', '/'.join(cmake_to_prefix)) + cmake_conf.set('NLOHMANN_JSON_COMPILE_DEFINITIONS', ';'.join(json_defines)) foreach cmake_file : [ ['cmake/config.cmake.in', 'nlohmann_jsonConfig.cmake'], diff --git a/meson_options.txt b/meson_options.txt index d22af802f..ebb19bb40 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,7 +1,7 @@ option( 'MultipleHeaders', type: 'boolean', - value: true, + value: false, description: 'Use non-amalgamated version of the library', ) option( @@ -16,3 +16,33 @@ option( value: true, description: 'Enable implicit conversions', ) +option( + 'DisableEnumSerialization', + type: 'boolean', + value: false, + description: 'Disable default integer enum serialization', +) +option( + 'Diagnostics', + type: 'boolean', + value: false, + description: 'Use extended diagnostic messages', +) +option( + 'Diagnostic_Positions', + type: 'boolean', + value: false, + description: 'Enable diagnostic positions', +) +option( + 'LegacyDiscardedValueComparison', + type: 'boolean', + value: false, + description: 'Enable legacy discarded value comparison', +) +option( + 'StrictNulHandling', + type: 'boolean', + value: false, + description: 'Enable strict NUL-byte handling', +)