Skip to content

Commit 9ac27ea

Browse files
authored
Qt6 support (MEONMedical#46)
* Removed obsolete include * Adopt cmake files for Qt6 support * Support for Qt6 * include QTextCodec only for qt5 * Remove unneeded target dependency Qt::Core5Compat * Changed way to detect major qt version * suppress msvc waning 4913 * Fix usage in endl before Qt.5.14
1 parent 166c47e commit 9ac27ea

24 files changed

+158
-69
lines changed

Diff for: CMakeLists.txt

+34-41
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,83 @@
11
cmake_minimum_required(VERSION 3.3.0)
22
project(Log4Qt VERSION 1.6.0)
33

4-
#
54
# in-source builds should be avoided
6-
#
75
set(Log4Qt_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
86
set(CMAKE_MODULE_PATH "${Log4Qt_MODULE_DIR}")
97
include(MacroEnsureOutOfSourceBuild)
108

11-
#
129
# support for 'make test'
13-
#
1410
enable_testing()
1511

16-
#
1712
# Shared or static build of log4qt library
18-
#
1913
option(BUILD_STATIC_LOG4CXX_LIB "Build a static log4cxx library (default: off)" OFF)
2014

21-
#
2215
# With Database logging support or without
23-
#
2416
option(BUILD_WITH_DB_LOGGING "Build with database logging support, link against Qt sql lib (default: on)" OFF)
2517

26-
#
2718
# With Database logging support or without
28-
#
2919
option(BUILD_WITH_TELNET_LOGGING "Build with telnet logging support, link against Qt network lib (default: on)" OFF)
3020

31-
#
3221
# Enable documentation generation with doxygen
33-
#
3422
OPTION(BUILD_WITH_DOCS "Enable documentation generation (default: off)" OFF)
3523

36-
#
3724
# Helper to be able to properly install into the correct directories (esp. lib/lib64)
38-
#
3925
include(GNUInstallDirs)
4026

41-
#
4227
# Automatically include ${CMAKE_CURRENT_SOURCE_DIR} and ${CMAKE_CURRENT_BINARY_DIR}
43-
#
4428
set(CMAKE_INCLUDE_CURRENT_DIR ON)
4529
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
4630

47-
#
4831
# Set include dir src
49-
#
5032
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
5133
set(LOG4QT_BUILD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
5234

53-
#
5435
# We need C++11 and don't want to export all symbols, only the ones we mark for export
55-
#
5636
set(CMAKE_CXX_STANDARD 17)
5737
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
5838
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
5939

60-
#
6140
# Min. Qt version is 5.12, we want to use cmake automoc feature
6241
# and settings some defines for Qt
63-
#
6442
set(CMAKE_AUTOMOC TRUE)
6543
set(QT_MIN_VERSION 5.12.0)
66-
# TODO: make Network also optional?
67-
find_package(Qt5 COMPONENTS Core Network Concurrent Test REQUIRED)
44+
45+
find_package(Qt6 COMPONENTS Core QUIET)
46+
if (Qt6_FOUND)
47+
message("Qt6 gefunden!")
48+
message(STATUS "Qt version is ${Qt6Core_VERSION}")
49+
else()
50+
message("Qt6 not found, check Qt5!")
51+
find_package(Qt5 COMPONENTS Core QUIET)
52+
if (Qt5_FOUND)
53+
message("Qt5 found!")
54+
message(STATUS "Qt version is ${Qt5Core_VERSION}")
55+
else()
56+
message(FATAL_ERROR "No Qt found!")
57+
endif()
58+
endif()
59+
60+
if(Qt5_FOUND)
61+
find_package(Qt5 COMPONENTS Concurrent Test REQUIRED)
62+
else()
63+
find_package(Qt6 COMPONENTS Concurrent Test REQUIRED)
64+
endif()
65+
6866
if(BUILD_WITH_DB_LOGGING)
69-
find_package(Qt5 COMPONENTS Sql REQUIRED)
67+
if (Qt5_FOUND)
68+
find_package(Qt5 COMPONENTS Sql REQUIRED)
69+
else()
70+
find_package(Qt6 COMPONENTS Sql REQUIRED)
71+
endif()
7072
endif()
7173
if(BUILD_WITH_TELNET_LOGGING)
72-
find_package(Qt5 COMPONENTS Network REQUIRED)
74+
if (Qt5_FOUND)
75+
find_package(Qt5 COMPONENTS Network REQUIRED)
76+
else()
77+
find_package(Qt6 COMPONENTS Network REQUIRED)
78+
endif()
7379
endif()
74-
message(STATUS "Qt version is ${Qt5Core_VERSION_STRING}")
80+
7581
add_definitions(-DQT_USE_QSTRINGBUILDER)
7682
add_definitions(-DQT_NO_CAST_TO_ASCII)
7783
#add_definitions(-DQT_NO_CAST_FROM_ASCII)
@@ -83,18 +89,14 @@ if(NOT MSVC)
8389
endif()
8490
add_definitions(-DUNICODE -D_UNICODE)
8591

86-
#
8792
# Pass version as a string to the compiler (for LogManager::version())
88-
#
8993
add_definitions(-DLOG4QT_VERSION_STR="${Log4Qt_VERSION_MAJOR}.${Log4Qt_VERSION_MINOR}.${Log4Qt_VERSION_PATCH}"
9094
-DLOG4QT_VERSION_MAJOR=${Log4Qt_VERSION_MAJOR}
9195
-DLOG4QT_VERSION_MINOR=${Log4Qt_VERSION_MINOR}
9296
-DLOG4QT_VERSION_PATCH=${Log4Qt_VERSION_PATCH}
9397
)
9498

95-
#
9699
# We need gcc >= 4.8 or clang >= 3.3 or msvc >= 2015
97-
#
98100
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
99101
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.0)
100102
message(FATAL_ERROR "gcc 4.8 or higher required!")
@@ -116,7 +118,7 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
116118
# disable 4127: conditional expression is constant
117119
# 4512: assignment operator could not be generated
118120
# 4267: conversion from 'size_t' to 'type', possible loss of data
119-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4127 -wd4512 -wd4267 -we4265")
121+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4127 -wd4512 -wd4267 -wd4913 -we4265")
120122

121123
string(REGEX REPLACE "/W[0-3]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
122124

@@ -129,9 +131,7 @@ add_subdirectory(src/log4qt)
129131
add_subdirectory(tests)
130132
add_subdirectory(examples)
131133

132-
#
133134
# Create a proper FindLog4Qt - module
134-
#
135135
set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/Log4Qt" )
136136
install(EXPORT log4qt_targets
137137
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
@@ -156,9 +156,7 @@ install(FILES
156156
COMPONENT Devel
157157
)
158158

159-
#
160159
# Add support for an uninstall target
161-
#
162160
configure_file(
163161
"${Log4Qt_MODULE_DIR}/cmake_uninstall.cmake.in"
164162
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
@@ -169,9 +167,7 @@ add_custom_target(uninstall
169167
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
170168

171169

172-
#
173170
# Documentation generations
174-
#
175171
IF (BUILD_WITH_DOCS)
176172
find_package(Doxygen)
177173
if (DOXYGEN_FOUND)
@@ -194,11 +190,8 @@ IF (BUILD_WITH_DOCS)
194190
endif (DOXYGEN_FOUND)
195191
ENDIF()
196192

197-
198-
#
199193
# Packaging
200194
# https://cmake.org/cmake/help/latest/module/CPack.html
201-
#
202195
set( CPACK_PACKAGE_NAME ${PROJECT_NAME} )
203196
set( CPACK_PACKAGE_VENDOR "MEON Medical" ) # Github project owner
204197
set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Logging for the Qt cross-platform application framework" )

Diff for: g++.pri

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ msvc {
4040
# disable 4127: conditional expression is constant
4141
# 4512: assignment operator could not be generated
4242
# 4267: conversion from 'size_t' to 'type', possible loss of data
43-
QMAKE_CXXFLAGS += -wd4127 -wd4512 -wd4267 -we4265
43+
QMAKE_CXXFLAGS += -wd4127 -wd4512 -wd4267 -we4265 -wd4913
4444

4545
# /WX ... treat all warnings as errors
4646
# /we<n> ... Treat warning <n> as error

Diff for: log4qtlib.qbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Product {
2626
condition: qbs.toolchain.contains('msvc')
2727
cpp.cFlags: [ "-W4" ]
2828
cpp.cxxFlags: [ "-W4",
29-
"-wd4127", "-wd4512", "-wd4267", "-we4265"]
29+
"-wd4127", "-wd4512", "-wd4267", "-we4265", "-wd4913"]
3030

3131
//disable common warnings in Qt/stdlib
3232
//disable 4127: conditional expression is constant

Diff for: src/log4qt/CMakeLists.txt

+18-9
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,20 @@ if(BUILD_STATIC_LOG4CXX_LIB)
150150
set(_shared_static STATIC)
151151
endif()
152152
add_library(log4qt ${_shared_static} ${log4qt_SOURCES} ${log4qt_HEADERS} ${log4qt_HEADERS_helpers} ${log4qt_HEADERS_spi} ${log4qt_HEADERS_varia})
153-
target_link_libraries(log4qt
154-
PUBLIC
155-
Qt5::Core
156-
Qt5::Concurrent
157-
)
153+
if(QT_VERSION LESS 6.0.0)
154+
target_link_libraries(log4qt
155+
PUBLIC
156+
Qt::Core
157+
Qt::Concurrent
158+
)
159+
else()
160+
target_link_libraries(log4qt
161+
PUBLIC
162+
Qt::Core
163+
Qt::Concurrent
164+
)
165+
endif()
166+
158167
target_include_directories(log4qt PUBLIC
159168
$<BUILD_INTERFACE:${LOG4QT_BUILD_INCLUDE_DIR}>
160169
$<INSTALL_INTERFACE:include>)
@@ -176,11 +185,11 @@ if(BUILD_WITH_DB_LOGGING)
176185
)
177186
target_link_libraries(log4qt
178187
PRIVATE
179-
Qt5::Sql
188+
Qt::Sql
180189
)
181190
target_include_directories(log4qt
182191
PUBLIC
183-
$<TARGET_PROPERTY:Qt5::Sql,INTERFACE_INCLUDE_DIRECTORIES>
192+
$<TARGET_PROPERTY:Qt::Sql,INTERFACE_INCLUDE_DIRECTORIES>
184193
)
185194
message(STATUS "Enabling database logging support")
186195
else()
@@ -202,11 +211,11 @@ if(BUILD_WITH_TELNET_LOGGING)
202211
)
203212
target_link_libraries(log4qt
204213
PRIVATE
205-
Qt5::Network
214+
Qt::Network
206215
)
207216
target_include_directories(log4qt
208217
PUBLIC
209-
$<TARGET_PROPERTY:Qt5::Network,INTERFACE_INCLUDE_DIRECTORIES>
218+
$<TARGET_PROPERTY:Qt::Network,INTERFACE_INCLUDE_DIRECTORIES>
210219
)
211220
message(STATUS "Enabling telnet logging support")
212221
else()

Diff for: src/log4qt/appenderskeleton.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ inline RecursionGuardLocker::~RecursionGuardLocker()
6161

6262
AppenderSkeleton::AppenderSkeleton(QObject *parent) :
6363
Appender(parent),
64+
#if QT_VERSION < 0x050E00
6465
mObjectGuard(QMutex::Recursive), // Recursive for doAppend()
66+
#endif
6567
mAppendRecursionGuard(false),
6668
mIsActive(true),
6769
mIsClosed(false),
@@ -72,7 +74,9 @@ AppenderSkeleton::AppenderSkeleton(QObject *parent) :
7274
AppenderSkeleton::AppenderSkeleton(bool isActive,
7375
QObject *parent) :
7476
Appender(parent),
77+
#if QT_VERSION < 0x050E00
7578
mObjectGuard(QMutex::Recursive), // Recursive for doAppend()
79+
#endif
7680
mAppendRecursionGuard(false),
7781
mIsActive(isActive),
7882
mIsClosed(false),
@@ -84,7 +88,9 @@ AppenderSkeleton::AppenderSkeleton(bool isActive,
8488
const LayoutSharedPtr &layout,
8589
QObject *parent) :
8690
Appender(parent),
91+
#if QT_VERSION < 0x050E00
8792
mObjectGuard(QMutex::Recursive), // Recursive for doAppend()
93+
#endif
8894
mAppendRecursionGuard(false),
8995
mIsActive(isActive),
9096
mIsClosed(false),

Diff for: src/log4qt/appenderskeleton.h

+4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ class LOG4QT_EXPORT AppenderSkeleton : public Appender
135135
virtual bool checkEntryConditions() const;
136136

137137
protected:
138+
#if QT_VERSION < 0x050E00
138139
mutable QMutex mObjectGuard;
140+
#else
141+
mutable QRecursiveMutex mObjectGuard;
142+
#endif
139143

140144
private:
141145
Q_DISABLE_COPY(AppenderSkeleton)

Diff for: src/log4qt/dailyrollingfileappender.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include <QFile>
2828
#include <QMetaEnum>
29-
#include <QTextCodec>
3029

3130
namespace Log4Qt
3231
{

Diff for: src/log4qt/fileappender.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <QFile>
2727
#include <QFileInfo>
2828
#include <QTextStream>
29-
#include <QTextCodec>
3029

3130
// if we are in WIN*
3231
#ifdef Q_OS_WIN

Diff for: src/log4qt/helpers/initialisationhelper.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ void InitialisationHelper::doRegisterTypes()
8484
qRegisterMetaType<Log4Qt::LoggingEvent>("Log4Qt::LoggingEvent");
8585

8686
#ifndef QT_NO_DATASTREAM
87+
#if QT_VERSION < 0x060000
8788
qRegisterMetaTypeStreamOperators<Log4Qt::LogError>("Log4Qt::LogError");
8889
qRegisterMetaTypeStreamOperators<Log4Qt::Level>("Log4Qt::Level");
8990
qRegisterMetaTypeStreamOperators<LoggingEvent>("Log4Qt::LoggingEvent");
9091
#endif
92+
#endif
93+
9194
}
9295

9396
QString InitialisationHelper::doSetting(const QString &key,

Diff for: src/log4qt/helpers/logerror.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <QByteArray>
2626
#include <QDataStream>
2727
#include <QCoreApplication>
28-
#include <QTextCodec>
2928
#include <QThreadStorage>
3029

3130
namespace Log4Qt

Diff for: src/log4qt/helpers/optionconverter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ QString OptionConverter::findAndSubst(const Properties &properties,
5454
begin = value.indexOf(begin_subst, i);
5555
if (begin == -1)
5656
{
57-
result += value.midRef(i);
57+
result += value.mid(i);
5858
i = value.length();
5959
}
6060
else
6161
{
62-
result += value.midRef(i, begin - i);
62+
result += value.mid(i, begin - i);
6363
end = value.indexOf(end_subst, i + begin_length);
6464
if (end == -1)
6565
{

Diff for: src/log4qt/helpers/patternformatter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ void PatternFormatter::parse()
555555
if (state == ESCAPE_STATE)
556556
literal += c;
557557
else
558-
literal += mPattern.midRef(converter_start);
558+
literal += mPattern.mid(converter_start);
559559
}
560560

561561
if (!literal.isEmpty())
@@ -613,7 +613,7 @@ void PatternConverter::format(QString &format, const LoggingEvent &loggingEvent)
613613
// If the data item is longer than the maximum field, then the extra characters
614614
// are removed from the beginning of the data item and not from the end.
615615
if (s.length() > mFormattingInfo.mMaxLength)
616-
format += s.rightRef(mFormattingInfo.mMaxLength);
616+
format += s.right(mFormattingInfo.mMaxLength);
617617
else if (mFormattingInfo.mLeftAligned)
618618
format += s.leftJustified(mFormattingInfo.mMinLength, space, false);
619619
else

Diff for: src/log4qt/helpers/properties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void Properties::load(QIODevice *pDevice)
5353
line_number++;
5454

5555
if (!line.isEmpty() && line.at(line.length() - 1) == append_char)
56-
property += line.leftRef(line.length() - 1);
56+
property += line.left(line.length() - 1);
5757
else
5858
{
5959
property += line;

0 commit comments

Comments
 (0)