Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsoncons recipe #16256

Merged
merged 8 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/jsoncons/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.169.0":
url: "https://github.com/danielaparker/jsoncons/archive/refs/tags/v0.169.0.tar.gz"
sha256: 423dc99d6950056fb55782513daf74adf37501eaf01b977b2415873cd0c44243
43 changes: 43 additions & 0 deletions recipes/jsoncons/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from conan import ConanFile
from conan.tools.files import get, copy
from conan.tools.layout import basic_layout
import os

required_conan_version = ">=1.50.0"


class JsonconsConan(ConanFile):
name = "jsoncons"
description = "A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON"
topics = ("json", "csv", "cpp", "json-serialization", "cbor", "json-parser", "messagepack", "json-pointer", "json-patch", "json-diff", "bson", "ubjson", "json-parsing", "jsonpath", "jmespath", "csv-parser", "csv-reader", "jsonschema", "json-construction", "streaming-json-read")
homepage = "https://github.com/danielaparker/jsoncons"
url = "https://github.com/danielaparker/jsoncons"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run this locally with the hooks enabled 🙏

author = "Daniel Parker [email protected]"
license = "Boost Software License"
IronTony-Stark marked this conversation as resolved.
Show resolved Hide resolved
no_copy_source = True

def layout(self):
basic_layout(self, src_folder="src")

def source(self):
get(
self,
url=f"https://github.com/danielaparker/jsoncons/archive/refs/tags/v{self.version}.tar.gz",
IronTony-Stark marked this conversation as resolved.
Show resolved Hide resolved
destination=self.source_folder,
strip_root=True
)

def package(self):
copy(self, pattern="LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, pattern="*", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))

def package_id(self):
self.info.header_only()

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "jsoncons")
self.cpp_info.set_property("cmake_target_name", "jsoncons")

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.names["cmake_find_package"] = "jsoncons"
self.cpp_info.names["cmake_find_package_multi"] = "jsoncons"
Comment on lines +42 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake_find_package and cmake_find_package_multi are obviously broken here, no one noticed that?

Copy link
Contributor

@prince-chrismc prince-chrismc Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They shouldnt be used anyways :) Wasnt a blocker in my head

8 changes: 8 additions & 0 deletions recipes/jsoncons/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

find_package(jsoncons CONFIG REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncons)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
26 changes: 26 additions & 0 deletions recipes/jsoncons/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout

required_conan_version = ">=1.50.0"

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
self.run(os.path.join(self.cpp.build.bindirs[0], "test_package"), env="conanrun")
49 changes: 49 additions & 0 deletions recipes/jsoncons/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <jsoncons/json.hpp>
#include <jsoncons_ext/jsonpath/jsonpath.hpp>
#include <iostream>

using namespace jsoncons; // for convenience

std::string data = R"(
{
"application": "hiking",
"reputons": [
{
"rater": "HikingAsylum",
"assertion": "advanced",
"rated": "Marilyn C",
"rating": 0.90,
"generated": 1514862245
}
]
}
)";

int main()
{
// Parse the string of data into a json value
json j = json::parse(data);

// Does object member reputons exist?
std::cout << "(1) " << std::boolalpha << j.contains("reputons") << "\n\n";

// Get a reference to reputons array
const json& v = j["reputons"];

// Iterate over reputons array
std::cout << "(2)\n";
for (const auto& item : v.array_range())
{
// Access rated as string and rating as double
std::cout << item["rated"].as<std::string>() << ", " << item["rating"].as<double>() << "\n";
}
std::cout << "\n";

// Select all "rated" with JSONPath
std::cout << "(3)\n";
json result = jsonpath::json_query(j,"$..rated");
std::cout << pretty_print(result) << "\n\n";

// Serialize back to JSON
std::cout << "(4)\n" << pretty_print(j) << "\n\n";
}
11 changes: 11 additions & 0 deletions recipes/jsoncons/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(jsoncons CONFIG REQUIRED)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncons::jsoncons)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
17 changes: 17 additions & 0 deletions recipes/jsoncons/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
3 changes: 3 additions & 0 deletions recipes/jsoncons/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.169.0":
folder: "all"