-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
conanfile.py
183 lines (159 loc) · 8.67 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration, ConanException
import os
required_conan_version = ">=1.32.0"
class ImaglConan(ConanFile):
name = "imagl"
license = "GPL-3.0-or-later"
homepage = "https://github.com/Woazim/imaGL"
url = "https://github.com/conan-io/conan-center-index"
description = "A lightweight library to load image for OpenGL application."
topics = ("opengl", "texture", "image")
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_png": [True, False],
"with_jpeg": [True, False],
"allow_clang_11": [None, True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"with_png": True,
"with_jpeg": True,
"allow_clang_11": None
}
generators = "cmake"
exports_sources = "CMakeLists.txt"
_cmake = None
@property
def _source_subfolder(self):
return "source_subfolder"
@property
def _build_subfolder(self):
return "build_subfolder"
@property
def _compilers_minimum_version(self):
minimum_versions = {
"gcc": "9",
"Visual Studio": "16.2",
"msvc": "19.22",
"clang": "10",
"apple-clang": "11"
}
if tools.Version(self.version) <= "0.1.1" or tools.Version(self.version) == "0.2.0":
minimum_versions["Visual Studio"] = "16.5"
minimum_versions["msvc"] = "19.25"
return minimum_versions
@property
def _compiler_toolsets_minimum_version(self):
minimum_versions = {
"Visual Studio": "14.22"
}
if tools.Version(self.version) <= "0.1.1" or tools.Version(self.version) == "0.2.0":
minimum_versions["Visual Studio"] = "14.25"
return minimum_versions
@property
def _supports_jpeg(self):
return tools.Version(self.version) >= "0.2.0"
def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename(self.name + "-v" + self.version, self._source_subfolder)
def validate(self):
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 20)
def lazy_lt_semver(v1, v2):
lv1 = [int(v) for v in v1.split(".")]
lv2 = [int(v) for v in v2.split(".")]
min_length = min(len(lv1), len(lv2))
return lv1[:min_length] < lv2[:min_length]
#Special check for clang that can only be linked to libc++
if self.settings.compiler == "clang" and self.settings.compiler.libcxx != "libc++":
raise ConanInvalidConfiguration("imagl requires some C++20 features, which are available in libc++ for clang compiler.")
compiler_version = str(self.settings.compiler.version)
toolset_version = "0"
if str(self.settings.compiler) == "Visual Studio" and str(self.settings.compiler.version).find(".") == -1 and int(str(self.settings.compiler.version)) >= 16:
try:
compiler_version = tools.vswhere(requires=["Microsoft.VisualStudio.Component.VC.Tools.x86.x64"], products="*",
version="[{}.0,{}.0)".format(str(self.settings.compiler.version), int(str(self.settings.compiler.version))+1), latest=True, property_="installationVersion")[0]["installationVersion"]
toolset_version = tools.vcvars_dict(self).get("VCToolsVersion", os.environ.get("VCToolsVersion",""))
except ConanException:
raise ConanInvalidConfiguration("Your Visual Studio compiler seems not to be installed in a common way. It is not supported. This unfortunately happens in conan center index. To build imaGL, append '--build missing' to your 'conan install' command line.")
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
minimum_toolset_version = self._compiler_toolsets_minimum_version.get(str(self.settings.compiler), "0")
if not minimum_version:
self.output.warn("imaGL requires C++20. Your compiler is unknown. Assuming it supports C++20.")
elif lazy_lt_semver(compiler_version, minimum_version) or lazy_lt_semver(toolset_version, minimum_toolset_version):
raise ConanInvalidConfiguration("imaGL requires some C++20 features, which your {} {} compiler does not support.".format(str(self.settings.compiler), compiler_version)
+ (" Your Visual Studio toolset version is {}; version {}+ is required.".format(toolset_version, str(minimum_toolset_version)) if minimum_toolset_version else ""))
elif str(self.settings.compiler) == "clang" and compiler_version == "11" and not self.options.allow_clang_11:
raise ConanInvalidConfiguration("Clang 11 is not currently supported by conan center index. To build imaGL, append '-o imagl:allow_clang_11=True --build missing' to your 'conan install' command line.")
else:
print("Your compiler is {} {} and is compatible.".format(str(self.settings.compiler), compiler_version))
if minimum_toolset_version != "0":
print("Its toolset is in version {} and is compatible. Minimum version is {}.".format(toolset_version, minimum_toolset_version))
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if not self._supports_jpeg:
del self.options.with_jpeg
if not str(self.settings.compiler) == "clang" or not str(self.settings.compiler.version) == "11":
del self.options.allow_clang_11
else:
self.output.warn("allow_clang_11 option will be removed in the future when conan center index will support clang 11.")
def configure(self):
if self.options.shared:
del self.options.fPIC
if not self.settings.compiler.cppstd:
self.settings.compiler.cppstd = "20"
def requirements(self):
if self.options.with_png:
self.requires("libpng/1.6.37")
if self._supports_jpeg and self.options.with_jpeg:
self.requires("libjpeg/9d")
def _configure_cmake(self):
if self._cmake:
return self._cmake
# CMake generator must be set to Ninja when using Visual Studio to let choose the right
# MSVC compiler version when multiple versions are installed on build machine. The problem
# with default generator is that it will always choose the last MSVC version. It will
# generate Visual Studio solution and project files, and use MSBuild to build it. I think
# it's a "feature" of CMake / Visual Studio generator that does not use environment which
# is set by vcvars. So if you want to use a specific MSVC version, you have to use Ninja
# generator with CMake. You can find some side explanation here:
# https://devblogs.microsoft.com/cppblog/side-by-side-minor-version-msvc-toolsets-in-visual-studio-2019/
#
# Building with specific MSVC version could be needed since imaGL requires some minimal
# version to be compiled according to its own version. Following table links imaGL version
# to minimal MSVC version:
#
# | imaGL version | MSVC minimal version |
# |---------------|----------------------------|
# | 0.1.0 | 19.25 (default in VS 16.5) |
# | 0.1.1 | 19.25 (default in VS 16.5) |
# | 0.1.2 | 19.22 (default in VS 16.2) |
# | 0.2.0 | 19.25 (default in VS 16.5) |
# | 0.2.1 | 19.22 (default in VS 16.2) |
#
generator = "Ninja" if str(self.settings.compiler) == "Visual Studio" else None
self._cmake = CMake(self, generator=generator)
self._cmake.definitions["STATIC_LIB"] = not self.options.shared
self._cmake.definitions["SUPPORT_PNG"] = self.options.with_png
if self._supports_jpeg:
self._cmake.definitions["SUPPORT_JPEG"] = self.options.with_jpeg
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
def build(self):
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
def package_info(self):
debug_suffix = "d" if self.settings.build_type == "Debug" else ""
static_suffix = "" if self.options.shared else "s"
self.cpp_info.libs = ["imaGL{}{}".format(debug_suffix, static_suffix)]
if not self.options.shared:
self.cpp_info.defines = ["IMAGL_STATIC=1"]