2017-09-18 15:33:32 +00:00
|
|
|
include(ExternalProject)
|
|
|
|
|
|
|
|
if (${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
|
|
|
|
set(JSONCPP_CMAKE_COMMAND emcmake cmake)
|
|
|
|
else()
|
|
|
|
set(JSONCPP_CMAKE_COMMAND ${CMAKE_COMMAND})
|
|
|
|
endif()
|
|
|
|
|
2023-06-09 16:21:55 +00:00
|
|
|
set(prefix "${PROJECT_BINARY_DIR}/deps")
|
2018-06-06 06:03:07 +00:00
|
|
|
set(JSONCPP_LIBRARY "${prefix}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}jsoncpp${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
2017-09-18 15:33:32 +00:00
|
|
|
set(JSONCPP_INCLUDE_DIR "${prefix}/include")
|
|
|
|
|
2018-08-03 14:50:08 +00:00
|
|
|
# TODO: Investigate why this breaks some emscripten builds and
|
|
|
|
# check whether this can be removed after updating the emscripten
|
|
|
|
# versions used in the CI runs.
|
|
|
|
if(EMSCRIPTEN)
|
|
|
|
# Do not include all flags in CMAKE_CXX_FLAGS for emscripten,
|
2019-08-09 09:28:22 +00:00
|
|
|
# but only use -std=c++17. Using all flags causes build failures
|
2018-08-03 14:50:08 +00:00
|
|
|
# at the moment.
|
2019-08-09 09:28:22 +00:00
|
|
|
set(JSONCPP_CXX_FLAGS -std=c++17)
|
2018-08-03 14:50:08 +00:00
|
|
|
else()
|
2019-08-15 13:41:40 +00:00
|
|
|
# jsoncpp uses implicit casts for comparing integer and
|
|
|
|
# floating point numbers. This causes clang-10 (used by ossfuzz builder)
|
|
|
|
# to error on the implicit conversions. Here, we request jsoncpp
|
|
|
|
# to unconditionally use static casts for these conversions by defining the
|
|
|
|
# JSON_USE_INT64_DOUBLE_CONVERSION preprocessor macro. Doing so,
|
|
|
|
# not only gets rid of the implicit conversion error that clang-10 produces
|
|
|
|
# but also forces safer behavior in general.
|
|
|
|
set(JSONCPP_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJSON_USE_INT64_DOUBLE_CONVERSION")
|
2018-04-17 08:50:03 +00:00
|
|
|
endif()
|
|
|
|
|
2017-09-18 15:33:32 +00:00
|
|
|
set(byproducts "")
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER 3.1)
|
|
|
|
set(byproducts BUILD_BYPRODUCTS "${JSONCPP_LIBRARY}")
|
|
|
|
endif()
|
|
|
|
|
2020-09-15 12:16:22 +00:00
|
|
|
# Propagate CMAKE_MSVC_RUNTIME_LIBRARY on Windows builds, if set.
|
|
|
|
if (WIN32 AND POLICY CMP0091 AND CMAKE_MSVC_RUNTIME_LIBRARY)
|
|
|
|
list(APPEND JSONCPP_CMAKE_ARGS "-DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW")
|
|
|
|
list(APPEND JSONCPP_CMAKE_ARGS "-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}")
|
|
|
|
endif()
|
|
|
|
|
2017-09-18 15:33:32 +00:00
|
|
|
ExternalProject_Add(jsoncpp-project
|
|
|
|
PREFIX "${prefix}"
|
2023-06-08 11:03:59 +00:00
|
|
|
DOWNLOAD_DIR "${PROJECT_SOURCE_DIR}/deps/downloads"
|
2020-07-10 17:42:24 +00:00
|
|
|
DOWNLOAD_NAME jsoncpp-1.9.3.tar.gz
|
|
|
|
URL https://github.com/open-source-parsers/jsoncpp/archive/1.9.3.tar.gz
|
|
|
|
URL_HASH SHA256=8593c1d69e703563d94d8c12244e2e18893eeb9a8a9f8aa3d09a327aa45c8f7d
|
2017-09-18 15:33:32 +00:00
|
|
|
CMAKE_COMMAND ${JSONCPP_CMAKE_COMMAND}
|
|
|
|
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
|
|
|
|
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
2018-06-06 06:03:07 +00:00
|
|
|
-DCMAKE_INSTALL_LIBDIR=lib
|
2017-09-18 15:33:32 +00:00
|
|
|
# Build static lib but suitable to be included in a shared lib.
|
|
|
|
-DCMAKE_POSITION_INDEPENDENT_CODE=${BUILD_SHARED_LIBS}
|
2020-07-10 17:42:24 +00:00
|
|
|
-DJSONCPP_WITH_EXAMPLE=OFF
|
2017-09-18 15:33:32 +00:00
|
|
|
-DJSONCPP_WITH_TESTS=OFF
|
|
|
|
-DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF
|
2018-08-03 14:50:08 +00:00
|
|
|
-DCMAKE_CXX_FLAGS=${JSONCPP_CXX_FLAGS}
|
2018-07-10 13:12:32 +00:00
|
|
|
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
2020-09-15 12:16:22 +00:00
|
|
|
${JSONCPP_CMAKE_ARGS}
|
2017-09-18 15:33:32 +00:00
|
|
|
${byproducts}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Create jsoncpp imported library
|
|
|
|
add_library(jsoncpp STATIC IMPORTED)
|
|
|
|
file(MAKE_DIRECTORY ${JSONCPP_INCLUDE_DIR}) # Must exist.
|
|
|
|
set_property(TARGET jsoncpp PROPERTY IMPORTED_LOCATION ${JSONCPP_LIBRARY})
|
2018-12-17 12:42:48 +00:00
|
|
|
set_property(TARGET jsoncpp PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${JSONCPP_INCLUDE_DIR})
|
2017-09-18 15:33:32 +00:00
|
|
|
set_property(TARGET jsoncpp PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${JSONCPP_INCLUDE_DIR})
|
|
|
|
add_dependencies(jsoncpp jsoncpp-project)
|