#############
# RapidJSON #
#############

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules/ ${CMAKE_MODULE_PATH})
include(FetchContent)
include(ExternalProject)
cmake_policy(SET CMP0079 NEW)

# Head of master as of 2020-07-14, as last release is ~500 commits behind head
FetchContent_Declare(
    rapidjson
    GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
    GIT_TAG        f56928de85d56add3ca6ae7cf7f119a42ee1585b
    GIT_PROGRESS   ON
    # UPDATE_DISCONNECTED   ON
)
FetchContent_GetProperties(rapidjson)
if(NOT rapidjson_POPULATED)
    FetchContent_Populate(rapidjson)
    # RapidJSON has custom RapidJSONConfig.cmake, generated by cmake configure/generate
    execute_process(
    COMMAND ${CMAKE_COMMAND} . -DRAPIDJSON_BUILD_DOC=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD_TESTS=OFF -DRAPIDJSON_BUILD_THIRDPARTY_GTEST=OFF -Wno-deprecated
    WORKING_DIRECTORY "${rapidjson_SOURCE_DIR}"
    OUTPUT_QUIET
    )
    set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${rapidjson_SOURCE_DIR}")
    find_package(RapidJSON REQUIRED)
    # Include path is ${RapidJSON_INCLUDE_DIRS}
endif()
