Fix compilation with cmake (#767)

fix tests building with cmake. cmake: restore options parity with autotools
This commit is contained in:
Eugene Shalygin 2016-05-29 18:58:16 +02:00 committed by Arvid Norberg
parent 420b5f51e6
commit 9489eb23f4
5 changed files with 88 additions and 5 deletions

View File

@ -4,6 +4,8 @@ project(libtorrent)
set (SOVERSION "8") set (SOVERSION "8")
set (VERSION "1.1.0") set (VERSION "1.1.0")
list(APPEND CMAKE_MODULE_PATH ${libtorrent_SOURCE_DIR}/cmake/Modules)
set(sources set(sources
web_connection_base web_connection_base
alert alert
@ -163,7 +165,9 @@ option(encryption "link against openssl and enable encryption" ON)
option(dht "enable support for Mainline DHT" ON) option(dht "enable support for Mainline DHT" ON)
option(unicode "enable unicode support" ON) option(unicode "enable unicode support" ON)
option(deprecated-functions "enable deprecated functions for backwards compatibility" ON) option(deprecated-functions "enable deprecated functions for backwards compatibility" ON)
option(disk-stats "enable disk activity logging feature" OFF)
option(exceptions "build with exception support" ON) option(exceptions "build with exception support" ON)
option(libiconv "enable linking against system libiconv" OFF)
option(logging "build with logging" ON) option(logging "build with logging" ON)
option(build_tests "build tests" OFF) option(build_tests "build tests" OFF)
@ -191,6 +195,15 @@ find_package(Threads REQUIRED)
include_directories(${includes}) include_directories(${includes})
add_definitions(-DTORRENT_BUILDING_LIBRARY) add_definitions(-DTORRENT_BUILDING_LIBRARY)
if (disk-stats)
add_definitions(-DTORRENT_DISK_STATS)
endif (disk-stats)
if (libiconv)
find_package(Iconv REQUIRED)
add_definitions(-DTORRENT_USE_ICONV)
include_directories(SYSTEM ${ICONV_INCLUDE_DIR})
endif (libiconv)
if (encryption) if (encryption)
list(APPEND sources mpi pe_crypto) list(APPEND sources mpi pe_crypto)
@ -280,6 +293,10 @@ if (encryption)
target_link_libraries(torrent-rasterbar ${OPENSSL_LIBRARIES}) target_link_libraries(torrent-rasterbar ${OPENSSL_LIBRARIES})
endif() endif()
if (libiconv)
target_link_libraries(torrent-rasterbar ${ICONV_LIBRARIES})
endif (libiconv)
if (NOT pool-allocators) if (NOT pool-allocators)
add_definitions(-DTORRENT_DISABLE_POOL_ALLOCATOR) add_definitions(-DTORRENT_DISABLE_POOL_ALLOCATOR)
endif() endif()
@ -370,16 +387,20 @@ if(build_tests)
add_library(test_common OBJECT test/main.cpp test/test.cpp add_library(test_common OBJECT test/main.cpp test/test.cpp
test/setup_transfer.cpp test/dht_server.cpp test/udp_tracker.cpp test/setup_transfer.cpp test/dht_server.cpp test/udp_tracker.cpp
test/peer_server.cpp test/web_seed_suite.cpp test/swarm_suite.cpp test/peer_server.cpp test/web_seed_suite.cpp test/swarm_suite.cpp
test/test_utils.cpp) test/test_utils.cpp test/make_torrent.hpp test/make_torrent.cpp
test/settings.hpp test/settings.cpp)
set_target_properties(test_common PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
enable_testing() enable_testing()
foreach(s ${tests}) foreach(s ${tests})
get_filename_component (sn ${s} NAME_WE) get_filename_component (sn ${s} NAME_WE)
add_executable(${sn} ${s} $<TARGET_OBJECTS:test_common>) add_executable(${sn} ${s} $<TARGET_OBJECTS:test_common>)
target_link_libraries(${sn} torrent-rasterbar) target_link_libraries(${sn} torrent-rasterbar)
set_target_properties(${sn} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
add_test(${sn} ${s}) add_test(${sn} ${s})
endforeach(s) endforeach(s)
add_executable(bdecode_benchmark test/bdecode_benchmark.cpp) add_executable(bdecode_benchmark test/bdecode_benchmark.cpp)
target_link_libraries(bdecode_benchmark torrent-rasterbar) target_link_libraries(bdecode_benchmark torrent-rasterbar)
set_target_properties(bdecode_benchmark PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
endif() endif()

View File

@ -0,0 +1,60 @@
# - Try to find Iconv
# Once done this will define
#
# ICONV_FOUND - system has Iconv
# ICONV_INCLUDE_DIR - the Iconv include directory
# ICONV_LIBRARIES - Link these to use Iconv
# ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const
#
include(CheckCXXSourceCompiles)
IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
# Already in cache, be silent
SET(ICONV_FIND_QUIETLY TRUE)
ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
FIND_PATH(ICONV_INCLUDE_DIR iconv.h)
FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c)
IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
SET(ICONV_FOUND TRUE)
ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
IF(ICONV_FOUND)
check_cxx_source_compiles("
#include <iconv.h>
int main(){
iconv_t conv = 0;
const char* in = 0;
size_t ilen = 0;
char* out = 0;
size_t olen = 0;
iconv(conv, &in, &ilen, &out, &olen);
return 0;
}
" ICONV_SECOND_ARGUMENT_IS_CONST )
IF(ICONV_SECOND_ARGUMENT_IS_CONST)
SET(ICONV_CONST "const")
ENDIF(ICONV_SECOND_ARGUMENT_IS_CONST)
ENDIF(ICONV_FOUND)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_LIBRARIES)
IF(ICONV_FOUND)
IF(NOT ICONV_FIND_QUIETLY)
MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}")
ENDIF(NOT ICONV_FIND_QUIETLY)
ELSE(ICONV_FOUND)
IF(Iconv_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find Iconv")
ENDIF(Iconv_FIND_REQUIRED)
ENDIF(ICONV_FOUND)
MARK_AS_ADVANCED(
ICONV_INCLUDE_DIR
ICONV_LIBRARIES
ICONV_SECOND_ARGUMENT_IS_CONST
)

View File

@ -138,7 +138,7 @@ int main(int argc, char* argv[])
e = bdecode(&buf[0], &buf[0] + buf.size(), len); e = bdecode(&buf[0], &buf[0] + buf.size(), len);
// entry& info = e["info"]; // entry& info = e["info"];
} }
ptime stop(time_now_hires()); time_point stop(clock_type::now());
std::fprintf(stderr, "(slow) bdecode done in %5d ns per message\n" std::fprintf(stderr, "(slow) bdecode done in %5d ns per message\n"
, int(total_microseconds(stop - start) / 1000)); , int(total_microseconds(stop - start) / 1000));
@ -147,7 +147,7 @@ int main(int argc, char* argv[])
// =============================================== // ===============================================
{ {
ptime start(time_now_hires()); time_point start(clock_type::now());
lazy_entry e; lazy_entry e;
for (int i = 0; i < 1000000; ++i) for (int i = 0; i < 1000000; ++i)
{ {
@ -164,7 +164,7 @@ int main(int argc, char* argv[])
// =============================================== // ===============================================
{ {
ptime start(time_now_hires()); time_point start(clock_type::now());
bdecode_node e; bdecode_node e;
e.reserve(100); e.reserve(100);
for (int i = 0; i < 1000000; ++i) for (int i = 0; i < 1000000; ++i)
@ -173,7 +173,7 @@ int main(int argc, char* argv[])
bdecode(&buf[0], &buf[0] + buf.size(), e, ec); bdecode(&buf[0], &buf[0] + buf.size(), e, ec);
// bdecode_node info = e.dict_find("info"); // bdecode_node info = e.dict_find("info");
} }
ptime stop(time_now_hires()); time_point stop(clock_type::now());
std::fprintf(stderr, "bdecode done in %5d ns per message\n" std::fprintf(stderr, "bdecode done in %5d ns per message\n"
, int(total_microseconds(stop - start) / 1000)); , int(total_microseconds(stop - start) / 1000));

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alert_types.hpp" #include "libtorrent/alert_types.hpp"
#include "libtorrent/time.hpp" #include "libtorrent/time.hpp"
#include "libtorrent/random.hpp" #include "libtorrent/random.hpp"
#include <iostream>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include "test.hpp" #include "test.hpp"

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "setup_transfer.hpp" #include "setup_transfer.hpp"
#include "test.hpp" #include "test.hpp"
#include <iostream>
#include <fstream> #include <fstream>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>