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

cppcodec: conan v2 support #13110

Merged
merged 1 commit into from
Sep 26, 2022
Merged
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
43 changes: 32 additions & 11 deletions recipes/cppcodec/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.files import copy, get
from conan.tools.layout import basic_layout
import os
from conans import ConanFile, tools

required_conan_version = ">=1.50.0"


class CppcodecConan(ConanFile):
name = "cppcodec"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/tplgy/cppcodec"
description = "Header-only C++11 library to encode/decode base64, base64url, base32, base32hex and hex (a.k.a. base16) as specified in RFC 4648, plus Crockford's base32"
description = (
"Header-only C++11 library to encode/decode base64, base64url, base32, "
"base32hex and hex (a.k.a. base16) as specified in RFC 4648, plus Crockford's base32"
)
topics = ("base64", "cpp11", "codec", "base32")
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

_source_subfolder = "source_subfolder"
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"):
check_min_cppstd(self, 11)

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def package(self):
self.copy("*hpp", dst=os.path.join("include", "cppcodec"), src=os.path.join(self._source_subfolder, "cppcodec"))
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
def build(self):
pass

def package_id(self):
self.info.header_only()
def package(self):
copy(self, "*hpp", src=os.path.join(self.source_folder, "cppcodec"), dst=os.path.join(self.package_folder, "include", "cppcodec"))
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "cppcodec-1")
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
self.cpp_info.resdirs = []
13 changes: 6 additions & 7 deletions recipes/cppcodec/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

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

add_executable(example example.cpp)
target_link_libraries(example ${CONAN_LIBS})
set_property(TARGET example PROPERTY CXX_STANDARD 11)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE cppcodec::cppcodec)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
23 changes: 16 additions & 7 deletions recipes/cppcodec/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
from conans import ConanFile, CMake, tools


class CppcodecTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
class TestPackageConan(ConanFile):
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.cross_building(self.settings):
bin_path = os.path.join("bin", "example")
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")
11 changes: 11 additions & 0 deletions recipes/cppcodec/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.8)
project(test_package LANGUAGES CXX)

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

find_package(cppcodec REQUIRED CONFIG)

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