Skip to content

Commit

Permalink
(conan-io#25348) PcapPlusPlus: add version 24.09
Browse files Browse the repository at this point in the history
* Update PcapPlusPlus to v24.09

* Verify GCC version > 5.0

* Remove redundant code

* Let Conan choose fPIC

* Typo

* Typo, Im a dumdum

* Dummy

* 3 for 3...

* Handle fPIC

* Conan 1 workaround

* Validate windows shared out

* Old versions too

---------

Co-authored-by: Abril Rincón Blanco <git@rinconblanco.es>
  • Loading branch information
2 people authored and OMGtechy committed Dec 31, 2024
1 parent f78ad39 commit d143e1b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
3 changes: 3 additions & 0 deletions recipes/pcapplusplus/cmake/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ sources:
"23.09":
url: "https://github.com/seladb/PcapPlusPlus/archive/v23.09.tar.gz"
sha256: "608292f7d2a2e1b7af26adf89347597a6131547eea4e513194bc4f584a40fe74"
"24.09":
url: "https://github.com/seladb/PcapPlusPlus/archive/v24.09.tar.gz"
sha256: "b14998ecf5718c2bfb6f709060e53f7ef67639b98bf2222a3cd23d820d70acdc"
48 changes: 44 additions & 4 deletions recipes/pcapplusplus/cmake/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
import os
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.tools.files import copy, get, rmdir
from conan.tools.files import copy, get, rmdir, replace_in_file
from conan.tools.scm import Version
from conan.tools.microsoft import is_msvc
from conan.errors import ConanInvalidConfiguration


required_conan_version = ">=1.52.0"


class PcapplusplusConan(ConanFile):
name = "pcapplusplus"
package_type = "static-library"
license = "Unlicense"
description = "PcapPlusPlus is a multiplatform C++ library for capturing, parsing and crafting of network packets"
topics = ("pcap", "network", "security", "packet")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/seladb/PcapPlusPlus"
settings = "os", "arch", "build_type", "compiler"
package_type = "library"
options = {
"immediate_mode": [True, False],
"fPIC": [True, False],
"shared": [True, False],
"immediate_mode": [True, False],
}
default_options = {
"immediate_mode": False,
"fPIC": True,
"shared": False,
"immediate_mode": False,
}

@property
def _min_cppstd(self):
return 11

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand All @@ -34,24 +44,52 @@ def requirements(self):
self.requires("npcap/1.70")
else:
self.requires("libpcap/1.10.1")

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def validate(self):
if Version(self.version) <= "24.09" and self.options.shared and self.settings.os == "Windows":
# https://github.com/seladb/PcapPlusPlus/issues/1396
raise ConanInvalidConfiguration(f"{self.ref} does not support Windows shared builds for now")
if self.settings.compiler.cppstd:
# popen()/pclose() usage
check_min_cppstd(self, self._min_cppstd, gnu_extensions=not is_msvc(self))
if self.settings.os not in ("FreeBSD", "Linux", "Macos", "Windows"):
raise ConanInvalidConfiguration(f"{self.settings.os} is not supported")

def validate_build(self):
compiler_version = Version(self.settings.compiler.version)
if self.settings.compiler == "gcc" and compiler_version < "5.1":
raise ConanInvalidConfiguration("PcapPlusPlus requires GCC >= 5.1")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["PCAPPP_BUILD_TESTS"] = False
tc.variables["PCAPPP_BUILD_EXAMPLES"] = False
tc.variables["BUILD_SHARED_LIBS"] = self.options.shared
if not self.settings.compiler.cppstd:
tc.variables["CMAKE_CXX_STANDARD"] = self._min_cppstd
tc.generate()

def layout(self):
cmake_layout(self, src_folder="src")

def _patch_sources(self):
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"set(CMAKE_CXX_STANDARD 11)",
"")
if Version(self.version) >= "24.09":
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"set(CMAKE_POSITION_INDEPENDENT_CODE ON)",
"")

def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()
Expand All @@ -69,5 +107,7 @@ def package_info(self):
self.cpp_info.frameworks = ["CoreFoundation", "SystemConfiguration"]
elif self.settings.os == "Windows":
self.cpp_info.system_libs = ["ws2_32", "iphlpapi"]
elif self.settings.os in ("Linux", "FreeBSD"):
self.cpp_info.system_libs = ["pthread"]
self.cpp_info.set_property("cmake_file_name", "PcapPlusPlus")
self.cpp_info.set_property("cmake_target_name", "PcapPlusPlus::PcapPlusPlus")
2 changes: 2 additions & 0 deletions recipes/pcapplusplus/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ versions:
folder: all
"23.09":
folder: cmake
"24.09":
folder: cmake

0 comments on commit d143e1b

Please sign in to comment.