From bb4b0f14f61064d92037f69e6da080396652e019 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sat, 8 Feb 2020 19:53:48 +0100 Subject: [PATCH 1/2] Add libtorrent/1.2.3 recipe --- recipes/libtorrent/all/CMakeLists.txt | 7 + recipes/libtorrent/all/conandata.yml | 8 ++ recipes/libtorrent/all/conanfile.py | 132 ++++++++++++++++++ .../0001-cmake-fix-conan-boost-openssl.patch | 22 +++ .../all/test_package/CMakeLists.txt | 15 ++ .../libtorrent/all/test_package/conanfile.py | 19 +++ .../all/test_package/test_package.cpp | 53 +++++++ recipes/libtorrent/config.yml | 3 + 8 files changed, 259 insertions(+) create mode 100644 recipes/libtorrent/all/CMakeLists.txt create mode 100644 recipes/libtorrent/all/conandata.yml create mode 100644 recipes/libtorrent/all/conanfile.py create mode 100644 recipes/libtorrent/all/patches/0001-cmake-fix-conan-boost-openssl.patch create mode 100644 recipes/libtorrent/all/test_package/CMakeLists.txt create mode 100644 recipes/libtorrent/all/test_package/conanfile.py create mode 100644 recipes/libtorrent/all/test_package/test_package.cpp create mode 100644 recipes/libtorrent/config.yml diff --git a/recipes/libtorrent/all/CMakeLists.txt b/recipes/libtorrent/all/CMakeLists.txt new file mode 100644 index 0000000000000..a69305eb3971f --- /dev/null +++ b/recipes/libtorrent/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8.12) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory(source_subfolder) diff --git a/recipes/libtorrent/all/conandata.yml b/recipes/libtorrent/all/conandata.yml new file mode 100644 index 0000000000000..bff972661a0e4 --- /dev/null +++ b/recipes/libtorrent/all/conandata.yml @@ -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" diff --git a/recipes/libtorrent/all/conanfile.py b/recipes/libtorrent/all/conanfile.py new file mode 100644 index 0000000000000..9a09ff2a213fe --- /dev/null +++ b/recipes/libtorrent/all/conanfile.py @@ -0,0 +1,132 @@ +from conans import CMake, ConanFile, tools +from conans.errors import ConanInvalidConfiguration +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 and self.settings.compiler.cppstd in ("98", "gnu98"): + raise ConanInvalidConfiguration("libtorrent requires at least c++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) + + 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"] diff --git a/recipes/libtorrent/all/patches/0001-cmake-fix-conan-boost-openssl.patch b/recipes/libtorrent/all/patches/0001-cmake-fix-conan-boost-openssl.patch new file mode 100644 index 0000000000000..0fd0b09b5440f --- /dev/null +++ b/recipes/libtorrent/all/patches/0001-cmake-fix-conan-boost-openssl.patch @@ -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() diff --git a/recipes/libtorrent/all/test_package/CMakeLists.txt b/recipes/libtorrent/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..20498d449f7de --- /dev/null +++ b/recipes/libtorrent/all/test_package/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.12) +project(test_package) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_VERBOSE_MAKEFILE TRUE) + +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}) diff --git a/recipes/libtorrent/all/test_package/conanfile.py b/recipes/libtorrent/all/test_package/conanfile.py new file mode 100644 index 0000000000000..3ec50d9d3b7b8 --- /dev/null +++ b/recipes/libtorrent/all/test_package/conanfile.py @@ -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) diff --git a/recipes/libtorrent/all/test_package/test_package.cpp b/recipes/libtorrent/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..f5601a6b151de --- /dev/null +++ b/recipes/libtorrent/all/test_package/test_package.cpp @@ -0,0 +1,53 @@ +// From https://www.libtorrent.org/tutorial.html + +#include +#include +#include +#include +#include + +#include +#include +#include + +int main(int argc, char const* argv[]) try +{ + if (argc != 2) { + std::cerr << "usage: " << argv[0] << " " << 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 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(a)) { +// goto done; +// } +// if (lt::alert_cast(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; +} diff --git a/recipes/libtorrent/config.yml b/recipes/libtorrent/config.yml new file mode 100644 index 0000000000000..81ff4bc37c872 --- /dev/null +++ b/recipes/libtorrent/config.yml @@ -0,0 +1,3 @@ +versions: + "1.2.3": + folder: "all" From 7a6c3ac564b310cdf9e8121a40c8e7d2d8ce6faf Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 3 Mar 2020 02:12:59 +0100 Subject: [PATCH 2/2] libtorrent: remove noexcept from defaulted file_entry assign operator on clang --- recipes/libtorrent/all/conanfile.py | 11 ++++++++--- recipes/libtorrent/all/test_package/CMakeLists.txt | 4 +--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/recipes/libtorrent/all/conanfile.py b/recipes/libtorrent/all/conanfile.py index 9a09ff2a213fe..09edba7690333 100644 --- a/recipes/libtorrent/all/conanfile.py +++ b/recipes/libtorrent/all/conanfile.py @@ -1,5 +1,5 @@ from conans import CMake, ConanFile, tools -from conans.errors import ConanInvalidConfiguration +from conans.tools import Version import os @@ -57,8 +57,8 @@ def config_options(self): def configure(self): if self.options.shared: del self.options.fPIC - if self.settings.compiler.cppstd and self.settings.compiler.cppstd in ("98", "gnu98"): - raise ConanInvalidConfiguration("libtorrent requires at least c++11") + if self.settings.compiler.cppstd: + tools.check_min_cppstd(self, 11) def requirements(self): self.requires("boost/1.71.0") @@ -102,6 +102,11 @@ def _patch_sources(self): 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() diff --git a/recipes/libtorrent/all/test_package/CMakeLists.txt b/recipes/libtorrent/all/test_package/CMakeLists.txt index 20498d449f7de..5cbeb85d55412 100644 --- a/recipes/libtorrent/all/test_package/CMakeLists.txt +++ b/recipes/libtorrent/all/test_package/CMakeLists.txt @@ -1,9 +1,6 @@ cmake_minimum_required(VERSION 2.8.12) project(test_package) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_VERBOSE_MAKEFILE TRUE) - include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() @@ -13,3 +10,4 @@ endif() add_executable(${PROJECT_NAME} test_package.cpp) target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)