mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-17 18:39:17 -06:00
Making libtorrent work with Launcher application
This commit is contained in:
@@ -67,9 +67,35 @@ if (APPLE)
|
||||
" COMPONENT Runtime)
|
||||
endif ()
|
||||
|
||||
# if(NOT DEFINED Boost_INCLUDE_DIR OR NOT DEFINED Boost_LIBRARIES)
|
||||
# FIND_PACKAGE( Boost COMPONENTS system thread date_time chrono)
|
||||
# endif()
|
||||
# include_directories(${Boost_INCLUDE_DIR})
|
||||
# target_link_libraries(${APPLICATION_NAME} ${Boost_LIBRARIES})
|
||||
|
||||
# Libtorrent
|
||||
set(encryption OFF CACHE BOOL "")
|
||||
set(shared OFF CACHE BOOL "")
|
||||
include_external_library(${APPLICATION_NAME} torrent-rasterbar ${application_path}/ext/libtorrent)
|
||||
add_subdirectory(${application_path}/ext/libtorrent)
|
||||
target_link_libraries(${APPLICATION_NAME} libtorrent)
|
||||
target_compile_definitions(${APPLICATION_NAME} PUBLIC BOOST_ASIO_SEPARATE_COMPILATION)
|
||||
|
||||
|
||||
# get_property(INCLUDE_DIR TARGET ${target_name} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
# target_link_libraries(${target_name} ${library_name})
|
||||
target_include_directories(${APPLICATION_NAME} PUBLIC SYSTEM ${application_path}/ext/libtorrent/include)
|
||||
set_property(TARGET libtorrent PROPERTY FOLDER "External")
|
||||
if (OPENSPACE_DISABLE_EXTERNAL_WARNINGS)
|
||||
if (MSVC)
|
||||
target_compile_options(libtorrent PUBLIC "/W0" "/MP")
|
||||
else ()
|
||||
target_compile_options(libtorrent PUBLIC "-w")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# include_external_library(${APPLICATION_NAME} libtorrent ${application_path}/ext/libtorrent)
|
||||
# We have to set it manually since the libtorrent doesn't use the new system that can be queried
|
||||
# target_include_directories(${APPLICATION_NAME} PUBLIC SYSTEM ${application_path}/ext/libtorrent/include)
|
||||
|
||||
target_compile_definitions(${APPLICATION_NAME} PUBLIC BOOST_LIB_DIAGNOSTIC)
|
||||
target_compile_definitions(libtorrent PUBLIC BOOST_LIB_DIAGNOSTIC)
|
||||
|
||||
copy_files(${APPLICATION_NAME} "${CURL_ROOT_DIR}/lib/libcurl.dll")
|
||||
|
||||
@@ -124,7 +124,6 @@ option(shared "build libtorrent as a shared library" ON)
|
||||
option(static_runtime "build libtorrent with static runtime" OFF)
|
||||
option(tcmalloc "link against google performance tools tcmalloc" OFF)
|
||||
option(pool-allocators "Uses a pool allocator for disk and piece buffers" ON)
|
||||
option(encryption "link against openssl and enable encryption" ON)
|
||||
option(geoip "link against LGPL GeoIP code from Maxmind, to enable geoip database support" OFF)
|
||||
option(dht "enable support for Mainline DHT" ON)
|
||||
option(resolve-countries "enable support for resolving countries from peer IPs" ON)
|
||||
@@ -133,7 +132,6 @@ option(deprecated-functions "enable deprecated functions for backwards compatibi
|
||||
option(exceptions "build with exception support" ON)
|
||||
option(logging "build with logging" OFF)
|
||||
option(verbose-logging "build with verbose logging" OFF)
|
||||
option(build_tests "build tests" OFF)
|
||||
|
||||
set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo)
|
||||
|
||||
@@ -148,25 +146,10 @@ if(UNIX)
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
||||
endif()
|
||||
|
||||
if (build_tests)
|
||||
# this will make some internal functions available in the
|
||||
# DLL interface, for the tests to access
|
||||
add_definitions(-DTORRENT_EXPORT_EXTRA)
|
||||
endif (build_tests)
|
||||
|
||||
include_directories(${includes})
|
||||
|
||||
if (encryption)
|
||||
list(APPEND sources pe_crypto asio_ssl)
|
||||
if(NOT DEFINED OPENSSL_INCLUDE_DIR OR NOT DEFINED OPENSSL_LIBRARIES)
|
||||
FIND_PACKAGE(OpenSSL REQUIRED)
|
||||
endif()
|
||||
add_definitions(-DTORRENT_USE_OPENSSL)
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
else()
|
||||
add_definitions(-DTORRENT_DISABLE_ENCRYPTION)
|
||||
list(APPEND sources sha1)
|
||||
endif (encryption)
|
||||
add_definitions(-DTORRENT_DISABLE_ENCRYPTION)
|
||||
list(APPEND sources sha1)
|
||||
|
||||
if (logging)
|
||||
add_definitions(-DTORRENT_LOGGING)
|
||||
@@ -197,7 +180,7 @@ endif()
|
||||
|
||||
if (shared)
|
||||
add_definitions(-DTORRENT_BUILDING_SHARED)
|
||||
add_library(torrent-rasterbar SHARED ${sources2})
|
||||
add_library(libtorrent SHARED ${sources2})
|
||||
else (shared)
|
||||
if(static_runtime)
|
||||
# fix /MT flag:
|
||||
@@ -215,37 +198,38 @@ else (shared)
|
||||
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
|
||||
endforeach()
|
||||
endif()
|
||||
add_library(torrent-rasterbar STATIC ${sources2})
|
||||
add_library(libtorrent STATIC ${sources2})
|
||||
endif()
|
||||
|
||||
# Boost
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
if(NOT DEFINED Boost_INCLUDE_DIR OR NOT DEFINED Boost_LIBRARIES)
|
||||
FIND_PACKAGE( Boost COMPONENTS system thread date_time chrono)
|
||||
endif()
|
||||
include_directories(${Boost_INCLUDE_DIR})
|
||||
target_link_libraries(torrent-rasterbar ${Boost_LIBRARIES})
|
||||
target_link_libraries(libtorrent ${Boost_LIBRARIES})
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(libtorrent Iphlpapi.lib)
|
||||
endif ()
|
||||
|
||||
# this works around a bug in asio in boost-1.39
|
||||
#add_definitions(-DBOOST_ASIO_HASH_MAP_BUCKETS=1021 -D__USE_W32_SOCKETS -DWIN32_LEAN_AND_MEAN )
|
||||
|
||||
if(NOT static_runtime)
|
||||
add_definitions(-DBOOST_ASIO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_THREAD_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_CHRONO_DYN_LINK)
|
||||
else()
|
||||
# if(NOT static_runtime)
|
||||
# add_definitions(-DBOOST_ASIO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_THREAD_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_CHRONO_DYN_LINK)
|
||||
# else()
|
||||
add_definitions(-DBOOST_ASIO_SEPARATE_COMPILATION)
|
||||
endif()
|
||||
# endif()
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(torrent-rasterbar wsock32 ws2_32)
|
||||
target_link_libraries(libtorrent wsock32 ws2_32)
|
||||
add_definitions(-D_WIN32_WINNT=0x0600)
|
||||
if (MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") # multicore compilation
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (encryption)
|
||||
target_link_libraries(torrent-rasterbar ${OPENSSL_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if (NOT pool-allocators)
|
||||
add_definitions(-DTORRENT_DISABLE_POOL_ALLOCATOR)
|
||||
endif()
|
||||
@@ -303,10 +287,10 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
endif()
|
||||
|
||||
if (tcmalloc)
|
||||
target_link_libraries(torrent-rasterbar tcmalloc)
|
||||
target_link_libraries(libtorrent tcmalloc)
|
||||
endif()
|
||||
|
||||
set_target_properties(torrent-rasterbar PROPERTIES
|
||||
set_target_properties(libtorrent PROPERTIES
|
||||
SOVERSION ${SOVERSION})
|
||||
|
||||
get_property (COMPILETIME_OPTIONS_LIST
|
||||
@@ -327,7 +311,7 @@ else()
|
||||
set (LIBDIR "lib")
|
||||
endif()
|
||||
|
||||
install(TARGETS torrent-rasterbar DESTINATION ${LIBDIR})
|
||||
install(TARGETS libtorrent DESTINATION ${LIBDIR})
|
||||
install(DIRECTORY include/libtorrent
|
||||
DESTINATION include
|
||||
PATTERN ".svn" EXCLUDE)
|
||||
@@ -337,25 +321,3 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar.pc DESTINATION ${
|
||||
#file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/examples)
|
||||
#configure_file(examples/run_cmake.sh.in examples/run_cmake.sh)
|
||||
# to build the examples, run examples/run_cmake.sh after building libtorrent
|
||||
|
||||
# === build tests ===
|
||||
if(build_tests)
|
||||
FILE(GLOB tests RELATIVE "${PROJECT_SOURCE_DIR}" "test/test_*.cpp")
|
||||
add_library(test_common STATIC test/main.cpp test/setup_transfer.cpp
|
||||
test/dht_server.cpp test/udp_tracker.cpp test/peer_server.cpp
|
||||
test/web_seed_suite.cpp)
|
||||
enable_testing()
|
||||
|
||||
foreach(s ${tests})
|
||||
get_filename_component (sn ${s} NAME_WE)
|
||||
add_executable(${sn} ${s})
|
||||
target_link_libraries(${sn} torrent-rasterbar test_common)
|
||||
add_test(${sn} ${s})
|
||||
endforeach(s)
|
||||
|
||||
# add_executable(test_upnp test/test_upnp.cpp)
|
||||
# target_link_libraries(test_upnp torrent-rasterbar)
|
||||
|
||||
# add_executable(test_natpmp test/test_natpmp.cpp)
|
||||
# target_link_libraries(test_natpmp torrent-rasterbar)
|
||||
endif()
|
||||
|
||||
@@ -40,6 +40,10 @@
|
||||
#include <QString>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <libtorrent/entry.hpp>
|
||||
#include <libtorrent/bencode.hpp>
|
||||
#include <libtorrent/session.hpp>
|
||||
|
||||
namespace {
|
||||
const int nColumns = 3;
|
||||
|
||||
@@ -112,6 +116,7 @@ void SyncWidget::clear() {
|
||||
}
|
||||
|
||||
void SyncWidget::handleDirectFiles(QString module, DirectFiles files) {
|
||||
return;
|
||||
qDebug() << "Direct Files";
|
||||
for (const DirectFile& f : files) {
|
||||
qDebug() << f.url << " -> " << f.destination;
|
||||
@@ -125,6 +130,7 @@ void SyncWidget::handleDirectFiles(QString module, DirectFiles files) {
|
||||
}
|
||||
|
||||
void SyncWidget::handleFileRequest(QString module, FileRequests files) {
|
||||
return;
|
||||
qDebug() << "File Requests";
|
||||
for (const FileRequest& f : files) {
|
||||
qDebug() << f.identifier << " (" << f.version << ")" << " -> " << f.destination;
|
||||
@@ -143,6 +149,27 @@ void SyncWidget::handleTorrentFiles(QString module, TorrentFiles files) {
|
||||
qDebug() << "Torrent Files";
|
||||
for (const TorrentFile& f : files) {
|
||||
qDebug() << f.file;
|
||||
|
||||
libtorrent::session s;
|
||||
libtorrent::error_code ec;
|
||||
s.listen_on(std::make_pair(6881, 6889), ec);
|
||||
if (ec) {
|
||||
qDebug() << "Failed to open socket: " << QString::fromStdString(ec.message());
|
||||
return;
|
||||
}
|
||||
|
||||
libtorrent::add_torrent_params p;
|
||||
p.save_path = fullPath(module, ".").toStdString();
|
||||
p.ti = new libtorrent::torrent_info(f.file.toStdString(), ec);
|
||||
if (ec) {
|
||||
qDebug() << QString::fromStdString(ec.message());
|
||||
return;
|
||||
}
|
||||
s.add_torrent(p, ec);
|
||||
if (ec) {
|
||||
qDebug() << QString::fromStdString(ec.message());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Submodule ext/ghoul updated: 0dbde3f6ee...f38a8ada58
@@ -41,5 +41,4 @@ function (include_external_library target_name library_name path)
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
endfunction ()
|
||||
Reference in New Issue
Block a user