-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Changes from 3 commits
98b4dee
7665791
7d73337
3e73a4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
|
||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
|
||
add_subdirectory("source_subfolder") |
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" |
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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
self.cpp_info.names["cmake_find_package"] = "RectangleBinPack" | ||||||
self.cpp_info.names["cmake_find_package_multi"] = "RectangleBinPack" | ||||||
Comment on lines
+77
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. targets are not exported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blah #7153 they match upstream |
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(); |
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) |
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" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
not used |
||||||
|
||||||
def build(self): | ||||||
cmake = CMake(self) | ||||||
cmake.configure() | ||||||
cmake.build() | ||||||
|
||||||
def test(self): | ||||||
if not tools.cross_building(self.settings): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
bin_path = os.path.join("bin", "test_package") | ||||||
self.run(bin_path, run_environment=True) |
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()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"cci.20210829": | ||
folder: "all" |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
andMaxRectsBinPackTest
) which need C++11 support, isn't it better to just defineset(CMAKE_CXX_STANDARD 11)
instead of definingtarget_compile_features
for both targets?There was a problem hiding this comment.
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. Nowadaystarget_compile_features
should be preferred in libraries, it allows to ask for a minimum C++ standard (whileCMAKE_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 totarget_compile_features(target PUBLIC cxx_std_11)
: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).There was a problem hiding this comment.
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!