Skip to content

Commit

Permalink
(conan-io#12964) eternal: add recipe
Browse files Browse the repository at this point in the history
* eternal: add recipe

* remove comment

* add limits header

* remove apply_conandata_patches

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>

* fix msvc version number

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>
  • Loading branch information
2 people authored and marc-mw committed Oct 7, 2022
1 parent e3d0fd5 commit 1fb8dda
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/eternal/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.1":
url: "https://github.com/mapbox/eternal/archive/refs/tags/v1.0.1.tar.gz"
sha256: "7d799381b3786d0bd987eea75df2a81f581a64ee962e922a2f7a7d3d0c3d0421"
69 changes: 69 additions & 0 deletions recipes/eternal/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import get, copy
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.layout import basic_layout
import os


required_conan_version = ">=1.51.3"


class EternalConan(ConanFile):
name = "eternal"
description = "A C++14 compile-time/constexpr map and hash map with minimal binary footprint"
license = "ISC"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/mapbox/eternal"
topics = ("hashing", "map", "constexpr", "header-only")
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

@property
def _minimum_cpp_standard(self):
return 14

@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "15",
"msvc": "191",
"gcc": "5",
"clang": "4",
"apple-clang": "10",
}

def export_sources(self):
for p in self.conan_data.get("patches", {}).get(self.version, []):
copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder)

def layout(self):
basic_layout(self, src_folder="src")

def package_id(self):
self.info.clear()

def validate(self):
if self.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, self._minimum_cpp_standard)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.get_safe("compiler.version")) < minimum_version:
raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._minimum_cpp_standard}, which your compiler does not support.")

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

def build(self):
pass

def package(self):
copy(self, pattern="LICENSE.md", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(self, pattern="*.hpp", dst=os.path.join(self.package_folder, "include"), src=os.path.join(self.source_folder, "include"))

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.frameworkdirs = []
self.cpp_info.libdirs = []
self.cpp_info.resdirs = []
9 changes: 9 additions & 0 deletions recipes/eternal/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.8)

project(test_package CXX)

find_package(eternal REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE eternal::eternal)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
26 changes: 26 additions & 0 deletions recipes/eternal/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 = "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 can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
41 changes: 41 additions & 0 deletions recipes/eternal/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
#include <cmath>
#include <limits>

#include "mapbox/eternal.hpp"

struct Color {
constexpr inline Color() {
}
constexpr inline Color(unsigned char r_, unsigned char g_, unsigned char b_, float a_)
: r(r_), g(g_), b(b_), a(a_ > 1 ? 1 : a_ < 0 ? 0 : a_) {
}
unsigned char r = 0, g = 0, b = 0;
float a = 1.0f;

constexpr bool operator==(const Color& rhs) const {
return r == rhs.r && g == rhs.g && b == rhs.b &&
(a >= rhs.a ? a - rhs.a : rhs.a - a) < std::numeric_limits<float>::epsilon();
}
};

MAPBOX_ETERNAL_CONSTEXPR const auto multi_colors = mapbox::eternal::map<mapbox::eternal::string, Color>({
{ "red", { 255, 0, 0, 1 } },
{ "yellow", { 255, 255, 0, 1 } },
{ "white", { 255, 255, 255, 1 } }, // comes before yellow!
{ "yellow", { 255, 220, 0, 1 } }, // a darker yellow
});

int main(void) {
static_assert(!multi_colors.unique(), "multi_colors are not unique");
static_assert(multi_colors.find("yellow") != multi_colors.end(), "colors contains yellow");
static_assert(multi_colors.find("yellow")->second == Color(255, 255, 0, 1), "yellow returns the correct color");
static_assert((++multi_colors.find("yellow"))->second == Color(255, 220, 0, 1), "yellow returns the correct color");
static_assert(multi_colors.equal_range("white").first == multi_colors.find("white"), "white range returns the correct begin");
static_assert(multi_colors.equal_range("white").second == multi_colors.find("yellow"), "white range end is the next color");
static_assert(multi_colors.equal_range("yellow").first == multi_colors.find("yellow"), "yellow range returns the correct begin");
static_assert(multi_colors.equal_range("yellow").second == multi_colors.end(), "yellow range end returns end");
static_assert(multi_colors.count("yellow") == 2, "has 2 yellows");

return EXIT_SUCCESS;
}
12 changes: 12 additions & 0 deletions recipes/eternal/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.8)

project(test_package CXX)

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

find_package(eternal REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE eternal::eternal)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
18 changes: 18 additions & 0 deletions recipes/eternal/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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)
3 changes: 3 additions & 0 deletions recipes/eternal/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.1":
folder: all

0 comments on commit 1fb8dda

Please sign in to comment.