Skip to content

Commit

Permalink
(#24262) reflect-cpp: add option for using with msgpack
Browse files Browse the repository at this point in the history
* reflect-cpp: add option for using with msgpack

* reflect-cpp: fix with_msgpack option

---------

Co-authored-by: Luis Caro Campos <3535649+jcar87@users.noreply.github.com>
  • Loading branch information
uyha and jcar87 authored Jun 13, 2024
1 parent bf4fe25 commit 5f5ee4d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 34 deletions.
4 changes: 4 additions & 0 deletions recipes/reflect-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ class ReflectCppConan(ConanFile):
"with_xml" : [True, False],
"with_flatbuffers" : [True, False],
"with_yaml": [True, False],
"with_msgpack": [True, False],
}
default_options = {
"with_json" : False,
"with_xml" : False,
"with_flatbuffers" : False,
"with_yaml" : False,
"with_msgpack": False,
}

@property
Expand Down Expand Up @@ -56,6 +58,8 @@ def requirements(self):
self.requires("flatbuffers/23.5.26", transitive_headers=True)
if self.options.with_yaml:
self.requires("yaml-cpp/0.8.0", transitive_headers=True)
if self.options.with_msgpack:
self.requires("msgpack-c/6.0.0", transitive_headers=True)

def package_id(self):
self.info.clear()
Expand Down
10 changes: 5 additions & 5 deletions recipes/reflect-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.12)
project(test_package LANGUAGES CXX)

if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(reflect-cpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE reflect-cpp::reflect-cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)

if(CONAN_TEST_WITH_MSGPACK)
target_compile_definitions(${PROJECT_NAME} PRIVATE CONAN_TEST_WITH_MSGPACK)
endif()
10 changes: 8 additions & 2 deletions recipes/reflect-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def generate(self):
tc = CMakeToolchain(self)
if self.dependencies[self.tested_reference_str].options.with_msgpack:
tc.cache_variables["CONAN_TEST_WITH_MSGPACK"] = True
tc.generate()

def build(self):
cmake = CMake(self)
Expand Down
14 changes: 14 additions & 0 deletions recipes/reflect-cpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include <string>
#include <iostream>
#include <rfl.hpp>

#if defined(CONAN_TEST_WITH_MSGPACK)
#include <rfl/msgpack.hpp>
#endif

struct TestStruct {
int x;
std::string name;
Expand All @@ -11,5 +16,14 @@ int main(void) {
(void) f.name();
(void) f.type();
}

#if defined(CONAN_TEST_WITH_MSGPACK)
const auto test = TestStruct{.x = 15, .name = "test_package"};
std::cout << "msgpack test: ";
rfl::msgpack::write(test, std::cout) << std::endl;
#endif

std::cout << "reflect-cpp test successful\n";

return 0;
}
9 changes: 0 additions & 9 deletions recipes/reflect-cpp/all/test_v1_package/CMakeLists.txt

This file was deleted.

18 changes: 0 additions & 18 deletions recipes/reflect-cpp/all/test_v1_package/conanfile.py

This file was deleted.

0 comments on commit 5f5ee4d

Please sign in to comment.