-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
jsoncons recipe #16256
Changes from 4 commits
b8f4987
436f851
96000c1
d83d176
76ba9f6
1a68dff
08a7463
30ce285
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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" | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They shouldnt be used anyways :) Wasnt a blocker in my head |
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) |
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") |
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"; | ||
} |
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) |
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.169.0": | ||
folder: "all" |
There was a problem hiding this comment.
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 🙏