mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-17 06:37:43 -05:00
update examples
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -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 ----
|
||||
|
||||
22
examples/json/CMakeLists.txt
Normal file
22
examples/json/CMakeLists.txt
Normal 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
25
examples/json/main.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user