improve CMakeLists.txt
This commit is contained in:
parent
9cc7c3bbf9
commit
6590f5f053
159
CMakeLists.txt
159
CMakeLists.txt
|
@ -98,6 +98,9 @@ set(kademlia_sources
|
|||
routing_table
|
||||
traversal_algorithm
|
||||
logging
|
||||
item
|
||||
get_peers
|
||||
get_item
|
||||
)
|
||||
|
||||
# -- ed25519 --
|
||||
|
@ -114,9 +117,10 @@ set(ed25519_sources
|
|||
verify
|
||||
)
|
||||
|
||||
set(includes include)
|
||||
set(includes include ed25519/src)
|
||||
|
||||
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)
|
||||
|
@ -135,13 +139,14 @@ set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo)
|
|||
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release FORCE)
|
||||
endif (NOT CMAKE_BUILD_TYPE)
|
||||
endif()
|
||||
|
||||
# add_definitions() doesn't seem to let you say wich build type to apply it to
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DTORRENT_DEBUG")
|
||||
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -g")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
||||
if(UNIX)
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -g")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
||||
endif()
|
||||
|
||||
if (encryption)
|
||||
list(APPEND sources pe_crypto)
|
||||
|
@ -149,10 +154,10 @@ endif (encryption)
|
|||
|
||||
if (logging)
|
||||
add_definitions(-DTORRENT_LOGGING)
|
||||
endif (logging)
|
||||
endif()
|
||||
if (verbose-logging)
|
||||
add_definitions(-DTORRENT_VERBOSE_LOGGING)
|
||||
endif (verbose-logging)
|
||||
endif()
|
||||
|
||||
foreach(s ${sources})
|
||||
list(APPEND sources2 src/${s})
|
||||
|
@ -165,9 +170,9 @@ if (dht)
|
|||
foreach(s ${ed25519_sources})
|
||||
list(APPEND sources2 ed25519/src/${s})
|
||||
endforeach(s)
|
||||
else (dht)
|
||||
else()
|
||||
add_definitions(-DTORRENT_DISABLE_DHT)
|
||||
endif (dht)
|
||||
endif()
|
||||
|
||||
if(NOT MSVC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
|
||||
|
@ -178,57 +183,73 @@ if (shared)
|
|||
add_definitions(-DTORRENT_BUILDING_SHARED)
|
||||
add_library(torrent-rasterbar SHARED ${sources2})
|
||||
else (shared)
|
||||
if(static_runtime)
|
||||
# fix /MT flag:
|
||||
set(CompilerFlags
|
||||
CMAKE_CXX_FLAGS
|
||||
CMAKE_CXX_FLAGS_DEBUG
|
||||
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||
CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_C_FLAGS
|
||||
CMAKE_C_FLAGS_DEBUG
|
||||
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||
CMAKE_C_FLAGS_RELEASE
|
||||
)
|
||||
foreach(CompilerFlag ${CompilerFlags})
|
||||
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
|
||||
endforeach()
|
||||
endif()
|
||||
add_library(torrent-rasterbar STATIC ${sources2})
|
||||
endif (shared)
|
||||
endif()
|
||||
|
||||
if (NOT Boost_VERSION LESS 103500)
|
||||
if(NOT MSVC)
|
||||
FIND_PACKAGE( Boost 1.35 COMPONENTS system)
|
||||
else(NOT MSVC)
|
||||
FIND_PACKAGE( Boost 1.35 COMPONENTS system thread date_time)
|
||||
endif(NOT MSVC)
|
||||
endif (NOT Boost_VERSION LESS 103500)
|
||||
# Boost
|
||||
FIND_PACKAGE( Boost COMPONENTS system thread date_time chrono)
|
||||
include_directories(${Boost_INCLUDE_DIR})
|
||||
target_link_libraries(torrent-rasterbar ${Boost_LIBRARIES})
|
||||
|
||||
# this works around a bug in asio in boost-1.39
|
||||
add_definitions(-DBOOST_ASIO_HASH_MAP_BUCKETS=1021 -DBOOST_ASIO_DYN_LINK -D__USE_W32_SOCKETS -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0500)
|
||||
#add_definitions(-DBOOST_ASIO_HASH_MAP_BUCKETS=1021 -D__USE_W32_SOCKETS -DWIN32_LEAN_AND_MEAN )
|
||||
|
||||
add_definitions(-DBOOST_DATE_TIME_DYN_LINK -DBOOST_THREAD_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_CHRONO_DYN_LINK)
|
||||
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()
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(torrent-rasterbar wsock32 ws2_32)
|
||||
endif (WIN32)
|
||||
add_definitions(-D_WIN32_WINNT=0x0500)
|
||||
endif()
|
||||
|
||||
if (encryption)
|
||||
FIND_PACKAGE(OpenSSL REQUIRED)
|
||||
add_definitions(-DTORRENT_USE_OPENSSL)
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
target_link_libraries(torrent-rasterbar ${OPENSSL_LIBRARIES})
|
||||
else (encryption)
|
||||
else()
|
||||
add_definitions(-DTORRENT_DISABLE_ENCRYPTION)
|
||||
list(APPEND sources sha1)
|
||||
endif (encryption)
|
||||
endif()
|
||||
|
||||
if (NOT pool-allocators)
|
||||
add_definitions(-DTORRENT_DISABLE_POOL_ALLOCATOR)
|
||||
endif (NOT pool-allocators)
|
||||
endif()
|
||||
|
||||
if (NOT geoip)
|
||||
add_definitions(-DTORRENT_DISABLE_GEO_IP)
|
||||
endif (NOT geoip)
|
||||
endif()
|
||||
|
||||
if (NOT resolve-countries)
|
||||
add_definitions(-DTORRENT_DISABLE_RESOLVE_COUNTRIES)
|
||||
endif (NOT resolve-countries)
|
||||
endif()
|
||||
|
||||
if (unicode)
|
||||
add_definitions(-DUNICODE -D_UNICODE)
|
||||
endif (unicode)
|
||||
endif()
|
||||
|
||||
if (NOT deprecated-functions)
|
||||
add_definitions(-DTORRENT_NO_DEPRECATE)
|
||||
endif (NOT deprecated-functions)
|
||||
endif()
|
||||
|
||||
if (exceptions)
|
||||
if (MSVC)
|
||||
|
@ -236,9 +257,13 @@ if (exceptions)
|
|||
else (MSVC)
|
||||
add_definitions(-fexceptions)
|
||||
endif (MSVC)
|
||||
else (exceptions)
|
||||
add_definitions(-fno-exceptions)
|
||||
endif (exceptions)
|
||||
else()
|
||||
if (MSVC)
|
||||
add_definitions(-D_HAS_EXCEPTIONS=0)
|
||||
else (MSVC)
|
||||
add_definitions(-fno-exceptions)
|
||||
endif (MSVC)
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
# disable bogus deprecation warnings on msvc8
|
||||
|
@ -248,9 +273,9 @@ if (MSVC)
|
|||
# for multi-core compilation
|
||||
add_definitions(/MP)
|
||||
|
||||
# <toolset>msvc,<variant>release:<linkflags>/OPT:ICF=5
|
||||
# <toolset>msvc,<variant>release:<linkflags>/OPT:REF
|
||||
endif(MSVC)
|
||||
#$(SolutionDir)<toolset>msvc,<variant>release:<linkflags>/OPT:ICF=5
|
||||
#$(SolutionDir)<toolset>msvc,<variant>release:<linkflags>/OPT:REF
|
||||
endif()
|
||||
|
||||
add_definitions(-D_FILE_OFFSET_BITS=64)
|
||||
add_definitions(-DBOOST_DISABLE_EXCEPTION)
|
||||
|
@ -258,7 +283,7 @@ add_definitions(-DBOOST_ASIO_ENABLE_CANCELIO)
|
|||
|
||||
if (tcmalloc)
|
||||
target_link_libraries(torrent-rasterbar tcmalloc)
|
||||
endif (tcmalloc)
|
||||
endif()
|
||||
|
||||
include_directories(${includes})
|
||||
|
||||
|
@ -278,15 +303,15 @@ endforeach (s)
|
|||
|
||||
if (MSVC)
|
||||
configure_file(libtorrent-rasterbar-cmake.pc.in libtorrent-rasterbar.pc)
|
||||
endif (MSVC)
|
||||
endif()
|
||||
|
||||
string (COMPARE EQUAL "${CMAKE_SIZEOF_VOID_P}" "8" IS64BITS)
|
||||
|
||||
if (IS64BITS AND RESPECTLIB64)
|
||||
set (LIBDIR "lib64")
|
||||
else (IS64BITS AND RESPECTLIB64)
|
||||
else()
|
||||
set (LIBDIR "lib")
|
||||
endif (IS64BITS AND RESPECTLIB64)
|
||||
endif()
|
||||
|
||||
install(TARGETS torrent-rasterbar DESTINATION ${LIBDIR} CONFIGURATIONS release)
|
||||
install(DIRECTORY include/libtorrent
|
||||
|
@ -296,63 +321,27 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar.pc DESTINATION ${
|
|||
|
||||
# === build examples ===
|
||||
if(build_examples)
|
||||
set(examples client_test dump_torrent simple_client enum_if make_torrent)
|
||||
|
||||
FILE(GLOB examples RELATIVE "${CMAKE_SOURCE_DIR}" "examples/*.cpp")
|
||||
foreach(s ${examples})
|
||||
add_executable(${s} examples/${s}.cpp)
|
||||
target_link_libraries(${s} torrent-rasterbar)
|
||||
get_filename_component (sn ${s} NAME_WE)
|
||||
add_executable(${sn} ${s})
|
||||
target_link_libraries(${sn} torrent-rasterbar)
|
||||
endforeach(s)
|
||||
|
||||
include_directories(${Boost_INCLUDE_DIR})
|
||||
endif(build_examples)
|
||||
endif()
|
||||
|
||||
# === build tests ===
|
||||
if(build_tests)
|
||||
set(tests
|
||||
test_file_storage
|
||||
test_auto_unchoke
|
||||
test_http_connection
|
||||
test_buffer
|
||||
test_utp
|
||||
test_storage
|
||||
test_torrent
|
||||
test_dht
|
||||
test_transfer
|
||||
test_piece_picker
|
||||
test_fast_extension
|
||||
test_pe_crypto
|
||||
test_peer_priority
|
||||
test_bencoding
|
||||
test_bdecode_performance
|
||||
test_xml
|
||||
test_string
|
||||
test_primitives
|
||||
test_http_parser
|
||||
test_packet_buffer
|
||||
test_magnet
|
||||
test_ip_filter
|
||||
test_hasher
|
||||
test_metadata_extension
|
||||
test_trackers_extension
|
||||
test_swarm
|
||||
test_lsd
|
||||
test_pex
|
||||
test_web_seed
|
||||
test_bandwidth_limiter
|
||||
test_session
|
||||
test_torrent_parse
|
||||
test_threads
|
||||
test_gzip
|
||||
test_utf8
|
||||
test_socket_io
|
||||
)
|
||||
|
||||
FILE(GLOB tests RELATIVE "${CMAKE_SOURCE_DIR}" "tests/*.cpp")
|
||||
add_library(test_common STATIC test/main.cpp test/setup_transfer.cpp)
|
||||
enable_testing()
|
||||
|
||||
foreach(s ${tests})
|
||||
add_executable(${s} test/${s}.cpp)
|
||||
target_link_libraries(${s} torrent-rasterbar test_common)
|
||||
add_test(${s} ${s})
|
||||
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)
|
||||
|
@ -360,4 +349,4 @@ if(build_tests)
|
|||
|
||||
add_executable(test_natpmp test/test_natpmp.cpp)
|
||||
target_link_libraries(test_natpmp torrent-rasterbar)
|
||||
endif(build_tests)
|
||||
endif()
|
||||
|
|
Loading…
Reference in New Issue