-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Building
Thanks to David Seifert (@SoapGentoo), we (the maintainers) now use meson and ninja to build for debugging, as well as for continuous integration (see meson_builder.sh
). Other systems may work, but minor things like version strings might break.
First, install both meson (which requires Python3) and ninja.
Then,
cd jsoncpp/
BUILD_TYPE=release
#plain, debug, debugoptimized, release, minsize
LIB_TYPE=shared
#LIB_TYPE=static
meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE}
ninja -v -C build-${LIB_TYPE} test
(Deprecated, but still works for now. The version string may soon be wrong.)
CMake is a C++ Makefiles/Solution generator. It is usually available on most Linux system as package. On Ubuntu:
sudo apt-get install cmake
Note that Python is also required to run the JSON reader/writer tests. If missing, the build will skip running those tests.
When running CMake, a few parameters are required:
- A build directory where the makefiles/solution are generated. It is also used to store objects, libraries and executables files.
- The generator to use: makefiles or Visual Studio solution? What version or Visual Studio, 32 or 64 bits solution?
Steps for generating solution/makefiles using cmake-gui
:
- Make "source code" point to the source directory.
- Make "where to build the binary" point to the directory to use for the build.
- Click on the "Grouped" check box.
- Review JsonCpp build options (tick
BUILD_SHARED_LIBS
to build as a dynamic library). - Click the configure button at the bottom, then the generate button.
- The generated solution/makefiles can be found in the binary directory.
Alternatively, from the command-line on Unix in the source directory:
mkdir -p build/debug
cd build/debug
cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DARCHIVE_INSTALL_DIR=. -G "Unix Makefiles" ../..
make
For a good pkg-config file, add:
-DCMAKE_INSTALL_INCLUDEDIR=include/jsoncpp
Running cmake -h
will display the list of available generators (passed using
the -G
option).
By default CMake hides compilation commands. This can be modified by specifying
-DCMAKE_VERBOSE_MAKEFILE=true
when generating makefiles.
When building the solution file on Visual Studio, it would try to run the tests. In this case, or when running the tests from the command line, if you build a DLL of jsoncpp, then it must be installed, or at least copied into the output directory holding jsontestrunner_exe.exe
The jsoncppConfig.cmake
defines property INTERFACE_INCLUDE_DIRECTORIES
for targets jsoncpp_lib
and jsoncpp_lib_static
.
You need to query the target property and set it manually:
get_target_property(JSON_INC_PATH jsoncpp_lib INTERFACE_INCLUDE_DIRECTORIES)
include_directories(${JSON_INC_PATH})
Linking is done via:
target_link_libraries(${PROJECT_NAME} jsoncpp_lib)
(This works, but it currently uses cmake
, which is deprecated.)
Conan is an open source package manager intended for C/C++ projects. It is cross platform and build system agnostic.
Conan requires Python for running, and can be installed using pip:
pip install conan
Detailed instructions can be found on conan docs.
For build jsoncpp with conan, you need to create a conanfile.txt or a conanfile.py. The first is simpler, but the second is more flexible.
This is a sample conanfile.txt:
[requires]
jsoncpp/1.8.0@theirix/ci
[generators]
cmake
Note: cmake is not required, you can use other integrations. Or you can set the appropriate environment variables, using virtualenv generators.
Then run the following command from the conanfile directory:
conan install --build missing
This will try to download the appropriate package for your settings (OS, compiler, architecture) from the recipe packages. If it is not found, the package will be built.
Note: you do not need to install cmake to build jsoncpp using conan, because the recipe will download it automatically.
If you need, you can customize the jsoncpp recipe. Just clone/fork it from github.
See integrations instructions for how to use your build system with conan.
No longer supported. But you might be able to recover it at commit at https://github.com/open-source-parsers/jsoncpp/commit/6d31cec7cf44dd7e14263f0ffbc888abf515d3dc .
To use specific JsonCpp version in your Bazel project, edit your WORKSPACE
file and add a http_archive
rule:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# ...
http_archive(
name = "jsoncpp",
# sha256 = "X.Y.Z.tar.gz SHA256",
strip_prefix = "jsoncpp-X.Y.Z",
urls = [
"https://github.com/open-source-parsers/jsoncpp/archive/X.Y.Z.tar.gz",
],
)
Replace X.Y.Z
with a correct version, and optionally specify archive file's SHA256 hash.
To get the code directly from a git repository, add a git_repository
instead:
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
# ...
git_repository(
name = "jsoncpp",
branch = "master",
remote = "https://github.com/open-source-parsers/jsoncpp.git",
)
In either case, add "@jsoncpp//:jsoncpp"
as a dependency to targets that use JsonCpp.