Skip to content

Commit 55c8f45

Browse files
committed
polymorphic_value: conan v2 support
done as part of @prince-chrismc's webinar
1 parent f030779 commit 55c8f45

File tree

5 files changed

+66
-31
lines changed

5 files changed

+66
-31
lines changed
Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from conans import ConanFile, tools
2-
from conans.errors import ConanInvalidConfiguration
1+
import os
32

4-
required_conan_version = ">=1.43.0"
3+
from conan import ConanFile, tools
4+
from conan.errors import ConanInvalidConfiguration
5+
from conan.tools.files import copy, get
6+
from conan.tools.layout import basic_layout
7+
8+
required_conan_version = ">=1.50.0"
59

610

711
class PolymorphictValueConan(ConanFile):
@@ -14,10 +18,6 @@ class PolymorphictValueConan(ConanFile):
1418
settings = "os", "arch", "compiler", "build_type"
1519
no_copy_source = True
1620

17-
@property
18-
def _source_subfolder(self):
19-
return "source_subfolder"
20-
2121
@property
2222
def _minimum_cpp_standard(self):
2323
return 17
@@ -32,38 +32,42 @@ def _minimum_compilers_version(self):
3232
}
3333

3434
def validate(self):
35-
if self.settings.compiler.get_safe("cppstd"):
36-
tools.check_min_cppstd(self, self._minimum_cpp_standard)
35+
if self.info.settings.get_safe("compiler.cppstd"):
36+
tools.build.check_min_cppstd(self, self._minimum_cpp_standard)
3737
min_version = self._minimum_compilers_version.get(
38-
str(self.settings.compiler))
38+
str(self.info.settings.compiler))
3939
if not min_version:
40-
self.output.warn("{} recipe lacks information about the {} "
41-
"compiler support.".format(
42-
self.name, self.settings.compiler))
40+
self.output.warning("{} recipe lacks information about the {} "
41+
"compiler support.".format(
42+
self.name, self.info.settings.compiler))
4343
else:
44-
if tools.Version(self.settings.compiler.version) < min_version:
44+
if tools.Version(self.info.settings.compiler.version) < min_version:
4545
raise ConanInvalidConfiguration(
4646
"{} requires C++{} support. "
4747
"The current compiler {} {} does not support it.".format(
4848
self.name, self._minimum_cpp_standard,
49-
self.settings.compiler,
50-
self.settings.compiler.version))
49+
self.info.settings.compiler,
50+
self.info.settings.compiler.version))
5151

5252
def package_id(self):
53-
self.info.header_only()
53+
self.info.clear()
54+
55+
def layout(self):
56+
basic_layout(self, src_folder="source")
5457

5558
def source(self):
56-
tools.get(**self.conan_data["sources"][self.version],
57-
strip_root=True, destination=self._source_subfolder)
59+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
5860

5961
def package(self):
60-
self.copy(pattern="polymorphic_value.*", dst="include",
61-
src=self._source_subfolder)
62-
self.copy("*LICENSE*", dst="licenses", keep_path=False)
62+
copy(self, "polymorphic_value.*", self.source_folder,
63+
os.path.join(self.package_folder, "include"))
64+
copy(self, "*LICENSE*", self.source_folder,
65+
os.path.join(self.package_folder, "licenses"), keep_path=False)
6366

6467
def package_info(self):
6568
self.cpp_info.set_property("cmake_file_name", "polymorphic_value")
66-
self.cpp_info.set_property("cmake_target_name", "polymorphic_value::polymorphic_value")
69+
self.cpp_info.set_property(
70+
"cmake_target_name", "polymorphic_value::polymorphic_value")
6771

6872
self.cpp_info.names["cmake_find_package"] = "polymorphic_value"
6973
self.cpp_info.names["cmake_find_package_multi"] = "polymorphic_value"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(test_package CXX)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup(TARGETS)
6-
74
find_package(polymorphic_value REQUIRED CONFIG)
85

96
add_executable(${PROJECT_NAME} test_package.cpp)
107
target_link_libraries(${PROJECT_NAME} PRIVATE polymorphic_value::polymorphic_value)
118
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
9+
10+
enable_testing()
11+
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
from conans import ConanFile, CMake, tools
2-
import os
1+
from conan import ConanFile, tools
2+
from conan.tools.cmake import CMake
33

44

55
class TestPackageConan(ConanFile):
66
settings = "os", "arch", "compiler", "build_type"
7-
generators = "cmake", "cmake_find_package_multi"
7+
generators = "CMakeDeps", "CMakeToolchain"
8+
9+
def requirements(self):
10+
self.requires(self.tested_reference_str)
811

912
def build(self):
1013
cmake = CMake(self)
1114
cmake.configure()
1215
cmake.build()
1316

1417
def test(self):
15-
if not tools.cross_building(self):
16-
self.run(os.path.join("bin", "test_package"), run_environment=True)
18+
if not tools.build.cross_building(self):
19+
cmake = CMake(self)
20+
cmake.test()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(test_package CXX)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
find_package(polymorphic_value REQUIRED CONFIG)
8+
9+
add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
10+
target_link_libraries(${PROJECT_NAME} PRIVATE polymorphic_value::polymorphic_value)
11+
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
self.run(os.path.join("bin", "test_package"), run_environment=True)

0 commit comments

Comments
 (0)