Skip to content

Commit

Permalink
(conan-io#15646) objectbox: add version 0.18.1, support conan v2
Browse files Browse the repository at this point in the history
* objectbox: add version 0.18.1, support conan v2

* link pthread

* remove unused import

* link dl since 0.18.0
  • Loading branch information
toge authored and sabelka committed Feb 12, 2023
1 parent 73a8aee commit 2b2d4c9
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 50 deletions.
7 changes: 0 additions & 7 deletions recipes/objectbox/all/CMakeLists.txt

This file was deleted.

13 changes: 11 additions & 2 deletions recipes/objectbox/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"0.18.1":
url: "https://github.com/objectbox/objectbox-c/archive/v0.18.1.tar.gz"
sha256: "108ac7fac843f2962374a12b361bb57b4d114013d16f7716cfedbc7df52feb2e"
"0.18.0":
url: "https://github.com/objectbox/objectbox-c/archive/v0.18.0.tar.gz"
sha256: "e86e921d59c6c36a4a0c0ddc5a2b641789bfa012e0824506c285feb4e9285ae7"
Expand All @@ -7,9 +10,15 @@ sources:
sha256: "3b936b3352ae0c8ea3706cc0a1790d2714a415cdce16007c2caca367ead5af8d"

patches:
"0.18.1":
- patch_file: "patches/0001-fix-cmake.patch"
patch_description: "add sync option, disable tests/examples, support max length of windows path"
patch_type: "conan"
"0.18.0":
- patch_file: "patches/0001-fix-cmake.patch"
base_path: "source_subfolder"
patch_description: "add sync option, disable tests/examples, support max length of windows path"
patch_type: "conan"
"0.17.0":
- patch_file: "patches/0001-fix-cmake.patch"
base_path: "source_subfolder"
patch_description: "add sync option, disable tests/examples, support max length of windows path"
patch_type: "conan"
52 changes: 23 additions & 29 deletions recipes/objectbox/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from conans import CMake, ConanFile, tools
import functools
from conan import ConanFile
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.scm import Version
import os

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.53.0"

class ObjectboxCConan(ConanFile):
name = "objectbox"
Expand All @@ -17,46 +20,37 @@ class ObjectboxCConan(ConanFile):
default_options = {
"with_sync": False,
}
generators = "cmake",

@property
def _source_subfolder(self):
return "source_subfolder"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
def layout(self):
cmake_layout(self, src_folder="src")

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

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["OBJECTBOX_WITH_SYNC"] = self.options.with_sync
cmake.configure()
return cmake
def generate(self):
# BUILD_SHARED_LIBS and POSITION_INDEPENDENT_CODE are automatically parsed when self.options.shared or self.options.fPIC exist
tc = CMakeToolchain(self)
tc.variables["OBJECTBOX_WITH_SYNC"] = self.options.with_sync
tc.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy(pattern="LICENSE*", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, pattern="LICENSE.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

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

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")

self.cpp_info.system_libs.extend(["m", "pthread"])
if Version(self.version) >= "0.18.0":
self.cpp_info.system_libs.append("dl")
7 changes: 1 addition & 6 deletions recipes/objectbox/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
cmake_minimum_required(VERSION 3.1)

project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)

conan_basic_setup(TARGETS)

find_package(objectbox REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} objectbox::objectbox)
target_link_libraries(${PROJECT_NAME} PRIVATE objectbox::objectbox)
20 changes: 14 additions & 6 deletions recipes/objectbox/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


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

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

def layout(self):
cmake_layout(self)

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/objectbox/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
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/)
17 changes: 17 additions & 0 deletions recipes/objectbox/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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)
2 changes: 2 additions & 0 deletions recipes/objectbox/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"0.18.1":
folder: all
"0.18.0":
folder: all
"0.17.0":
Expand Down

0 comments on commit 2b2d4c9

Please sign in to comment.