Skip to content

Commit

Permalink
(#19912) crc_cpp: conan v2 support
Browse files Browse the repository at this point in the history
* conan v2 support

* add test_v1_package
  • Loading branch information
SpaceIm authored Sep 19, 2023
1 parent aebb3c5 commit e1e14ff
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 55 deletions.
18 changes: 9 additions & 9 deletions recipes/crc_cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
sources:
"1.0.0":
url: "https://github.com/AshleyRoll/crc_cpp/archive/refs/tags/v1.0.0.tar.gz"
sha256: "035ed616e0662eddbe7db7c920faaef99bbeb8953ebf98c3bb76cb81a2c4de2b"
"1.0.1":
url: "https://github.com/AshleyRoll/crc_cpp/archive/refs/tags/v1.0.1.tar.gz"
sha256: "865a0e110bf7e94061ceef1683947a7788b54f932c7ce3848edc89d36e1aea26"
"1.1.0":
url: "https://github.com/AshleyRoll/crc_cpp/archive/refs/tags/v1.1.0.tar.gz"
sha256: "50e46e3c44eb39809f6697b253f7b36c089642d7b7f2ebe2f75adf23c50676be"
"1.2.0":
url: "https://github.com/AshleyRoll/crc_cpp/archive/refs/tags/v1.2.0.tar.gz"
sha256: "508a609d9ef12c3088ed17a8ed820c965161a36dd90738c7358333fbfbe96af5"
"1.1.0":
url: "https://github.com/AshleyRoll/crc_cpp/archive/refs/tags/v1.1.0.tar.gz"
sha256: "50e46e3c44eb39809f6697b253f7b36c089642d7b7f2ebe2f75adf23c50676be"
"1.0.1":
url: "https://github.com/AshleyRoll/crc_cpp/archive/refs/tags/v1.0.1.tar.gz"
sha256: "865a0e110bf7e94061ceef1683947a7788b54f932c7ce3848edc89d36e1aea26"
"1.0.0":
url: "https://github.com/AshleyRoll/crc_cpp/archive/refs/tags/v1.0.0.tar.gz"
sha256: "035ed616e0662eddbe7db7c920faaef99bbeb8953ebf98c3bb76cb81a2c4de2b"
67 changes: 38 additions & 29 deletions recipes/crc_cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from conan import ConanFile, tools
from conan.tools.scm import Version
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import copy, get
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os

required_conan_version = ">=1.50.0"
Expand All @@ -9,45 +12,51 @@
class Crc_CppConan(ConanFile):
name = "crc_cpp"
description = "A header only constexpr / compile time small-table based CRC library for C++17 and newer"
topics = "crc_cpp", "crc", "constexpr", "cpp17", "cpp20", "header-only"
settings = "compiler", "os"
topics = ("crc", "constexpr", "cpp17", "cpp20", "header-only")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/AshleyRoll/crc_cpp"
license = "MIT"
package_type = "header-library"
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

@property
def _source_subfolder(self):
return "source_subfolder"
def _min_cppstd(self):
return "17"

@property
def _supported_compiler(self):
compiler = str(self.settings.compiler)
version = Version(self.settings.compiler.version)
if compiler == "Visual Studio" and version >= "15":
return True
elif compiler == "gcc" and version >= "9":
return True
elif compiler == "clang" and version >= "5":
return True
elif compiler == "apple-clang" and version >= "10":
return True
else:
self.output.warn("{} recipe lacks information about the {} compiler standard version support".format(self.name, compiler))
return False
def _compilers_minimum_version(self):
return {
"gcc": "9",
"clang": "5",
"apple-clang": "10",
"Visual Studio": "15",
"msvc": "191",
}

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

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

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.build.check_min_cppstd(self, "17")
if not self._supported_compiler:
raise ConanInvalidConfiguration("crc_cpp: Unsupported compiler: {}-{} "
"Minimum C++17 constexpr features required.".format(self.settings.compiler, self.settings.compiler.version))
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 source(self):
tools.files.get(self, **self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="*", dst="include", src=os.path.join(self._source_subfolder, "include"))
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "*", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))

def package_id(self):
self.info.header_only()
def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
9 changes: 3 additions & 6 deletions recipes/crc_cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(crc_cpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE crc_cpp::crc_cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
22 changes: 15 additions & 7 deletions recipes/crc_cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
from conan import ConanFile, tools
from conans import CMake
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

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

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

def test(self):
if not tools.build.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/crc_cpp/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/crc_cpp/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)
8 changes: 4 additions & 4 deletions recipes/crc_cpp/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
versions:
"1.0.0":
folder: "all"
"1.0.1":
"1.2.0":
folder: "all"
"1.1.0":
folder: "all"
"1.2.0":
"1.0.1":
folder: "all"
"1.0.0":
folder: "all"

0 comments on commit e1e14ff

Please sign in to comment.