This repository has been archived by the owner on Oct 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
conanfile.py
102 lines (88 loc) · 4.15 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
import os
from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
class SpdlogConan(ConanFile):
name = "spdlog"
version = "1.4.2"
description = "Fast C++ logging library"
url = "https://github.com/bincrafters/conan-spdlog"
homepage = "https://github.com/gabime/spdlog"
author = "Bincrafters <[email protected]>"
topics = ("conan", "spdlog", "logging", "header-only")
license = "MIT"
exports = ["LICENSE.md"]
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False],
"header_only": [True, False], "wchar_support": [True, False],
"wchar_filenames": [True, False], "no_exceptions": [True, False]}
default_options = {"shared": False, "fPIC": True, "header_only": False,
"wchar_support": False, "wchar_filenames": False,
"no_exceptions": False}
@property
def _source_subfolder(self):
return "source_subfolder"
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.header_only:
del self.options.shared
del self.options.fPIC
elif self.settings.os == "Windows" and self.options.shared:
raise ConanInvalidConfiguration("spdlog shared lib is not yet supported under windows")
if self.settings.os != "Windows":
if self.options.wchar_support or self.options.wchar_filenames:
raise ConanInvalidConfiguration("wchar is not yet supported under windows")
def requirements(self):
self.requires("fmt/6.0.0@bincrafters/stable")
def source(self):
tools.get("{0}/archive/v{1}.tar.gz".format(self.homepage, self.version))
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["SPDLOG_BUILD_EXAMPLE"] = False
cmake.definitions["SPDLOG_BUILD_EXAMPLE_HO"] = False
cmake.definitions["SPDLOG_BUILD_TESTS"] = False
cmake.definitions["SPDLOG_BUILD_TESTS_HO"] = False
cmake.definitions["SPDLOG_BUILD_BENCH"] = False
cmake.definitions["SPDLOG_FMT_EXTERNAL"] = True
cmake.definitions["SPDLOG_BUILD_SHARED"] = not self.options.header_only and self.options.shared
cmake.definitions["SPDLOG_WCHAR_SUPPORT"] = self.options.wchar_support
cmake.definitions["SPDLOG_WCHAR_FILENAMES"] = self.options.wchar_filenames
cmake.definitions["SPDLOG_INSTALL"] = True
cmake.definitions["SPDLOG_NO_EXCEPTIONS"] = self.options.no_exceptions
cmake.configure()
return cmake
def build(self):
if self.options.header_only:
tools.patch(base_path=self._source_subfolder,
patch_file=os.path.join("patches", "0001-header-only.patch"))
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_id(self):
if self.options.header_only:
self.info.header_only()
def package_info(self):
if self.options.header_only:
self.cpp_info.defines = ["SPDLOG_HEADER_ONLY", "SPDLOG_FMT_EXTERNAL"]
else:
if self.settings.build_type == "Release":
self.cpp_info.libs = ["spdlog"]
else:
self.cpp_info.libs = ["spdlogd"]
self.cpp_info.defines = ["SPDLOG_COMPILED_LIB", "SPDLOG_FMT_EXTERNAL"]
if self.options.wchar_support:
self.cpp_info.defines.append("SPDLOG_WCHAR_TO_UTF8_SUPPORT")
if self.options.wchar_filenames:
self.cpp_info.defines.append("SPDLOG_WCHAR_FILENAMES")
if self.options.no_exceptions:
self.cpp_info.defines.append("SPDLOG_NO_EXCEPTIONS")
if tools.os_info.is_linux:
self.cpp_info.libs.append("pthread")