From dcc3c7dfe2aca748e5ad721c93a663bfe397def2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Fri, 13 Sep 2024 18:26:51 +0200 Subject: [PATCH] json_struct receipt --- recipes/json_struct/all/conandata.yml | 4 ++ recipes/json_struct/all/conanfile.py | 67 +++++++++++++++++++ .../all/test_package/CMakeLists.txt | 11 +++ .../json_struct/all/test_package/conanfile.py | 28 ++++++++ recipes/json_struct/all/test_package/main.cpp | 21 ++++++ recipes/json_struct/config.yml | 3 + 6 files changed, 134 insertions(+) create mode 100644 recipes/json_struct/all/conandata.yml create mode 100644 recipes/json_struct/all/conanfile.py create mode 100644 recipes/json_struct/all/test_package/CMakeLists.txt create mode 100644 recipes/json_struct/all/test_package/conanfile.py create mode 100644 recipes/json_struct/all/test_package/main.cpp create mode 100644 recipes/json_struct/config.yml diff --git a/recipes/json_struct/all/conandata.yml b/recipes/json_struct/all/conandata.yml new file mode 100644 index 00000000000000..31102ff6a0fa4b --- /dev/null +++ b/recipes/json_struct/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.0.2": + url: "https://github.com/jorgen/json_struct/archive/refs/tags/1.0.2.tar.gz" + sha256: "c424ae3e8dbe6846311cb878d2d400c98a297a28eb1556961a985b6ed7b16090" diff --git a/recipes/json_struct/all/conanfile.py b/recipes/json_struct/all/conanfile.py new file mode 100644 index 00000000000000..e3db0e5755a5a3 --- /dev/null +++ b/recipes/json_struct/all/conanfile.py @@ -0,0 +1,67 @@ +from conan import ConanFile +from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout +from conan.tools.env import VirtualBuildEnv, VirtualRunEnv +from conan.tools.scm import Git, Version +from conan.tools.files import copy, get + +import os + +class JsonStructLibrary(ConanFile): + name = "json_struct" + + # Metadata + license = "MIT" + version = "1.0.2" + author = "Jørgen Lind " + url = "https://github.com/jorgen/json_struct" + description = "json_struct is a single header only C++ library for parsing JSON directly to C++ structs and vice versa" + + topics = ("serialization", "deserialization", "reflection", "json") + + settings = "os", "compiler", "build_type", "arch" + pacgake_type = "header-library" + implements = ["auto_header_only"] + exports_sources = "include/*", "cmake/*", "CMakeLists.txt", "COPYING", "README.md", "package.xml" + + options = { + "opt_build_benchmarks": [True, False], + "opt_build_examples": [True, False], + "opt_build_tests": [True, False], + "opt_disable_pch": [True, False], + "opt_install": [True, False], + } + + default_options = { + "opt_build_benchmarks": False, + "opt_build_examples": False, + "opt_build_tests": False, + "opt_disable_pch": False, + "opt_install": True, + } + + def generate(self): + toolchain = CMakeToolchain(self) + + toolchain.variables["JSON_STRUCT_OPT_BUILD_BENCHMARKS"] = self.options.opt_build_benchmarks.value + toolchain.variables["JSON_STRUCT_OPT_BUILD_EXAMPLES"] = self.options.opt_build_examples.value + toolchain.variables["JSON_STRUCT_OPT_BUILD_TESTS"] = self.options.opt_build_tests.value + toolchain.variables["JSON_STRUCT_OPT_DISABLE_PCH"] = self.options.opt_disable_pch.value + toolchain.variables["JSON_STRUCT_OPT_INSTALL"] = self.options.opt_install + + toolchain.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + # Invoke cmake --install + cmake = CMake(self) + cmake.install() + + def layout(self): + cmake_layout(self) + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) diff --git a/recipes/json_struct/all/test_package/CMakeLists.txt b/recipes/json_struct/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..889a2933058e68 --- /dev/null +++ b/recipes/json_struct/all/test_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.15) + +project(JsonStructTester + DESCRIPTION "Tester package for json_struct" + LANGUAGES C CXX) + +find_package(json_struct REQUIRED) + +add_executable(${PROJECT_NAME} main.cpp) + +target_link_libraries(${PROJECT_NAME} json_struct::json_struct) diff --git a/recipes/json_struct/all/test_package/conanfile.py b/recipes/json_struct/all/test_package/conanfile.py new file mode 100644 index 00000000000000..f0d4e6b76d5797 --- /dev/null +++ b/recipes/json_struct/all/test_package/conanfile.py @@ -0,0 +1,28 @@ +import os + +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout +from conan.tools.build import can_run + + +class JsonStructTest(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeDeps", "CMakeToolchain" + + def requirements(self): + self.requires(self.tested_reference_str) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def layout(self): + cmake_layout(self) + + def test(self): + if can_run(self): + self.output.info("Checking compiled tester...") + cmd = os.path.join(self.cpp.build.bindir, "JsonStructTester") + self.run(cmd, env="conanrun") + diff --git a/recipes/json_struct/all/test_package/main.cpp b/recipes/json_struct/all/test_package/main.cpp new file mode 100644 index 00000000000000..a61797c693d60e --- /dev/null +++ b/recipes/json_struct/all/test_package/main.cpp @@ -0,0 +1,21 @@ +#include "json_struct/json_struct.h" +#include + +struct MyTestStruct +{ + std::string name; + unsigned age; + JS_OBJ(name, age); +}; + +int main() +{ + MyTestStruct person; + person.name="Jonh"; + person.age=23; + + std::string person_json = JS::serializeStruct(person); + std::cout << person_json << std::endl; + + return 0; +} diff --git a/recipes/json_struct/config.yml b/recipes/json_struct/config.yml new file mode 100644 index 00000000000000..8457ca9a4a8cd8 --- /dev/null +++ b/recipes/json_struct/config.yml @@ -0,0 +1,3 @@ +versions: + "1.0.2": + folder: all