From 4df244b4481942808db7275bcb8b1cfa199b6121 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Fri, 23 Sep 2022 16:34:40 +0200 Subject: [PATCH] conan v2 support --- recipes/cppcodec/all/conanfile.py | 43 ++++++++++++++----- .../cppcodec/all/test_package/CMakeLists.txt | 13 +++--- .../cppcodec/all/test_package/conanfile.py | 23 +++++++--- .../{example.cpp => test_package.cpp} | 0 .../all/test_v1_package/CMakeLists.txt | 11 +++++ .../cppcodec/all/test_v1_package/conanfile.py | 17 ++++++++ recipes/cppcodec/config.yml | 1 - 7 files changed, 82 insertions(+), 26 deletions(-) rename recipes/cppcodec/all/test_package/{example.cpp => test_package.cpp} (100%) create mode 100644 recipes/cppcodec/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/cppcodec/all/test_v1_package/conanfile.py diff --git a/recipes/cppcodec/all/conanfile.py b/recipes/cppcodec/all/conanfile.py index c843146d3df75..59f96dbe4a59f 100644 --- a/recipes/cppcodec/all/conanfile.py +++ b/recipes/cppcodec/all/conanfile.py @@ -1,5 +1,10 @@ +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): @@ -7,21 +12,37 @@ class CppcodecConan(ConanFile): 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 = [] diff --git a/recipes/cppcodec/all/test_package/CMakeLists.txt b/recipes/cppcodec/all/test_package/CMakeLists.txt index 6aab347eddf53..d359976811ee3 100644 --- a/recipes/cppcodec/all/test_package/CMakeLists.txt +++ b/recipes/cppcodec/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/cppcodec/all/test_package/conanfile.py b/recipes/cppcodec/all/test_package/conanfile.py index 9a662bfeb73fe..0a6bc68712d90 100644 --- a/recipes/cppcodec/all/test_package/conanfile.py +++ b/recipes/cppcodec/all/test_package/conanfile.py @@ -1,10 +1,19 @@ +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) @@ -12,6 +21,6 @@ def build(self): 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") diff --git a/recipes/cppcodec/all/test_package/example.cpp b/recipes/cppcodec/all/test_package/test_package.cpp similarity index 100% rename from recipes/cppcodec/all/test_package/example.cpp rename to recipes/cppcodec/all/test_package/test_package.cpp diff --git a/recipes/cppcodec/all/test_v1_package/CMakeLists.txt b/recipes/cppcodec/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..4e3738c68e0b9 --- /dev/null +++ b/recipes/cppcodec/all/test_v1_package/CMakeLists.txt @@ -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) diff --git a/recipes/cppcodec/all/test_v1_package/conanfile.py b/recipes/cppcodec/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/cppcodec/all/test_v1_package/conanfile.py @@ -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) diff --git a/recipes/cppcodec/config.yml b/recipes/cppcodec/config.yml index 4862588660bd8..7e65100e62b2c 100644 --- a/recipes/cppcodec/config.yml +++ b/recipes/cppcodec/config.yml @@ -1,4 +1,3 @@ ---- versions: "0.2": folder: all