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 3 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
14 changes: 14 additions & 0 deletions recipes/rectanglebinpack/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.4)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

if(NOT "${CMAKE_CXX_STANDARD}")
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe move this in a patch and submit it upstream?

It would prefer target_compile_features(RectangleBinPack PUBLIC cxx_std_11)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will submit this to upstream, but since the upstream cmake file has two targets (RectangleBinPack and MaxRectsBinPackTest) which need C++11 support, isn't it better to just define set(CMAKE_CXX_STANDARD 11) instead of defining target_compile_features for both targets?

Copy link
Contributor

@SpaceIm SpaceIm Aug 30, 2021

Choose a reason for hiding this comment

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

No, CMAKE_CXX_STANDARD should never be used in libraries. Nowadays target_compile_features should be preferred in libraries, it allows to ask for a minimum C++ standard (while CMAKE_CXX_STANDARD asks for the upper bound).
Then final project can decide to enforce a specific C++ standard through CMAKE_CXX_STANDARD in all its dependencies.

It also plays better with compiler.cppstd in conan profiles.

It's worth noting that even with if(NOT "${CMAKE_CXX_STANDARD}"), this block is NOT equivalent to target_compile_features(target PUBLIC cxx_std_11):

if(NOT "${CMAKE_CXX_STANDARD}")
    set(CMAKE_CXX_STANDARD 11)
endif()

Indeed, if CMAKE_CXX_STANDARD has not been explicitly set downstream, target_compile_features(target PUBLIC cxx_std_11) may use any standard greater or equal than 11 (I guess CMake prefers default C++ standard of the compiler if possible).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All right, I'll use target_compile_features, thanks for the explanation!


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.20210829":
- url: "https://github.com/juj/RectangleBinPack/archive/d503ea88f110396be948019288bec1f7a2123166.zip"
sha256: "3425a111fac110e58f21e588bf770a2d8bad23c2f01a426b5d3f4f77a0dcbe55"
- url: "https://unlicense.org/UNLICENSE"
sha256: "7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c"
patches:
"cci.20210829":
- patch_file: "patches/0001_fix_win32_build.patch"
base_path: "source_subfolder"
74 changes: 74 additions & 0 deletions recipes/rectanglebinpack/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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 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 = tools.collect_libs(self)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.cpp_info.libs = tools.collect_libs(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", "cmake_find_package"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
generators = "cmake", "cmake_find_package"
generators = "cmake"

not used


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

def test(self):
if not tools.cross_building(self.settings):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if not tools.cross_building(self.settings):
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.20210829":
folder: "all"