|
| 1 | +from conan import ConanFile |
| 2 | +from conan.tools.build import check_min_cppstd |
| 3 | +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout |
| 4 | +from conan.tools.files import copy, get, rm, rmdir, replace_in_file |
| 5 | +from conan.tools.microsoft import is_msvc, is_msvc_static_runtime |
| 6 | +import os |
| 7 | + |
| 8 | + |
| 9 | +required_conan_version = ">=2.0.9" |
| 10 | + |
| 11 | +class PackageConan(ConanFile): |
| 12 | + name = "cpp-smtpclient-library" |
| 13 | + description = "An SMTP client library built in C++ that support authentication and secure connections" |
| 14 | + license = "MIT" |
| 15 | + url = "https://github.com/conan-io/conan-center-index" |
| 16 | + homepage = "https://github.com/jeremydumais/CPP-SMTPClient-library" |
| 17 | + topics = ("c", "cpp", "cpp-library", "macos", "windows", "linux", "smtp", "email") |
| 18 | + package_type = "library" |
| 19 | + settings = "os", "arch", "compiler", "build_type" |
| 20 | + options = { |
| 21 | + "shared": [True, False], |
| 22 | + "fPIC": [True, False], |
| 23 | + } |
| 24 | + default_options = { |
| 25 | + "shared": False, |
| 26 | + "fPIC": True, |
| 27 | + } |
| 28 | + implements = ["auto_shared_fpic"] |
| 29 | + |
| 30 | + def layout(self): |
| 31 | + cmake_layout(self, src_folder="src") |
| 32 | + |
| 33 | + def requirements(self): |
| 34 | + self.requires("openssl/[>=1.1 <4]") |
| 35 | + |
| 36 | + def validate(self): |
| 37 | + check_min_cppstd(self, 14) |
| 38 | + |
| 39 | + def source(self): |
| 40 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
| 41 | + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY}", "OpenSSL::Crypto OpenSSL::SSL") |
| 42 | + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "ssl crypto", "OpenSSL::Crypto OpenSSL::SSL") |
| 43 | + |
| 44 | + def generate(self): |
| 45 | + tc = CMakeToolchain(self) |
| 46 | + if is_msvc(self): |
| 47 | + tc.cache_variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self) |
| 48 | + tc.generate() |
| 49 | + |
| 50 | + deps = CMakeDeps(self) |
| 51 | + deps.generate() |
| 52 | + |
| 53 | + def build(self): |
| 54 | + cmake = CMake(self) |
| 55 | + cmake.configure() |
| 56 | + cmake.build() |
| 57 | + |
| 58 | + def package(self): |
| 59 | + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) |
| 60 | + cmake = CMake(self) |
| 61 | + cmake.install() |
| 62 | + |
| 63 | + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) |
| 64 | + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) |
| 65 | + rmdir(self, os.path.join(self.package_folder, "share")) |
| 66 | + rm(self, "*.pdb", self.package_folder, recursive=True) |
| 67 | + |
| 68 | + def package_info(self): |
| 69 | + self.cpp_info.libdirs = [os.path.join("lib", "smtpclient")] |
| 70 | + self.cpp_info.libs = ["smtpclient"] |
| 71 | + self.cpp_info.set_property("cmake_module_file_name", "smtpclient") |
| 72 | + self.cpp_info.set_property("cmake_module_target_name", "smtpclient::smtpclient") |
| 73 | + self.cpp_info.set_property("cmake_file_name", "smtpclient") |
| 74 | + self.cpp_info.set_property("cmake_target_name", "smtpclient::smtpclient") |
| 75 | + if not self.options.shared: |
| 76 | + self.cpp_info.defines.append("SMTPCLIENT_STATIC") |
| 77 | + if self.settings.os in ["Linux", "FreeBSD"]: |
| 78 | + self.cpp_info.system_libs.extend(["m", "pthread", "dl"]) |
0 commit comments