Skip to content

Commit

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

* fix description, license

* remove unused function

* remove comment of template

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* use `self.info.settings`

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* use self.settings instead of self.info.settings (workaround)

Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
2 people authored and marc-mw committed Oct 7, 2022
1 parent 302f801 commit ad9c337
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/svector/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.2":
url: "https://github.com/martinus/svector/archive/refs/tags/v1.0.2.tar.gz"
sha256: "317743113aff89c7c11682ad7ed504a043885be7497f791cb393ba5a7a8d3c41"
65 changes: 65 additions & 0 deletions recipes/svector/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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.52.0"

class PackageConan(ConanFile):
name = "svector"
description = "Compact SVO optimized vector for C++17 or higher"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/martinus/svector"
topics = ("vector", "container", "small-vector", "header-only")
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

@property
def _minimum_cpp_standard(self):
return 17

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

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

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

def validate(self):
# FIXME: self.info.settings.compiler does not work with header-only packages
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", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(self, pattern="*.h", 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/svector/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(svector REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE svector::svector)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
26 changes: 26 additions & 0 deletions recipes/svector/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")
11 changes: 11 additions & 0 deletions recipes/svector/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "ankerl/svector.h"

int main(void) {
auto vec = ankerl::svector<int, 10>();
for (int i = 0; i < 100; ++i) {
vec.push_back(i);
}
auto data = vec.data();

return 0;
}
12 changes: 12 additions & 0 deletions recipes/svector/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(svector REQUIRED CONFIG)

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

0 comments on commit ad9c337

Please sign in to comment.