88.9. nlohmann-json-3.12.0
JSON for Modern C++, header-only
| Version | 3.12.0, release 1 |
| Shelf | formats — Data-format and serialisation libraries (XML, JSON, YAML, TOML, INI, RDF, protobuf, thrift), plus data query and convert tools |
| Phase | 41_system (System), 271 of 1047 in build order |
| Licence | MIT |
| Homepage | https://github.com/nlohmann/json |
| Build time | 0.1 SBU |
| Installed size | 937.8 KiB in 51 files |
| Recipe | ports/core/formats/nlohmann-json/kpkgbuild |
About
JSON for Modern C++, by Niels Lohmann, is a header-only C++ library that makes a JSON value behave like an STL container: json j = json::parse(text); j["key"] = 1;. Among the tree’s C++ programs fcitx5, imhex, amiberry, avogadrolibs and many others name it in depends. The package is headers, a CMake package configuration (nlohmann_json::nlohmann_json) and a pkg-config file; nothing is compiled.
Sources
nlohmann-json-3.12.0.tar.xz(111.9 KiB)
sha25642f6e95cad6ec532fd372391373363b62a14af6d771056dbfc86160e6dfff7aa
upstream: https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz
archive copy: sources-2/formats--nlohmann-json-3.12.0.tar.xz
Dependencies
Depends on: cmake.
Required by (20): amiberry, avogadrolibs, coolprop, fcitx5, fcitx5-chinese-addons, ifcopenshell, imhex, kddockwidgets, libsigmf, mkvtoolnix, mtxclient, mumble, musescore, nheko, obs-studio, openrct2, proj, prusaslicer, qgis, vtk.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install nlohmann-json'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/formats/nlohmann-json.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/formats/nlohmann-json
echo '42f6e95cad6ec532fd372391373363b62a14af6d771056dbfc86160e6dfff7aa nlohmann-json-3.12.0.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/nlohmann-json
SRC=$SRC_ROOT/nlohmann-json-3.12.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf nlohmann-json-3.12.0.tar.xz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
cmake -S . -B build -G Ninja \
-D CMAKE_INSTALL_PREFIX=/usr \
-D CMAKE_BUILD_TYPE=Release \
-D JSON_BuildTests=OFF \
-Wno-dev
DESTDIR=$PKG cmake --install build
The switches, and why each is set:
-D JSON_BuildTests=OFF— Do not configure the unit tests. They default to on when the library is the top-level project, and the release tarball (json.tar.xz) carries notests/directory, so with them on configure stops at the missingadd_subdirectory(tests).-Wno-dev— Silences CMake’s warnings meant for the project’s own developers.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/nlohmann-json, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf nlohmann-json-3.12.0-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/nlohmann-json, and runs the triggers its paths call for.
Contents
Installed directories: /usr/include/nlohmann/detail, /usr/include/nlohmann/thirdparty, /usr/share/cmake/nlohmann_json, /usr/share/licenses/nlohmann-json.
Short descriptions
nlohmann_json.pc |
JSON for Modern C++ |
Notes
There is no build step: build.sh configures and then runs cmake --install directly, which copies the headers from include/ (upstream’s multiple-header layout, its default) and writes the CMake and pkg-config files.
The release tarball’s top directory is json/, not nlohmann-json-<version>; kpkg strips the one wrapping directory whatever its name.