Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better cmake #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ doc/
*.pro.user
*.pro.user.*
CMakeLists.txt.user

# CMake build
build

# Clangd
.cache
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)

SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)

PROJECT(CuteLogger)

FIND_PACKAGE(Qt5Core REQUIRED)
project(CuteLogger)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
ADD_DEFINITIONS(-DCUTELOGGER_LIBRARY)

INCLUDE_DIRECTORIES(BEFORE include)

SET(sources
Expand Down Expand Up @@ -41,8 +41,11 @@ ENDIF(WIN32)
SET(library_target CuteLogger)

ADD_LIBRARY(${library_target} SHARED ${sources} ${includes})
TARGET_LINK_LIBRARIES(${library_target} Qt5::Core)
TARGET_INCLUDE_DIRECTORIES(${library_target} PUBLIC include)
TARGET_LINK_LIBRARIES(
${library_target}
Qt${QT_VERSION_MAJOR}::Core
)
target_include_directories(${library_target} PUBLIC include)

INSTALL(TARGETS ${library_target} DESTINATION lib)

Expand Down
4 changes: 2 additions & 2 deletions include/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <QString>
#include <QDebug>
#include <QDateTime>

#include <QElapsedTimer>
// Local
#include "CuteLogger_global.h"
class AbstractAppender;
Expand Down Expand Up @@ -224,7 +224,7 @@ class CUTELOGGERSHARED_EXPORT LoggerTimingHelper

private:
Logger* m_logger;
QTime m_time;
QElapsedTimer m_time;
Logger::LogLevel m_logLevel;
Logger::TimingMode m_timingMode;
const char* m_file;
Expand Down
12 changes: 6 additions & 6 deletions src/AbstractStringAppender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <QReadLocker>
#include <QWriteLocker>
#include <QDateTime>
#include <QRegExp>
#include <QRegularExpression>
#include <QCoreApplication>
#include <QThread>

Expand Down Expand Up @@ -155,14 +155,14 @@ QByteArray AbstractStringAppender::qCleanupFuncinfo(const char* name)
}

bool hasLambda = false;
QRegExp lambdaRegex("::<lambda\\(.*\\)>");
int lambdaIndex = lambdaRegex.indexIn(QString::fromLatin1(info));
QRegularExpression lambdaRegex("::<lambda\\(.*\\)>");
QRegularExpressionMatch match = lambdaRegex.match(QString::fromLatin1(info));
int lambdaIndex = match.capturedStart();
if (lambdaIndex != -1)
{
hasLambda = true;
info.remove(lambdaIndex, lambdaRegex.matchedLength());
info.remove(lambdaIndex, match.capturedLength());
}

// operator names with '(', ')', '<', '>' in it
static const char operator_call[] = "operator()";
static const char operator_lessThan[] = "operator<";
Expand Down Expand Up @@ -405,7 +405,7 @@ QString AbstractStringAppender::formattedString(const QDateTime& timeStamp, Logg

// Filename without a path
else if (command == QLatin1String("file"))
chunk = QString(QLatin1String(file)).section(QRegExp("[/\\\\]"), -1);
chunk = QString(QLatin1String(file)).section(QRegularExpression("[/\\\\]"), -1);

// Source line number
else if (command == QLatin1String("line"))
Expand Down
15 changes: 11 additions & 4 deletions src/Logger.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/*
Copyright (c) 2012 Boris Moiseev (cyberbobs at gmail dot com)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 2.1
as published by the Free Software Foundation and appearing in the file
LICENSE.LGPL included in the packaging of this file.

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
Expand All @@ -22,7 +20,6 @@
#include <QSemaphore>
#include <QDateTime>
#include <QIODevice>
#include <QTextCodec>

#if defined(Q_OS_ANDROID)
# include <android/log.h>
Expand Down Expand Up @@ -600,8 +597,14 @@ Logger::~Logger()

// Cleanup appenders
QMutexLocker appendersLocker(&d->loggerMutex);
#if QT_VERSION >= 0x050e00
QSet<AbstractAppender*> deleteList(d->appenders.begin(), d->appenders.end());
auto cal = d->categoryAppenders.values();
deleteList.unite(QSet<AbstractAppender*>(cal.begin(), cal.end()));
#else
QSet<AbstractAppender*> deleteList(QSet<AbstractAppender*>::fromList(d->appenders));
deleteList.unite(QSet<AbstractAppender*>::fromList(d->categoryAppenders.values()));
#endif
qDeleteAll(deleteList);

appendersLocker.unlock();
Expand Down Expand Up @@ -1032,7 +1035,11 @@ void LoggerTimingHelper::start(const char* msg, ...)
{
va_list va;
va_start(va, msg);
#if QT_VERSION >= 0x050500
m_block = QString().vasprintf(msg, va);
#else
m_block = QString().vsprintf(msg, va);
#endif
va_end(va);

m_time.start();
Expand Down Expand Up @@ -1062,7 +1069,7 @@ LoggerTimingHelper::~LoggerTimingHelper()
else
message = QString(QLatin1String("\"%1\" finished in ")).arg(m_block);

int elapsed = m_time.elapsed();
qint64 elapsed = m_time.elapsed();
if (elapsed >= 10000 && m_timingMode == Logger::TimingAuto)
message += QString(QLatin1String("%1 s.")).arg(elapsed / 1000);
else
Expand Down
4 changes: 4 additions & 0 deletions src/RollingFileAppender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ void RollingFileAppender::computeRollOverTime()
break;
default:
Q_ASSERT_X(false, "DailyRollingFileAppender::computeInterval()", "Invalid datePattern constant");
#if QT_VERSION >= 0x060000
m_rollOverTime = QDateTime::fromSecsSinceEpoch(0);
#else
m_rollOverTime = QDateTime::fromTime_t(0);
#endif
}

m_rollOverSuffix = start.toString(m_datePatternString);
Expand Down