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

yomm2: new recipe #23920

Merged
merged 11 commits into from
May 14, 2024
4 changes: 4 additions & 0 deletions recipes/yomm2/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.5.1":
url: "https://github.com/jll63/yomm2/archive/refs/tags/v1.5.1.tar.gz"
sha256: "323abba27a356555cc3ead3e3e950746ab43f90d97ad21950f2ba3afaf565ecc"
109 changes: 109 additions & 0 deletions recipes/yomm2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout, CMakeDeps
from conan.tools.files import get, rm, rmdir, copy
from conan.tools.scm import Version

required_conan_version = ">=1.54.0"


class yomm2Recipe(ConanFile):
name = "yomm2"
package_type = "shared-library"
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
# Optional metadata
license = "BSL-1.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/jll63/yomm2"
description = "Fast, orthogonal, open multi-methods. Solve the Expression Problem in C++17"
topics = ("multi-methods", "multiple-dispatch", "open-methods", "shared-library",
"header-only", "polymorphism", "expression-problem", "c++17")
# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {
"header_only": [True, False],
}
default_options = {
"header_only": False
}

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"gcc": "8",
"clang": "5",
"apple-clang": "12",
"msvc": "192"
}

def configure(self):
if self.options.header_only:
self.package_type = "header-library"

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
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 build_requirements(self):
self.tool_requires("cmake/[>=3.20 <4]")

def requirements(self):
# Upstream requires Boost 1.74
# Using more modern Boost version to avoid issues like the one commented here:
# - https://github.com/conan-io/conan/issues/15977#issuecomment-2098003085
self.requires("boost/1.85.0", transitive_headers=True)

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

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

def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.variables["YOMM2_ENABLE_EXAMPLES"] = "OFF"
tc.variables["YOMM2_ENABLE_TESTS"] = "OFF"
tc.variables["YOMM2_SHARED"] = not bool(self.options.header_only)
tc.generate()

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

def package_id(self):
# if yomm2 is built as static, it behaves as a header-only one
if self.info.options.header_only:
self.info.clear()

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
if self.options.header_only:
rmdir(self, os.path.join(self.package_folder, "lib"))
else:
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "YOMM2")
self.cpp_info.set_property("cmake_target_name", "YOMM2::yomm2")
if self.options.header_only:
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
else:
self.cpp_info.libs = ["yomm2"]
8 changes: 8 additions & 0 deletions recipes/yomm2/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(YOMM2 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE YOMM2::yomm2 ${CMAKE_THREAD_LIBS_INIT})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
26 changes: 26 additions & 0 deletions recipes/yomm2/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run


class yomm2TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"

def requirements(self):
self.requires(self.tested_reference_str)

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

def layout(self):
cmake_layout(self)

def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "test_package")
self.run(cmd, env="conanrun")
25 changes: 25 additions & 0 deletions recipes/yomm2/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2021 Jean-Louis Leroy
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <yorel/yomm2/keywords.hpp>

#include <iostream>
#include <memory>
#include <string>

using std::cout;
using yorel::yomm2::virtual_;

// register_class(classes);

// declare_method(return, name, (params));

// define_method(return, name, (params)) {
// }

int main() {
yorel::yomm2::update();
return 0;
}
3 changes: 3 additions & 0 deletions recipes/yomm2/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.5.1":
folder: all