我要评分
获取效率
正确性
完整性
易理解

Installation Guide

This document describes how to compile and install the RapidJSON optimized for Kunpeng.

Environment Requirements

Software Version Requirement Description
OS openEuler 22.03 LTS SP3 Linux distribution
Compiler Clang 16.0.6 or later
GCC 9.0 or later
C++03 or later. C++11 or later is recommended.
CMake 3.5 or later Build tool
Git 2.0 or later Version control
Doxygen 1.8 or later (optional) Documentation generator tool

Obtaining Code

  1. Run the following commands to obtain code:

    git clone -b dev https://gitcode.com/boostkit/rapidjson.git
    cd rapidjson
  2. If integrating the optimization via a patch, you can first obtain the upstream RapidJSON source code and then apply the optimization patch from the master branch.

    git clone https://github.com/Tencent/rapidjson.git
    cd rapidjson
    git checkout 24b5e7a
    git apply /path/to/kunpeng_opti_v1.0.0.patch

Compilation and Installation

  1. Create a custom installation directory. You can change the directory as required.

    mkdir -p /path/to/install/rapidjson-bin
    export RAPIDJSON_INSTALL_DIR=/path/to/install/rapidjson-bin
  2. Configure the build.

    1. Create a build directory.

      mkdir build
      cd build
    2. Configure and build. RapidJSON is a header-only library, so the installation primarily copies header files and CMake configurations.

      cmake -DCMAKE_BUILD_TYPE=Release \
            -DCMAKE_CXX_FLAGS="-O3" \
            -DCMAKE_INSTALL_PREFIX=${RAPIDJSON_INSTALL_DIR} \
            ..
  3. Perform compilation.

    • Use all available CPU cores for parallel compilation.

      cmake --build . --parallel $(nproc)
    • Alternatively, specify the number of cores (for example, 32 cores).

      cmake --build . --parallel 32
  4. Start installation.

    cmake --install .
  5. Verify the installation directory.

    ls -la ${RAPIDJSON_INSTALL_DIR}

    Command output:

    total 16
    drwxr-xr-x.  4 user user 4096 May 30 12:19 .
    drwxr-xr-x. 33 user user 4096 May 30 16:39 ..
    drwxr-xr-x.  3 user user 4096 May 30 12:19 include
    drwxr-xr-x.  3 user user 4096 May 30 12:19 lib
  6. Check the header files.

    ls -la ${RAPIDJSON_INSTALL_DIR}/include/rapidjson

    Command output:

    -rw-r--r--. 1 user user  ... document.h
    -rw-r--r--. 1 user user  ... reader.h
    -rw-r--r--. 1 user user  ... writer.h
    -rw-r--r--. 1 user user  ... stringbuffer.h

Compilation Option Description

Common CMake Options

Option Default Value Description
-DRAPIDJSON_BUILD_DOC OFF Specifies whether to build documentation.
-DRAPIDJSON_BUILD_EXAMPLES ON Specifies whether to build examples.
-DRAPIDJSON_BUILD_TESTS ON Specifies whether to build tests.
-DCMAKE_BUILD_TYPE Release Specifies the build type (Release or Debug).
-DCMAKE_CXX_FLAGS - Specifies additional compilation flags (-O3 recommended).

Performance Optimization Compilation Flag

Recommended compilation flag for the Arm architecture (Kunpeng processors).

cmake -DCMAKE_CXX_FLAGS="-O3 -march=armv8.2-a" ..

# Enables the NEON string scan path (typically available by default on AArch64).
cmake -DCMAKE_CXX_FLAGS="-O3 -march=armv8.2-a+simd -DRAPIDJSON_NEON" ..

Running Test

  1. Ensure you are in the build directory.

    • If the directory is not in the build directory, run the following command to go to the build directory.

      cd build
    • If the directory is already in the build directory, go to the next step.

  2. Select any of the following methods:

    • Run all tests.
    ctest --verbose
    • Run a specific test.
    ctest -R unittest
    • Run tests in parallel.
    ctest --parallel $(nproc)