Skip to content

Commit

Permalink
(conan-io#15415) libtorrent: add version 2.0.8, support conan v2, upd…
Browse files Browse the repository at this point in the history
…ate dependencies

* libtorrent: add version 2.0.8, support conan v2, update dependencies

* drop support gcc5, update cmake version

* use dependencies instead of options

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>

* remove unused imports, add layout, refine validate(), use is_msvc_static_runtime

---------

Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
  • Loading branch information
2 people authored and StellaSmith committed Feb 2, 2023
1 parent 66e9578 commit 95e5353
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 149 deletions.
7 changes: 0 additions & 7 deletions recipes/libtorrent/all/CMakeLists.txt

This file was deleted.

17 changes: 9 additions & 8 deletions recipes/libtorrent/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
sources:
"2.0.8":
url: "https://github.com/arvidn/libtorrent/releases/download/v2.0.8/libtorrent-rasterbar-2.0.8.tar.gz"
sha256: "09dd399b4477638cf140183f5f85d376abffb9c192bc2910002988e27d69e13e"
"2.0.1":
url: "https://github.com/arvidn/libtorrent/releases/download/v2.0.1/libtorrent-rasterbar-2.0.1.tar.gz"
sha256: "7b39599bf602bf2f208f8f05bf2327576356a3c192175b3a4603262ede42ffd7"
"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:
"2.0.1":
- patch_file: "patches/2.0.1-0001-cmake-fix-conan-boost-openssl.patch"
base_path: "source_subfolder"
"1.2.3":
- patch_file: "patches/1.2.3-0001-cmake-fix-conan-boost-openssl.patch"
base_path: "source_subfolder"
- patch_file: "patches/1.2.3-0002-boost-system-header-only-1.69+.patch"
base_path: "source_subfolder"
patch_description: "use find_package with component only boost >= 1.69"
patch_type: "portability"
- patch_file: "patches/1.2.3-0003-include-cstddef.patch"
base_path: "source_subfolder"
patch_description: "include cstddef instead stddef.h"
patch_type: "portability"
- patch_file: "patches/1.2.3-0004-increase-handle-storage-sizes.patch"
base_path: "source_subfolder"
patch_description: "increase handle storage size"
patch_type: "portability"
145 changes: 76 additions & 69 deletions recipes/libtorrent/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from conan.tools.microsoft import msvc_runtime_flag
from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir, replace_in_file
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
import os

required_conan_version = ">=1.43.0"

required_conan_version = ">=1.53.0"

class LibtorrentConan(ConanFile):
name = "libtorrent"
Expand Down Expand Up @@ -45,126 +48,130 @@ class LibtorrentConan(ConanFile):
"enable_mutable_torrents": True,
}

generators = "cmake"
_cmake = None

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

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

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

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def _check_compiler_supports_cxx14(self):
min_compiler_version = {
"Visual Studio": "15",
"gcc": "5",
"msvc": "191",
"gcc": "5" if Version(self.version) < "2.0.8" else "6",
"clang": "5",
"apple-clang": "5",
}.get(str(self.settings.compiler))
if min_compiler_version is None:
self.output.warn("Unknown compiler. Assuming it is supporting c++14")
if tools.Version(self.settings.compiler.version) < min_compiler_version:
if Version(self.settings.compiler.version) < min_compiler_version:
raise ConanInvalidConfiguration("This compiler (version) does not support c++ 14.")
return True, None

def validate(self):
if tools.Version(self.version) < "2.0":
if Version(self.version) < "2.0":
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
check_min_cppstd(self, 11)
else:
self._check_compiler_supports_cxx14()
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 14)
check_min_cppstd(self, 14)

if Version(self.dependencies["boost"].ref.version) < "1.69.0" and \
(self.dependencies["boost"].options.header_only or self.dependencies["boost"].options.without_system):
raise ConanInvalidConfiguration(f"{self.ref} requires boost with system, which is non-header only in boost < 1.69.0")

def requirements(self):
if tools.Version(self.version) < "2.0.0":
self.requires("boost/1.79.0")
# libtorrent 2.0.x [x<=6] have issue for recent boost https://github.com/arvidn/libtorrent/discussions/6757
if Version(self.version) < "2.0.0" or "2.0.6" < Version(self.version):
self.requires("boost/1.81.0")
else:
self.requires("boost/1.76.0")
if self.options.enable_encryption:
self.requires("openssl/1.1.1q")
self.requires("openssl/1.1.1s")
if self.options.enable_iconv:
self.requires("libiconv/1.17")

def _validate_dependency_graph(self):
if tools.Version(self.deps_cpp_info["boost"].version) < "1.69.0" and \
(self.options["boost"].header_only or self.options["boost"].without_system):
raise ConanInvalidConfiguration("libtorrent requires boost with system, which is non-header only in boost < 1.69.0")
def _cmake_new_enough(self, required_version):
try:
import re
from io import StringIO
output = StringIO()
self.run("cmake --version", output=output)
m = re.search(r'cmake version (\d+\.\d+\.\d+)', output.getvalue())
return Version(m.group(1)) >= required_version
except:
return False

def build_requirements(self):
if Version(self.version) >= "2.0.4" and not self._cmake_new_enough("3.16.0"):
self.tool_requires("cmake/3.25.1")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

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
if self._is_msvc:
self._cmake.definitions["static_runtime"] = "MT" in msvc_runtime_flag(self)
self._cmake.configure()
return self._cmake
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["Boost_USE_STATIC_LIBS"] = not self.dependencies["boost"].options.shared
tc.variables["deprecated-functions"] = self.options.enable_deprecated_functions
tc.variables["dht"] = self.options.enable_dht
tc.variables["encryption"] = self.options.enable_encryption
tc.variables["exceptions"] = self.options.enable_exceptions
tc.variables["i2p"] = self.options.enable_i2p
tc.variables["logging"] = self.options.enable_logging
tc.variables["mutable-torrents"] = self.options.enable_mutable_torrents
tc.variables["build_tests"] = False
tc.variables["build_examples"] = False
tc.variables["build_tools"] = False
tc.variables["python-bindings"] = False
tc.variables["python-bindings"] = False
if is_msvc(self):
tc.variables["static_runtime"] = is_msvc_static_runtime(self)
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
for patch_data in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch_data)
apply_conandata_patches(self)

tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"), "/W4", "")
if tools.Version(self.version) < "2.0":
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "/W4", "")
if Version(self.version) < "2.0":
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"),
replace_in_file(self, os.path.join(self.source_folder, "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"),
replace_in_file(self, os.path.join(self.source_folder, "include", "libtorrent", "file_storage.hpp"),
"file_entry& operator=(file_entry&&) & noexcept = default;",
"file_entry& operator=(file_entry&&) & = default;")

def build(self):
self._validate_dependency_graph()
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(self, pattern="COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
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"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "LibtorrentRasterbar")
Expand Down

This file was deleted.

This file was deleted.

13 changes: 5 additions & 8 deletions recipes/libtorrent/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

if(WIN32)
add_definitions(-D_WIN32_WINNT=0x0601)
Expand All @@ -11,9 +8,9 @@ endif()
find_package(LibtorrentRasterbar REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} LibtorrentRasterbar::torrent-rasterbar)
target_link_libraries(${PROJECT_NAME} PRIVATE LibtorrentRasterbar::torrent-rasterbar)
if(LibtorrentRasterbar_VERSION VERSION_LESS "2.0")
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
else()
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
endif()
19 changes: 14 additions & 5 deletions recipes/libtorrent/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "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)
self.run(f"{bin_path} {magnet_url}", env="conanrun")
8 changes: 8 additions & 0 deletions recipes/libtorrent/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
20 changes: 20 additions & 0 deletions recipes/libtorrent/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


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

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

def test(self):
if not cross_building(self):
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)
Loading

0 comments on commit 95e5353

Please sign in to comment.