Browse Source
* 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.adaptive-webui-19844
Chocobo1
2 years ago
committed by
GitHub
12 changed files with 311 additions and 206 deletions
@ -0,0 +1,67 @@
@@ -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() |
@ -0,0 +1,106 @@
@@ -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 @@
@@ -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) |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
if (QT6) |
||||
find_package(Qt6 REQUIRED COMPONENTS Test) |
||||
else() |
||||
find_package(Qt5 REQUIRED COMPONENTS Test) |
||||
endif() |
||||
|
||||
enable_testing(true) |
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure) |
||||
|
||||
include_directories("../src") |
||||
|
||||
file(GLOB testFiles "${CMAKE_CURRENT_SOURCE_DIR}/test*.cpp") |
||||
foreach(testFile ${testFiles}) |
||||
get_filename_component(testFilename "${testFile}" NAME_WLE) |
||||
|
||||
add_executable("${testFilename}" "${testFile}") |
||||
target_link_libraries("${testFilename}" PRIVATE Qt::Test qbt_base) |
||||
add_test(NAME "${testFilename}" COMMAND "${testFilename}") |
||||
endforeach() |
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
# Test suite |
||||
|
||||
To run tests, add `-DTESTING=ON` argument when invoking cmake, then build the app as usual. \ |
||||
After building, run `cmake --build <build> --target check` where `<build>` is your cmake build directory. |
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent. |
||||
* Copyright (C) 2022 Mike Tzou (Chocobo1) |
||||
* |
||||
* This program is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU General Public License |
||||
* as published by the Free Software Foundation; either version 2 |
||||
* of the License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
* |
||||
* In addition, as a special exception, the copyright holders give permission to |
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with |
||||
* modified versions of it that use the same license as the "OpenSSL" library), |
||||
* and distribute the linked executables. You must obey the GNU General Public |
||||
* License in all respects for all of the code used other than "OpenSSL". If you |
||||
* modify file(s), you may extend this exception to your version of the file(s), |
||||
* but you are not obligated to do so. If you do not wish to do so, delete this |
||||
* exception statement from your version. |
||||
*/ |
||||
|
||||
#include <QTest> |
||||
|
||||
#include "base/global.h" |
||||
#include "base/utils/gzip.h" |
||||
|
||||
class TestUtilsGzip final : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
Q_DISABLE_COPY_MOVE(TestUtilsGzip) |
||||
|
||||
public: |
||||
TestUtilsGzip() = default; |
||||
|
||||
private slots: |
||||
void testCompress() const |
||||
{ |
||||
// compressed data is not reproducible, see: https://stackoverflow.com/questions/30150972/are-there-test-vectors-available-for-gzip
|
||||
const QByteArray data = QByteArrayLiteral("abc"); |
||||
|
||||
bool ok = false; |
||||
const QByteArray compressedData = Utils::Gzip::compress(data, 6, &ok); |
||||
QVERIFY(ok); |
||||
} |
||||
|
||||
void testDecompress() const |
||||
{ |
||||
const QByteArray data = QByteArrayLiteral("abc"); |
||||
|
||||
bool ok = false; |
||||
const QByteArray compressedData = Utils::Gzip::compress(data, 6, &ok); |
||||
QVERIFY(ok); |
||||
QVERIFY(compressedData != data); |
||||
|
||||
ok = false; |
||||
const QByteArray decompressedData = Utils::Gzip::decompress(compressedData, &ok); |
||||
QVERIFY(ok); |
||||
QCOMPARE(decompressedData, data); |
||||
} |
||||
}; |
||||
|
||||
QTEST_APPLESS_MAIN(TestUtilsGzip) |
||||
#include "testutilsgzip.moc" |
Loading…
Reference in new issue