forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(conan-io#12964) eternal: add recipe
* 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
Showing
8 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"1.0.1": | ||
folder: all |