mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-05 12:45:58 -07:00
Add support for unit testing
* Downgraded macOS CI to Qt 6.2.0 due to a bug in Qt Test module * Revised cmake build scripts * For now, only building via cmake is supported PR #17338.
This commit is contained in:
parent
890630944d
commit
03da68b1cf
12 changed files with 311 additions and 206 deletions
67
cmake/Modules/CheckPackages.cmake
Normal file
67
cmake/Modules/CheckPackages.cmake
Normal file
|
@ -0,0 +1,67 @@
|
|||
# use CONFIG mode first in find_package
|
||||
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
|
||||
|
||||
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()
|
||||
else()
|
||||
find_package(LibtorrentRasterbar ${version} REQUIRED COMPONENTS torrent-rasterbar)
|
||||
endif()
|
||||
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)
|
||||
find_package(OpenSSL ${minOpenSSLVersion} REQUIRED)
|
||||
find_package(ZLIB ${minZlibVersion} REQUIRED)
|
||||
if (QT6)
|
||||
find_package(Qt6 ${minQt6Version} REQUIRED COMPONENTS Core Network Sql Xml LinguistTools)
|
||||
if (DBUS)
|
||||
find_package(Qt6 ${minQt6Version} REQUIRED COMPONENTS DBus)
|
||||
set_package_properties(Qt6DBus PROPERTIES
|
||||
DESCRIPTION "Qt6 module for inter-process communication over the D-Bus protocol"
|
||||
PURPOSE "Required by the DBUS feature"
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
find_package(Qt5 ${minQt5Version} REQUIRED COMPONENTS Core Network Sql Xml LinguistTools)
|
||||
if (DBUS)
|
||||
find_package(Qt5 ${minQt5Version} REQUIRED COMPONENTS DBus)
|
||||
set_package_properties(Qt5DBus PROPERTIES
|
||||
DESCRIPTION "Qt5 module for inter-process communication over the D-Bus protocol"
|
||||
PURPOSE "Required by the DBUS feature"
|
||||
)
|
||||
endif()
|
||||
endif()
|
106
cmake/Modules/CommonConfig.cmake
Normal file
106
cmake/Modules/CommonConfig.cmake
Normal file
|
@ -0,0 +1,106 @@
|
|||
# Set platform variables and create some interface-only library targets
|
||||
# that some or all other targets will link to, either directly or transitively,
|
||||
# to consume common compile options/definitions
|
||||
|
||||
# treat value specified by the CXX_STANDARD target property as a requirement by default
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTORCC_OPTIONS --compress 9 --threshold 5)
|
||||
|
||||
add_library(qbt_common_cfg INTERFACE)
|
||||
|
||||
# Full C++ 17 support is required
|
||||
# See also https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
|
||||
# for a breakdown of the features that CMake recognizes for each C++ standard
|
||||
target_compile_features(qbt_common_cfg INTERFACE
|
||||
cxx_std_17
|
||||
)
|
||||
|
||||
target_compile_definitions(qbt_common_cfg INTERFACE
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x050f02
|
||||
QT_NO_CAST_FROM_ASCII
|
||||
QT_NO_CAST_TO_ASCII
|
||||
QT_NO_CAST_FROM_BYTEARRAY
|
||||
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
|
||||
QT_USE_QSTRINGBUILDER
|
||||
QT_STRICT_ITERATORS
|
||||
$<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG_OUTPUT>
|
||||
)
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
target_compile_definitions(qbt_common_cfg INTERFACE
|
||||
_DARWIN_FEATURE_64_BIT_INODE
|
||||
)
|
||||
endif()
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_compile_definitions(qbt_common_cfg INTERFACE
|
||||
NTDDI_VERSION=0x06010000
|
||||
_WIN32_WINNT=0x0601
|
||||
_WIN32_IE=0x0601
|
||||
WIN32_LEAN_AND_MEAN
|
||||
NOMINMAX
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
endif()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
|
||||
target_compile_options(qbt_common_cfg INTERFACE
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wcast-qual
|
||||
-Wcast-align
|
||||
-Winvalid-pch
|
||||
-Woverloaded-virtual
|
||||
-Wold-style-cast
|
||||
-Wnon-virtual-dtor
|
||||
-pedantic
|
||||
-pedantic-errors
|
||||
)
|
||||
|
||||
# Clang 11 still doesn't support -Wstrict-null-sentinel
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag(-Wstrict-null-sentinel SNS_SUPPORT)
|
||||
if (SNS_SUPPORT)
|
||||
target_compile_options(qbt_common_cfg INTERFACE -Wstrict-null-sentinel)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
|
||||
target_compile_options(qbt_common_cfg INTERFACE
|
||||
-Wno-range-loop-analysis
|
||||
)
|
||||
endif()
|
||||
|
||||
if (MINGW)
|
||||
target_link_options(qbt_common_cfg INTERFACE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:LINKER:--dynamicbase>)
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(qbt_common_cfg INTERFACE
|
||||
/guard:cf
|
||||
/utf-8
|
||||
# https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
|
||||
/Zc:__cplusplus
|
||||
)
|
||||
target_link_options(qbt_common_cfg INTERFACE
|
||||
/guard:cf
|
||||
$<$<NOT:$<CONFIG:Debug>>:/OPT:REF /OPT:ICF>
|
||||
# suppress linking warning due to /INCREMENTAL and /OPT:ICF being both ON
|
||||
$<$<CONFIG:RelWithDebInfo>:/INCREMENTAL:NO>
|
||||
)
|
||||
|
||||
if (MSVC_RUNTIME_DYNAMIC)
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
else()
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (LibtorrentRasterbar_VERSION VERSION_GREATER_EQUAL ${minLibtorrentVersion})
|
||||
target_compile_definitions(qbt_common_cfg INTERFACE QBT_USES_LIBTORRENT2)
|
||||
endif()
|
|
@ -1,104 +0,0 @@
|
|||
# Set common variables and create some interface-only library targets
|
||||
# that some or all other targets will link to, either directly or transitively,
|
||||
# to consume common compile options/definitions
|
||||
|
||||
macro(qbt_common_config)
|
||||
# treat value specified by the CXX_STANDARD target property as a requirement by default
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
add_library(qbt_common_cfg INTERFACE)
|
||||
|
||||
# Full C++ 17 support is required
|
||||
# See also https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
|
||||
# for a breakdown of the features that CMake recognizes for each C++ standard
|
||||
target_compile_features(qbt_common_cfg INTERFACE
|
||||
cxx_std_17
|
||||
)
|
||||
|
||||
target_compile_definitions(qbt_common_cfg INTERFACE
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x050f02
|
||||
QT_NO_CAST_FROM_ASCII
|
||||
QT_NO_CAST_TO_ASCII
|
||||
QT_NO_CAST_FROM_BYTEARRAY
|
||||
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
|
||||
QT_USE_QSTRINGBUILDER
|
||||
QT_STRICT_ITERATORS
|
||||
$<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG_OUTPUT>
|
||||
)
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
target_compile_definitions(qbt_common_cfg INTERFACE
|
||||
_DARWIN_FEATURE_64_BIT_INODE
|
||||
)
|
||||
endif()
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_compile_definitions(qbt_common_cfg INTERFACE
|
||||
NTDDI_VERSION=0x06010000
|
||||
_WIN32_WINNT=0x0601
|
||||
_WIN32_IE=0x0601
|
||||
WIN32_LEAN_AND_MEAN
|
||||
NOMINMAX
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
endif()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
|
||||
target_compile_options(qbt_common_cfg INTERFACE
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wcast-qual
|
||||
-Wcast-align
|
||||
-Winvalid-pch
|
||||
-Woverloaded-virtual
|
||||
-Wold-style-cast
|
||||
-Wnon-virtual-dtor
|
||||
-pedantic
|
||||
-pedantic-errors
|
||||
)
|
||||
|
||||
# Clang 11 still doesn't support -Wstrict-null-sentinel
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag(-Wstrict-null-sentinel SNS_SUPPORT)
|
||||
if (SNS_SUPPORT)
|
||||
target_compile_options(qbt_common_cfg INTERFACE -Wstrict-null-sentinel)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
|
||||
target_compile_options(qbt_common_cfg INTERFACE
|
||||
-Wno-range-loop-analysis
|
||||
)
|
||||
endif()
|
||||
|
||||
if (MINGW)
|
||||
target_link_options(qbt_common_cfg INTERFACE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:LINKER:--dynamicbase>)
|
||||
endif()
|
||||
|
||||
if (MSVC_RUNTIME_DYNAMIC)
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
else()
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(qbt_common_cfg INTERFACE
|
||||
/guard:cf
|
||||
/utf-8
|
||||
# https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
|
||||
/Zc:__cplusplus
|
||||
)
|
||||
target_link_options(qbt_common_cfg INTERFACE
|
||||
/guard:cf
|
||||
$<$<NOT:$<CONFIG:Debug>>:/OPT:REF /OPT:ICF>
|
||||
# suppress linking warning due to /INCREMENTAL and /OPT:ICF being both ON
|
||||
$<$<CONFIG:RelWithDebInfo>:/INCREMENTAL:NO>
|
||||
)
|
||||
endif()
|
||||
|
||||
if (LibtorrentRasterbar_VERSION VERSION_GREATER_EQUAL ${minLibtorrentVersion})
|
||||
target_compile_definitions(qbt_common_cfg INTERFACE QBT_USES_LIBTORRENT2)
|
||||
endif()
|
||||
endmacro(qbt_common_config)
|
Loading…
Add table
Add a link
Reference in a new issue