-
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.
(#18740) libnfnetlink: migrate to Conan v2
Co-authored-by: Daniel <danimanzaneque@gmail.com>
- Loading branch information
Showing
6 changed files
with
92 additions
and
55 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 |
---|---|---|
@@ -1,67 +1,70 @@ | ||
import os | ||
import functools | ||
from conans import ConanFile, tools, AutoToolsBuildEnvironment | ||
from conans.errors import ConanInvalidConfiguration | ||
|
||
required_conan_version = ">=1.43.0" | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.files import copy, get, rm, rmdir | ||
from conan.tools.gnu import Autotools, AutotoolsToolchain | ||
from conan.tools.layout import basic_layout | ||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class LibnfnetlinkConan(ConanFile): | ||
name = "libnfnetlink" | ||
description = "low-level library for netfilter related kernel/userspace communication" | ||
license = "GPL-2.0-or-later" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://netfilter.org/projects/libnfnetlink/index.html" | ||
description = "low-level library for netfilter related kernel/userspace communication" | ||
topics = ("libnfnetlink", "netlink", "netfilter") | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
topics = ("netlink", "netfilter") | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
} | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version], | ||
destination=self._source_subfolder, strip_root=True) | ||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
self.settings.rm_safe("compiler.libcxx") | ||
self.settings.rm_safe("compiler.cppstd") | ||
|
||
def layout(self): | ||
basic_layout(self, src_folder="src") | ||
|
||
def validate(self): | ||
if self.settings.os != "Linux": | ||
if self.settings.os not in ["Linux", "FreeBSD"]: | ||
raise ConanInvalidConfiguration("libnfnetlink is only supported on Linux") | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
del self.options.fPIC | ||
del self.settings.compiler.libcxx | ||
del self.settings.compiler.cppstd | ||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
@functools.lru_cache(1) | ||
def _configure_autotools(self): | ||
autotools = AutoToolsBuildEnvironment(self) | ||
conf_args = [] | ||
if self.options.shared: | ||
conf_args.extend(["--enable-shared", "--disable-static"]) | ||
else: | ||
conf_args.extend(["--disable-shared", "--enable-static"]) | ||
autotools.configure(configure_dir=self._source_subfolder, args=conf_args) | ||
return autotools | ||
def generate(self): | ||
tc = AutotoolsToolchain(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
autotools = self._configure_autotools() | ||
autotools = Autotools(self) | ||
autotools.configure() | ||
autotools.make() | ||
|
||
def package(self): | ||
self.copy("COPYING", dst="licenses", src=self._source_subfolder) | ||
autotools = self._configure_autotools() | ||
copy(self, "COPYING", | ||
dst=os.path.join(self.package_folder, "licenses"), | ||
src=self.source_folder) | ||
autotools = Autotools(self) | ||
autotools.install() | ||
|
||
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") | ||
tools.rmdir(os.path.join(self.package_folder, "share")) | ||
tools.rmdir(os.path.join(self.package_folder, "etc")) | ||
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rm(self, "*.la", self.package_folder, recursive=True) | ||
rmdir(self, os.path.join(self.package_folder, "share")) | ||
rmdir(self, os.path.join(self.package_folder, "etc")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["nfnetlink"] | ||
self.cpp_info.set_property("pkg_config_name", "libnfnetlink") | ||
|
||
# TODO: to remove in conan v2 once pkg_config generator is removed | ||
self.cpp_info.names["pkg_config"] = "libnfnetlink" | ||
self.cpp_info.set_property("pkg_config_name", "libnfnetlink") |
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
cmake_minimum_required(VERSION 3.15) | ||
project(PackageTest CXX) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
find_package(libnfnetlink REQUIRED CONFIG) | ||
|
||
add_executable(example example.cpp) | ||
target_link_libraries(example ${CONAN_LIBS}) | ||
target_link_libraries(example libnfnetlink::libnfnetlink) |
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 |
---|---|---|
@@ -1,18 +1,26 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
from conans import ConanFile, CMake, tools | ||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain" | ||
test_type = "explicit" | ||
|
||
class LibnfnetlinkTestConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake" | ||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
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", "example") | ||
self.run(bin_path, run_environment=True) | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindir, "example") | ||
self.run(bin_path, 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
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.15) | ||
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,18 @@ | ||
import os | ||
|
||
from conans import ConanFile, CMake, tools | ||
|
||
|
||
class LibnfnetlinkTestConan(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", "example") | ||
self.run(bin_path, run_environment=True) |