-
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
Merged
Merged
jsoncons recipe #16256
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b8f4987
jsoncons
IronTony-Stark 436f851
Fixed imports
IronTony-Stark 96000c1
layout src_folder=src
IronTony-Stark d83d176
Fixed get
IronTony-Stark 76ba9f6
Fixed build and other improvements
IronTony-Stark 1a68dff
Merge branch 'conan-io:master' into jsoncons
IronTony-Stark 08a7463
Added settings
IronTony-Stark 30ce285
More fixes
IronTony-Stark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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" | ||
license = "BSL-1.0" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/danielaparker/jsoncons" | ||
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", "header-only") | ||
settings = "os", "arch", "compiler", "build_type" | ||
no_copy_source = True | ||
|
||
def layout(self): | ||
basic_layout(self, src_folder="src") | ||
|
||
def package_id(self): | ||
self.info.clear() | ||
|
||
def source(self): | ||
get( | ||
self, | ||
**self.conan_data["sources"][self.version], | ||
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_info(self): | ||
# Folders not used for header-only | ||
self.cpp_info.bindirs = [] | ||
self.cpp_info.libdirs = [] | ||
|
||
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" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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): | ||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from conans import ConanFile, CMake | ||
from conan.tools.build import cross_building | ||
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 cross_building(self): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.169.0": | ||
folder: "all" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 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