Skip to content

Commit bf41b3c

Browse files
cpp-smtpclient-library: add new recipe (#27470)
* initial conan package creation for version 1.1.10 * fix: Solve the issue to generate the correct symbols when build as static. * fix: Force OpenSSL::SSL OpenSSL::Crypto instead of variable in target link libraries * fix: Provide the correct target_link_libraries for Linux and macOS * Recipe cleanup --------- Co-authored-by: PerseoGI <[email protected]>
1 parent 076635f commit bf41b3c

File tree

6 files changed

+127
-0
lines changed

6 files changed

+127
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sources:
2+
"1.1.10":
3+
url: "https://github.com/jeremydumais/CPP-SMTPClient-library/archive/refs/tags/v1.1.10.zip"
4+
sha256: "760e34417fa00b7bd56618f0d9e382867b65729c16175da1abb77d70fe1d1cd6"
5+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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"])
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(test_package LANGUAGES CXX)
3+
4+
find_package(smtpclient REQUIRED CONFIG)
5+
6+
add_executable(${PROJECT_NAME} test_package.cpp)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE smtpclient::smtpclient)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import cmake_layout, CMake
4+
import os
5+
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain"
10+
11+
def layout(self):
12+
cmake_layout(self)
13+
14+
def requirements(self):
15+
self.requires(self.tested_reference_str)
16+
17+
def build(self):
18+
cmake = CMake(self)
19+
cmake.configure()
20+
cmake.build()
21+
22+
def test(self):
23+
if can_run(self):
24+
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
25+
self.run(bin_path, env="conanrun")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <cstdlib>
2+
#include "smtpclient/cpp/credential.hpp"
3+
4+
5+
int main(void) {
6+
jed_utils::cpp::Credential creds("Test", "Test2");
7+
8+
return EXIT_SUCCESS;
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"1.1.10":
3+
folder: all

0 commit comments

Comments
 (0)