This repository has been archived by the owner on Oct 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
conanfile.py
114 lines (99 loc) · 5.25 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
import os
import shutil
from conans import ConanFile, CMake, tools
class LibeventConan(ConanFile):
name = "libevent"
version = "2.1.11"
description = "libevent - an event notification library"
topics = ("conan", "libevent", "event")
url = "https://github.com/bincrafters/conan-libevent"
homepage = "https://github.com/libevent/libevent"
author = "Bincrafters <[email protected]>"
license = "BSD-3-Clause"
exports = ["LICENSE.md"]
exports_sources = ["CMakeLists.txt"]
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False],
"fPIC": [True, False],
"with_openssl": [True, False],
"disable_threads": [True, False]}
default_options = {"shared": False,
"fPIC": True,
"with_openssl": True,
"disable_threads": False}
generators = "cmake"
_source_subfolder = "source_subfolder"
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
del self.settings.compiler.libcxx
if self.options.with_openssl and self.options.shared:
# static OpenSSL cannot be properly detected because libevent picks up system ssl first
# so enforce shared openssl
self.output.warn("Enforce shared OpenSSL for shared build")
self.options["OpenSSL"].shared = self.options.shared
def requirements(self):
if self.options.with_openssl:
self.requires.add("OpenSSL/1.1.1c@conan/stable")
def source(self):
if self.version == '2.1.11':
# temporary fix due to missing files in dist package for 2.1.11, see upstream bug 863
checksum = "229393ab2bf0dc94694f21836846b424f3532585bac3468738b7bf752c03901e"
tools.get("{0}/archive/release-{1}-stable.tar.gz".format(self.homepage, self.version), sha256=checksum)
extracted_folder = "libevent-release-{0}-stable".format(self.version)
else:
checksum = "a65bac6202ea8c5609fd5c7e480e6d25de467ea1917c08290c521752f147283d"
tools.get("{0}/releases/download/release-{1}-stable/libevent-{1}-stable.tar.gz".format(self.homepage, self.version), sha256=checksum)
extracted_folder = "libevent-{0}-stable".format(self.version)
os.rename(extracted_folder, self._source_subfolder)
os.rename(os.path.join(self._source_subfolder, "CMakeLists.txt"),
os.path.join(self._source_subfolder, "CMakeListsOriginal.txt"))
shutil.copy("CMakeLists.txt",
os.path.join(self._source_subfolder, "CMakeLists.txt"))
# patch 'beta' to 'stable' because there is no git repository which cmake uses to determine stage name
# needed for 2.1.10, not needed for 2.1.11 so marked as non-strict
tools.replace_in_file(os.path.join(self._source_subfolder, "cmake", "VersionViaGit.cmake"),
'set(EVENT_GIT___VERSION_STAGE "beta")',
'set(EVENT_GIT___VERSION_STAGE "stable")',
strict=False)
def imports(self):
# Copy shared libraries for dependencies to fix DYLD_LIBRARY_PATH problems
#
# Configure script creates conftest that cannot execute without shared openssl binaries.
# Ways to solve the problem:
# 1. set *LD_LIBRARY_PATH (works with Linux with RunEnvironment
# but does not work on OS X 10.11 with SIP)
# 2. copying dylib's to the build directory (fortunately works on OS X)
if self.settings.os == "Macos":
self.copy("*.dylib*", dst=self._source_subfolder, keep_path=False)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["EVENT__LIBRARY_TYPE"] = "SHARED" if self.options.shared else "STATIC"
cmake.definitions["EVENT__DISABLE_DEBUG_MODE"] = self.settings.build_type == "Release"
cmake.definitions["EVENT__DISABLE_OPENSSL"] = not self.options.with_openssl
cmake.definitions["EVENT__DISABLE_THREAD_SUPPORT"] = self.options.disable_threads
cmake.definitions["EVENT__DISABLE_BENCHMARK"] = True
cmake.definitions["EVENT__DISABLE_TESTS"] = True
cmake.definitions["EVENT__DISABLE_REGRESS"] = True
cmake.definitions["EVENT__DISABLE_SAMPLES"] = True
# libevent uses static runtime (MT) for static builds by default
cmake.definitions["EVENT__MSVC_STATIC_RUNTIME"] = self.settings.compiler == "Visual Studio" and \
self.settings.compiler.runtime == "MT"
cmake.configure(source_folder=self._source_subfolder)
return cmake
def build(self):
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
cmake.install()
def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == "Linux":
self.cpp_info.libs.extend(["rt"])
if self.settings.os == "Windows":
self.cpp_info.libs.append('ws2_32')
if self.options.with_openssl:
self.cpp_info.defines.append('EVENT__HAVE_OPENSSL=1')