This repository has been archived by the owner on May 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
conanfile.py
143 lines (121 loc) · 6.12 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
from conans import ConanFile, tools, MSBuild, AutoToolsBuildEnvironment
from conans.errors import ConanInvalidConfiguration
import os
class PcapplusplusConan(ConanFile):
name = "pcapplusplus"
version = "20.08"
license = "Unlicense"
description = "PcapPlusPlus is a multiplatform C++ library for capturing, parsing and crafting of network packets"
topics = ("conan", "pcapplusplus", "pcap", "network", "security", "packet")
url = "https://github.com/bincrafters/conan-pcapplusplus"
homepage = "https://github.com/seladb/PcapPlusPlus"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
"immediate_mode": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"immediate_mode": False,
}
generators = "make", "visual_studio"
_source_subfolder = "PcapPlusPlus"
_vs_projects_to_build =[
"Common++",
"LightPcapNg",
"Packet++",
"Pcap++",
]
def configure(self):
if self.settings.os not in ["Windows", "Macos", "Linux"]:
raise ConanInvalidConfiguration("%s is not supported" % self.settings.os)
def config_options(self):
if self.settings.os == 'Windows':
del self.options.fPIC
del self.options.immediate_mode
def requirements(self):
if self.settings.os == 'Windows':
self.requires("winpcap/4.1.3@bincrafters/stable")
if self.settings.compiler == "Visual Studio":
self.requires("pthreads4w/3.0.0")
else:
self.requires("libpcap/1.9.1")
def source(self):
sha256 = "b35150a8517d3e5d5d8d1514126e4e8e4688f0941916af4256214c013c06ff50"
tools.get("{0}/archive/v{1}.tar.gz".format(self.homepage, self.version), sha256=sha256)
extracted_dir = self._source_subfolder + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)
def build(self):
with tools.chdir(self._source_subfolder):
if self.settings.os == "Linux":
libpcap_include_path = self.deps_cpp_info["libpcap"].include_paths[0]
libpcap_lib_path = self.deps_cpp_info["libpcap"].lib_paths[0]
config_command = ("./configure-linux.sh --libpcap-include-dir %s --libpcap-lib-dir %s" % (libpcap_include_path, libpcap_lib_path))
if self.options.immediate_mode:
config_command += " --use-immediate-mode"
self.run(config_command)
env_build = AutoToolsBuildEnvironment(self)
env_build.make()
elif self.settings.os == "Macos":
libpcap_include_path = self.deps_cpp_info["libpcap"].include_paths[0]
libpcap_lib_path = self.deps_cpp_info["libpcap"].lib_paths[0]
config_command = ("./configure-mac_os_x.sh --libpcap-include-dir %s --libpcap-lib-dir %s" % (libpcap_include_path, libpcap_lib_path))
if self.options.immediate_mode:
config_command += " --use-immediate-mode"
self.run(config_command)
env_build = AutoToolsBuildEnvironment(self)
env_build.make()
elif self.settings.os == "Windows":
if self.settings.compiler != "Visual Studio":
raise ConanInvalidConfiguration("Compiler %s is not supported" % self.settings.compiler)
vs_version = "vs2015"
if self.settings.compiler.version == "15":
vs_version = "vs2017"
elif self.settings.compiler.version == "16":
vs_version = "vs2019"
sln_file = "mk/%s/PcapPlusPlus.sln" % (vs_version)
winpcap_path = self.deps_cpp_info["winpcap"].rootpath
pthreads_path = self.deps_cpp_info["pthreads4w"].rootpath
self.run("configure-windows-visual-studio.bat --vs-version %s --pcap-sdk %s --pthreads-home %s" % (vs_version, winpcap_path, pthreads_path))
self.generate_directory_build_props_file()
msbuild = MSBuild(self)
msbuild.build(
sln_file,
targets=self._vs_projects_to_build,
use_env=False,
properties={"WholeProgramOptimization":"None"},
)
def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder, keep_path=False)
self.copy("*.h", dst="include", src="PcapPlusPlus/Dist/header")
self.copy("*.lib", dst="lib", src="PcapPlusPlus/Dist/", keep_path=False)
self.copy("*.a", dst="lib", src="PcapPlusPlus/Dist/", keep_path=False)
self.copy("*.pdb", dst="lib", src="PcapPlusPlus/Dist/", keep_path=False)
self.copy("*", dst="bin", src="PcapPlusPlus/Dist/examples", keep_path=False)
def package_info(self):
self.cpp_info.libs = ["Pcap++", "Packet++", "Common++"]
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("pthread")
if self.settings.os == "Windows":
self.cpp_info.system_libs.append("Iphlpapi")
if self.settings.os == "Macos":
self.cpp_info.frameworks.append("CoreFoundation")
self.cpp_info.frameworks.append("Security")
self.cpp_info.frameworks.append("SystemConfiguration")
def generate_directory_build_props_file(self):
log_message = (
"Generating Directory.Build.Props in the build directory which"
"injects conan variables into all vcxproj files in the directory tree beneath it. "
"https://docs.microsoft.com/en-us/visualstudio/msbuild/what-s-new-in-msbuild-15-0"
)
props_content = r"""<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets">
<Import Project="../conanbuildinfo.props" />
</ImportGroup>
</Project>
"""
self.output.warn(log_message)
tools.save("Directory.Build.props", props_content)