Skip to content

Commit

Permalink
(#15478) mgs: add version 0.2.1, support conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
toge authored Feb 1, 2023
1 parent 5b46a25 commit 3241184
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 56 deletions.
25 changes: 14 additions & 11 deletions recipes/mgs/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
sources:
0.1.2:
url: https://github.com/theodelrieu/mgs/releases/download/v0.1.2/mgs.zip
sha256: aba95870eafad95147c969c167a0e7c09b2c749ccafadbdd477de815e3e5bfd3
0.1.4:
url: https://github.com/theodelrieu/mgs/releases/download/v0.1.4/mgs.zip
sha256: e247976860a0c8d237caaf62a918627f59d4f8a5b5bb811ab01e7cbecf31d4ce
0.1.5:
url: https://github.com/theodelrieu/mgs/releases/download/v0.1.5/mgs.zip
sha256: ca00e5d26be18beac9874270c17bddbc4f96cad6d92aab685c9eb4be0e6d7fc7
0.2.1:
url: "https://github.com/theodelrieu/mgs/releases/download/v0.2.1/mgs.zip"
sha256: "da4a74d1cdaeb6c32c2097bcbebe21ba912ad84176a89014ac8232885d76bcc7"
0.2.0:
url: https://github.com/theodelrieu/mgs/releases/download/v0.2.0/mgs.zip
sha256: aa057a4096da9451bef1950a3e784350df590f09f6bad0c0ca59ed1874df4a36
url: "https://github.com/theodelrieu/mgs/releases/download/v0.2.0/mgs.zip"
sha256: "aa057a4096da9451bef1950a3e784350df590f09f6bad0c0ca59ed1874df4a36"
0.1.5:
url: "https://github.com/theodelrieu/mgs/releases/download/v0.1.5/mgs.zip"
sha256: "ca00e5d26be18beac9874270c17bddbc4f96cad6d92aab685c9eb4be0e6d7fc7"
0.1.4:
url: "https://github.com/theodelrieu/mgs/releases/download/v0.1.4/mgs.zip"
sha256: "e247976860a0c8d237caaf62a918627f59d4f8a5b5bb811ab01e7cbecf31d4ce"
0.1.2:
url: "https://github.com/theodelrieu/mgs/releases/download/v0.1.2/mgs.zip"
sha256: "aba95870eafad95147c969c167a0e7c09b2c749ccafadbdd477de815e3e5bfd3"
91 changes: 63 additions & 28 deletions recipes/mgs/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,93 @@
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import get, copy
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os

required_conan_version = ">=1.52.0"

class MgsConan(ConanFile):
name = "mgs"
url = "https://github.com/conan-io/conan-center-index"
description = "C++14 codec library"
homepage = "https://theodelrieu.github.io/mgs-docs"
license = "MIT"
topics = ("codec", "base64", "base32", "base16")
settings = "compiler"
_source_subfolder = "source_subfolder"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://theodelrieu.github.io/mgs-docs"
topics = ("codec", "base64", "base32", "base16", "header-only")
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

@property
def _min_cppstd(self):
return 14

@property
def _compilers_minimum_version(self):
return {
"gcc": "5",
"Visual Studio": "14",
"msvc": "190",
"clang": "3.4",
"apple-clang": "3.4",
}

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

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

def validate(self):
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 14)
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version:
if tools.Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("mgs requires C++14, which your compiler does not fully support.")
if Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not fully support.")
else:
self.output.warn("mgs requires C++14. Your compiler is unknown. Assuming it supports C++14.")
self.output.warn(f"{self.ref} requires C++{self._min_cppstd}. Your compiler is unknown. Assuming it supports C++{self._min_cppstd}.")

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

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

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

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "mgs")

self.cpp_info.components["mgs-config"].set_property("cmake_target_name", "mgs::config")

self.cpp_info.components["mgs-meta"].set_property("cmake_target_name", "mgs::meta")
self.cpp_info.components["mgs-meta"].requires = ["mgs-config"]

self.cpp_info.components["mgs-exceptions"].set_property("cmake_target_name", "mgs::exceptions")
self.cpp_info.components["mgs-exceptions"].requires = ["mgs-config"]

self.cpp_info.components["mgs-codecs"].set_property("cmake_target_name", "mgs::codecs")
self.cpp_info.components["mgs-codecs"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions"]

self.cpp_info.components["mgs-base_n"].set_property("cmake_target_name", "mgs::base_n")
self.cpp_info.components["mgs-base_n"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs"]

self.cpp_info.components["mgs-base16"].set_property("cmake_target_name", "mgs::base16")
self.cpp_info.components["mgs-base16"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs", "mgs-base_n"]

self.cpp_info.components["mgs-base32"].set_property("cmake_target_name", "mgs::base32")
self.cpp_info.components["mgs-base32"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs", "mgs-base_n"]

self.cpp_info.components["mgs-base64"].set_property("cmake_target_name", "mgs::base64")
self.cpp_info.components["mgs-base64"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs", "mgs-base_n"]

self.cpp_info.components["mgs-base64url"].set_property("cmake_target_name", "mgs::base64url")
self.cpp_info.components["mgs-base64url"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs", "mgs-base_n"]

self.cpp_info.components["mgs-base32hex"].set_property("cmake_target_name", "mgs::base32hex")
self.cpp_info.components["mgs-base32hex"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs", "mgs-base_n"]

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "mgs"
self.cpp_info.names["cmake_find_package_multi"] = "mgs"

Expand All @@ -52,36 +96,27 @@ def package_info(self):

self.cpp_info.components["mgs-meta"].names["cmake_find_package"] = "meta"
self.cpp_info.components["mgs-meta"].names["cmake_find_package"] = "meta"
self.cpp_info.components["mgs-meta"].requires = ["mgs-config"]

self.cpp_info.components["mgs-exceptions"].names["cmake_find_package"] = "exceptions"
self.cpp_info.components["mgs-exceptions"].names["cmake_find_package_multi"] = "exceptions"
self.cpp_info.components["mgs-exceptions"].requires = ["mgs-config"]

self.cpp_info.components["mgs-codecs"].names["cmake_find_package"] = "codecs"
self.cpp_info.components["mgs-codecs"].names["cmake_find_package_multi"] = "codecs"
self.cpp_info.components["mgs-codecs"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions"]

self.cpp_info.components["mgs-base_n"].names["cmake_find_package"] = "base_n"
self.cpp_info.components["mgs-base_n"].names["cmake_find_package_multi"] = "base_n"
self.cpp_info.components["mgs-base_n"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs"]

self.cpp_info.components["mgs-base16"].names["cmake_find_package"] = "base16"
self.cpp_info.components["mgs-base16"].names["cmake_find_package_multi"] = "base16"
self.cpp_info.components["mgs-base16"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs", "mgs-base_n"]

self.cpp_info.components["mgs-base32"].names["cmake_find_package"] = "base32"
self.cpp_info.components["mgs-base32"].names["cmake_find_package_multi"] = "base32"
self.cpp_info.components["mgs-base32"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs", "mgs-base_n"]

self.cpp_info.components["mgs-base64"].names["cmake_find_package"] = "base64"
self.cpp_info.components["mgs-base64"].names["cmake_find_package_multi"] = "base64"
self.cpp_info.components["mgs-base64"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs", "mgs-base_n"]

self.cpp_info.components["mgs-base64url"].names["cmake_find_package"] = "base64url"
self.cpp_info.components["mgs-base64url"].names["cmake_find_package_multi"] = "base64url"
self.cpp_info.components["mgs-base64url"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs", "mgs-base_n"]

self.cpp_info.components["mgs-base32hex"].names["cmake_find_package"] = "base32hex"
self.cpp_info.components["mgs-base32hex"].names["cmake_find_package_multi"] = "base32hex"
self.cpp_info.components["mgs-base32hex"].requires = ["mgs-config", "mgs-meta", "mgs-exceptions", "mgs-codecs", "mgs-base_n"]
13 changes: 5 additions & 8 deletions recipes/mgs/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(mgs REQUIRED base64 CONFIG)
add_executable(example example.cpp)
target_link_libraries(example mgs::base64)
set_property(TARGET example PROPERTY CXX_STANDARD 14)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE mgs::base64)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
22 changes: 16 additions & 6 deletions recipes/mgs/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os

class TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "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):
self.run(os.path.join("bin", "example"), 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")
File renamed without changes.
8 changes: 8 additions & 0 deletions recipes/mgs/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.8)
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/)
18 changes: 18 additions & 0 deletions recipes/mgs/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)
8 changes: 5 additions & 3 deletions recipes/mgs/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
versions:
"0.1.2":
"0.2.1":
folder: all
"0.1.4":
"0.2.0":
folder: all
"0.1.5":
folder: all
"0.2.0":
"0.1.4":
folder: all
"0.1.2":
folder: all

0 comments on commit 3241184

Please sign in to comment.