Skip to content

Commit 8649e2b

Browse files
authored
(#14252) enum-flags: conan v2 support
1 parent 5d4d607 commit 8649e2b

File tree

12 files changed

+128
-88
lines changed

12 files changed

+128
-88
lines changed

recipes/enum-flags/0.1a/conandata.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

recipes/enum-flags/0.1a/conanfile.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

recipes/enum-flags/0.1a/test_package/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

recipes/enum-flags/0.1a/test_package/conanfile.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

recipes/enum-flags/all/conandata.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sources:
2+
"0.1a":
3+
url: "https://github.com/grisumbras/enum-flags/archive/refs/tags/v0.1a.tar.gz"
4+
sha256: "34a952a39e9f079357003566da01cabae434e3679c52fafc6bc09f94d0b9d525"

recipes/enum-flags/all/conanfile.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from conan import ConanFile
2+
from conan.tools.build import check_min_cppstd
3+
from conan.tools.files import copy, get
4+
from conan.tools.layout import basic_layout
5+
import os
6+
7+
required_conan_version = ">=1.50.0"
8+
9+
10+
class EnumFlagsConan(ConanFile):
11+
name = "enum-flags"
12+
description = "Bit flags for C++11 scoped enums"
13+
homepage = "https://github.com/grisumbras/enum-flags"
14+
url = "https://github.com/conan-io/conan-center-index"
15+
topics = ("bitmask", "enum")
16+
license = "MIT"
17+
18+
settings = "os", "arch", "compiler", "build_type"
19+
options = {
20+
"forbid_implicit_conversions": [True, False],
21+
}
22+
default_options = {
23+
"forbid_implicit_conversions": True,
24+
}
25+
26+
no_copy_source = True
27+
28+
def layout(self):
29+
basic_layout(self, src_folder="src")
30+
31+
def package_id(self):
32+
self.info.clear()
33+
34+
def validate(self):
35+
if self.settings.compiler.get_safe("cppstd"):
36+
check_min_cppstd(self, 11)
37+
38+
def source(self):
39+
get(self, **self.conan_data["sources"][self.version],
40+
destination=self.source_folder, strip_root=True)
41+
42+
def build(self):
43+
pass
44+
45+
def package(self):
46+
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
47+
copy(self, "*", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))
48+
49+
def package_info(self):
50+
self.cpp_info.set_property("cmake_file_name", "enumflags")
51+
self.cpp_info.set_property("cmake_target_name", "EnumFlags::EnumFlags")
52+
self.cpp_info.bindirs = []
53+
self.cpp_info.libdirs = []
54+
# Yes, there is a typo in the macro name.
55+
# This macro is only useful when using regular C enums,
56+
# since enum classes prevent implicit conversions already.
57+
if self.options.forbid_implicit_conversions:
58+
self.cpp_info.defines = ["ENUM_CLASS_FLAGS_FORBID_IMPLICT_CONVERSION"]
59+
60+
# TODO: to remove in conan v2
61+
self.cpp_info.filenames["cmake_find_package"] = "enumflags"
62+
self.cpp_info.filenames["cmake_find_package_multi"] = "enumflags"
63+
self.cpp_info.names["cmake_find_package"] = "EnumFlags"
64+
self.cpp_info.names["cmake_find_package_multi"] = "EnumFlags"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(test_package LANGUAGES CXX)
3+
4+
find_package(enumflags REQUIRED CONFIG)
5+
6+
add_executable(${PROJECT_NAME} test_package.cpp)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE EnumFlags::EnumFlags)
8+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import CMake, cmake_layout
4+
import os
5+
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def layout(self):
13+
cmake_layout(self)
14+
15+
def requirements(self):
16+
self.requires(self.tested_reference_str)
17+
18+
def build(self):
19+
cmake = CMake(self)
20+
cmake.configure()
21+
cmake.build()
22+
23+
def test(self):
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "arch", "compiler", "build_type"
7+
generators = "cmake", "cmake_find_package_multi"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self):
16+
bin_path = os.path.join("bin", "test_package")
17+
self.run(bin_path, run_environment=True)

recipes/enum-flags/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
versions:
22
"0.1a":
3-
folder: "0.1a"
3+
folder: all

0 commit comments

Comments
 (0)