-
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.
* Init libdnet * move to cmake * prepare for cmake * rename package * fix license * fix write header * fix libcxx and cppstd * bump to upstream * Apply suggestions from code review Co-authored-by: Martin Valgur <[email protected]> * Remove test_v1_package, fix configure method --------- Co-authored-by: Martin Valgur <[email protected]> Co-authored-by: Luis Caro Campos <[email protected]>
- Loading branch information
1 parent
99ecffb
commit c631a5e
Showing
6 changed files
with
149 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.17.0": | ||
url: "https://github.com/ofalk/libdnet/archive/refs/tags/libdnet-1.17.0.tar.gz" | ||
sha256: "6be1ed0763151ede4c9665a403f1c9d974b2ffab2eacdb26b22078e461aae1dc" |
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,70 @@ | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
from conan.tools.files import copy, get, rmdir | ||
import os | ||
|
||
|
||
required_conan_version = ">=1.56.0" | ||
|
||
|
||
class dnetConan(ConanFile): | ||
name = "dnet" | ||
description = "Provides a simplified, portable interface to several low-level networking routines." | ||
homepage = "https://github.com/ofalk/libdnet" | ||
topics = ("dnet", "libdnet", "libdumbnet") | ||
license = "BSD-3-Clause" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
package_type = "library" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True | ||
} | ||
settings = "os", "arch", "compiler", "build_type" | ||
|
||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
# This is a pure C project | ||
self.settings.rm_safe("compiler.cppstd") | ||
self.settings.rm_safe("compiler.libcxx") | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.generate() | ||
|
||
deps = CMakeDeps(self) | ||
deps.generate() | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
copy(self,"LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.install() | ||
rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs.append("dnet") | ||
self.cpp_info.includedirs.append(os.path.join("include", "dnet")) | ||
|
||
if self.settings.os == 'Windows': | ||
self.cpp_info.system_libs = ['Iphlpapi', 'wsock32'] |
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(dnet REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE dnet::dnet) |
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,39 @@ | ||
#include <dnet/dnet.h> | ||
#include <dnet/config.h> | ||
#include <dnet/err.h> | ||
|
||
#include <sys/types.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) | ||
#include <unistd.h> | ||
#elif defined(_WIN32) | ||
#include <io.h> | ||
#endif | ||
|
||
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(1, 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,3 @@ | ||
versions: | ||
"1.17.0": | ||
folder: "all" |