diff --git a/recipes/jsoncons/all/conandata.yml b/recipes/jsoncons/all/conandata.yml new file mode 100644 index 0000000000000..522f8707b0c51 --- /dev/null +++ b/recipes/jsoncons/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "0.169.0": + url: "https://github.com/danielaparker/jsoncons/archive/refs/tags/v0.169.0.tar.gz" + sha256: 423dc99d6950056fb55782513daf74adf37501eaf01b977b2415873cd0c44243 diff --git a/recipes/jsoncons/all/conanfile.py b/recipes/jsoncons/all/conanfile.py new file mode 100644 index 0000000000000..32d3c9bc0d9c9 --- /dev/null +++ b/recipes/jsoncons/all/conanfile.py @@ -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" diff --git a/recipes/jsoncons/all/test_package/CMakeLists.txt b/recipes/jsoncons/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..a15fe60ff614b --- /dev/null +++ b/recipes/jsoncons/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/jsoncons/all/test_package/conanfile.py b/recipes/jsoncons/all/test_package/conanfile.py new file mode 100644 index 0000000000000..a803ae0923ba5 --- /dev/null +++ b/recipes/jsoncons/all/test_package/conanfile.py @@ -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") diff --git a/recipes/jsoncons/all/test_package/test_package.cpp b/recipes/jsoncons/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..c0ab09763124a --- /dev/null +++ b/recipes/jsoncons/all/test_package/test_package.cpp @@ -0,0 +1,49 @@ +#include +#include +#include + +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() << ", " << item["rating"].as() << "\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"; +} diff --git a/recipes/jsoncons/all/test_v1_package/CMakeLists.txt b/recipes/jsoncons/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..2e4adc0eddf16 --- /dev/null +++ b/recipes/jsoncons/all/test_v1_package/CMakeLists.txt @@ -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) diff --git a/recipes/jsoncons/all/test_v1_package/conanfile.py b/recipes/jsoncons/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..8037a9296cc42 --- /dev/null +++ b/recipes/jsoncons/all/test_v1_package/conanfile.py @@ -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) diff --git a/recipes/jsoncons/config.yml b/recipes/jsoncons/config.yml new file mode 100644 index 0000000000000..0354650b51267 --- /dev/null +++ b/recipes/jsoncons/config.yml @@ -0,0 +1,3 @@ +versions: + "0.169.0": + folder: "all"