From a626f75c5ec3dfad213a6bebc6bd702baa6976e3 Mon Sep 17 00:00:00 2001 From: Eugene Shalygin Date: Fri, 27 Apr 2018 16:27:51 +0200 Subject: [PATCH] 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 $. 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 --- .travis.yml | 12 +- CMakeLists.txt | 436 +++++++++++------- bindings/python/CMakeLists.txt | 8 +- cmake/Modules/FindIconv.cmake | 60 --- cmake/Modules/GeneratePkgConfig.cmake | 37 +- .../GeneratePkgConfig/pkg-config.cmake.in | 4 +- cmake/Modules/ucm_flags.cmake | 118 +++++ examples/CMakeLists.txt | 5 +- test/CMakeLists.txt | 2 +- 9 files changed, 428 insertions(+), 254 deletions(-) delete mode 100644 cmake/Modules/FindIconv.cmake create mode 100644 cmake/Modules/ucm_flags.cmake diff --git a/.travis.yml b/.travis.yml index f3a245f89..890b4b3ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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- which we don't want to use + # but /usr/local/cmake-/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 .. diff --git a/CMakeLists.txt b/CMakeLists.txt index 08acd496e..fc43d7304 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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/$ + include/libtorrent/$ + include/libtorrent/extensions/$ + 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 + $ + $ +) + target_compile_definitions(torrent-rasterbar PUBLIC - $<$:TORRENT_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/$ + ed25519/src/$ + 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) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index d02be0ed0..b2bebec5f 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -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() diff --git a/cmake/Modules/FindIconv.cmake b/cmake/Modules/FindIconv.cmake deleted file mode 100644 index 338d17d05..000000000 --- a/cmake/Modules/FindIconv.cmake +++ /dev/null @@ -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 - 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/cmake/Modules/GeneratePkgConfig.cmake b/cmake/Modules/GeneratePkgConfig.cmake index b1963f321..55df54477 100644 --- a/cmake/Modules/GeneratePkgConfig.cmake +++ b/cmake/Modules/GeneratePkgConfig.cmake @@ -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 "$<$:${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 "$<$:${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 "$