Skip to content
Christopher Dunn edited this page Aug 27, 2017 · 9 revisions

Building and testing with Meson/Ninja

Thanks to David Seifert (@SoapGentoo), we (the maintainers) now use meson and ninja to build for debugging, as well as for continuous integration (see travis.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=shared
#BUILD_TYPE=static
LIB_TYPE=debug
#LIB_TYPE=release
meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE}
ninja -v -C build-${LIB_TYPE} test

Building and testing with CMake

(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.

Building and testing with Conan

(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.

Clone this wiki locally