Detect incompatible libtorrent v2 versions in build systems

Although the detection is working, the error message in autotools is not
perfect, i.e. it would only mention valid range for libtorrent v1 and it
shouldn't be a problem since v2 support isn't fully ready yet.
This commit is contained in:
Chocobo1 2021-07-29 14:15:59 +08:00
commit 7d7f967d5e
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
5 changed files with 236 additions and 63 deletions

View file

@ -1,35 +1,43 @@
if (UNIX AND (NOT APPLE) AND (NOT CYGWIN))
find_package(LibtorrentRasterbar QUIET ${minLibtorrentVersion} COMPONENTS torrent-rasterbar)
if (NOT LibtorrentRasterbar_FOUND)
include(FindPkgConfig)
pkg_check_modules(LIBTORRENT_RASTERBAR IMPORTED_TARGET GLOBAL "libtorrent-rasterbar>=${minLibtorrentVersion}")
if (NOT LIBTORRENT_RASTERBAR_FOUND)
message(
FATAL_ERROR
"Package LibtorrentRasterbar >= ${minLibtorrentVersion} not found"
" with CMake or pkg-config.\n- Set LibtorrentRasterbar_DIR to a directory containing"
" a LibtorrentRasterbarConfig.cmake file or add the installation prefix of LibtorrentRasterbar"
" to CMAKE_PREFIX_PATH.\n- Alternatively, make sure there is a valid libtorrent-rasterbar.pc"
" file in your system's pkg-config search paths (use the system environment variable PKG_CONFIG_PATH"
" to specify additional search paths if needed)."
macro(find_libtorrent version)
if (UNIX AND (NOT APPLE) AND (NOT CYGWIN))
find_package(LibtorrentRasterbar QUIET ${version} COMPONENTS torrent-rasterbar)
if (NOT LibtorrentRasterbar_FOUND)
include(FindPkgConfig)
pkg_check_modules(LibtorrentRasterbar IMPORTED_TARGET GLOBAL "libtorrent-rasterbar>=${version}")
if (NOT LibtorrentRasterbar_FOUND)
message(
FATAL_ERROR
"Package LibtorrentRasterbar >= ${version} not found"
" with CMake or pkg-config.\n- Set LibtorrentRasterbar_DIR to a directory containing"
" a LibtorrentRasterbarConfig.cmake file or add the installation prefix of LibtorrentRasterbar"
" to CMAKE_PREFIX_PATH.\n- Alternatively, make sure there is a valid libtorrent-rasterbar.pc"
" file in your system's pkg-config search paths (use the system environment variable PKG_CONFIG_PATH"
" to specify additional search paths if needed)."
)
endif()
add_library(LibtorrentRasterbar::torrent-rasterbar ALIAS PkgConfig::LibtorrentRasterbar)
# force a fake package to show up in the feature summary
set_property(GLOBAL APPEND PROPERTY
PACKAGES_FOUND
"LibtorrentRasterbar via pkg-config (version >= ${version})"
)
set_package_properties("LibtorrentRasterbar via pkg-config (version >= ${version})"
PROPERTIES
TYPE REQUIRED
)
else()
set_package_properties(LibtorrentRasterbar PROPERTIES TYPE REQUIRED)
endif()
add_library(LibtorrentRasterbar::torrent-rasterbar ALIAS PkgConfig::LIBTORRENT_RASTERBAR)
# force a fake package to show up in the feature summary
set_property(GLOBAL APPEND PROPERTY
PACKAGES_FOUND
"LibtorrentRasterbar via pkg-config (version >= ${minLibtorrentVersion})"
)
set_package_properties("LibtorrentRasterbar via pkg-config (version >= ${minLibtorrentVersion})"
PROPERTIES
TYPE REQUIRED
)
else()
set_package_properties(LibtorrentRasterbar PROPERTIES TYPE REQUIRED)
find_package(LibtorrentRasterbar ${version} REQUIRED COMPONENTS torrent-rasterbar)
endif()
else()
find_package(LibtorrentRasterbar ${minLibtorrentVersion} REQUIRED COMPONENTS torrent-rasterbar)
endmacro()
find_libtorrent(${minLibtorrent1Version})
if (LibtorrentRasterbar_FOUND AND (LibtorrentRasterbar_VERSION VERSION_GREATER_EQUAL 2.0))
find_libtorrent(${minLibtorrentVersion})
endif()
# force variable type so that it always shows up in ccmake/cmake-gui frontends
set_property(CACHE LibtorrentRasterbar_DIR PROPERTY TYPE PATH)
find_package(Boost ${minBoostVersion} REQUIRED)