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

json_struct receipt #25335

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/json_struct/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
42 changes: 42 additions & 0 deletions recipes/json_struct/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.files import get, copy
from conan.tools.layout import basic_layout
import os

required_conan_version = ">=1.52.0"

class JsonStructConan(ConanFile):
name = "json_struct"
description = "json_struct is a single header only C++ library for parsing JSON directly to C++ structs and vice versa"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/jorgen/json_struct"

topics = ("serialization", "deserialization", "reflection", "json")

settings = "os", "compiler", "build_type", "arch"
package_type = "header-library"
no_copy_source = True

def validate(self):
check_min_cppstd(self, 14)

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

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

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

# Copy all files to the package folder
def package(self):
copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(
self,
"*.h",
os.path.join(self.source_folder, "include"),
os.path.join(self.package_folder, "include"),
)
12 changes: 12 additions & 0 deletions recipes/json_struct/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)
28 changes: 28 additions & 0 deletions recipes/json_struct/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")

21 changes: 21 additions & 0 deletions recipes/json_struct/all/test_package/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "json_struct/json_struct.h"
#include <iostream>

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;
}
3 changes: 3 additions & 0 deletions recipes/json_struct/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.2":
folder: all