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

New recipe: reflectcpp; intended to replace recipe reflect-cpp, which is named incorrectly #24857

Merged
merged 50 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0fe5add
Added a recipe for reflectcpp
liuzicheng1987 Aug 6, 2024
5b594c2
Reduced minimum version required for CMake in the test pipeline
liuzicheng1987 Aug 6, 2024
d8d561a
Even simpler test
liuzicheng1987 Aug 6, 2024
e0ae8fb
Set minimum C++ standard and compiler versions
liuzicheng1987 Aug 6, 2024
f82bb82
Restricted the settings to C++20
liuzicheng1987 Aug 6, 2024
c9ee4a4
Adapted the conanfile in the test package as well
liuzicheng1987 Aug 6, 2024
b67c805
Removed duplicate entries
liuzicheng1987 Aug 6, 2024
d48062d
Use original test package; removed settings
liuzicheng1987 Aug 7, 2024
7a1df97
Added validate
liuzicheng1987 Aug 7, 2024
6f2246d
Added missing imports
liuzicheng1987 Aug 7, 2024
9b72620
PR review
uilianries Aug 7, 2024
6a2baf3
fix old recipe
uilianries Aug 7, 2024
8469e1d
Merge branch 'reflectcpp-0.14.0' into reflectcpp-0.14.0
liuzicheng1987 Aug 7, 2024
2007cf3
Merge pull request #1 from uilianries/reflectcpp-0.14.0
liuzicheng1987 Aug 7, 2024
b47a296
Removed duplicate definition of validate
liuzicheng1987 Aug 7, 2024
207568b
Retrigger the pipeline
liuzicheng1987 Aug 8, 2024
322bd49
Link yyjson in the test environment
liuzicheng1987 Aug 13, 2024
b926c03
Use yyjson 0.8.0
liuzicheng1987 Aug 13, 2024
ac6a679
Link to YYJSON in the test package
liuzicheng1987 Aug 13, 2024
a3dd409
Removed yyjson again
liuzicheng1987 Aug 15, 2024
127b389
Make sure that shared=True compiles as well
liuzicheng1987 Aug 15, 2024
17d98e8
Added upstream fix to make MSVC work
liuzicheng1987 Aug 15, 2024
79e37b7
Format the testfile; retrigger pipeline
liuzicheng1987 Aug 15, 2024
0f59369
Fixed the msvc version
liuzicheng1987 Aug 15, 2024
1c8d106
Always use external dependencies
liuzicheng1987 Sep 23, 2024
dbfe7ac
Link to YYJSON
liuzicheng1987 Sep 23, 2024
d1e1031
Revert "Link to YYJSON"
liuzicheng1987 Sep 23, 2024
e1fa846
Revert "Always use external dependencies"
liuzicheng1987 Sep 23, 2024
5a16fbf
Tried using BUILD_SHARED_LIBS
liuzicheng1987 Nov 9, 2024
98fd462
Go back to old solution, once again
liuzicheng1987 Nov 9, 2024
77626dc
Added version 0.15.0
liuzicheng1987 Nov 9, 2024
c222ca4
Updated config.yml as well
liuzicheng1987 Nov 9, 2024
96f530e
Update recipes/reflectcpp/all/conanfile.py
liuzicheng1987 Nov 18, 2024
629c90d
Always link to ctre and yyjson
liuzicheng1987 Nov 23, 2024
f114de5
Try using the 0.16.0 release candidate
liuzicheng1987 Nov 23, 2024
f4d94c5
Fixed syntax error
liuzicheng1987 Nov 23, 2024
b757c28
Explicitly add yyjson
liuzicheng1987 Nov 23, 2024
6e4b548
Try yyjson 0.10.0
liuzicheng1987 Nov 23, 2024
e5c9555
Added some linker flags to the tests
liuzicheng1987 Nov 23, 2024
1d16667
Added UBJSON support
liuzicheng1987 Nov 23, 2024
8c75f55
Use REFLECTCPP_BUILD_SHARED
liuzicheng1987 Nov 23, 2024
8eb5961
Use the final 0.16.0 release version
liuzicheng1987 Nov 23, 2024
e87ab36
Removed linker flag
liuzicheng1987 Nov 26, 2024
c4503be
Update recipes/reflectcpp/all/conanfile.py
liuzicheng1987 Nov 26, 2024
7f85707
Update recipes/reflectcpp/all/conanfile.py
liuzicheng1987 Nov 26, 2024
22888d9
Added missing import
liuzicheng1987 Nov 26, 2024
ef12bee
Update recipes/reflectcpp/all/conanfile.py
liuzicheng1987 Nov 26, 2024
ebafb6d
Rename to reflect-cpp and use Conan 2.x
uilianries Nov 26, 2024
b735132
Check compiler version
uilianries Nov 26, 2024
20042e3
Require MSVC 194 for now
uilianries Nov 26, 2024
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
15 changes: 3 additions & 12 deletions recipes/reflect-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
sources:
"0.11.1":
url: "https://github.com/getml/reflect-cpp/archive/v0.11.1.tar.gz"
sha256: "e45f112fb3f14507a4aa53b99ae2d4ab6a4e7b2d5f04dd06fec00bf7faa7bbdc"
"0.11.0":
url: "https://github.com/getml/reflect-cpp/archive/v0.11.0.tar.gz"
sha256: "85f66939608acacf66dc782529af0c5a36b7d695c55b310b10c49700251b6221"
"0.10.0":
url: "https://github.com/getml/reflect-cpp/archive/v0.10.0.tar.gz"
sha256: "d2c8876d993ddc8c57c5804e767786bdb46a2bdf1a6cd81f4b14f57b1552dfd7"
"0.6.0":
url: "https://github.com/getml/reflect-cpp/archive/v0.6.0.tar.gz"
sha256: "D8231B91989397A67E841B56A0673FDCDF969DBE956D54BB629F14100B030664"
"0.16.0":
url: "https://github.com/getml/reflect-cpp/archive/refs/tags/v0.16.0.tar.gz"
sha256: "a84d94dbd353d788926d6e54507b44c046863f7bc4ecb35afe0338374a68a77d"
158 changes: 104 additions & 54 deletions recipes/reflect-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,145 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import get, copy
from conan.tools.files import get, copy, rmdir, replace_in_file
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.env import VirtualBuildEnv
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.layout import basic_layout
from conan.errors import ConanInvalidConfiguration

import os

required_conan_version = ">=1.51.1"
required_conan_version = ">=2.0.9"


class ReflectCppConan(ConanFile):
name = "reflect-cpp"
description = "C++-20 library for fast serialization, deserialization and validation using reflection"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/getml/reflect-cpp"
topics = ("reflection", "serialization", "memory", "json", "xml", "flatbuffers", "yaml", "toml", "msgpack", "header-only")
package_type = "header-library"
topics = (
"reflection",
"serialization",
"memory",
"cbor",
"flatbuffers",
"json",
"msgpack",
"toml",
"xml",
"yaml",
)
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"with_json" : [True, False],
"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
def _min_cppstd(self):
return 20

@property
def _compilers_minimum_version(self):
# TODO: MSVC 19.38 is required, but ConanCenterIndex CI has update 6 installed.
# Update msvc to 193 when having the CI updated to the latest update.
return {
"Visual Studio": "17",
"msvc": "193",
"gcc": "11.4",
"clang": "16",
"msvc": "194",
"gcc": "11",
"clang": "13",
"apple-clang": "15",
}

def layout(self):
basic_layout(self, src_folder="src")
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_cbor": [True, False],
"with_flatbuffers": [True, False],
"with_msgpack": [True, False],
"with_toml": [True, False],
"with_ubjson": [True, False],
"with_xml": [True, False],
"with_yaml": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_cbor": False,
"with_flatbuffers": False,
"with_msgpack": False,
"with_toml": False,
"with_ubjson": False,
"with_xml": False,
"with_yaml": False,
}
implements = ["auto_shared_fpic"]

def requirements(self):
if self.options.with_json:
self.requires("yyjson/0.8.0", transitive_headers=True)
self.requires("ctre/3.9.0", transitive_headers=True)
# INFO: include/rfl/json/Writer.hpp includes yyjson.h
# INFO: Transitive lib needed to avoid undefined reference to symbol 'yyjson_mut_doc_new'
self.requires("yyjson/0.10.0", transitive_headers=True, transitive_libs=True)
if self.options.with_cbor:
self.requires("tinycbor/0.6.0", transitive_headers=True)
if self.options.with_flatbuffers:
self.requires("flatbuffers/24.3.25", transitive_headers=True)
if self.options.with_msgpack:
self.requires("msgpack-c/6.0.0", transitive_headers=True)
if self.options.with_toml:
self.requires("tomlplusplus/3.4.0", transitive_headers=True)
if self.options.with_ubjson:
self.requires("jsoncons/0.176.0", transitive_headers=True)
if self.options.with_xml:
self.requires("pugixml/1.14", transitive_headers=True)
if self.options.with_flatbuffers:
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)

if Version(self.version) >= "0.11.1":
self.requires("ctre/3.9.0", transitive_headers=True)

def package_id(self):
self.info.clear()
def build_requirements(self):
self.tool_requires("cmake/[>=3.23 <4]")

def validate(self):
if self.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, self._min_cppstd)
check_min_cppstd(self, 20)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)
raise ConanInvalidConfiguration(f"{self.ref} requires C++20 features, which your compiler does not fully support.")

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

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
# INFO: Let Conan handle the C++ standard used via settings.compiler.cppstd
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "set(CMAKE_CXX_STANDARD 20)", "")

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
deps = CMakeDeps(self)
if self.options.with_flatbuffers:
deps.set_property("flatbuffers", "cmake_target_name", "flatbuffers::flatbuffers")
deps.generate()
tc = CMakeToolchain(self)
tc.cache_variables["REFLECTCPP_BUILD_SHARED"] = self.options.shared
tc.cache_variables["REFLECTCPP_USE_BUNDLED_DEPENDENCIES"] = False
tc.cache_variables["REFLECTCPP_USE_VCPKG"] = False
tc.cache_variables["REFLECTCPP_CBOR"] = self.options.with_cbor
tc.cache_variables["REFLECTCPP_FLEXBUFFERS"] = self.options.with_flatbuffers
tc.cache_variables["REFLECTCPP_MSGPACK"] = self.options.with_msgpack
tc.cache_variables["REFLECTCPP_TOML"] = self.options.with_toml
tc.cache_variables["REFLECTCPP_XML"] = self.options.with_xml
tc.cache_variables["REFLECTCPP_YAML"] = self.options.with_yaml
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, pattern="LICENSE*", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(
self,
pattern="*.hpp",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"),
pattern="LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder,
)
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
if Version(self.version) >= "0.11.1":
self.cpp_info.defines.append("REFLECTCPP_NO_BUNDLED_DEPENDENCIES")
self.cpp_info.libs = ["reflectcpp"]
self.cpp_info.set_property("cmake_target_name", "reflectcpp::reflectcpp")
self.cpp_info.set_property("cmake_file_name", "reflectcpp")
9 changes: 3 additions & 6 deletions recipes/reflect-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(reflect-cpp REQUIRED CONFIG)
find_package(reflectcpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE reflect-cpp::reflect-cpp)
target_link_libraries(${PROJECT_NAME} reflectcpp::reflectcpp)
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()
4 changes: 1 addition & 3 deletions recipes/reflect-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ 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):
Expand Down
34 changes: 10 additions & 24 deletions recipes/reflect-cpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
#include <string>
#include <cstdlib>
#include <iostream>
#include <rfl.hpp>

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

struct TestStruct {
int x;
std::string name;
};
#include "rfl.hpp"
#include "rfl/Generic.hpp"
#include "rfl/json.hpp"

int main(void) {
for (const auto& f : rfl::fields<TestStruct>()) {
(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;
auto person = rfl::Generic::Object();
person["first_name"] = "John";
person["last_name"] = "Doe";
rfl::json::write(person, std::cout) << std::endl;
return EXIT_SUCCESS;
}
8 changes: 1 addition & 7 deletions recipes/reflect-cpp/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
versions:
"0.11.1":
folder: all
"0.11.0":
folder: all
"0.10.0":
folder: all
"0.6.0":
"0.16.0":
folder: all