update examples

This commit is contained in:
Lars Melchior
2019-05-19 19:03:56 +02:00
committed by GitHub
parent 530fc8d42f
commit e0bfe05874
4 changed files with 47 additions and 2 deletions

View File

@@ -128,7 +128,6 @@ CPMAddPackage(
NAME lua
GIT_REPOSITORY https://github.com/lua/lua.git
VERSION 5-3-4
GIT_SHALLOW YES
DOWNLOAD_ONLY YES
)

View File

@@ -19,7 +19,6 @@ CPMAddPackage(
GIT_REPOSITORY https://github.com/onqtam/doctest.git
VERSION 2.3.2
GIT_TAG 2.3.2
GIT_SHALLOW True
)
# ---- Create binary ----

View File

@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
# ---- Dependencies ----
include(../../cmake/CPM.cmake)
CPMAddPackage(
NAME nlohmann_json
VERSION 3.6.1
# not using the git as it takes forever to clone
URL https://github.com/nlohmann/json/releases/download/v3.6.1/include.zip
URL_HASH SHA256=69cc88207ce91347ea530b227ff0776db82dcb8de6704e1a3d74f4841bc651cf
)
add_library(nlohmann_json INTERFACE)
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR})
# ---- Executable ----
add_executable(CPMJSONExample "main.cpp")
set_target_properties(CPMJSONExample PROPERTIES CXX_STANDARD 17)
target_link_libraries(CPMJSONExample nlohmann_json)

25
examples/json/main.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include <nlohmann/json.hpp>
#include <iostream>
#include <iomanip>
int main(){
nlohmann::json json = {
{"pi", 3.141},
{"happy", true},
{"name", "Niels"},
{"nothing", nullptr},
{"answer", {
{"everything", 42}
}},
{"list", {1, 0, 2}},
{"object", {
{"currency", "USD"},
{"value", 42.99}
}}
};
std::cout << "declared JSON object: " << std::setw(2) << json << std::endl;
return 0;
}