-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathconanfile.py
132 lines (114 loc) · 5.61 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os
import functools
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
required_conan_version = ">=1.43.0"
class ConanRecipe(ConanFile):
name = "catch2"
description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD"
topics = ("catch2", "unit-test", "tdd", "bdd")
license = "BSL-1.0"
homepage = "https://github.com/catchorg/Catch2"
url = "https://github.com/conan-io/conan-center-index"
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
"with_prefix": [True, False],
"default_reporter": "ANY",
}
default_options = {
"fPIC": True,
"with_prefix": False,
"default_reporter": None,
}
generators = "cmake"
@property
def _source_subfolder(self):
return "source_subfolder"
@property
def _build_subfolder(self):
return "build_subfolder"
@property
def _default_reporter_str(self):
return '"{}"'.format(str(self.options.default_reporter).strip('"'))
def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
@property
def _compilers_minimum_version(self):
return {
"gcc": "7",
"Visual Studio": "15",
"clang": "5",
"apple-clang": "10",
}
def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, "14")
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("{}/{}: Unsupported compiler: {}-{} "
"(https://github.com/p-ranav/structopt#compiler-compatibility)."
.format(self.name, self.version, self.settings.compiler, self.settings.compiler.version))
else:
self.output.warn("{}/{} requires C++14. Your compiler is unknown. Assuming it supports C++14.".format(self.name, self.version))
def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["BUILD_TESTING"] = "OFF"
cmake.definitions["CATCH_INSTALL_DOCS"] = "OFF"
cmake.definitions["CATCH_INSTALL_HELPERS"] = "ON"
cmake.definitions["CATCH_CONFIG_PREFIX_ALL"] = self.options.with_prefix
if self.options.default_reporter:
cmake.definitions["CATCH_CONFIG_DEFAULT_REPORTER"] = self._default_reporter_str
cmake.configure(build_folder=self._build_subfolder)
return cmake
def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "share"))
for cmake_file in ["ParseAndAddCatchTests.cmake", "Catch.cmake", "CatchAddTests.cmake"]:
self.copy(
cmake_file,
src=os.path.join(self._source_subfolder, "extras"),
dst=os.path.join("lib", "cmake", "Catch2"),
)
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Catch2")
self.cpp_info.set_property("cmake_target_name",
"Catch2::Catch2{}".format("WithMain" if self.options.get_safe("with_main") else ""))
self.cpp_info.names["cmake_find_package"] = "Catch2"
self.cpp_info.names["cmake_find_package_multi"] = "Catch2"
lib_suffix = "d" if self.settings.build_type == "Debug" else ""
self.cpp_info.components["Catch2"].set_property("cmake_target_name", "Catch2::Catch2")
self.cpp_info.components["Catch2"].names["cmake_find_package"] = "Catch2"
self.cpp_info.components["Catch2"].names["cmake_find_package_multi"] = "Catch2"
self.cpp_info.components["Catch2"].libs = ["Catch2" + lib_suffix]
self.cpp_info.components["Catch2WithMain"].builddirs = [os.path.join("lib", "cmake", "Catch2")]
self.cpp_info.components["Catch2WithMain"].libs = ["Catch2Main" + lib_suffix]
self.cpp_info.components["Catch2WithMain"].requires = ["Catch2"]
self.cpp_info.components["Catch2WithMain"].system_libs = ["log"] if self.settings.os == "Android" else []
self.cpp_info.components["Catch2WithMain"].set_property("cmake_target_name", "Catch2::Catch2WithMain")
self.cpp_info.components["Catch2WithMain"].names["cmake_find_package"] = "Catch2WithMain"
self.cpp_info.components["Catch2WithMain"].names["cmake_find_package_multi"] = "Catch2WithMain"
defines = self.cpp_info.components["Catch2WithMain"].defines
if self.options.with_prefix:
defines.append("CATCH_CONFIG_PREFIX_ALL")
if self.options.default_reporter:
defines.append("CATCH_CONFIG_DEFAULT_REPORTER={}".format(self._default_reporter_str))