Refactor CMakeLists.txt

1. Replace custom 'shared' option with the standard BUILD_SHARED_LIBS
flag
2. Replace foreach() calls for source items with target_sources() and
generator expression $<JOIN:>.
3. Remove build types definition: makes no sense for
single-configuration generators, and is populated automatically for
multi-configuration ones.
4. Add feature summary
5. Enahnce compiler flags management for static runtime by utilizing functions
from the ucm project
6. Copy almost all options from the Jamfile.
7. If compiler supports C++14, use it.
8. Raise minimum required CMake version to 3.11 and drop bundled FindIconv.cmake
This commit is contained in:
Eugene Shalygin 2018-04-27 16:27:51 +02:00 committed by Arvid Norberg
parent 7e390b1ca7
commit a626f75c5e
9 changed files with 428 additions and 254 deletions

View File

@ -45,7 +45,7 @@ addons:
- libboost1.55-tools-dev
- python2.7-dev
- g++-5
- cmake3
- [cmake3, ninja-build]
before_install:
@ -162,6 +162,14 @@ install:
fi'
- which python2
- |
if [[ $TRAVIS_OS_NAME == "linux" ]] ; then
# There is an outdated cmake in /usr/local/cmake-<version> which we don't want to use
# but /usr/local/cmake-<version>/bin is in $PATH, therefore
# remove all paths containing 'cmake' to use the executable from /usr/bin
export PATH=`echo ${PATH} | awk -v RS=: -v ORS=: '/cmake/ {next} {print}'`
fi
- which cmake
- cmake --version
script:
@ -232,7 +240,7 @@ script:
- if [[ "$cmake" == "1" ]]; then
export CXX=g++-5 &&
export CC=gcc-5 &&
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" -Dbuild_tests=ON -Dbuild_examples=ON -Dpython-bindings=ON -G "CodeBlocks - Unix Makefiles" .. &&
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" -Dbuild_tests=ON -Dbuild_examples=ON -Dpython-bindings=ON -G Ninja .. &&
cmake --build . -- -j2;
fi
- cd ..

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.11.0 FATAL_ERROR)
project(libtorrent
DESCRIPTION "Bittorrent library"
@ -7,6 +7,7 @@ project(libtorrent
set (SOVERSION "10")
list(APPEND CMAKE_MODULE_PATH ${libtorrent_SOURCE_DIR}/cmake/Modules)
include(FeatureSummary)
include(GNUInstallDirs)
include(GeneratePkgConfig)
@ -260,22 +261,6 @@ set(libtorrent_aux_include_files
win_crypto_provider
win_util)
foreach(s ${libtorrent_include_files})
list(APPEND include_files include/libtorrent/${s})
endforeach(s)
foreach(s ${libtorrent_kademlia_include_files})
list(APPEND include_files include/libtorrent/kademlia/${s})
endforeach(s)
foreach(s ${libtorrent_extensions_include_files})
list(APPEND include_files include/libtorrent/extensions/${s})
endforeach(s)
foreach(s ${libtorrent_aux_include_files})
list(APPEND include_files include/libtorrent/aux_/${s})
endforeach(s)
set(sources
web_connection_base
alert
@ -440,65 +425,47 @@ set(ed25519_sources
verify
)
set(includes include ed25519/src)
option(shared "build libtorrent as a shared library" ON)
option(static_runtime "build libtorrent with static runtime" OFF)
option(encryption "link against openssl and enable encryption" ON)
option(dht "enable support for Mainline DHT" ON)
option(deprecated-functions "enable deprecated functions for backwards compatibility" ON)
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)
option(build_examples "build examples" OFF)
option(build_tools "build tools" OFF)
option(python-bindings "build python bindings" OFF)
set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release FORCE)
endif()
# add_definitions() doesn't seem to let you say wich build type to apply it to
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DTORRENT_DEBUG")
if(UNIX)
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -g")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
endif()
find_package(Threads REQUIRED)
set(_package_dependencies "Threads") # Dependencies to be used below for generating Config.cmake file
include_directories(${includes})
if (encryption)
list(APPEND sources pe_crypto)
else()
if (NOT WIN32 AND NOT APPLE)
list(APPEND sources sha1)
function(target_optional_compile_definitions _target _scope)
set(options FEATURE)
set(oneValueArgs NAME DESCRIPTION DEFAULT)
set(multiValueArgs ENABLED DISABLED)
cmake_parse_arguments(TOCD ${options} "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
option(${TOCD_NAME} "${TOCD_DESCRIPTION}" ${TOCD_DEFAULT})
if (${${TOCD_NAME}})
target_compile_definitions(${_target} ${_scope} ${TOCD_ENABLED})
else()
target_compile_definitions(${_target} ${_scope} ${TOCD_DISABLED})
endif()
endif (encryption)
foreach(s ${sources})
list(APPEND sources2 src/${s})
endforeach(s)
if (dht)
foreach(s ${kademlia_sources})
list(APPEND sources2 src/kademlia/${s})
endforeach(s)
foreach(s ${ed25519_sources})
list(APPEND sources2 ed25519/src/${s})
endforeach(s)
list(APPEND sources2 src/hasher512)
if (NOT encryption AND NOT WIN32 AND NOT APPLE)
list(APPEND sources2 src/sha512)
if(${TOCD_FEATURE})
add_feature_info(${TOCD_NAME} ${TOCD_NAME} "${TOCD_DESCRIPTION}")
endif()
endif()
endfunction()
list(APPEND sources2 ${include_files})
macro(feature_option _name _description _default)
option(${_name} "${_description}" ${_default})
add_feature_info(${_name} ${_name} "${_description}")
endmacro()
# these options control target creation and thus have to be declared before the add_library() call
feature_option(BUILD_SHARED_LIBS "build libtorrent as a shared library" ON)
feature_option(static_runtime "build libtorrent with static runtime" OFF)
macro(find_public_dependency _name)
find_package(${_name} ${ARGN})
string(TOUPPER "${_name}" _name_uppercased)
if (${_name}_FOUND OR ${_name_uppercased}_FOUND)
# Dependencies to be used below for generating Config.cmake file
# We don't need the 'REQUIRED' argument there
set(_args "${_name}")
list(APPEND _args "${ARGN}")
list(REMOVE_ITEM _args "REQUIRED")
list(REMOVE_ITEM _args "") # just in case
string(REPLACE ";" " " _args "${_args}")
list(APPEND _package_dependencies "${_args}")
endif()
endmacro()
find_public_dependency(Threads REQUIRED)
if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
add_compile_options(
@ -538,89 +505,71 @@ elseif(MSVC)
/wd4503)
endif()
if (shared)
add_library(torrent-rasterbar SHARED ${sources2})
if(static_runtime)
include(ucm_flags)
ucm_set_runtime(STATIC)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
set(OPENSSL_USE_STATIC_LIBS TRUE)
set(OPENSSL_MSVC_STATIC_RT TRUE)
endif()
if (NOT BUILD_SHARED_LIBS)
set(Boost_USE_STATIC_LIBS ON)
endif()
add_library(torrent-rasterbar
src/$<JOIN:${sources}, src/>
include/libtorrent/$<JOIN:${libtorrent_include_files}, include/libtorrent/>
include/libtorrent/extensions/$<JOIN:${libtorrent_extensions_include_files}, include/libtorrent/extensions/>
include/libtorrent/aux_/$<JOIN:${libtorrent_aux_include_files}, include/libtorrent/aux_/>
)
if (BUILD_SHARED_LIBS)
target_compile_definitions(torrent-rasterbar
PRIVATE TORRENT_BUILDING_SHARED
INTERFACE TORRENT_LINKING_SHARED
)
set_target_properties(torrent-rasterbar
PROPERTIES
CXX_VISIBILITY_PRESET "hidden"
VISIBILITY_INLINES_HIDDEN "true"
VERSION ${PROJECT_VERSION}
SOVERSION ${SOVERSION}
)
else()
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()
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
set(Boost_USE_STATIC_LIBS ON)
add_library(torrent-rasterbar STATIC ${sources2})
endif()
target_compile_features(torrent-rasterbar PUBLIC cxx_std_11)
set_target_properties(torrent-rasterbar
PROPERTIES
CXX_VISIBILITY_PRESET "hidden"
VISIBILITY_INLINES_HIDDEN "true"
VERSION ${PROJECT_VERSION}
SOVERSION ${SOVERSION}
)
if (cxx_std_14 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
target_compile_features(torrent-rasterbar PUBLIC cxx_std_14)
message(STATUS "Building in C++14 mode")
else()
target_compile_features(torrent-rasterbar PUBLIC cxx_std_11)
message(STATUS "Building in C++11 mode")
endif()
target_include_directories(torrent-rasterbar PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_definitions(torrent-rasterbar
PUBLIC
$<$<CONFIG:Debug>:TORRENT_DEBUG>
$<$<CONFIG:Debug>:TORRENT_USE_ASSERTS>
PRIVATE
TORRENT_BUILDING_LIBRARY
_FILE_OFFSET_BITS=64
BOOST_EXCEPTION_DISABLE
BOOST_ASIO_ENABLE_CANCELIO
BOOST_ASIO_HAS_STD_CHRONO
)
target_link_libraries(torrent-rasterbar
PUBLIC
Threads::Threads
)
if (libiconv)
find_package(Iconv REQUIRED)
list(APPEND _package_dependencies "Iconv")
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_ICONV)
target_include_directories(torrent-rasterbar PUBLIC ${ICONV_INCLUDE_DIR})
target_link_libraries(torrent-rasterbar PRIVATE ${ICONV_LIBRARIES})
endif (libiconv)
if (encryption)
if(NOT TARGET OpenSSL::SSL)
find_package(OpenSSL REQUIRED)
endif()
list(APPEND _package_dependencies "OpenSSL")
target_link_libraries(torrent-rasterbar PUBLIC OpenSSL::SSL)
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_OPENSSL TORRENT_USE_LIBCRYPTO)
else()
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_DISABLE_ENCRYPTION)
endif()
if (NOT logging)
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_DISABLE_LOGGING)
endif()
if (NOT dht)
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_DISABLE_DHT)
endif()
# Boost
find_package(Boost REQUIRED COMPONENTS system)
target_include_directories(torrent-rasterbar PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(torrent-rasterbar PUBLIC ${Boost_SYSTEM_LIBRARY})
list(APPEND _package_dependencies "Boost COMPONENTS system")
# Unconditional platform-specific settings
if (WIN32)
target_link_libraries(torrent-rasterbar
PRIVATE
@ -633,24 +582,139 @@ if (WIN32)
_WIN32_WINNT=0x0600 # target Windows Vista or later
WIN32_LEAN_AND_MEAN # prevent winsock1 to be included
)
if (MSVC)
target_compile_definitions(torrent-rasterbar PUBLIC BOOST_ALL_NO_LIB)
target_compile_definitions(torrent-rasterbar
PUBLIC
BOOST_ALL_NO_LIB
_SCL_SECURE_NO_DEPRECATE _CRT_SECURE_NO_DEPRECATE # disable bogus deprecation warnings on msvc8
)
target_compile_options(torrent-rasterbar
PRIVATE
/Zc:wchar_t /Zc:forScope # these compiler settings just make the compiler standard conforming
/MP # for multi-core compilation
/bigobj # increase the number of sections for obj files
)
set_target_properties(torrent-rasterbar PROPERTIES LINK_FLAGS_RELEASE "/OPT:ICF=5 /OPT:REF")
endif()
endif()
if(ANDROID)
target_link_libraries(torrent-rasterbar PRIVATE ${CMAKE_DL_LIBS})
if (ANDROID)
target_link_libraries(torrent-rasterbar PRIVATE ${CMAKE_DL_LIBS})
endif()
if(APPLE)
if (APPLE)
# for ip_notifier
target_link_libraries(torrent-rasterbar PRIVATE "-framework CoreFoundation" "-framework SystemConfiguration")
endif (APPLE)
if (NOT deprecated-functions)
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_NO_DEPRECATE)
endif()
feature_option(build_tests "build tests" OFF)
feature_option(build_examples "build examples" OFF)
feature_option(build_tools "build tools" OFF)
feature_option(python-bindings "build python bindings" OFF)
# these options require existing target
feature_option(dht "enable support for Mainline DHT" ON)
if(NOT build_tests) # tests require deprecated symbols
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME deprecated-functions DEFAULT ON
DESCRIPTION "enable deprecated functions for backwards compatibility" DISABLED TORRENT_NO_DEPRECATE)
endif()
feature_option(encryption "Enables encryption in libtorrent" ON)
feature_option(exceptions "build with exception support" ON)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME extensions DEFAULT ON
DESCRIPTION "Enables protocol extensions" DISABLED TORRENT_DISABLE_EXTENSIONS)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME i2p DEFAULT ON
DESCRIPTION "build with I2P support" DISABLED TORRENT_USE_I2P=0)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME ipv6 DEFAULT ON
DESCRIPTION "build with IPv6 support" DISABLED TORRENT_USE_IPV6=0)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME logging DEFAULT ON
DESCRIPTION "build with logging" DISABLED TORRENT_DISABLE_LOGGING)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME mutable-torrents DEFAULT ON
DESCRIPTION "Enables mutable torrent support" DISABLED TORRENT_DISABLE_MUTABLE_TORRENTS)
find_public_dependency(Iconv)
if(MSVC)
set(iconv_package_type OPTIONAL)
else()
set(iconv_package_type RECOMMENDED)
endif()
set_package_properties(Iconv
PROPERTIES
URL "https://www.gnu.org/software/libiconv/"
DESCRIPTION "GNU encoding conversion library"
TYPE ${iconv_package_type}
PURPOSE "Convert strings between various encodings"
)
if(Iconv_FOUND)
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_ICONV)
target_link_libraries(torrent-rasterbar PRIVATE Iconv::Iconv)
endif()
find_public_dependency(OpenSSL)
set_package_properties(OpenSSL
PROPERTIES
URL "https://www.openssl.org/"
DESCRIPTION "Full-strength general purpose cryptography library"
TYPE RECOMMENDED
PURPOSE "Provides HTTPS support to libtorrent"
)
if(OPENSSL_FOUND)
target_link_libraries(torrent-rasterbar PUBLIC OpenSSL::SSL)
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_OPENSSL)
target_sources(torrent-rasterbar PRIVATE src/pe_crypto)
endif()
if(OPENSSL_FOUND)
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_LIBCRYPTO)
else(OPENSSL_FOUND)
find_public_dependency(LibGcrypt)
set_package_properties(LibGcrypt
PROPERTIES
URL "https://www.gnupg.org/software/libgcrypt/index.html"
DESCRIPTION "A general purpose cryptographic library"
TYPE RECOMMENDED
PURPOSE "Use GCrypt instead of the built-in functions for RC4 and SHA1"
)
if (LibGcrypt_FOUND)
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_LIBGCRYPT)
target_link_libraries(torrent-rasterbar PRIVATE LibGcrypt::LibGcrypt)
else()
if (NOT WIN32 AND NOT APPLE)
target_sources(torrent-rasterbar PRIVATE src/sha1)
endif()
endif()
endif(OPENSSL_FOUND)
if (encryption)
target_sources(torrent-rasterbar PRIVATE src/pe_crypto)
else()
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_DISABLE_ENCRYPTION)
endif()
if (dht)
target_sources(torrent-rasterbar PRIVATE
src/kademlia/$<JOIN:${kademlia_sources}, src/kademlia/>
ed25519/src/$<JOIN:${ed25519_sources}, ed25519/src/>
include/libtorrent/kademlia/$<JOIN:${libtorrent_kademlia_include_files}, include/libtorrent/kademlia/>
src/hasher512
)
target_include_directories(torrent-rasterbar PRIVATE ed25519/src)
if (NOT OpenSSL_FOUND AND NOT LibGcrypt_FOUND AND NOT WIN32 AND NOT APPLE)
target_sources(torrent-rasterbar PRIVATE src/sha512)
endif()
else()
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_DISABLE_DHT)
endif()
# Boost
find_public_dependency(Boost REQUIRED COMPONENTS system)
target_include_directories(torrent-rasterbar PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(torrent-rasterbar PUBLIC ${Boost_SYSTEM_LIBRARY})
if (exceptions)
if (MSVC)
target_compile_options(torrent-rasterbar PUBLIC /EHsc)
@ -665,26 +729,49 @@ else()
endif (MSVC)
endif()
if (MSVC)
target_compile_definitions(torrent-rasterbar
PUBLIC
_SCL_SECURE_NO_DEPRECATE _CRT_SECURE_NO_DEPRECATE # disable bogus deprecation warnings on msvc8
)
target_compile_options(torrent-rasterbar
PRIVATE
/Zc:wchar_t /Zc:forScope # these compiler settings just make the compiler standard conforming
/MP # for multi-core compilation
/bigobj # increase the number of sections for obj files
)
endif()
# developer options
option(developer-options "Activates options useful for a developer")
if(developer-options)
set(asserts "auto" CACHE STRING "use assertions")
set_property(CACHE asserts PROPERTY STRINGS auto on off production system)
if ("${asserts}" MATCHES "on|production|system")
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_ASSERTS=1)
endif()
if ("${asserts}" STREQUAL "production")
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_PRODUCTION_ASSERTS=1)
elseif("${asserts}" STREQUAL "system")
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_SYSTEM_ASSERTS=1)
endif()
target_compile_definitions(torrent-rasterbar
PUBLIC
_FILE_OFFSET_BITS=64
BOOST_EXCEPTION_DISABLE
BOOST_ASIO_ENABLE_CANCELIO
BOOST_ASIO_HAS_STD_CHRONO
)
target_optional_compile_definitions(torrent-rasterbar PUBLIC NAME asio-debugging DEFAULT OFF
ENABLED TORRENT_ASIO_DEBUGGING)
target_optional_compile_definitions(torrent-rasterbar PUBLIC NAME picker-debugging DEFAULT OFF
ENABLED TORRENT_DEBUG_REFCOUNTS)
set(invariant-checks "off" CACHE STRING "")
set_property(CACHE invariant-checks PROPERTY STRINGS off on full)
if (invariant-checks MATCHES "on|full")
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_USE_INVARIANT_CHECKS=1)
endif()
if (invariant-checks STREQUAL "full")
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_EXPENSIVE_INVARIANT_CHECKS)
endif()
target_optional_compile_definitions(torrent-rasterbar PUBLIC NAME utp-log DEFAULT OFF
ENABLED TORRENT_UTP_LOG_ENABLE)
target_optional_compile_definitions(torrent-rasterbar PUBLIC NAME simulate-slow-read DEFAULT OFF
ENABLED TORRENT_SIMULATE_SLOW_READ)
option(debug-iterators "" OFF)
if (debug-iterators)
if (MSVC)
target_compile_definitions(torrent-rasterbar PUBLIC _ITERATOR_DEBUG_LEVEL=2)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_definitions(torrent-rasterbar PUBLIC _GLIBCXX_DEBUG _GLIBCXX_DEBUG_PEDANTIC)
endif()
endif()
target_optional_compile_definitions(torrent-rasterbar PUBLIC NAME profile-calls DEFAULT OFF
ENABLED TORRENT_PROFILE_CALLS=1)
endif()
generate_and_install_pkg_config_file(torrent-rasterbar)
@ -705,10 +792,16 @@ set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/libtorrent-rasterbar)
string(REGEX REPLACE "([^;]+)" "find_dependency(\\1)" _find_dependency_calls "${_package_dependencies}")
string(REPLACE ";" "\n" _find_dependency_calls "${_find_dependency_calls}")
if(CMAKE_VERSION VERSION_LESS "3.11.0")
set(_compatibility ExactVersion)
else()
set(_compatibility SameMinorVersion)
endif()
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar/libtorrent-rasterbarConfigVersion.cmake"
VERSION ${libtorrent_VERSION}
COMPATIBILITY ExactVersion
COMPATIBILITY ${_compatibility}
)
export(EXPORT torrent-rasterbarTargets
@ -739,6 +832,13 @@ install(
${ConfigPackageLocation}
)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/examples/cmake/FindLibtorrentRasterbar.cmake
DESTINATION
${CMAKE_INSTALL_DATADIR}/cmake/Modules
)
# === build tools ===
if (build_tools)
add_subdirectory(tools)
@ -756,3 +856,5 @@ if(build_tests)
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_EXPORT_EXTRA)
add_subdirectory(test)
endif()
feature_summary(DEFAULT_DESCRIPTION WHAT ALL)

View File

@ -99,11 +99,11 @@ target_link_libraries(python-libtorrent
${PYTHON_LIBRARIES}
)
# Bindings module uses deprecated libtorrent features, thus we disable these errors
# Bindings module uses deprecated libtorrent features, thus we disable these warnings
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
check_cxx_compiler_flag("-Wno-error=deprecated-declarations" _WNO_ERROR_DEPRECATED_DECLARATIONS)
if (_WNO_ERROR_DEPRECATED_DECLARATIONS)
target_compile_options(python-libtorrent PRIVATE -Wno-error=deprecated-declarations)
check_cxx_compiler_flag("-Wno-deprecated-declarations" _WNO_DEPRECATED_DECLARATIONS)
if (_WNO_DEPRECATED_DECLARATIONS)
target_compile_options(python-libtorrent PRIVATE -Wno-deprecated-declarations)
endif()
endif()

View File

@ -1,60 +0,0 @@
# - 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

@ -12,21 +12,30 @@ include(GNUInstallDirs)
function(_get_target_property_merging_configs _var_name _target_name _propert_name)
get_target_property(vals ${_target_name} ${_propert_name})
if (NOT vals)
set(vals "")
if (CMAKE_BUILD_TYPE)
list(APPEND configs ${CMAKE_BUILD_TYPE})
elseif()
list(APPEND configs ${CMAKE_CONFIGURATION_TYPES})
endif()
foreach(cfg ${configs})
string(TOUPPER "${cfg}" UPPERCFG)
get_target_property(mapped_configs ${_target_name} "MAP_IMPORTED_CONFIG_${UPPERCFG}")
if (mapped_configs)
list(GET "${mapped_configs}" 0 target_cfg)
else()
set(target_cfg "${UPPERCFG}")
endif()
get_target_property(val_for_cfg ${_target_name} "${_propert_name}_${target_cfg}")
if (val_for_cfg)
list(APPEND vals "$<$<CONFIG:${cfg}>:${val_for_cfg}>")
endif()
endforeach()
endif()
foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${cfg}" UPPERCFG)
get_target_property(mapped_configs ${_target_name} "MAP_IMPORTED_CONFIG_${UPPERCFG}")
if (mapped_configs)
list(GET "${mapped_configs}" 0 target_cfg)
else()
set(target_cfg "${UPPERCFG}")
endif()
get_target_property(val_for_cfg ${_target_name} "${_propert_name}_${target_cfg}")
if (val_for_cfg)
list(APPEND vals "$<$<CONFIG:${cfg}>:${val_for_cfg}>")
endif()
endforeach()
# HACK file(GENERATE), which we use foe expanding generator expressions, is BUILD_INTERFACE,
# but we need INSTALL_INTERFACE here. As such, let us inter-change them.
string(REPLACE "$<BUILD_INTERFACE:" "$<TMP_INTERFACE:" vals "${vals}")
string(REPLACE "$<INSTALL_INTERFACE:" "@CMAKE_INSTALL_PREFIX@/$<BUILD_INTERFACE:" vals "${vals}")
string(REPLACE "$<TMP_INTERFACE:" "$<INSTALL_INTERFACE:" vals "${vals}")
set(${_var_name} "${vals}" PARENT_SCOPE)
endfunction()

View File

@ -1,10 +1,8 @@
prefix=@CMAKE_INSTALL_PREFIX@
libdir=${prefix}/@_INSTALL_LIBDIR@
includedir=${prefix}/@_INSTALL_INCLUDEDIR@
Name: @_PROJECT_NAME@
Description: @_PROJECT_DESCRIPTION@
Version: @_PROJECT_VERSION@
Libs: -L${libdir} -l@_TARGET_OUTPUT_NAME@ @_interface_link_libraries@
Cflags: -I${includedir} @_interface_compile_options@ @_interface_include_dirs@ @_interface_definitions@
Cflags: @_interface_compile_options@ @_interface_include_dirs@ @_interface_definitions@

View File

@ -0,0 +1,118 @@
# taken from https://github.com/onqtam/ucm/blob/master/cmake/ucm.cmake
#
# ucm.cmake - useful cmake macros
#
# Copyright (c) 2016 Viktor Kirilov
#
# Distributed under the MIT Software License
# See accompanying file LICENSE.txt or copy at
# https://opensource.org/licenses/MIT
#
# The documentation can be found at the library's page:
# https://github.com/onqtam/ucm
include(CMakeParseArguments)
# ucm_gather_flags
# Gathers all lists of flags for printing or manipulation
macro(ucm_gather_flags with_linker result)
set(${result} "")
# add the main flags without a config
list(APPEND ${result} CMAKE_C_FLAGS)
list(APPEND ${result} CMAKE_CXX_FLAGS)
if(${with_linker})
list(APPEND ${result} CMAKE_EXE_LINKER_FLAGS)
list(APPEND ${result} CMAKE_MODULE_LINKER_FLAGS)
list(APPEND ${result} CMAKE_SHARED_LINKER_FLAGS)
list(APPEND ${result} CMAKE_STATIC_LINKER_FLAGS)
endif()
if("${CMAKE_CONFIGURATION_TYPES}" STREQUAL "" AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
# handle single config generators - like makefiles/ninja - when CMAKE_BUILD_TYPE is set
string(TOUPPER ${CMAKE_BUILD_TYPE} config)
list(APPEND ${result} CMAKE_C_FLAGS_${config})
list(APPEND ${result} CMAKE_CXX_FLAGS_${config})
if(${with_linker})
list(APPEND ${result} CMAKE_EXE_LINKER_FLAGS_${config})
list(APPEND ${result} CMAKE_MODULE_LINKER_FLAGS_${config})
list(APPEND ${result} CMAKE_SHARED_LINKER_FLAGS_${config})
list(APPEND ${result} CMAKE_STATIC_LINKER_FLAGS_${config})
endif()
else()
# handle multi config generators (like msvc, xcode)
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config)
list(APPEND ${result} CMAKE_C_FLAGS_${config})
list(APPEND ${result} CMAKE_CXX_FLAGS_${config})
if(${with_linker})
list(APPEND ${result} CMAKE_EXE_LINKER_FLAGS_${config})
list(APPEND ${result} CMAKE_MODULE_LINKER_FLAGS_${config})
list(APPEND ${result} CMAKE_SHARED_LINKER_FLAGS_${config})
list(APPEND ${result} CMAKE_STATIC_LINKER_FLAGS_${config})
endif()
endforeach()
endif()
endmacro()
# ucm_set_runtime
# Sets the runtime (static/dynamic) for msvc/gcc
macro(ucm_set_runtime)
cmake_parse_arguments(ARG "STATIC;DYNAMIC" "" "" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" STREQUAL "")
message(AUTHOR_WARNING "ucm_set_runtime() does not support clang yet!")
endif()
ucm_gather_flags(0 flags_configs)
# add/replace the flags
# note that if the user has messed with the flags directly this function might fail
# - for example if with MSVC and the user has removed the flags - here we just switch/replace them
if("${ARG_STATIC}")
foreach(flags ${flags_configs})
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(NOT ${flags} MATCHES "-static-libstdc\\+\\+")
set(${flags} "${${flags}} -static-libstdc++")
endif()
if(NOT ${flags} MATCHES "-static-libgcc")
set(${flags} "${${flags}} -static-libgcc")
endif()
elseif(MSVC)
if(${flags} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flags} "${${flags}}")
endif()
endif()
endforeach()
elseif("${ARG_DYNAMIC}")
foreach(flags ${flags_configs})
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(${flags} MATCHES "-static-libstdc\\+\\+")
string(REGEX REPLACE "-static-libstdc\\+\\+" "" ${flags} "${${flags}}")
endif()
if(${flags} MATCHES "-static-libgcc")
string(REGEX REPLACE "-static-libgcc" "" ${flags} "${${flags}}")
endif()
elseif(MSVC)
if(${flags} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${flags} "${${flags}}")
endif()
endif()
endforeach()
endif()
endmacro()
# ucm_print_flags
# Prints all compiler flags for all configurations
macro(ucm_print_flags)
ucm_gather_flags(1 flags_configs)
message("")
foreach(flags ${flags_configs})
message("${flags}: ${${flags}}")
endforeach()
message("")
endmacro()

View File

@ -1,5 +1,4 @@
project(libtorrent-examples)
cmake_minimum_required(VERSION 2.6)
set(single_file_examples
simple_client
@ -11,7 +10,7 @@ set(single_file_examples
foreach(example ${single_file_examples})
add_executable(${example} "${example}.cpp")
target_link_libraries(${example} torrent-rasterbar)
target_link_libraries(${example} PRIVATE torrent-rasterbar)
endforeach(example)
add_executable(client_test
@ -19,4 +18,4 @@ add_executable(client_test
print.cpp
torrent_view.cpp
session_view.cpp)
target_link_libraries(client_test torrent-rasterbar)
target_link_libraries(client_test PRIVATE torrent-rasterbar)

View File

@ -15,7 +15,7 @@ list(REMOVE_ITEM tests "${CMAKE_CURRENT_SOURCE_DIR}/test_utils.cpp") # helper fi
add_library(test_common 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_link_libraries(test_common torrent-rasterbar)
target_link_libraries(test_common PUBLIC torrent-rasterbar)
target_compile_features(test_common PUBLIC cxx_std_11)
foreach(TARGET_SRC ${tests})