-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"1.16.3": | ||
url: "https://github.com/ofalk/libdnet/archive/refs/tags/libdnet-1.16.3.tar.gz" | ||
sha256: "83171a9f6e96d7a5047d6537fce4c376bdf6d867f8d49cf6ba434a0f3f7b45c1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.apple import fix_apple_shared_install_name | ||
from conan.tools.files import copy, get, rm, rmdir | ||
from conan.tools.env import VirtualBuildEnv | ||
from conan.tools.gnu import Autotools, AutotoolsToolchain, PkgConfigDeps | ||
from conan.tools.microsoft import is_msvc | ||
from conan.tools.layout import basic_layout | ||
import os | ||
|
||
|
||
required_conan_version = ">=1.54.0" | ||
|
||
|
||
class LibDNetConan(ConanFile): | ||
name = "libdnet" | ||
description = "Provides a simplified, portable interface to several low-level networking routines." | ||
homepage = "https://github.com/ofalk/libdnet" | ||
topics = ("libdnet", "libdumbnet") | ||
license = "BSD-3-Clause" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True | ||
} | ||
settings = "os", "arch", "compiler", "build_type" | ||
|
||
@property | ||
def _settings_build(self): | ||
return getattr(self, "settings_build", self.settings) | ||
|
||
|
||
def layout(self): | ||
basic_layout(self) | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
del self.options.fPIC | ||
del self.settings.compiler.libcxx | ||
del self.settings.compiler.cppstd | ||
|
||
def validate(self): | ||
if is_msvc(self): | ||
raise ConanInvalidConfiguration("libdnet has not supported Visual Studio yet") | ||
# windows build requires winpcap (looks like we can use npcap) | ||
|
||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def requirements(self): | ||
self.requires("libcheck/0.15.2") | ||
|
||
def build_requirements(self): | ||
if not self.conf.get("tools.gnu:pkg_config", check_type=str): | ||
self.tool_requires("pkgconf/1.9.3") | ||
self.tool_requires("libtool/2.4.7") | ||
if self._settings_build.os == "Windows": | ||
self.win_bash = True | ||
if not self.conf.get("tools.microsoft.bash:path", check_type=str): | ||
self.tool_requires("msys2/cci.latest") | ||
|
||
def generate(self): | ||
env = VirtualBuildEnv(self) | ||
env.generate() | ||
tc = AutotoolsToolchain(self) | ||
env = tc.environment() | ||
# if is_msvc(self): | ||
# env.define("CC", "cl -nologo") | ||
# env.define("CXX", "cl -nologo") | ||
# env.define("LD", "link -nologo") | ||
# env.define("AR", "lib -nologo") | ||
# if self._settings_build.os == "Windows": | ||
# # TODO: Something to fix in conan client or pkgconf recipe? | ||
# # This is a weird workaround when build machine is Windows. Here we have to inject regular | ||
# # Windows path to pc files folder instead of unix path flavor injected by AutotoolsToolchain... | ||
# env.define("PKG_CONFIG_PATH", self.generators_folder) | ||
tc.generate() | ||
pkg = PkgConfigDeps(self) | ||
pkg.generate() | ||
|
||
def build(self): | ||
autotools = Autotools(self) | ||
autotools.autoreconf() | ||
autotools.configure() | ||
autotools.make() | ||
|
||
def package(self): | ||
copy(self,"COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) | ||
autotools = Autotools(self) | ||
autotools.install() | ||
|
||
copy(self, "config.h", src=os.path.join(self.build_folder, "include"), dst=os.path.join(self.package_folder, "include")) | ||
|
||
rm(self, "*.la", os.path.join(self.package_folder, "lib")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
fix_apple_shared_install_name(self) | ||
|
||
def package_id(self): | ||
del self.info.options.default | ||
|
||
def package_info(self): | ||
self.cpp_info.components["dnet"].libs = ["dnet"] | ||
self.cpp_info.components["dnet"].names["pkg_config"] = "libdnet" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package C) | ||
|
||
find_package(libdnet REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE libdnet::libdnet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import CMake, cmake_layout | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") | ||
self.run("{} {}".format(bin_path, "127.0.0.1"), env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <config.h> | ||
|
||
#include <sys/types.h> | ||
|
||
#include <err.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
#include <dnet.h> | ||
|
||
void addr_usage(void) | ||
{ | ||
fprintf(stderr, "Usage: dnet addr <address> ...\n"); | ||
exit(1); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
struct addr addr; | ||
int c, len; | ||
|
||
if (argc == 1 || *(argv[1]) == '-') | ||
addr_usage(); | ||
|
||
for (c = 1; c < argc; c++) { | ||
if (addr_aton(argv[c], &addr) < 0) | ||
addr_usage(); | ||
|
||
len = addr.addr_bits / 8; | ||
|
||
if (write(STDOUT_FILENO, addr.addr_data8, len) != len) | ||
err(1, "write"); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package | ||
${CMAKE_CURRENT_BINARY_DIR}/test_package) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "cmake_find_package_multi" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not tools.cross_building(self): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run("{} {}".format(bin_path, "127.0.0.1"), run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"1.16.3": | ||
folder: "all" |