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 2 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/ulid/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"cci.20230615":
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
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"
107 changes: 107 additions & 0 deletions recipes/ulid/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc

Check warning on line 3 in recipes/ulid/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused is_msvc_static_runtime imported from conan.tools.microsoft
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file

Check warning on line 4 in recipes/ulid/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused replace_in_file imported from conan.tools.files
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout

Check warning on line 7 in recipes/ulid/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused CMakeDeps imported from conan.tools.cmake
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
from conan.tools.env import VirtualBuildEnv

Check warning on line 8 in recipes/ulid/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused VirtualBuildEnv imported from conan.tools.env
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
import os


required_conan_version = ">=1.53.0"

class UlidConan(ConanFile):
name = "ulid"
description = "Lightweight ulid implementation in C++ suitable for embedded environments"
license = "The Unlicense"
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
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",
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.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."
)
if is_msvc(self) and self.options.shared:
raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.")

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.filenames["cmake_find_package"] = "ULID"
self.cpp_info.filenames["cmake_find_package_multi"] = "ulid"
self.cpp_info.names["cmake_find_package"] = "ULID"
self.cpp_info.names["cmake_find_package_multi"] = "ulid"
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions recipes/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/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)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
27 changes: 27 additions & 0 deletions recipes/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/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;
}
11 changes: 11 additions & 0 deletions recipes/ulid/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES CXX)

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

find_package(ulid REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ulid::ulid)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
17 changes: 17 additions & 0 deletions recipes/ulid/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(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 tools.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/ulid/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20230615":
folder: all