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

objectbox: add recipe #11359

Merged
merged 3 commits into from
Jun 27, 2022
Merged
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 recipes/objectbox/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper C)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(source_subfolder)
9 changes: 9 additions & 0 deletions recipes/objectbox/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"0.17.0":
url: "https://github.com/objectbox/objectbox-c/archive/refs/tags/v0.17.0.tar.gz"
sha256: "3b936b3352ae0c8ea3706cc0a1790d2714a415cdce16007c2caca367ead5af8d"

patches:
"0.17.0":
- patch_file: "patches/0001-fix-cmake.patch"
base_path: "source_subfolder"
62 changes: 62 additions & 0 deletions recipes/objectbox/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from conans import CMake, ConanFile, tools
import functools

required_conan_version = ">=1.33.0"

class ObjectboxCConan(ConanFile):
name = "objectbox"
description = "ObjectBox C and C++: super-fast database for objects and structs"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/objectbox/objectbox-c"
topics = ("performance", "database", "flatbuffers")
settings = "os", "arch", "compiler", "build_type"
options = {
"with_sync": [True, False],
}
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"])

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, 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 build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy(pattern="LICENSE*", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
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")

66 changes: 66 additions & 0 deletions recipes/objectbox/all/patches/0001-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e32c84b..c2c535f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,10 +9,17 @@ if (${CMAKE_VERSION} VERSION_LESS "3.11.0")
endif ()
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/lib")
else ()
+ include(GNUInstallDirs)
+
function(defineObjectBoxLibForURL VARIANT DL_URL)
include(FetchContent)
project(objectbox${VARIANT}-download)
- FetchContent_Declare(${PROJECT_NAME} URL ${DL_URL})
+ FetchContent_Declare(${PROJECT_NAME}
+ URL ${DL_URL}
+ # workaround for max path length in Windows (260byte)
+ SUBBUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sub
+ SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tmp
+ )

FetchContent_Populate(${PROJECT_NAME})
set(DL_DIR "${${PROJECT_NAME}_SOURCE_DIR}")
@@ -27,6 +34,25 @@ else ()
IMPORTED_IMPLIB ${DL_DIR}/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}objectbox${CMAKE_IMPORT_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES "${objectbox_include_dirs}"
)
+
+ if(EXISTS "${DL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}objectbox${CMAKE_SHARED_LIBRARY_SUFFIX}")
+ install(
+ FILES ${DL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}objectbox${CMAKE_SHARED_LIBRARY_SUFFIX}
+ DESTINATION $<IF:$<PLATFORM_ID:Windows>,${CMAKE_INSTALL_BINDIR},${CMAKE_INSTALL_LIBDIR}>
+ )
+ endif()
+ if(EXISTS "${DL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}objectbox${CMAKE_IMPORT_LIBRARY_SUFFIX}")
+ install(
+ FILES ${DL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}objectbox${CMAKE_IMPORT_LIBRARY_SUFFIX}
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ )
+ endif()
+
+ install(
+ DIRECTORY ${DL_DIR}/include/
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+ )
+
endfunction()

function(defineObjectBoxLib VARIANT)
@@ -72,10 +98,15 @@ else ()
defineObjectBoxLibForURL("" "${DL_URL}")
else ()
defineObjectBoxLib("")
- defineObjectBoxLib("-sync")
+ if(OBJECTBOX_WITH_SYNC)
+ defineObjectBoxLib("-sync")
+ endif()
endif ()
endif ()

+if(0)
add_subdirectory(src-test)
add_subdirectory(src-test-gen)
add_subdirectory(examples)
+endif()
+
12 changes: 12 additions & 0 deletions recipes/objectbox/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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)
17 changes: 17 additions & 0 deletions recipes/objectbox/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(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 tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
10 changes: 10 additions & 0 deletions recipes/objectbox/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>

#include "objectbox.h"

int main() {
printf("ObjectBox version %s\n", obx_version_string());

return 0;
}

3 changes: 3 additions & 0 deletions recipes/objectbox/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.17.0":
folder: all