From 5f5ee4d7522079dee490f651ce9126a14e968d5d Mon Sep 17 00:00:00 2001 From: Beartama <8091245+uyha@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:51:52 +0300 Subject: [PATCH] (#24262) reflect-cpp: add option for using with msgpack * 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> --- recipes/reflect-cpp/all/conanfile.py | 4 ++++ .../all/test_package/CMakeLists.txt | 10 +++++----- .../reflect-cpp/all/test_package/conanfile.py | 10 ++++++++-- .../all/test_package/test_package.cpp | 14 ++++++++++++++ .../all/test_v1_package/CMakeLists.txt | 9 --------- .../all/test_v1_package/conanfile.py | 18 ------------------ 6 files changed, 31 insertions(+), 34 deletions(-) delete mode 100644 recipes/reflect-cpp/all/test_v1_package/CMakeLists.txt delete mode 100644 recipes/reflect-cpp/all/test_v1_package/conanfile.py diff --git a/recipes/reflect-cpp/all/conanfile.py b/recipes/reflect-cpp/all/conanfile.py index ddf0ede842e03..55a0bebdd34ed 100644 --- a/recipes/reflect-cpp/all/conanfile.py +++ b/recipes/reflect-cpp/all/conanfile.py @@ -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 @@ -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() diff --git a/recipes/reflect-cpp/all/test_package/CMakeLists.txt b/recipes/reflect-cpp/all/test_package/CMakeLists.txt index 1a6253f9dc61a..767315c296e76 100644 --- a/recipes/reflect-cpp/all/test_package/CMakeLists.txt +++ b/recipes/reflect-cpp/all/test_package/CMakeLists.txt @@ -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() diff --git a/recipes/reflect-cpp/all/test_package/conanfile.py b/recipes/reflect-cpp/all/test_package/conanfile.py index a9fb96656f203..c0ce5c17be896 100644 --- a/recipes/reflect-cpp/all/test_package/conanfile.py +++ b/recipes/reflect-cpp/all/test_package/conanfile.py @@ -1,12 +1,12 @@ 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): @@ -14,6 +14,12 @@ def requirements(self): 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) diff --git a/recipes/reflect-cpp/all/test_package/test_package.cpp b/recipes/reflect-cpp/all/test_package/test_package.cpp index 04e4309cba5ea..ed7b54690e256 100644 --- a/recipes/reflect-cpp/all/test_package/test_package.cpp +++ b/recipes/reflect-cpp/all/test_package/test_package.cpp @@ -1,6 +1,11 @@ #include +#include #include +#if defined(CONAN_TEST_WITH_MSGPACK) + #include +#endif + struct TestStruct { int x; std::string name; @@ -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; } diff --git a/recipes/reflect-cpp/all/test_v1_package/CMakeLists.txt b/recipes/reflect-cpp/all/test_v1_package/CMakeLists.txt deleted file mode 100644 index 9652e22fc19d5..0000000000000 --- a/recipes/reflect-cpp/all/test_v1_package/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -cmake_minimum_required(VERSION 3.12) - -project(test_package) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ - ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/reflect-cpp/all/test_v1_package/conanfile.py b/recipes/reflect-cpp/all/test_v1_package/conanfile.py deleted file mode 100644 index 5a05af3c2dfd2..0000000000000 --- a/recipes/reflect-cpp/all/test_v1_package/conanfile.py +++ /dev/null @@ -1,18 +0,0 @@ -from conans import ConanFile, CMake -from conan.tools.build import cross_building -import os - - -class TestPackageV1Conan(ConanFile): - settings = "os", "arch", "compiler", "build_type" - 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)