Skip to content

Commit

Permalink
(#12894) magic_enum: conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Sep 14, 2022
1 parent d067ccb commit 62df6e5
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 44 deletions.
77 changes: 45 additions & 32 deletions recipes/magic_enum/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
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 copy, get
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os

required_conan_version = ">=1.50.0"


class MagicEnumConan(ConanFile):
name = "magic_enum"
description = "Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code."
topics = (
"conan",
"cplusplus",
"enum-to-string",
"string-to-enum"
"serialization",
"reflection",
"header-only",
"compile-time"
description = (
"Header-only C++17 library provides static reflection for enums, work "
"with any enum type without any macro or boilerplate code."
)
url = "https://github.com/conan-io/conan-center-index "
topics = ("cplusplus", "enum-to-string", "string-to-enum", "serialization",
"reflection", "header-only", "compile-time")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/Neargye/magic_enum"
license = "MIT"
settings = "compiler", "arch", "build_type", "os"
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 _compilers_minimum_version(self):
Expand All @@ -34,25 +36,36 @@ def _compilers_minimum_version(self):
"apple-clang": "10",
}

def configure(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, "17")
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if not minimum_version:
self.output.warn("magic_enum requires C++17. Your compiler is unknown. Assuming it supports C++17.")
elif tools.Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("magic_enum: Unsupported compiler: {}-{} "
"(https://github.com/Neargye/magic_enum#compiler-compatibility)."
.format(self.settings.compiler, self.settings.compiler.version))
def layout(self):
basic_layout(self, src_folder="src")

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

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
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.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 build(self):
pass

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

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "magic_enum")
self.cpp_info.set_property("cmake_target_name", "magic_enum::magic_enum")
self.cpp_info.bindirs = []
self.cpp_info.frameworkdirs = []
self.cpp_info.libdirs = []
self.cpp_info.resdirs = []
9 changes: 3 additions & 6 deletions recipes/magic_enum/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)

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

find_package(magic_enum REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
target_link_libraries(${PROJECT_NAME} magic_enum::magic_enum)
target_link_libraries(${PROJECT_NAME} PRIVATE magic_enum::magic_enum)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
21 changes: 15 additions & 6 deletions recipes/magic_enum/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
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", "cmake_find_package_multi"
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", "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")
11 changes: 11 additions & 0 deletions recipes/magic_enum/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(magic_enum REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE magic_enum::magic_enum)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
17 changes: 17 additions & 0 deletions recipes/magic_enum/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)

0 comments on commit 62df6e5

Please sign in to comment.