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

rectanglebinpack: add rectanglebinpack/cci.20210901 recipe #7112

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions recipes/rectanglebinpack/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.8)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_subdirectory("source_subfolder")
10 changes: 10 additions & 0 deletions recipes/rectanglebinpack/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
"cci.20210901":
- url: "https://github.com/juj/RectangleBinPack/archive/a40fcaf3871da57b0f6a080655b3387374840877.zip"
sha256: "88cec105ca8d90d09e9e81f9862caa0cc1cdb851560fb701555eb58b29515748"
- url: "https://unlicense.org/UNLICENSE"
sha256: "7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c"
patches:
"cci.20210901":
- patch_file: "patches/0001_fix_win32_build.patch"
base_path: "source_subfolder"
78 changes: 78 additions & 0 deletions recipes/rectanglebinpack/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from conans import ConanFile, CMake, tools
import os

required_conan_version = ">=1.33.0"


class RectangleBinPackConan(ConanFile):
name = "rectanglebinpack"
license = "Unlicense"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/juj/RectangleBinPack"
description = "The code can be used to solve the problem of packing a set of 2D rectangles into a larger bin."
topics = ("rectangle", "packing", "bin")
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

_cmake = None

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

@property
def _build_subfolder(self):
return "build_subfolder"

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

def configure(self):
if self.options.shared:
del self.options.fPIC

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][0],
strip_root=True, destination=self._source_subfolder)
tools.download(filename="LICENSE", **self.conan_data["sources"][self.version][1])

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

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def package(self):
self.copy("LICENSE", dst="licenses")
self.copy("*.h", dst=os.path.join("include", self.name), src=self._source_subfolder, excludes="old/**")
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.lib", dst="lib", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.dylib", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)

def package_info(self):
self.cpp_info.libs = ["RectangleBinPack"]
self.cpp_info.names["cmake_find_package"] = "RectangleBinPack"
self.cpp_info.names["cmake_find_package_multi"] = "RectangleBinPack"
Comment on lines +77 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targets are not exported

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blah #7153 they match upstream

11 changes: 11 additions & 0 deletions recipes/rectanglebinpack/all/patches/0001_fix_win32_build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/test/MaxRectsBinPackTest.cpp
+++ b/test/MaxRectsBinPackTest.cpp
@@ -24,8 +24,6 @@
#if defined(WIN32)
LARGE_INTEGER ddwTimer;
BOOL success = QueryPerformanceCounter(&ddwTimer);
- assume(success != 0);
- MARK_UNUSED(success);
return ddwTimer.QuadPart;
#elif defined(__APPLE__)
return mach_absolute_time();
9 changes: 9 additions & 0 deletions recipes/rectanglebinpack/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.4)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
17 changes: 17 additions & 0 deletions recipes/rectanglebinpack/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
from conans import ConanFile, CMake, tools


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

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)
47 changes: 47 additions & 0 deletions recipes/rectanglebinpack/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Original source code:
* https://github.com/juj/RectangleBinPack/blob/29eec60fe2c9aa0df855dddabd8d4d17023b95f3/test/MaxRectsBinPackTest.cpp
*/

#include <cstdint>
#include <cstdio>
#include <vector>
#include <rectanglebinpack/MaxRectsBinPack.h>

using namespace rbp;

bool AreDisjoint(const Rect &a, const Rect &b)
{
return a.x >= b.x + b.width || a.x + a.width <= b.x ||
a.y >= b.y + b.height || a.y + a.height <= b.y;
}

bool AllRectsDisjoint(std::vector<Rect> &packed)
{
for(size_t i = 0; i < packed.size(); ++i)
for(size_t j = i+1; j < packed.size(); ++j)
{
if (!AreDisjoint(packed[i], packed[j]))
return false;
}
return true;
}

int main()
{
MaxRectsBinPack pack(256, 256, true);

std::vector<Rect> packed;
srand(12412);
for(int i = 1; i < 128; ++i)
{
int a = (rand() % 128) + 1;
int b = (rand() % 128) + 1;
Rect r = pack.Insert(a, b, MaxRectsBinPack::RectBestShortSideFit);
if (!r.width)
break;
packed.push_back(r);
}
printf("Packed %d rectangles. All rects disjoint: %s. Occupancy: %f\n",
(int)packed.size(), AllRectsDisjoint(packed) ? "yes" : "NO!", pack.Occupancy());
}
3 changes: 3 additions & 0 deletions recipes/rectanglebinpack/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20210901":
folder: "all"