|
| 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 |
| 5 | +from conan.tools.microsoft import is_msvc |
| 6 | +from conan.errors import ConanInvalidConfiguration |
| 7 | + |
| 8 | +import os |
| 9 | + |
| 10 | +required_conan_version = ">=2.0.9" |
| 11 | + |
| 12 | +class LiftHttpConan(ConanFile): |
| 13 | + name = "liblifthttp" |
| 14 | + description = "Safe and easy to use C++17 HTTP client library." |
| 15 | + license = "Apache-2.0" |
| 16 | + url = "https://github.com/conan-io/conan-center-index" |
| 17 | + homepage = "https://github.com/jbaldwin/liblifthttp" |
| 18 | + topics = ("cpp", "async", "asynchronous", "http", "https", "web", "client") |
| 19 | + package_type = "library" |
| 20 | + settings = "os", "arch", "compiler", "build_type" |
| 21 | + options = { |
| 22 | + "shared": [True, False], |
| 23 | + "fPIC": [True, False], |
| 24 | + } |
| 25 | + default_options = { |
| 26 | + "shared": False, |
| 27 | + "fPIC": True, |
| 28 | + } |
| 29 | + |
| 30 | + def export_sources(self): |
| 31 | + copy(self, "conan_deps.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src")) |
| 32 | + |
| 33 | + def config_options(self): |
| 34 | + if self.settings.os == "Windows": |
| 35 | + del self.options.fPIC |
| 36 | + |
| 37 | + def configure(self): |
| 38 | + if self.options.shared: |
| 39 | + self.options.rm_safe("fPIC") |
| 40 | + |
| 41 | + def layout(self): |
| 42 | + cmake_layout(self, src_folder="src") |
| 43 | + |
| 44 | + def requirements(self): |
| 45 | + self.requires("libcurl/[>=7.88.0 <9]", transitive_headers=True) |
| 46 | + self.requires("libuv/[>=1.45.0 <2]", transitive_headers=True) |
| 47 | + |
| 48 | + def source(self): |
| 49 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
| 50 | + def validate(self): |
| 51 | + check_min_cppstd(self, 17) |
| 52 | + if is_msvc(self) and self.options.shared: |
| 53 | + # INFO: It lacks of exposing symbols in a .lib |
| 54 | + raise ConanInvalidConfiguration("The project does not support Windows shared build.") |
| 55 | + |
| 56 | + def generate(self): |
| 57 | + tc = CMakeToolchain(self) |
| 58 | + tc.variables["CMAKE_PROJECT_lifthttp_INCLUDE"] = "conan_deps.cmake" |
| 59 | + tc.variables["LIFT_BUILD_EXAMPLES"] = False |
| 60 | + tc.variables["LIFT_BUILD_TESTS"] = False |
| 61 | + tc.variables["LIFT_USER_LINK_LIBRARIES"] = "CURL::libcurl;libuv::uv" |
| 62 | + if self.settings.os in ["Linux", "FreeBSD"]: |
| 63 | + tc.variables["LIFT_USER_LINK_LIBRARIES"] += ";pthread;dl" |
| 64 | + tc.generate() |
| 65 | + |
| 66 | + deps = CMakeDeps(self) |
| 67 | + # INFO: Avoid guessing libuv target name as it changes according version/configuration |
| 68 | + deps.set_property("libuv", "cmake_target_name", "libuv::uv") |
| 69 | + deps.generate() |
| 70 | + |
| 71 | + def build(self): |
| 72 | + cmake = CMake(self) |
| 73 | + cmake.configure() |
| 74 | + cmake.build() |
| 75 | + |
| 76 | + def package(self): |
| 77 | + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) |
| 78 | + copy(self, pattern="*.hpp", src=os.path.join(self.source_folder, "inc"), dst=os.path.join(self.package_folder, "include")) |
| 79 | + for pattern in ["*.a", "*.so*", "*.dylib", "*.lib"]: |
| 80 | + copy(self, pattern, src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False) |
| 81 | + copy(self, "*.dll", src=self.build_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False) |
| 82 | + |
| 83 | + def package_info(self): |
| 84 | + self.cpp_info.set_property("cmake_file_name", "lifthttp") |
| 85 | + self.cpp_info.set_property("cmake_target_name", "lifthttp::lifthttp") |
| 86 | + self.cpp_info.libs = ["lifthttp"] |
| 87 | + if self.settings.os in ["Linux", "FreeBSD"]: |
| 88 | + self.cpp_info.system_libs.extend(["pthread", "dl"]) |
0 commit comments