CMake improvements
CMake build scripts improved to simplify configuring and building of project and tests. Better use of compile definitions by replacing add_definitions with target_compile_definitions. Use INTERFACE, PUBLIC and PRIVATE keywords to separate scope of TORRENT_BUILDING_SHARED and TORRENT_LINKING_SHARED definitions. * Move tests to the separate file - test/CmakeLists.txt * Fix use of compile definitions * Remove redundant tailqueue.cpp
This commit is contained in:
parent
1ede34da8a
commit
f94b62acf7
|
@ -182,18 +182,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)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
include_directories(${includes})
|
||||
|
||||
add_definitions(-DTORRENT_BUILDING_LIBRARY)
|
||||
|
||||
if (encryption)
|
||||
list(APPEND sources mpi pe_crypto)
|
||||
if(NOT DEFINED OPENSSL_INCLUDE_DIR OR NOT DEFINED OPENSSL_LIBRARIES)
|
||||
|
@ -226,8 +218,11 @@ else()
|
|||
endif()
|
||||
|
||||
if (shared)
|
||||
add_definitions(-DTORRENT_BUILDING_SHARED)
|
||||
add_library(torrent-rasterbar SHARED ${sources2})
|
||||
target_compile_definitions(torrent-rasterbar
|
||||
PRIVATE TORRENT_BUILDING_SHARED
|
||||
INTERFACE TORRENT_LINKING_SHARED
|
||||
)
|
||||
if(NOT MSVC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
|
||||
|
@ -256,6 +251,8 @@ else()
|
|||
add_library(torrent-rasterbar STATIC ${sources2})
|
||||
endif()
|
||||
|
||||
target_compile_definitions(torrent-rasterbar PRIVATE TORRENT_BUILDING_LIBRARY)
|
||||
|
||||
# Boost
|
||||
if(NOT DEFINED Boost_INCLUDE_DIR OR NOT DEFINED Boost_LIBRARIES)
|
||||
FIND_PACKAGE(Boost REQUIRED COMPONENTS system chrono random)
|
||||
|
@ -289,10 +286,6 @@ if (NOT pool-allocators)
|
|||
add_definitions(-DTORRENT_DISABLE_POOL_ALLOCATOR)
|
||||
endif()
|
||||
|
||||
if (NOT resolve-countries)
|
||||
add_definitions(-DTORRENT_DISABLE_RESOLVE_COUNTRIES)
|
||||
endif()
|
||||
|
||||
if (unicode)
|
||||
add_definitions(-DUNICODE -D_UNICODE)
|
||||
endif()
|
||||
|
@ -372,23 +365,8 @@ configure_file(examples/run_cmake.sh.in examples/run_cmake.sh)
|
|||
|
||||
# === build tests ===
|
||||
if(build_tests)
|
||||
file(GLOB tests RELATIVE "${PROJECT_SOURCE_DIR}" "test/test_*.cpp")
|
||||
list(REMOVE_ITEM tests "test/test_natpmp.cpp") # doesn't build at time of writing
|
||||
list(REMOVE_ITEM tests "test/test_utils.cpp") # helper file, not a test
|
||||
|
||||
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/make_torrent.cpp test/settings.cpp)
|
||||
enable_testing()
|
||||
|
||||
foreach(s ${tests})
|
||||
get_filename_component (sn ${s} NAME_WE)
|
||||
add_executable(${sn} ${s} $<TARGET_OBJECTS:test_common>)
|
||||
target_link_libraries(${sn} torrent-rasterbar)
|
||||
add_test(${sn} ${s})
|
||||
endforeach(s)
|
||||
|
||||
add_executable(bdecode_benchmark test/bdecode_benchmark.cpp)
|
||||
target_link_libraries(bdecode_benchmark torrent-rasterbar)
|
||||
# this will make some internal functions available in the DLL interface
|
||||
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_EXPORT_EXTRA)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
|
|
@ -68,8 +68,7 @@ namespace libtorrent
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
//#error boost::enable_if< is_base<T, tailqueue_node<T> > >
|
||||
struct TORRENT_EXTRA_EXPORT tailqueue
|
||||
struct tailqueue
|
||||
{
|
||||
tailqueue(): m_first(NULL), m_last(NULL), m_size(0) {}
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2012-2016, Arvid Norberg
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "libtorrent/tailqueue.hpp"
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
file(GLOB tests "${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp")
|
||||
list(REMOVE_ITEM tests "${CMAKE_CURRENT_SOURCE_DIR}/test_natpmp.cpp") # doesn't build at time of writing
|
||||
list(REMOVE_ITEM tests "${CMAKE_CURRENT_SOURCE_DIR}/test_utils.cpp") # helper file, not a test
|
||||
|
||||
add_library(test_common OBJECT main.cpp test.cpp setup_transfer.cpp dht_server.cpp udp_tracker.cpp
|
||||
peer_server.cpp web_seed_suite.cpp swarm_suite.cpp test_utils.cpp make_torrent.cpp settings.cpp
|
||||
)
|
||||
target_compile_definitions(test_common PRIVATE $<TARGET_PROPERTY:torrent-rasterbar,INTERFACE_COMPILE_DEFINITIONS>)
|
||||
|
||||
if(MSVC)
|
||||
set_property(TARGET test_common PROPERTY COMPILE_PDB_NAME "${CMAKE_CURRENT_BINARY_DIR}/test_common")
|
||||
endif()
|
||||
|
||||
foreach(TARGET_SRC ${tests})
|
||||
get_filename_component(TARGET ${TARGET_SRC} NAME_WE)
|
||||
add_executable(${TARGET} ${TARGET_SRC} $<TARGET_OBJECTS:test_common>)
|
||||
target_link_libraries(${TARGET} torrent-rasterbar)
|
||||
add_test(${TARGET} ${TARGET})
|
||||
endforeach(s)
|
||||
|
||||
if (deprecated-functions)
|
||||
add_executable(bdecode_benchmark bdecode_benchmark.cpp)
|
||||
target_link_libraries(bdecode_benchmark torrent-rasterbar)
|
||||
endif()
|
||||
|
||||
file(GLOB GZIP_ASSETS "${CMAKE_CURRENT_SOURCE_DIR}/*.gz")
|
||||
file(COPY ${GZIP_ASSETS} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
file(GLOB PYTHON_ASSETS "${CMAKE_CURRENT_SOURCE_DIR}/*.py")
|
||||
file(COPY ${PYTHON_ASSETS} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
file(GLOB XML_ASSETS "${CMAKE_CURRENT_SOURCE_DIR}/*.xml")
|
||||
file(COPY ${XML_ASSETS} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
file(COPY "utf8_test.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
file(COPY "mutable_test_torrents" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
file(COPY "test_torrents" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
file(COPY "ssl" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
Loading…
Reference in New Issue