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

F/conan #279

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ jobs:
run: |
sudo apt update
sudo apt install -y ninja-build ${{ matrix.additional-dep }}
- name: Install Conan
run: |
sudo apt install -y pipx
pipx install conan
conan profile detect
- name: Make sure the library compiles with Conan
run: conan build . --build=missing -s compiler.cppstd=gnu20 -o *:with_cbor=True -o *:with_flatbuffers=True -o *:with_msgpack=True -o *:with_toml=True -o *:with_ubjson=True -o *:with_xml=True -o *:with_yaml=True
- name: Compile
run: |
if [[ "${{ matrix.compiler }}" == "llvm" ]]; then
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/macos-clang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ jobs:
create-symlink: true
- name: Run vcpkg
uses: lukka/run-vcpkg@v11
- name: Install Conan
run: |
brew install pipx
pipx install conan
conan profile detect
- name: Install ninja
run: brew install ninja
if: matrix.os == 'macos-latest'
- name: Make sure the library compiles with Conan
env:
CC: clang
CXX: clang++
run: conan build . --build=missing -s compiler.cppstd=gnu20 -o *:with_cbor=True -o *:with_flatbuffers=True -o *:with_msgpack=True -o *:with_toml=True -o *:with_ubjson=True -o *:with_xml=True -o *:with_yaml=True
- name: Compile
env:
CC: clang
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/windows-msvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ jobs:
.\build\benchmarks\json\Release\reflect-cpp-json-benchmarks.exe --benchmark_filter=canada >> $env:GITHUB_STEP_SUMMARY
.\build\benchmarks\json\Release\reflect-cpp-json-benchmarks.exe --benchmark_filter=licenses >> $env:GITHUB_STEP_SUMMARY
echo '```' >> $env:GITHUB_STEP_SUMMARY
- name: Install Conan
id: conan
uses: turtlebrowser/get-conan@main
- name: Create default profile
run: conan profile detect
- name: Make sure the library compiles with Conan
run: conan build . --build=missing -s compiler.cppstd=20 -o *:with_cbor=True -o *:with_flatbuffers=True -o *:with_msgpack=True -o *:with_toml=True -o *:with_ubjson=True -o *:with_xml=True -o *:with_yaml=True

1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ if (REFLECTCPP_USE_BUNDLED_DEPENDENCIES)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/rfl/thirdparty>)
else ()
find_package(ctre CONFIG REQUIRED)
target_link_libraries(reflectcpp PUBLIC ctre::ctre)
endif ()

if (REFLECTCPP_JSON)
Expand Down
147 changes: 147 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
from conan import ConanFile
from conan.tools.files import get, copy, rmdir
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.errors import ConanInvalidConfiguration

import os

required_conan_version = ">=1.54"


class ReflectCppConan(ConanFile):
name = "reflectcpp"
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",
"cbor",
"flatbuffers",
"json",
"msgpack",
"toml",
"xml",
"yaml",
)
package_type = "library"
settings = "os", "arch", "compiler", "build_type"

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,
}

def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def requirements(self):
self.requires("ctre/3.9.0", transitive_headers=True)
self.requires("yyjson/0.10.0", transitive_headers=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_yaml:
self.requires("yaml-cpp/0.8.0", transitive_headers=True)

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)

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

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

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
deps = CMakeDeps(self)
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,
)
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.libs = ["reflectcpp"]

@property
def _min_cppstd(self):
return 20

@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "17",
"msvc": "1938",
"gcc": "11",
"clang": "13",
"apple-clang": "15",
}
30 changes: 28 additions & 2 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,38 @@ set(REFLECTCPP_YAML ON) # Optional
target_link_libraries(your_project PRIVATE reflectcpp) # Link against the library
```

## Troubleshooting vcpkg
### Troubleshooting vcpkg

vcpkg is a great, but very ambitious and complex project (just like C++ is a great, but very ambitious and complex language). Here are some of the you might run into and how to resolve them:

1. A lot of problems can simply be resolved by deleting the build directory using `rm -rf build`.

2. *Environment variable VCPKG_FORCE_SYSTEM_BINARIES must be set on arm, s390x, ppc64le and riscv platforms.* - This usually happens on arm platforms like the Apple Silicon chips and can be resolved by simply preceding your build with `export VCPKG_FORCE_SYSTEM_BINARIES=arm` or `export VCPKG_FORCE_SYSTEM_BINARIES=1`.

3. On some occasions you might be asked to specify a compiler. You can do so by simply adding it to the cmake command as follows: `cmake -S . -B build ... -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++` or `cmake -S . -B build ... -DCMAKE_C_COMPILER=clang-17 -DCMAKE_CXX_COMPILER=clang++-17` (or whatever supported compiler you would like to use).
3. On some occasions you might be asked to specify a compiler. You can do so by simply adding it to the cmake command as follows: `cmake -S . -B build ... -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++` or `cmake -S . -B build ... -DCMAKE_C_COMPILER=clang-17 -DCMAKE_CXX_COMPILER=clang++-17` (or whatever supported compiler you would like to use).

## Option 4: Compilation using Conan

To install Conan (assuming you have Python and pipx installed):

```bash
pipx install conan
conan profile detect
```

For older versions of pip, you can also use `pip` instead of `pipx`.

To install the basic (JSON-only) version, cd into the `reflect-cpp`
repository and call the following:

```bash
conan build . --build=missing -s compiler.cppstd=gnu20
```

You can call `conan inspect .` to get an overview of the supported options.

So, if you want XML and YAML support as well, you can call the following:

```bash
conan build . --build=missing -s compiler.cppstd=gnu20 -o *:with_xml=True -o *:with_yaml=True
```
10 changes: 5 additions & 5 deletions docs/plugins/people.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
maintainers:
- login: liuzicheng1987
answers: 0
prs: 63
prs: 61
avatarUrl: https://avatars.githubusercontent.com/u/19538706?u=1ca794b4e5aa9bbe50277f249e701eea86b0fdd3&v=4
url: https://github.com/liuzicheng1987
- login: Urfoex
Expand Down Expand Up @@ -137,14 +137,14 @@ top_contributors:
avatarUrl: https://avatars.githubusercontent.com/u/6700184?u=1a24c6def1a65fb96c7ebf5b95a1a589d4968b0a&v=4
url: https://github.com/SecondFlight
top_reviewers:
- login: lixin-wei
count: 1
avatarUrl: https://avatars.githubusercontent.com/u/19600697?u=539692f60ba009b3e2a6a66db90b1fa47be6b0bc&v=4
url: https://github.com/lixin-wei
- login: schaumb
count: 1
avatarUrl: https://avatars.githubusercontent.com/u/6457941?u=542743f214f2197bd08b7b7112a2ba1b1e6e73ac&v=4
url: https://github.com/schaumb
- login: lixin-wei
count: 1
avatarUrl: https://avatars.githubusercontent.com/u/19600697?u=539692f60ba009b3e2a6a66db90b1fa47be6b0bc&v=4
url: https://github.com/lixin-wei
- login: StephanTLavavej
count: 1
avatarUrl: https://avatars.githubusercontent.com/u/4231088?u=fd10ba4ada8f71ecd4a6be3f4b3cb9993528babc&v=4
Expand Down
Loading