Skip to content

Commit 2d1f9b6

Browse files
authored
Add Bazel build support (nlohmann#3709)
1 parent 9dfa722 commit 2d1f9b6

File tree

7 files changed

+88
-2
lines changed

7 files changed

+88
-2
lines changed

BUILD.bazel

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
cc_library(
2+
name = "json",
3+
hdrs = [
4+
"include/nlohmann/adl_serializer.hpp",
5+
"include/nlohmann/byte_container_with_subtype.hpp",
6+
"include/nlohmann/detail/abi_macros.hpp",
7+
"include/nlohmann/detail/conversions/from_json.hpp",
8+
"include/nlohmann/detail/conversions/to_chars.hpp",
9+
"include/nlohmann/detail/conversions/to_json.hpp",
10+
"include/nlohmann/detail/exceptions.hpp",
11+
"include/nlohmann/detail/hash.hpp",
12+
"include/nlohmann/detail/input/binary_reader.hpp",
13+
"include/nlohmann/detail/input/input_adapters.hpp",
14+
"include/nlohmann/detail/input/json_sax.hpp",
15+
"include/nlohmann/detail/input/lexer.hpp",
16+
"include/nlohmann/detail/input/parser.hpp",
17+
"include/nlohmann/detail/input/position_t.hpp",
18+
"include/nlohmann/detail/iterators/internal_iterator.hpp",
19+
"include/nlohmann/detail/iterators/iter_impl.hpp",
20+
"include/nlohmann/detail/iterators/iteration_proxy.hpp",
21+
"include/nlohmann/detail/iterators/iterator_traits.hpp",
22+
"include/nlohmann/detail/iterators/json_reverse_iterator.hpp",
23+
"include/nlohmann/detail/iterators/primitive_iterator.hpp",
24+
"include/nlohmann/detail/json_custom_base_class.hpp",
25+
"include/nlohmann/detail/json_pointer.hpp",
26+
"include/nlohmann/detail/json_ref.hpp",
27+
"include/nlohmann/detail/macro_scope.hpp",
28+
"include/nlohmann/detail/macro_unscope.hpp",
29+
"include/nlohmann/detail/meta/call_std/begin.hpp",
30+
"include/nlohmann/detail/meta/call_std/end.hpp",
31+
"include/nlohmann/detail/meta/cpp_future.hpp",
32+
"include/nlohmann/detail/meta/detected.hpp",
33+
"include/nlohmann/detail/meta/identity_tag.hpp",
34+
"include/nlohmann/detail/meta/is_sax.hpp",
35+
"include/nlohmann/detail/meta/std_fs.hpp",
36+
"include/nlohmann/detail/meta/type_traits.hpp",
37+
"include/nlohmann/detail/meta/void_t.hpp",
38+
"include/nlohmann/detail/output/binary_writer.hpp",
39+
"include/nlohmann/detail/output/output_adapters.hpp",
40+
"include/nlohmann/detail/output/serializer.hpp",
41+
"include/nlohmann/detail/string_concat.hpp",
42+
"include/nlohmann/detail/string_escape.hpp",
43+
"include/nlohmann/detail/value_t.hpp",
44+
"include/nlohmann/json.hpp",
45+
"include/nlohmann/json_fwd.hpp",
46+
"include/nlohmann/ordered_map.hpp",
47+
"include/nlohmann/thirdparty/hedley/hedley.hpp",
48+
"include/nlohmann/thirdparty/hedley/hedley_undef.hpp",
49+
],
50+
includes = ["include"],
51+
visibility = ["//visibility:public"],
52+
alwayslink = True,
53+
)

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ option(JSON_Diagnostics "Use extended diagnostic messages." O
4343
option(JSON_GlobalUDLs "Place use-defined string literals in the global namespace." ON)
4444
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
4545
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
46-
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
46+
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
4747
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
4848
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
4949
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF)

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ check-amalgamation:
192192
@mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE)
193193
@mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE)
194194

195+
BUILD.bazel: $(SRCS)
196+
cmake -P cmake/scripts/gen_bazel_build_file.cmake
195197

196198
##########################################################################
197199
# ChangeLog

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,9 @@ endif()
13101310

13111311
If you are using the [Meson Build System](https://mesonbuild.com), add this source tree as a [meson subproject](https://mesonbuild.com/Subprojects.html#using-a-subproject). You may also use the `include.zip` published in this project's [Releases](https://github.com/nlohmann/json/releases) to reduce the size of the vendored source tree. Alternatively, you can get a wrap file by downloading it from [Meson WrapDB](https://wrapdb.mesonbuild.com/nlohmann_json), or simply use `meson wrap install nlohmann_json`. Please see the meson project for any issues regarding the packaging.
13121312

1313-
The provided `meson.build` can also be used as an alternative to cmake for installing `nlohmann_json` system-wide in which case a pkg-config file is installed. To use it, simply have your build system require the `nlohmann_json` pkg-config dependency. In Meson, it is preferred to use the [`dependency()`](https://mesonbuild.com/Reference-manual.html#dependency) object with a subproject fallback, rather than using the subproject directly.
1313+
The provided `meson.build` can also be used as an alternative to CMake for installing `nlohmann_json` system-wide in which case a pkg-config file is installed. To use it, simply have your build system require the `nlohmann_json` pkg-config dependency. In Meson, it is preferred to use the [`dependency()`](https://mesonbuild.com/Reference-manual.html#dependency) object with a subproject fallback, rather than using the subproject directly.
1314+
1315+
If you are using [Bazel](https://bazel.build/) you can simply reference this repository using `http_archive` or `git_repository` and depend on `@nlohmann_json//:json`.
13141316

13151317
If you are using [Conan](https://www.conan.io/) to manage your dependencies, merely add [`nlohmann_json/x.y.z`](https://conan.io/center/nlohmann_json) to your `conanfile`'s requires, where `x.y.z` is the release version you want to use. Please file issues [here](https://github.com/conan-io/conan-center-index/issues) if you experience problems with the packages.
13161318

WORKSPACE.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
workspace(name = "nlohmann_json")
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# generate Bazel BUILD file
2+
3+
set(PROJECT_ROOT "${CMAKE_CURRENT_LIST_DIR}/../..")
4+
set(BUILD_FILE "${PROJECT_ROOT}/BUILD.bazel")
5+
6+
file(GLOB_RECURSE HEADERS LIST_DIRECTORIES false RELATIVE "${PROJECT_ROOT}" "include/*.hpp")
7+
8+
file(WRITE "${BUILD_FILE}" [=[
9+
cc_library(
10+
name = "json",
11+
hdrs = [
12+
]=])
13+
14+
foreach(header ${HEADERS})
15+
file(APPEND "${BUILD_FILE}" " \"${header}\",\n")
16+
endforeach()
17+
18+
file(APPEND "${BUILD_FILE}" [=[
19+
],
20+
includes = ["include"],
21+
visibility = ["//visibility:public"],
22+
alwayslink = True,
23+
)
24+
]=])

docs/mkdocs/docs/integration/package_managers.md

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ If you are using the [Meson Build System](http://mesonbuild.com), add this sourc
6262

6363
The provided `meson.build` can also be used as an alternative to cmake for installing `nlohmann_json` system-wide in which case a pkg-config file is installed. To use it, simply have your build system require the `nlohmann_json` pkg-config dependency. In Meson, it is preferred to use the [`dependency()`](https://mesonbuild.com/Reference-manual.html#dependency) object with a subproject fallback, rather than using the subproject directly.
6464

65+
## Bazel
66+
67+
This repository provides a [Bazel](https://bazel.build/) `WORKSPACE.bazel` and a corresponding `BUILD.bazel` file. Therefore, this repository can be referenced by workspace rules such as `http_archive`, `git_repository`, or `local_repository` from other Bazel workspaces. To use the library you only need to depend on the target `@nlohmann_json//:json` (e.g. via `deps` attribute).
68+
6569
## Conan
6670

6771
If you are using [Conan](https://www.conan.io/) to manage your dependencies, merely add `nlohmann_json/x.y.z` to your `conanfile`'s requires, where `x.y.z` is the release version you want to use. Please file issues [here](https://github.com/conan-io/conan-center-index/issues) if you experience problems with the packages.

0 commit comments

Comments
 (0)