diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ee2252..4cbb200 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,247 +1,252 @@ project(Libkolab) cmake_minimum_required(VERSION 2.6.4) option( BUILD_TESTS "Build the tests" TRUE ) option( BUILD_TOOLS "Build the tools" TRUE ) option( PYTHON_BINDINGS "Build bindings for python" FALSE ) option( PHP_BINDINGS "Build bindings for php" FALSE ) option( USE_LIBCALENDARING "Use libcalendaring" FALSE ) +option( INTERCEPT_DEBUGMESSAGES "Intercept Debugmessages" ${USE_LIBCALENDARING} ) set(Libkolab_MODULE_DIR ${Libkolab_SOURCE_DIR}/cmake/modules) set(CMAKE_MODULE_PATH ${Libkolab_MODULE_DIR}) # only available from cmake-2.8.0 if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 7) cmake_policy(SET CMP0012 NEW) endif() # only available from cmake-2.8.4 if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 7 AND ${CMAKE_PATCH_VERSION} GREATER 3) cmake_policy(SET CMP0017 NEW) endif() # Versioning # x.y.z scheme # Development versions are only x.y # # i.e. # 0.1 (0.1 development version towards 0.1.0) # 0.1.0 (first release) # 0.1.1 (patch release for 0.1.0) # 0.2 (0.2 development version towards 0.2.0) set(Libkolab_VERSION_MAJOR 0) set(Libkolab_VERSION_MINOR 6) # Enable the full x.y.z version only for release versions set(Libkolab_VERSION_PATCH 2) set(Libkolab_VERSION ${Libkolab_VERSION_MAJOR}.${Libkolab_VERSION_MINOR}.${Libkolab_VERSION_PATCH} ) #set(Libkolab_VERSION ${Libkolab_VERSION_MAJOR}.${Libkolab_VERSION_MINOR} ) set(Libkolab_VERSION_STRING ${CMAKE_PROJECT_NAME}-${Libkolab_VERSION}) # set up install directories. set(LIB_INSTALL_DIR lib${LIB_SUFFIX} CACHE STRING "The directories where to install libraries to") set(INCLUDE_INSTALL_DIR include CACHE STRING "The directory where to install headers to") set(INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/kolab) set(CMAKECONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/Libkolab ) # Make relative paths absolute (needed later on) foreach(p LIB INCLUDE CMAKECONFIG) set(var ${p}_INSTALL_DIR) if(NOT IS_ABSOLUTE "${${var}}") set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") endif() endforeach() include(MacroLogFeature) # Do the building find_package(Libkolabxml 1.1 REQUIRED) macro_log_feature(Libkolabxml_FOUND "Libkolabxml" "Kolab XML Format 3 serializing library" "http://git.kolab.org/libkolabxml/" TRUE "1.0" "Required for reading/writing Kolab XML Objects") find_package(Qt4 4.6.0 REQUIRED) if (USE_LIBCALENDARING) find_package(Libcalendaring) macro_log_feature(LIBCALENDARING_FOUND "Libcalendaring" "KDE Calendaring-Dependencies Library" "http://git.kolab.org/libcalendaring/" TRUE "" "Required if KDE libraries are not available.") else() find_package(KDE4 4.8 REQUIRED) find_package(KdepimLibs 4.8 REQUIRED) endif() find_package(SWIG) #Show summary of found libraries macro_display_feature_log() # add_definitions( -DKDEPIMLIBS_VERSION=((${KdepimLibs_VERSION_MAJOR}<<16)|(${KdepimLibs_VERSION_MINOR}<<8)|(${KDEPIMLIBS_VERSION_PATCH})) ) add_definitions( -DKDEPIMLIBS_VERSION_MAJOR=${KdepimLibs_VERSION_MAJOR} ) add_definitions( -DKDEPIMLIBS_VERSION_MINOR=${KdepimLibs_VERSION_MINOR} ) add_definitions( -DKDEPIMLIBS_VERSION_PATCH=${KdepimLibs_VERSION_PATCH} ) #Tag::GENERIC is only available at the moment at the kolab/integration branches if (KDEPIMLIBS_HAS_GENERIC_TAG) add_definitions( -DKDEPIMLIBS_HAS_GENERIC_TAG) endif() if("${KdepimLibs_VERSION}" VERSION_GREATER "4.8.40" OR USE_LIBCALENDARING) add_definitions(-DKDEPIMLIBS_VERSION_DEVEL) endif() if ("${KdepimLibs_VERSION}" VERSION_GREATER "4.11.52") add_definitions( -DLIBCALENDARING_DURATION_DECLARED) endif() if(CMAKE_COMPILER_IS_GNUCXX) if(NOT MINGW) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -DQT_NO_EXCEPTIONS -fno-common -Woverloaded-virtual -fno-threadsafe-statics -fvisibility=hidden -Werror=return-type -fvisibility-inlines-hidden -fexceptions -UQT_NO_EXCEPTIONS -g") endif() # message("${CMAKE_CXX_FLAGS}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DQT_NO_DEBUG") if (USE_LIBCALENDARING) set( KDE_INCLUDES ${Libcalendaring_INCLUDE_DIRS} ) set( KDE_LIBRARIES ${Libcalendaring_LIBRARIES} ) message("${Libcalendaring_INCLUDE_DIRS} ${Libcalendaring_LIBRARIES}") else() set( KDE_INCLUDES ${KDEPIMLIBS_INCLUDE_DIRS} ${KDE4_INCLUDES} ) set( KDE_LIBRARIES ${KDEPIMLIBS_KCALCORE_LIBS} ${KDEPIMLIBS_KABC_LIBS} ${KDEPIMLIBS_KMIME_LIBS} ${KDEPIMLIBS_AKONADI_LIBS} ${KDEPIMLIBS_AKONADI_NOTES_LIBS} ${KDEPIMLIBS_KCALUTILS_LIBS} ${KDEPIMLIBS_KPIMUTILS_LIBS} ${KDE4_KDECORE_LIBS} ${KDE4_KIO_LIBS} ) endif() find_package(Boost REQUIRED) include_directories( ${QT_INCLUDES} ${KDE_INCLUDES} ${CMAKE_BINARY_DIR} ${Boost_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/kolabformatV2 ${Libkolabxml_INCLUDES} ./ ) configure_file(libkolab-version.h.cmake "${CMAKE_BINARY_DIR}/libkolab-version.h" @ONLY) set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS}) set(CMAKE_REQUIRED_INCLUDES "/opt/devel/kolab/include/") # include(CheckIncludeFileCXX) # check_include_file_cxx(akonadi/tag.h HAVE_TAG_H) #check_include_file_cxx doesn't work for some reason, so we use find_path instead. #we have to make sure that we only search in KDE_INCLUDES though, to not accidentally include a system akonadi/tag.h #when we're searching for one in libcalendaring. find_path(HAVE_TAG_H akonadi/tag.h PATHS ${KDE_INCLUDES} NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH) find_path(HAVE_RELATION_H akonadi/relation.h PATHS ${KDE_INCLUDES} NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libkolab_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/libkolab_config.h) add_subdirectory(kolabformatV2) add_subdirectory(conversion) add_subdirectory(calendaring) add_subdirectory(icalendar) add_subdirectory(freebusy) if (BUILD_TOOLS) add_subdirectory(utils) endif() QT4_WRAP_CPP(CALENDARING_MOC calendaring/event.h) # QT4_WRAP_CPP(CONVERSION_MOC conversion/qtevent.h conversion/qtduration.h) set(KOLAB_SRCS kolabformat/kolabobject.cpp kolabformat/xmlobject.cpp kolabformat/formathelpers.cpp kolabformat/errorhandler.cpp kolabformat/v2helpers.cpp kolabformat/mimeobject.cpp mime/mimeutils.cpp ${CONVERSION_SRCS} ${kolabformatv2_SRCS} ${CALENDARING_SRCS} ${ICALENDAR_SRCS} ${CALENDARING_MOC} ${CONVERSION_MOC} ${FREEBUSY_SRCS} ) +if (INTERCEPT_DEBUGMESSAGES) + add_definitions( -DINTERCEPT_DEBUGMESSAGES ) +endif() + set(KOLAB_LINK_LIBRARIES ${Libkolabxml_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE_LIBRARIES} ) if (BUILD_TOOLS OR BUILD_TESTS) add_library(kolab_static STATIC ${KOLAB_SRCS}) target_link_libraries(kolab_static ${KOLAB_LINK_LIBRARIES}) endif() if(BUILD_TESTS) enable_testing() add_subdirectory(tests) endif(BUILD_TESTS) add_library(kolab SHARED ${KOLAB_SRCS}) target_link_libraries(kolab ${KOLAB_LINK_LIBRARIES}) set_target_properties(kolab PROPERTIES VERSION ${Libkolab_VERSION} SOVERSION ${Libkolab_VERSION_MAJOR} ) install(TARGETS kolab EXPORT LibkolabExport RUNTIME DESTINATION ${BIN_INSTALL_DIR} LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR} ) install(FILES kolab_export.h kolabformat/kolabdefinitions.h kolabformat/formathelpers.h kolabformat/kolabobject.h kolabformat/errorhandler.h kolabformat/xmlobject.h kolabformat/mimeobject.h ${CMAKE_CURRENT_BINARY_DIR}/libkolab_config.h conversion/kcalconversion.h conversion/kabcconversion.h conversion/commonconversion.h freebusy/freebusy.h DESTINATION ${INCLUDE_INSTALL_DIR} ) #Get the include directory relative to CMAKECONFIG_INSTALL_DIR file(RELATIVE_PATH REL_INCLUDE_DIR "${CMAKECONFIG_INSTALL_DIR}" "${INCLUDE_INSTALL_DIR}") #Assemble the full relative path. This will be used in the LibkolabConfig.cmake, which will be installed in CMAKECONFIG_INSTALL_DIR set(CONF_INCLUDE_DIRS "\${Libkolab_CMAKE_DIR}/${REL_INCLUDE_DIR}") install(EXPORT LibkolabExport DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE LibkolabTargets.cmake ) configure_file(${Libkolab_MODULE_DIR}/LibkolabConfig.cmake.in ${Libkolab_BINARY_DIR}/LibkolabConfig.cmake @ONLY ) configure_file(${Libkolab_MODULE_DIR}/LibkolabConfigVersion.cmake.in ${Libkolab_BINARY_DIR}/LibkolabConfigVersion.cmake @ONLY ) # Install these two files into the same directory as the generated exports-file. install(FILES ${Libkolab_BINARY_DIR}/LibkolabConfig.cmake ${Libkolab_BINARY_DIR}/LibkolabConfigVersion.cmake DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) include(SWIGUtils) if(PYTHON_BINDINGS) generatePythonBindings(shared shared.i) add_subdirectory(kolabformat/python) endif(PYTHON_BINDINGS) if(PHP_BINDINGS) generatePHPBindings(kolabshared shared.i) generatePHPBindings(dummy dummy.i) add_subdirectory(kolabformat/php) endif(PHP_BINDINGS) diff --git a/kolabformat/errorhandler.cpp b/kolabformat/errorhandler.cpp index 91021f4..5a25b52 100644 --- a/kolabformat/errorhandler.cpp +++ b/kolabformat/errorhandler.cpp @@ -1,138 +1,161 @@ /* * Copyright (C) 2012 Christian Mollekopf * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "errorhandler.h" #include #include #include #include #include #include +#ifdef INTERCEPT_DEBUGMESSAGES + +void interceptDebugMsgs(QtMsgType type, const char *msg) +{ + switch (type) { + case QtFatalMsg: + abort(); + default: + break; + } +} + +struct Initializer { + Initializer() + { + qInstallMsgHandler(interceptDebugMsgs); + } +}; + +static Initializer initializer; + +#endif + QDebug operator<<(QDebug dbg, const std::string &s) { dbg.nospace() << QString::fromStdString(s); return dbg.space(); } namespace Kolab { DebugStream::DebugStream() : QIODevice() { open(WriteOnly); } DebugStream::~DebugStream(){} qint64 DebugStream::writeData(const char *data, qint64 len) { const QByteArray buf = QByteArray::fromRawData(data, len); // qt_message_output(QtDebugMsg, buf.trimmed().constData()); ErrorHandler::instance().addError(m_severity, buf, m_location); return len; } QMutex mutex; void logMessage(const QString &message, const QString &file, int line, ErrorHandler::Severity s) { ErrorHandler::instance().addError(s, message, file+" "+QString::number(line)); } ErrorHandler::ErrorHandler() : m_worstError(Debug), m_debugStream(new DebugStream) { }; QDebug ErrorHandler::debugStream(ErrorHandler::Severity severity, int line, const char* file) { QMutexLocker locker(&mutex); ErrorHandler::instance().m_debugStream->m_location = QString(QString(file) + "(" + QString::number(line)+")"); ErrorHandler::instance().m_debugStream->m_severity = severity; return QDebug(ErrorHandler::instance().m_debugStream.data()); } void ErrorHandler::addError(ErrorHandler::Severity s, const QString& message, const QString &location) { QMutexLocker locker(&mutex); QString filename = location; if (!filename.split(QLatin1Char('/')).isEmpty()) { filename = filename.split(QLatin1Char('/')).last(); } const QString output = QTime::currentTime().toString(QLatin1String("(hh:mm:ss) ")) + filename + QLatin1String(":\t") + message; std::cout << output.toStdString() << std::endl; if (s == Debug) { return; } if (s > m_worstError) { m_worstError = s; m_worstErrorMessage = message; } m_errorQueue.append(Err(s, message, location)); } ErrorHandler::Severity ErrorHandler::error() const { QMutexLocker locker(&mutex); return m_worstError; } QString ErrorHandler::errorMessage() const { QMutexLocker locker(&mutex); return m_worstErrorMessage; } const QList< ErrorHandler::Err >& ErrorHandler::getErrors() const { QMutexLocker locker(&mutex); return m_errorQueue; } void ErrorHandler::clear() { QMutexLocker locker(&mutex); m_errorQueue.clear(); m_worstError = Debug; } void ErrorHandler::handleLibkolabxmlErrors() { switch (Kolab::error()) { case Kolab::Warning: instance().addError(ErrorHandler::Warning, QString::fromStdString(Kolab::errorMessage()), "libkolabxml"); break; case Kolab::Error: instance().addError(ErrorHandler::Error, QString::fromStdString(Kolab::errorMessage()), "libkolabxml"); break; case Kolab::Critical: instance().addError(ErrorHandler::Critical, QString::fromStdString(Kolab::errorMessage()), "libkolabxml"); break; default: //Do nothing, there is no message available in this case break; } } }