From 9489eb23f463b63a7aea602d84776fa223e75258 Mon Sep 17 00:00:00 2001 From: Eugene Shalygin Date: Sun, 29 May 2016 18:58:16 +0200 Subject: [PATCH] Fix compilation with cmake (#767) fix tests building with cmake. cmake: restore options parity with autotools --- CMakeLists.txt | 23 +++++++++++++- cmake/Modules/FindIconv.cmake | 60 +++++++++++++++++++++++++++++++++++ test/bdecode_benchmark.cpp | 8 ++--- test/swarm_suite.cpp | 1 + test/test_remap_files.cpp | 1 + 5 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 cmake/Modules/FindIconv.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 922951bea..47d04d67e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project(libtorrent) set (SOVERSION "8") set (VERSION "1.1.0") +list(APPEND CMAKE_MODULE_PATH ${libtorrent_SOURCE_DIR}/cmake/Modules) + set(sources web_connection_base alert @@ -163,7 +165,9 @@ option(encryption "link against openssl and enable encryption" ON) option(dht "enable support for Mainline DHT" ON) option(unicode "enable unicode support" 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(libiconv "enable linking against system libiconv" OFF) option(logging "build with logging" ON) option(build_tests "build tests" OFF) @@ -191,6 +195,15 @@ find_package(Threads REQUIRED) include_directories(${includes}) 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) list(APPEND sources mpi pe_crypto) @@ -280,6 +293,10 @@ if (encryption) target_link_libraries(torrent-rasterbar ${OPENSSL_LIBRARIES}) endif() +if (libiconv) + target_link_libraries(torrent-rasterbar ${ICONV_LIBRARIES}) +endif (libiconv) + if (NOT pool-allocators) add_definitions(-DTORRENT_DISABLE_POOL_ALLOCATOR) endif() @@ -370,16 +387,20 @@ if(build_tests) add_library(test_common OBJECT test/main.cpp test/test.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/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() foreach(s ${tests}) get_filename_component (sn ${s} NAME_WE) add_executable(${sn} ${s} $) target_link_libraries(${sn} torrent-rasterbar) + set_target_properties(${sn} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) add_test(${sn} ${s}) endforeach(s) add_executable(bdecode_benchmark test/bdecode_benchmark.cpp) target_link_libraries(bdecode_benchmark torrent-rasterbar) + set_target_properties(bdecode_benchmark PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) endif() diff --git a/cmake/Modules/FindIconv.cmake b/cmake/Modules/FindIconv.cmake new file mode 100644 index 000000000..338d17d05 --- /dev/null +++ b/cmake/Modules/FindIconv.cmake @@ -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 + 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 +) diff --git a/test/bdecode_benchmark.cpp b/test/bdecode_benchmark.cpp index 36d61cd07..f3f0eaf1e 100644 --- a/test/bdecode_benchmark.cpp +++ b/test/bdecode_benchmark.cpp @@ -138,7 +138,7 @@ int main(int argc, char* argv[]) e = bdecode(&buf[0], &buf[0] + buf.size(), len); // 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" , 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; 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; e.reserve(100); 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_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" , int(total_microseconds(stop - start) / 1000)); diff --git a/test/swarm_suite.cpp b/test/swarm_suite.cpp index acb0cb976..2a142cd71 100644 --- a/test/swarm_suite.cpp +++ b/test/swarm_suite.cpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert_types.hpp" #include "libtorrent/time.hpp" #include "libtorrent/random.hpp" +#include #include #include "test.hpp" diff --git a/test/test_remap_files.cpp b/test/test_remap_files.cpp index cc37a7aad..05c574b33 100644 --- a/test/test_remap_files.cpp +++ b/test/test_remap_files.cpp @@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "setup_transfer.hpp" #include "test.hpp" +#include #include #include