diff --git a/recipes/net-snmp/all/conandata.yml b/recipes/net-snmp/all/conandata.yml index 269a227ecf9b0..8dd9d5cb3eef5 100644 --- a/recipes/net-snmp/all/conandata.yml +++ b/recipes/net-snmp/all/conandata.yml @@ -1,14 +1,18 @@ sources: - "5.9.1": - sha256: "75b59d67e871aaaa31c8cef89ba7d06972782b97736b7e8c3399f36b50a8816f" - url: https://sourceforge.net/projects/net-snmp/files/net-snmp/5.9.1/net-snmp-5.9.1.zip/download + "5.9.3": + sha256: 2097f29b7e1bf3f1300b4bae52fa2308d0bb8d5d3998dbe02f9462a413a2ef0a + url: https://sourceforge.net/projects/net-snmp/files/net-snmp/5.9.3/net-snmp-5.9.3.tar.gz/download patches: - "5.9.1": + "5.9.3": - patch_file: patches/0001-fix-openssl-linking-msvc.patch - base_path: "" - - patch_file: patches/0002-install-only-libnetsnmp.patch - base_path: "" - - patch_file: patches/0003-fix-perl-scripts-msvc.patch - base_path: "" + patch_type: portability + patch_description: fix linking to openssl in msvc - patch_file: patches/0004-fix-apple-arm64-build.patch - base_path: "" + patch_type: portability + patch_description: fix apple arm64 build + - patch_file: patches/0005-exclude_syslog.patch + patch_type: portability + patch_description: fix for including syslog.h instead of sys/syslog.h + - patch_file: patches/0006-include_select.patch + patch_type: portability + patch_description: fix for including select.h if present diff --git a/recipes/net-snmp/all/conanfile.py b/recipes/net-snmp/all/conanfile.py index cf81f5bab247a..8c26fd3518518 100644 --- a/recipes/net-snmp/all/conanfile.py +++ b/recipes/net-snmp/all/conanfile.py @@ -1,12 +1,15 @@ -import functools -import os -import stat - -from conans import AutoToolsBuildEnvironment, ConanFile, tools -from conans.errors import ConanInvalidConfiguration - -required_conan_version = ">=1.43.0" - +from conan import ConanFile +from conan.tools.files import copy, get, export_conandata_patches, apply_conandata_patches, replace_in_file, rm, rmdir +from conan.errors import ConanInvalidConfiguration +from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps, PkgConfigDeps +from conan.tools.microsoft import VCVars +from conan.tools.microsoft import is_msvc +from conan.tools.apple import is_apple_os +from conan.tools.layout import basic_layout +from conan.tools.env import VirtualRunEnv, Environment +from os.path import join + +required_conan_version = ">=1.60.0" class NetSnmpConan(ConanFile): name = "net-snmp" @@ -20,6 +23,8 @@ class NetSnmpConan(ConanFile): topics = "snmp" license = "BSD-3-Clause" settings = "os", "arch", "compiler", "build_type" + package_type = "library" + options = { "shared": [True, False], "fPIC": [True, False], @@ -30,21 +35,23 @@ class NetSnmpConan(ConanFile): "fPIC": True, "with_ipv6": True, } - requires = "openssl/1.1.1m" - exports_sources = "patches/*" - - @property - def _is_msvc(self): - return self.settings.compiler in ("Visual Studio", "msvc") def validate(self): - if self.settings.os == "Windows" and not self._is_msvc: - raise ConanInvalidConfiguration( - "net-snmp is setup to build only with MSVC on Windows" - ) + if self.settings.os == "Windows" and not is_msvc(self): + raise ConanInvalidConfiguration("net-snmp is setup to build only with MSVC on Windows") + + if is_apple_os(self): + raise ConanInvalidConfiguration("Building for Apple OS types not supported") + + + def export_sources(self): + export_conandata_patches(self) + + def layout(self): + basic_layout(self, src_folder="src") def source(self): - tools.get(**self.conan_data["sources"][self.version], strip_root=True) + get(self, **self.conan_data["sources"][self.version], filename=f"net-snmp-{self.version}.tar.gz", strip_root=True) def config_options(self): if self.settings.os == "Windows": @@ -52,145 +59,152 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + self.options.rm_safe("fPIC") + + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def requirements(self): + self.requires("openssl/1.1.1q") + self.requires("pcre/8.45") def build_requirements(self): - if self._is_msvc: + if is_msvc(self): self.build_requires("strawberryperl/5.30.0.1") @property def _is_debug(self): return self.settings.build_type == "Debug" + def generate(self): + if is_msvc(self): + self._generate_msvc() + else: + self._generate_unix() + + def build(self): + apply_conandata_patches(self) + + if is_msvc(self): + self._build_msvc() + else: + self._build_unix() + + def package(self): + if is_msvc(self): + self._package_msvc() + else: + self._package_unix() + + copy(self, "COPYING", src=self.source_folder, dst=join(self.package_folder, "licenses"), ignore_case=True) + + def package_info(self): + self.cpp_info.libs = ["netsnmp"] + self.cpp_info.requires = ["openssl::openssl", "pcre::pcre"] + + if self.settings.os == "Neutrino": + self.cpp_info.system_libs.append("socket") + + if self.settings.os == "Neutrino" and self.settings.os.version == "7.1": + self.cpp_info.system_libs.append("regex") + + def _generate_msvc(self): + ms = VCVars(self) + ms.generate() + def _patch_msvc(self): - ssl_info = self.deps_cpp_info["openssl"] - openssl_root = ssl_info.rootpath.replace("\\", "/") - search_replace = [ - ( - r'$default_openssldir . "\\include"', - f"'{openssl_root}/include'" - ), - (r'$default_openssldir . "\\lib\\VC"', f"'{openssl_root}/lib'"), - ("$openssl = false", "$openssl = true") - ] - if self._is_debug: - search_replace.append(("$debug = false", "$debug = true")) - if self.options.shared: - search_replace.append(( - "$link_dynamic = false", - "$link_dynamic = true" - )) - if self.options.with_ipv6: - search_replace.append(("$b_ipv6 = false", "$b_ipv6 = true")) - for search, replace in search_replace: - tools.replace_in_file("win32\\build.pl", search, replace) - runtime = self.settings.compiler.runtime - tools.replace_in_file("win32\\Configure", '"/runtime', f'"/{runtime}') + ssl_info = self.dependencies["openssl"].cpp_info.aggregated_components() + link_lines = "\n".join( f'# pragma comment(lib, "{lib}.lib")' for lib in ssl_info.libs + ssl_info.system_libs ) - config = r"win32\net-snmp\net-snmp-config.h.in" - tools.replace_in_file(config, "/* Conan: system_libs */", link_lines) + replace_in_file(self, join(self.source_folder, "win32", "net-snmp", "net-snmp-config.h.in"), "/* Conan: system_libs */", link_lines) def _build_msvc(self): - if self.should_configure: - self._patch_msvc() - self.run("perl build.pl", cwd="win32") - if self.should_build: - with tools.vcvars(self): - self.run("nmake /nologo libsnmp", cwd="win32") - - @functools.lru_cache(1) - def _configure_autotools(self): + self._patch_msvc() + + openssl_include_dir = join(self.dependencies["openssl"].package_folder, "include") + openssl_lib_dir = join(self.dependencies["openssl"].package_folder, "lib") + configure_folder = join(self.source_folder, "win32") + config_type = "debug" if self._is_debug else "release" + link_type = "dynamic" if self.options.shared else "static" + self.run(f"perl Configure --config={config_type} --linktype={link_type} --with-ssl --with-sslincdir={openssl_include_dir} --with-ssllibdir={openssl_lib_dir} --prefix={self.build_folder}", cwd=f"{configure_folder}", env="conanbuild") + self.run("nmake /nologo libs_clean libs install", cwd=f"{configure_folder}", env="conanbuild") + + def _package_msvc(self): + cfg = "debug" if self._is_debug else "release" + from_folder = join(self.source_folder,"win32", "bin", f"{cfg}") + self.output.info(f"klaus {from_folder}") + copy(self, "netsnmp.dll", dst=join(self.package_folder,"bin"), src=join(self.source_folder,"win32", "bin", f"{cfg}")) + copy(self, "netsnmp.lib", dst=join(self.package_folder,"lib"), src=join(self.source_folder,"win32", "lib", f"{cfg}")) + copy(self, "net-snmp/*", dst=join(self.package_folder, "include"), src=join(self.source_folder, "include"), keep_path=True) + copy(self, "net-snmp/*", dst=join(self.package_folder, "include"), src=join(self.build_folder, "include"), keep_path=True) + + def _generate_unix(self): + ad = AutotoolsDeps(self) + ad.generate() + + pd = PkgConfigDeps(self) + pd.generate() + + tc = AutotoolsToolchain(self) + + if self.settings.os in ["Linux"]: + tc.extra_ldflags.append("-ldl") + tc.extra_ldflags.append("-lpthread") + + if self.settings.os in ["Neutrino"]: + tc.extra_ldflags.append("-ldl") + tc.extra_ldflags.append("-lsocket") + + if self.settings.os.version == "7.1": + tc.extra_ldflags.append("-lregex") + + tc.generate() + + def _build_unix(self): disabled_link_type = "static" if self.options.shared else "shared" debug_flag = "enable" if self._is_debug else "disable" ipv6_flag = "enable" if self.options.with_ipv6 else "disable" - ssl_path = self.deps_cpp_info["openssl"].rootpath + openssl_path = self.dependencies["openssl"].package_folder + zlib_path = self.dependencies["zlib"].package_folder args = [ + f"--with-openssl={openssl_path}", + f"--with-zlib={zlib_path}", "--with-defaults", "--without-rpm", - "--without-pcre", - "--disable-agent", - "--disable-applications", "--disable-manuals", "--disable-scripts", - "--disable-mibs", "--disable-embedded-perl", - f"--disable-{disabled_link_type}", f"--{debug_flag}-debugging", + "--without-kmem-usage", + "--with-out-mib-modules=mibII,ucd_snmp,agentx", + f"--disable-{disabled_link_type}", f"--{ipv6_flag}-ipv6", - f"--with-openssl={ssl_path}", ] - autotools = AutoToolsBuildEnvironment(self) - autotools.libs = [] - autotools.configure(args=args) - return autotools - - def _patch_unix(self): - tools.replace_in_file( - "configure", - "-install_name \\$rpath/", - "-install_name @rpath/" - ) - crypto_libs = self.deps_cpp_info["openssl"].system_libs - if len(crypto_libs) != 0: - crypto_link_flags = " -l".join(crypto_libs) - tools.replace_in_file( - "configure", - 'LIBCRYPTO="-l${CRYPTO}"', - 'LIBCRYPTO="-l${CRYPTO} -l%s"' % (crypto_link_flags,) - ) - tools.replace_in_file( - "configure", - 'LIBS="-lcrypto $LIBS"', - f'LIBS="-lcrypto -l{crypto_link_flags} $LIBS"' - ) - def build(self): - for patch in self.conan_data["patches"][self.version]: - tools.patch(**patch) - if self._is_msvc: - self._build_msvc() - else: - self._patch_unix() - os.chmod("configure", os.stat("configure").st_mode | stat.S_IEXEC) - self._configure_autotools()\ - .make(target="snmplib", args=["NOAUTODEPS=1"]) + if self.settings.os == "Neutrino": + args.append("--with-endianness=little") - def _package_msvc(self): - cfg = "debug" if self._is_debug else "release" - self.copy("netsnmp.dll", "bin", fr"win32\bin\{cfg}") - self.copy("netsnmp.lib", "lib", fr"win32\lib\{cfg}") - self.copy("include/net-snmp/*.h") - for directory in ["", "agent/", "library/"]: - self.copy(f"net-snmp/{directory}*.h", "include", "win32") - self.copy("COPYING", "licenses") - - def _remove(self, path): - if os.path.isdir(path): - tools.rmdir(path) - else: - os.remove(path) + if self.settings.os.version == "7.0": + args.append("ac_cv_func_asprintf=no") + + + autotools = Autotools(self) + + env = VirtualRunEnv(self) + with env.vars().apply(): + autotools.configure(args=args) + + autotools.make() def _package_unix(self): - self._configure_autotools().install(args=["NOAUTODEPS=1"]) - tools.remove_files_by_mask(self.package_folder, "README") - tools.rmdir(os.path.join(self.package_folder, "bin")) - lib_dir = os.path.join(self.package_folder, "lib") - for entry in os.listdir(lib_dir): - if not entry.startswith("libnetsnmp.") or entry.endswith(".la"): - self._remove(os.path.join(lib_dir, entry)) - self.copy("COPYING", "licenses") + autotools = Autotools(self) - def package(self): - if self._is_msvc: - self._package_msvc() - else: - self._package_unix() + #only install with -j1 as parallel install will break dependencies. Probably a bug in the dependencies + #install specific targets instead of just everything as it will try to do perl stuff on you host machine + autotools.install(args=["-j1"], target="installsubdirs installlibs installprogs installheaders") - def package_info(self): - self.cpp_info.libs = ["netsnmp"] - self.cpp_info.requires = ["openssl::openssl"] + rm(self, "*.la", join(self.package_folder, "lib")) + rmdir(self, join(self.package_folder, "share")) diff --git a/recipes/net-snmp/all/patches/0002-install-only-libnetsnmp.patch b/recipes/net-snmp/all/patches/0002-install-only-libnetsnmp.patch deleted file mode 100644 index 96ca26e6964f6..0000000000000 --- a/recipes/net-snmp/all/patches/0002-install-only-libnetsnmp.patch +++ /dev/null @@ -1,35 +0,0 @@ ---- agent/Makefile.in -+++ agent/Makefile.in -@@ -19,8 +19,8 @@ - FTSUBDIRS=mibgroup helpers - - INSTALLSBINPROGS= @SNMPD@ --INSTALLLIBS = libnetsnmpagent.$(LIB_EXTENSION)$(LIB_VERSION) --INSTALLPOSTLIBS = libnetsnmpmibs.$(LIB_EXTENSION)$(LIB_VERSION) -+INSTALLLIBS = -+INSTALLPOSTLIBS = - - INCLUDESUBDIR=agent - HEADERS=\ ---- agent/helpers/Makefile.in -+++ agent/helpers/Makefile.in -@@ -14,7 +14,7 @@ - # What to install - # - --INSTALLLIBS=libnetsnmphelpers.$(LIB_EXTENSION)$(LIB_VERSION) -+INSTALLLIBS= - INCLUDESUBDIR=agent - - # ---- Makefile.in -+++ Makefile.in -@@ -39,7 +39,7 @@ - # - # other install rules. - # --OTHERINSTALL=copypersistentfiles @PERLINSTALLTARGS@ @PYTHONINSTALLTARGS@ -+OTHERINSTALL= - OTHERUNINSTALL=@PERLUNINSTALLTARGS@ @PYTHONUNINSTALLTARGS@ - COPY_PERSISTENT_FILES=@COPY_PERSISTENT_FILES@ - PERSISTENT_DIRECTORY=@PERSISTENT_DIRECTORY@ diff --git a/recipes/net-snmp/all/patches/0003-fix-perl-scripts-msvc.patch b/recipes/net-snmp/all/patches/0003-fix-perl-scripts-msvc.patch deleted file mode 100644 index 992914c1a489c..0000000000000 --- a/recipes/net-snmp/all/patches/0003-fix-perl-scripts-msvc.patch +++ /dev/null @@ -1,101 +0,0 @@ ---- win32/build.pl -+++ win32/build.pl -@@ -35,7 +35,7 @@ - my $install_devel = false; - my $perl = false; - my $perl_install = false; --my $logging = true; -+my $logging = false; - my $debug = false; - my $configOpts; - my $link_dynamic = false; -@@ -44,15 +44,7 @@ - # Path of this script (source tree path + "win32"). - my $current_pwd = dirname(abs_path($0)); - --if (!defined($ENV{MSVCDir}) && !defined($ENV{VCINSTALLDIR}) && -- !defined($ENV{TARGET_CPU})) { -- print "\nPlease run VCVARS32.BAT first to set up the Visual Studio build\n" . -- "environment.\n\n"; -- system("pause"); -- exit; --} -- --while (1) { -+while (0) { - print "\n\nNet-SNMP build and install options\n"; - print "==================================\n\n"; - print "1. OpenSSL support: " . ($openssl ? "enabled" : "disabled"). "\n"; -@@ -192,6 +184,8 @@ - print "Running Configure...\n"; - system("perl Configure $configOpts --linktype=$linktype --prefix=\"$install_base\"" . ($logging ? " > configure.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see configure.out)" : "Build error (see above)"); - -+exit; -+ - print "Cleaning...\n"; - system("nmake /nologo clean" . ($logging ? " > clean.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see clean.out)" : "Build error (see above)"); - ---- win32/Configure -+++ win32/Configure -@@ -6,7 +6,6 @@ - # - use strict; - use warnings; --use ExtUtils::Embed; - use Getopt::Long; - - my $version = "unknown"; -@@ -190,8 +189,6 @@ - - my $perl_inc = $opensslincdir ? "/I $opensslincdir" : ""; - --my $perl_cflags = ExtUtils::Embed::ccopts(); -- - my %makefile_subs = ( - "app" => [ "^APPS=", "APPS=" . join(" ", @apps) ], - "apc" => [ "^APPS_CLEAN=", "APPS_CLEAN=" . join(" ", @apps_clean)], -@@ -205,29 +202,23 @@ - "sdk" => [ "^SDK=", $sdk == 1 ? "SDK=true" : "SDK=false" ], - "pin" => [ "^PERL_DEFINE=","PERL_DEFINE=$perl_define" ], - "pdf" => [ "^PERL_INC=", "PERL_INC=$perl_inc" ], -- "pcf" => [ "^PERL_CFLAGS=","PERL_CFLAGS=$perl_cflags" ], -+ "pcf" => [ "^PERL_CFLAGS=","PERL_CFLAGS=" ], - "cfl" => [ "^CFLAGS=", "CFLAGS=$perl_define " . - "/D WIN32_LEAN_AND_MEAN " . -- "/EHsc " . -- "/FD " . -- "/FR\$(INTDIR)\\ " . - "/Fd\$(INTDIR)\\\$(PROGNAME).pdb " . - "/Fo\$(INTDIR)\\ " . - "$perl_inc " . -- "$perl_cflags " . - "/c " . -- "/W3 " . -- "/Zi " . -+ "/W3 /wd4267 /wd4244 /GS " . - "/nologo " . - ($config eq "release" ? -- "/MD /D NDEBUG /O2 " : -- "/MDd /D _DEBUG /Od /Gm ") -+ "/runtime /O2 /Ob2 /DNDEBUG " : -+ "/runtime /Zi /Ob0 /Od /RTC1 ") - ], - "lfl" => [ "^LDFLAGS=", "LDFLAGS=" . - ($config eq "debug" ? "/debug " : "") . - ($openssllibdir ? "/libpath:$openssllibdir" : -- "") . " " . -- "/MANIFEST:EMBED" -+ "") - ], - "rsc" => [ "^RSCFLAGS=", "RSCFLAGS=/l 0x409 " . - ($config eq "release" ? "/d NDEBUG" : -@@ -308,9 +299,3 @@ - print " Blumenthal AES: " . ($blumenthal_aes ? "enabled" : "disabled") . "\n"; - print " IPv6 transport: " . ($b_ipv6 == 1 ? "enabled" : "disabled") . "\n"; - print " winExtDLL agent: " . ($b_winextdll == 1 ? "enabled" : "disabled") . "\n"; -- --if ($ENV{INCLUDE} eq "") { -- print "\n\nVisual Studio environment not detected. Please run VCVARS32.BAT before\n"; -- print "running nmake\n\n"; --} -- diff --git a/recipes/net-snmp/all/patches/0005-exclude_syslog.patch b/recipes/net-snmp/all/patches/0005-exclude_syslog.patch new file mode 100644 index 0000000000000..5ad0bcfb6d6ff --- /dev/null +++ b/recipes/net-snmp/all/patches/0005-exclude_syslog.patch @@ -0,0 +1,11 @@ +--- snmplib/snmp_debug.c 2021-05-26 00:19:35.000000000 +0200 ++++ snmplib/snmp_debug.c 2022-09-05 13:51:14.733064200 +0200 +@@ -37,7 +37,7 @@ + #endif + + #ifdef HAVE_PRIORITYNAMES +-#include ++#include + #endif + + #include diff --git a/recipes/net-snmp/all/patches/0006-include_select.patch b/recipes/net-snmp/all/patches/0006-include_select.patch new file mode 100644 index 0000000000000..57a82800b5795 --- /dev/null +++ b/recipes/net-snmp/all/patches/0006-include_select.patch @@ -0,0 +1,12 @@ +--- include/net-snmp/library/types.h 2023-07-16 15:14:12.240768782 +0200 ++++ include/net-snmp/library/types.h 2023-07-16 15:14:43.021108707 +0200 +@@ -5,6 +5,9 @@ + #error "Please include before this file" + #endif + ++#if HAVE_SYS_SELECT_H ++ #include ++#endif + + #include + diff --git a/recipes/net-snmp/all/test_package/CMakeLists.txt b/recipes/net-snmp/all/test_package/CMakeLists.txt index bed2bf477f616..3e8830caa55db 100644 --- a/recipes/net-snmp/all/test_package/CMakeLists.txt +++ b/recipes/net-snmp/all/test_package/CMakeLists.txt @@ -1,10 +1,7 @@ cmake_minimum_required(VERSION 3.1) project(test_package C) -include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") -conan_basic_setup(TARGETS KEEP_RPATHS) - find_package(net-snmp REQUIRED CONFIG) -add_executable(test_package test_package.c) -target_link_libraries(test_package PRIVATE net-snmp::net-snmp) +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE net-snmp::net-snmp) diff --git a/recipes/net-snmp/all/test_package/conanfile.py b/recipes/net-snmp/all/test_package/conanfile.py index 56657365795bd..5b81793a7f537 100644 --- a/recipes/net-snmp/all/test_package/conanfile.py +++ b/recipes/net-snmp/all/test_package/conanfile.py @@ -1,11 +1,16 @@ import os - -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) def build_requirements(self): if self.settings.os == "Macos" and self.settings.arch == "armv8": @@ -15,12 +20,18 @@ def build_requirements(self): # because CMake's platform configuration is corrupt. self.build_requires("cmake/3.20.1") + 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", "test_package") - self.run(bin_path, run_environment=True) + if not can_run(self): + return + + + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/net-snmp/config.yml b/recipes/net-snmp/config.yml index f15097f7b11ab..0cb20301a0abc 100644 --- a/recipes/net-snmp/config.yml +++ b/recipes/net-snmp/config.yml @@ -1,3 +1,3 @@ versions: - "5.9.1": + "5.9.3": folder: all