Skip to content

Commit e63eb3e

Browse files
authored
(#14358) luple: conan v2 support
1 parent 9c9f44e commit e63eb3e

File tree

5 files changed

+94
-40
lines changed

5 files changed

+94
-40
lines changed

recipes/luple/all/conanfile.py

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,71 @@
1+
from conan import ConanFile
2+
from conan.errors import ConanInvalidConfiguration
3+
from conan.tools.build import check_min_cppstd
4+
from conan.tools.files import copy, download, get
5+
from conan.tools.layout import basic_layout
16
import os
2-
from conans import ConanFile, tools
3-
from conans.errors import ConanInvalidConfiguration
47

5-
required_conan_version = ">=1.33.0"
8+
required_conan_version = ">=1.50.0"
9+
610

711
class LupleConan(ConanFile):
812
name = "luple"
913
license = "Unlicense"
1014
url = "https://github.com/conan-io/conan-center-index"
1115
homepage = "https://github.com/alexpolt/luple"
1216
description = "Home to luple, nuple, C++ String Interning, Struct Reader and C++ Type Loophole"
13-
topics = ("conan", "loophole", "luple", "nuple", "struct", "intern")
14-
settings = "compiler"
17+
topics = ("loophole", "luple", "nuple", "struct", "intern")
18+
settings = "os", "arch", "compiler", "build_type"
1519
no_copy_source = True
1620

17-
def validate(self):
18-
minimal_cpp_standard = "14"
19-
if self.settings.compiler.cppstd:
20-
tools.check_min_cppstd(self, minimal_cpp_standard)
21-
minimal_version = {
21+
@property
22+
def _min_cppstd(self):
23+
return "14"
24+
25+
@property
26+
def _compilers_minimum_version(self):
27+
return {
2228
"gcc": "5",
2329
"clang": "3.4",
2430
"apple-clang": "10",
25-
"Visual Studio": "14"
31+
"Visual Studio": "14",
32+
"msvc": "190",
2633
}
27-
compiler = str(self.settings.compiler)
28-
if compiler not in minimal_version:
29-
self.output.warn(
30-
"%s recipe lacks information about the %s compiler standard version support" % (self.name, compiler))
31-
self.output.warn(
32-
"%s requires a compiler that supports at least C++%s" % (self.name, minimal_cpp_standard))
33-
return
34-
version = tools.Version(self.settings.compiler.version)
35-
if version < minimal_version[compiler]:
36-
raise ConanInvalidConfiguration("%s requires a compiler that supports at least C++%s" % (self.name, minimal_cpp_standard))
34+
35+
def layout(self):
36+
basic_layout(self, src_folder="src")
37+
38+
def package_id(self):
39+
self.info.clear()
40+
41+
def validate(self):
42+
if self.settings.compiler.get_safe("cppstd"):
43+
check_min_cppstd(self, self._min_cppstd)
44+
45+
def loose_lt_semver(v1, v2):
46+
lv1 = [int(v) for v in v1.split(".")]
47+
lv2 = [int(v) for v in v2.split(".")]
48+
min_length = min(len(lv1), len(lv2))
49+
return lv1[:min_length] < lv2[:min_length]
50+
51+
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
52+
if minimum_version and loose_lt_semver(str(self.settings.compiler.version), minimum_version):
53+
raise ConanInvalidConfiguration(
54+
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.",
55+
)
3756

3857
def source(self):
39-
tools.get(**self.conan_data["sources"][self.version][0], strip_root=True)
40-
tools.download(filename="LICENSE", **self.conan_data["sources"][self.version][1])
58+
get(self, **self.conan_data["sources"][self.version][0],
59+
destination=self.source_folder, strip_root=True)
60+
download(self, filename="LICENSE", **self.conan_data["sources"][self.version][1])
4161

42-
def package(self):
43-
self.copy("LICENSE", dst="licenses")
44-
self.copy("*.h", dst="include")
62+
def build(self):
63+
pass
4564

46-
def package_id(self):
47-
self.info.header_only()
65+
def package(self):
66+
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
67+
copy(self, "*.h", src=self.source_folder, dst=os.path.join(self.package_folder, "include"))
4868

4969
def package_info(self):
70+
self.cpp_info.bindirs = []
5071
self.cpp_info.libdirs = []
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
cmake_minimum_required(VERSION 3.1)
2-
project(test_package)
1+
cmake_minimum_required(VERSION 3.8)
2+
project(test_package LANGUAGES CXX)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup()
4+
find_package(luple REQUIRED CONFIG)
65

76
add_executable(${PROJECT_NAME} test_package.cpp)
8-
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
9-
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE luple::luple)
8+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
from conans import ConanFile, CMake, tools
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import CMake, cmake_layout
24
import os
35

46

57
class TestPackageConan(ConanFile):
6-
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake", "cmake_find_package"
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)
817

918
def build(self):
1019
cmake = CMake(self)
1120
cmake.configure()
1221
cmake.build()
1322

1423
def test(self):
15-
if not tools.cross_building(self.settings):
16-
bin_path = os.path.join("bin", "test_package")
17-
self.run(bin_path, run_environment=True)
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)

0 commit comments

Comments
 (0)