-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Building and Testing
Thanks to David Seifert (@SoapGentoo), the maintainers now use Meson and Ninja to build for debugging, as well as for continuous integration (see meson.yml). Other systems may work, but minor things like version strings might break.
First, install both Meson and Ninja (both require Python 3):
# Install Meson
pip install meson
# Install Ninja
pip install ninjaThen, configure and build the project:
cd jsoncpp/
BUILD_TYPE=release # plain, debug, debugoptimized, release, minsize
LIB_TYPE=shared # shared, static
meson setup --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} build-${LIB_TYPE} .
ninja -v -C build-${LIB_TYPE} testDeprecated: Still functional, but the version string may be inaccurate.
CMake is a C++ Makefiles/Solution generator. It is usually available on most Linux systems as a package. On Ubuntu:
sudo apt-get install cmakeNote: Python is 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:
- Build Directory: Where the makefiles/solution are generated. Used to store objects, libraries, and executables.
- Generator: Makefiles or Visual Studio solution? 32-bit or 64-bit?
- Set "Where is the source code" to the source directory.
- Set "Where to build the binaries" to the build directory.
- Check the "Grouped" box.
- Review JsonCpp build options (check
BUILD_SHARED_LIBSto build as a dynamic library). - Click Configure, then Generate.
- The generated solution/makefiles can be found in the binary directory.
From 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" ../..
makeFor a proper pkg-config file, add:
-DCMAKE_INSTALL_INCLUDEDIR=include/jsoncpp- Run
cmake -hto see the list of available generators (passed using the-Goption). - By default, CMake hides compilation commands. To see them, add
-DCMAKE_VERBOSE_MAKEFILE=truewhen generating makefiles.
When building the solution file on Visual Studio, it may try to run the tests. If you build a DLL of jsoncpp, it must be installed or copied into the output directory containing jsontestrunner_exe.exe.
See Issue #455.
The jsoncppConfig.cmake file defines the INTERFACE_INCLUDE_DIRECTORIES property for the jsoncpp_lib and jsoncpp_lib_static targets. 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)Package manager ports (like Conan and vcpkg) are community-maintained. We do not provide official support or documentation for them. Please refer to their respective repositories and documentation for instructions, and report any issues directly to those communities.
Instructions for using Bazel can be found in the Bazel Central Registry.
On macOS, the Meson and Ninja instructions above are the most straightforward way to build the libraries.
If you are compiling and running the examples manually, the following command line may be helpful:
g++ readFromString.cpp -ljsoncpp -std=c++11 -o readFromString -L../../build-shared -Wl,-rpath,../../build-sharedIncluding -Wl,-rpath,../../build-shared prevents runtime linking errors caused by missing LC_RPATH configurations.