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

ulid: add recipe #19573

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions recipes/marcomagdy-ulid/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"cci.20230615":
url: "https://github.com/marcomagdy/ulid/archive/a14ff0987bc327cca60333ac3bfda37e42a71f2d.zip"
sha256: "e7884fee1a6973a7a83ab07bf229d3e86d6e59afabc7418be318aa3f42af5872"
patches:
"cci.20230615":
- patch_file: "patches/cci.20230615-msvc-fix.patch"
patch_description: "MSVC compile fix patch"
patch_type: "portability"
104 changes: 104 additions & 0 deletions recipes/marcomagdy-ulid/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import check_min_vs, is_msvc
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
import os


required_conan_version = ">=1.53.0"


class UlidConan(ConanFile):
name = "marcomagdy-ulid"
description = "Lightweight ulid implementation in C++ suitable for embedded environments"
license = "Unlicense"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/marcomagdy/ulid"
topics = ("ulid", "id", "embedded")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"gcc": "7",
"clang": "7",
"apple-clang": "10",
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
del self.options.shared
self.package_type = "static-library"

def configure(self):
if self.options.get_safe("shared"):
self.options.rm_safe("fPIC")

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

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

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ENABLE_SANITIZERS"] = False
tc.variables["BUILD_TESTING"] = False
tc.generate()

def _patch_sources(self):
apply_conandata_patches(self)

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

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.libs = ["ulid"]
self.cpp_info.set_property("cmake_file_name", "ulid")
self.cpp_info.set_property("cmake_target_name", "ULID::ulid")
20 changes: 20 additions & 0 deletions recipes/marcomagdy-ulid/all/patches/cci.20230615-msvc-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index 12ba41b..e0f59b1 100644
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -1,7 +1,11 @@
add_library(${PROJECT_NAME} ulid.cpp)
target_compile_options(${PROJECT_NAME} PRIVATE
-fno-exceptions
- -fno-rtti
- -Wall
- -Wextra
- -Werror)
+ -fno-rtti)
+
+if(NOT MSVC)
+ target_compile_options(${PROJECT_NAME} PRIVATE
+ -Wall
+ -Werror
+ -Wextra)
+endif()
9 changes: 9 additions & 0 deletions recipes/marcomagdy-ulid/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.15)

project(test_package CXX)

find_package(ulid REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ULID::ulid)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
27 changes: 27 additions & 0 deletions recipes/marcomagdy-ulid/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


# It will become the standard on Conan 2.x
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.bindir, "test_package")
self.run(bin_path, env="conanrun")
11 changes: 11 additions & 0 deletions recipes/marcomagdy-ulid/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <cstdlib>
#include <iostream>

#include "ulid/ulid.h"

int main(void)
{
std::cout << ulid::generate().str();

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/marcomagdy-ulid/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20230615":
folder: all
Loading