support compiling against system json library #1858

Closed
rathann opened this Issue Jan 19, 2017 · 8 comments

Projects

None yet

2 participants

@rathann
Contributor
rathann commented Jan 19, 2017

In Fedora, we have Niels Lohmann's json library packaged system-wide, so it would be nice to have the option to compile mkvtoolnix using that version instead of the bundled one (mkvtoolnix-9.7.1/lib/nlohmann-json), assuming it's new enough. It looks like nlohman/json@54d3cab, which is what you have bundled, is included in 2.0.0+.

@mbunkus
Owner
mbunkus commented Jan 19, 2017

I wasn't aware that distributions had started packaging the library. I'll look into it. At the moment I'm using a slightly modified version, not the original code, but it should be possible to change that.

@mbunkus
Owner
mbunkus commented Jan 20, 2017

Meh, json.hpp doesn't provide anything to identify its version programmatically. Neither do the json-devel (Fedora) nor the nlohmann-json-dev (Ubuntu) packages provide a pkg-config file or something else that I could use in configure to detect the version. Oh well…

@mbunkus mbunkus added a commit that referenced this issue Jan 20, 2017
@mbunkus build system: look for & use system-wide version of nlohmann json-cpp
If one is found, it will be used. Otherwise the included version in
lib/nlohmann-json will be used.

Implements #1858.
e52f878
@mbunkus mbunkus closed this Jan 20, 2017
@rathann
Contributor
rathann commented Jan 21, 2017

That was very quick, thank you!

@mbunkus
Owner
mbunkus commented Jan 21, 2017

You're welcome.

@rathann
Contributor
rathann commented Jan 21, 2017

Looks like 2.0.11 will provide meta() with version information: nlohmann/json#397 .

@mbunkus
Owner
mbunkus commented Jan 21, 2017

Unfortunately that doesn't help me as I cannot use that function at configure time. I'd have to run a binary, and that doesn't work when cross-compiling. I'll just leave the current test in place and hope for the best…

@rathann
Contributor
rathann commented Jan 24, 2017

One more thing. The configure check fails to detect system json header on Fedora 23, because the default C++ standard is still -std=gnu++98 (gcc-5.3.1) and the minimum required for compiling the header is -std=c++11. GCC 6.x in Fedora 24+ uses -std=gnu++14, so it doesn't have this issue:

configure:7587: checking nlohmann's json-cpp
configure:7624: g++ -c -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic  conftest.cpp >&5
In file included from /usr/include/c++/5.3.1/cstdint:35:0,
                 from conftest.cpp:39:
/usr/include/c++/5.3.1/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
In file included from conftest.cpp:43:0:
/usr/include/json.hpp:108:12: error: 'constexpr' does not name a type
     static constexpr bool value = sizeof(test<T>(0)) == 1;
            ^
/usr/include/json.hpp:108:12: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
...

Moreover, support for -std=gnu++14 is getting detected earlier and is used during actual compilation. Why not during the check?

@mbunkus
Owner
mbunkus commented Jan 24, 2017

No particular reason. I just forgot to add it. As it worked just fine on all the Linux distros I provide binaries for I didn't notice it either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment