Skip to content

Commit

Permalink
Merge pull request #815 from madebr/libtorrent
Browse files Browse the repository at this point in the history
Add libtorrent/1.2.3 recipe
  • Loading branch information
danimtb authored Mar 9, 2020
2 parents 0cb89a3 + 7a6c3ac commit fa41663
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/libtorrent/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
8 changes: 8 additions & 0 deletions recipes/libtorrent/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
"1.2.3":
url: "https://github.com/arvidn/libtorrent/releases/download/libtorrent-1_2_3/libtorrent-rasterbar-1.2.3.tar.gz"
sha256: "1582fdbbd0449bcfe4ffae2ccb9e5bf0577459a32bb25604e01accb847da1a2d"
patches:
"1.2.3":
- patch_file: "patches/0001-cmake-fix-conan-boost-openssl.patch"
base_path: "source_subfolder"
137 changes: 137 additions & 0 deletions recipes/libtorrent/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from conans import CMake, ConanFile, tools
from conans.tools import Version
import os


class LibtorrentConan(ConanFile):
name = "libtorrent"
description = "libtorrent is a feature complete C++ bittorrent implementation focusing on efficiency and scalability"
topics = ("conan", "libtorrent", "p2p", "network", "mesh")
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://libtorrent.org"
exports_sources = "CMakeLists.txt", "patches/**"
generators = "cmake"
license = ("BSD-3-clause", "ZLIB", "BSL-1.0")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"enable_deprecated_functions": [True, False],
"enable_dht": [True, False],
"enable_encryption": [True, False],
"enable_exceptions": [True, False],
"enable_extensions": [True, False],
"enable_i2p": [True, False],
"enable_iconv": [True, False],
"enable_logging": [True, False],
"enable_mutable_torrents": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"enable_dht": True,
"enable_deprecated_functions": True,
"enable_encryption": True,
"enable_exceptions": True,
"enable_extensions": True,
"enable_i2p": True,
"enable_iconv": False,
"enable_logging": True,
"enable_mutable_torrents": True,
}

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)

def requirements(self):
self.requires("boost/1.71.0")
if self.options.enable_encryption:
self.requires("openssl/1.1.1d")
if self.options.enable_iconv:
self.requires("libiconv/1.15")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("libtorrent-rasterbar-{}".format(self.version), self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["Boost_USE_STATIC_LIBS"] = not self.options["boost"].shared
self._cmake.definitions["deprecated-functions"] = self.options.enable_deprecated_functions
self._cmake.definitions["dht"] = self.options.enable_dht
self._cmake.definitions["encryption"] = self.options.enable_encryption
self._cmake.definitions["exceptions"] = self.options.enable_exceptions
self._cmake.definitions["i2p"] = self.options.enable_i2p
self._cmake.definitions["logging"] = self.options.enable_logging
self._cmake.definitions["mutable-torrents"] = self.options.enable_mutable_torrents
self._cmake.definitions["build_tests"] = False
self._cmake.definitions["build_examples"] = False
self._cmake.definitions["build_tools"] = False
self._cmake.definitions["python-bindings"] = False
self._cmake.definitions["python-bindings"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def _patch_sources(self):
for patch_data in self.conan_data["patches"][self.version]:
tools.patch(**patch_data)

if self.options.enable_iconv:
replace = "find_public_dependency(Iconv REQUIRED)"
else:
replace = "set(Iconv_FOUND OFF)"
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"find_public_dependency(Iconv)",
replace)
if self.settings.compiler == "clang" and self.settings.compiler.libcxx == "libstdc++":
# https://github.com/arvidn/libtorrent/issues/3557
tools.replace_in_file(os.path.join(self._source_subfolder, "include", "libtorrent", "file_storage.hpp"),
"file_entry& operator=(file_entry&&) & noexcept = default;",
"file_entry& operator=(file_entry&&) & = default;")

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
cmake.install()

tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.names["pkg_config"] = "libtorrent-rasterbar"
self.cpp_info.names["cmake_find_package"] = "LibtorrentRasterbar"
self.cpp_info.names["cmake_find_package_multi"] = "LibtorrentRasterbar"
self.cpp_info.includedirs = ["include", os.path.join("include", "libtorrent")]
self.cpp_info.libs = ["torrent-rasterbar"]

if self.settings.os == "Linux":
self.cpp_info.system_libs = ["dl", "pthread"]
if self.settings.os == "Windows":
self.cpp_info.system_libs = ["wsock32", "ws2_32", "iphlpapi", "debug", "dbghelp"]
elif self.settings.os == "Macos":
self.cpp_info.frameworks = ["CoreFoundation", "SystemConfiguration"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -484,8 +484,8 @@
if(static_runtime)
include(ucm_flags)
ucm_set_runtime(STATIC)
- set(Boost_USE_MULTITHREADED ON)
- set(Boost_USE_STATIC_RUNTIME ON)
+ # set(Boost_USE_MULTITHREADED ON)
+ # set(Boost_USE_STATIC_RUNTIME ON)
set(OPENSSL_USE_STATIC_LIBS TRUE)
set(OPENSSL_MSVC_STATIC_RT TRUE)
endif()
@@ -630,7 +630,7 @@
)

if(OPENSSL_FOUND)
- target_link_libraries(torrent-rasterbar PUBLIC OpenSSL::SSL)
+ target_link_libraries(torrent-rasterbar PUBLIC OpenSSL::SSL ${CONAN_SYSTEM_LIBS_OPENSSL})
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_OPENSSL)
target_sources(torrent-rasterbar PRIVATE src/pe_crypto)
endif()
13 changes: 13 additions & 0 deletions recipes/libtorrent/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 2.8.12)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

if(WIN32)
add_definitions(-D_WIN32_WINNT=0x0601)
endif()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
19 changes: 19 additions & 0 deletions recipes/libtorrent/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
# from https://en.wikipedia.org/wiki/Magnet_URI_scheme
magnet_url = "magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a"
self.run("{} {}".format(bin_path, magnet_url), run_environment=True)
53 changes: 53 additions & 0 deletions recipes/libtorrent/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// From https://www.libtorrent.org/tutorial.html

#include <libtorrent/session.hpp>
#include <libtorrent/add_torrent_params.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <libtorrent/alert_types.hpp>
#include <libtorrent/magnet_uri.hpp>

#include <iostream>
#include <thread>
#include <chrono>

int main(int argc, char const* argv[]) try
{
if (argc != 2) {
std::cerr << "usage: " << argv[0] << " <magnet-url>" << std::endl;
return 1;
}
lt::settings_pack p;
p.set_int(lt::settings_pack::alert_mask, lt::alert::status_notification
| lt::alert::error_notification);
lt::session ses(p);

lt::add_torrent_params atp = lt::parse_magnet_uri(argv[1]);
atp.save_path = "."; // save in current dir
// lt::torrent_handle h = ses.add_torrent(std::move(atp));

std::cout << "skipping download...\n";

// for (;;) {
// std::vector<lt::alert*> alerts;
// ses.pop_alerts(&alerts);
//
// for (lt::alert const* a : alerts) {
// std::cout << a->message() << std::endl;
// // if we receive the finished alert or an error, we're done
// if (lt::alert_cast<lt::torrent_finished_alert>(a)) {
// goto done;
// }
// if (lt::alert_cast<lt::torrent_error_alert>(a)) {
// goto done;
// }
// }
// std::this_thread::sleep_for(std::chrono::milliseconds(200));
// }

done:
std::cout << "done, shutting down" << std::endl;
}
catch (std::exception& e)
{
std::cerr << "Error: " << e.what() << std::endl;
}
3 changes: 3 additions & 0 deletions recipes/libtorrent/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.2.3":
folder: "all"

0 comments on commit fa41663

Please sign in to comment.