diff --git a/cmake/modules/KDevelopMacrosInternal.cmake b/cmake/modules/KDevelopMacrosInternal.cmake --- a/cmake/modules/KDevelopMacrosInternal.cmake +++ b/cmake/modules/KDevelopMacrosInternal.cmake @@ -5,6 +5,8 @@ # # add_compile_flag_if_supported( [CXX_ONLY]) # add_target_compile_flag_if_supported( ) +# declare_qt_logging_category( HEADER IDENTIFIER CATEGORY_NAME EXPORT DESCRIPTION ) +# install_qt_logging_categories(EXPORT FILE ) # #============================================================================= # Copyright 2018 Friedrich W. H. Kossebau @@ -57,3 +59,124 @@ target_compile_options(${_target} ${_scope} "${_flag}") endif() endfunction() + + +# declare_qt_logging_category( HEADER IDENTIFIER CATEGORY_NAME EXPORT DESCRIPTION ) +# +# Example: +# declare_qt_logging_category(Foo_LIB_SRCS +# HEADER debug.h +# IDENTIFIER DOCUMENTATION +# CATEGORY_NAME "bar.foo" +# DESCRIPTION "The foo of bar" +# EXPORT BarCategories +# ) +macro(declare_qt_logging_category _sources) + set(options ) + set(oneValueArgs HEADER IDENTIFIER CATEGORY_NAME EXPORT DESCRIPTION) + set(multiValueArgs) + + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT DEFINED ARGS_HEADER) + message(FATAL_ERROR "HEADER needs to be defined when calling declare_qt_logging_category().") + endif() + if(NOT DEFINED ARGS_IDENTIFIER) + message(FATAL_ERROR "IDENTIFIER needs to be defined when calling declare_qt_logging_category().") + endif() + if(NOT DEFINED ARGS_CATEGORY_NAME) + message(FATAL_ERROR "CATEGORY_NAME needs to be defined when calling declare_qt_logging_category().") + endif() + if(NOT DEFINED ARGS_DESCRIPTION) + message(FATAL_ERROR "DESCRIPTION needs to be defined when calling declare_qt_logging_category().") + endif() + + ecm_qt_declare_logging_category(${_sources} + HEADER ${ARGS_HEADER} + IDENTIFIER ${ARGS_IDENTIFIER} + CATEGORY_NAME ${ARGS_CATEGORY_NAME} + ) + + # Nasty hack: we create a target just to store all the category data in some build-system global object + # which then can be accessed from other places like install_qt_logging_categories(). + # we also create it here on first usage, to spare some additional call. + # Better idea how to solve that welcome + set(_targetname "qt_logging_category_${ARGS_EXPORT}") + if (NOT TARGET ${_targetname}) + add_custom_target(${_targetname}) + set(_categories ${ARGS_CATEGORY_NAME}) + else() + get_target_property(_value ${_targetname} CATEGORIES) + set(_categories "${_value};${ARGS_CATEGORY_NAME}") + endif() + set_property(TARGET ${_targetname} PROPERTY CATEGORIES "${_categories}") + set_property(TARGET ${_targetname} PROPERTY "IDENTIFIER_${ARGS_CATEGORY_NAME}" "${ARGS_IDENTIFIER}") + set_property(TARGET ${_targetname} PROPERTY "DESCRIPTION_${ARGS_CATEGORY_NAME}" "${ARGS_DESCRIPTION}") +endmacro() + + +# install_qt_logging_categories(EXPORT FILE ) +# +# Needs to be called after the last declare_qt_logging_category call which uses the same EXPORT name. +# +# Example: +# install_qt_logging_categories( +# EXPORT KDevPlatformCategories +# FILE kdevplatform.test.categories +# ) +function(install_qt_logging_categories) + set(options ) + set(oneValueArgs FILE EXPORT) + set(multiValueArgs) + + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT DEFINED ARGS_FILE) + message(FATAL_ERROR "FILE needs to be defined when calling install_qt_logging_categories().") + endif() + + if(NOT DEFINED ARGS_EXPORT) + message(FATAL_ERROR "EXPORT needs to be defined when calling install_qt_logging_categories().") + endif() + + set(_targetname "qt_logging_category_${ARGS_EXPORT}") + if (NOT TARGET ${_targetname}) + message(FATAL_ERROR "${ARGS_EXPORT} is an unknown qt logging category export name.") + endif() + + get_target_property(_categories ${_targetname} CATEGORIES) + list(SORT _categories) + + set(_content +"# KDebugSettings data file +# This file was generated by install_qt_logging_categories(). DO NOT EDIT! + +") + + foreach(_category IN LISTS _categories) + get_target_property(_description ${_targetname} "DESCRIPTION_${_category}") + + # Format: + # lognamedescription + string(APPEND _content "${_category} ${_description}\n") + + # TODO: support newer not backward-compatible format as supported by kdebugsettings 18.12 + # Format: + # lognamedescription(optional DEFAULT_SEVERITY [DEFAULT_CATEGORY] as WARNING/DEBUG/INFO/CRITICAL) optional IDENTIFIER [...]) + # example: lognamedescriptionDEFAULT_SEVERITY[DEBUG]IDENTIFIER[foo] + # Needs idea how to ensure that at runtime kdebugsettings is min KA 18.12 + endforeach() + + if (NOT IS_ABSOLUTE ${ARGS_FILE}) + set(ARGS_FILE "${CMAKE_CURRENT_BINARY_DIR}/${ARGS_FILE}") + endif() + file(GENERATE + OUTPUT "${ARGS_FILE}" + CONTENT "${_content}" + ) + + install( + FILES "${ARGS_FILE}" + DESTINATION ${KDE_INSTALL_CONFDIR} + ) +endfunction() diff --git a/kdevplatform/CMakeLists.txt b/kdevplatform/CMakeLists.txt --- a/kdevplatform/CMakeLists.txt +++ b/kdevplatform/CMakeLists.txt @@ -89,4 +89,7 @@ FILE KDevPlatformTargets.cmake ) # kdebugsettings file -install( FILES kdevplatform.categories DESTINATION ${KDE_INSTALL_CONFDIR} ) +install_qt_logging_categories( + EXPORT KDevPlatformCategories + FILE kdevplatform.categories +) diff --git a/kdevplatform/debugger/CMakeLists.txt b/kdevplatform/debugger/CMakeLists.txt --- a/kdevplatform/debugger/CMakeLists.txt +++ b/kdevplatform/debugger/CMakeLists.txt @@ -20,10 +20,12 @@ framestack/framestackmodel.cpp framestack/framestackwidget.cpp ) -ecm_qt_declare_logging_category(KDevPlatformDebugger_LIB_SRCS +declare_qt_logging_category(KDevPlatformDebugger_LIB_SRCS HEADER debug.h IDENTIFIER DEBUGGER CATEGORY_NAME "kdevplatform.debugger" + DESCRIPTION "KDevPlatform lib: debugger" + EXPORT KDevPlatformCategories ) kdevplatform_add_library(KDevPlatformDebugger SOURCES ${KDevPlatformDebugger_LIB_SRCS}) target_link_libraries(KDevPlatformDebugger diff --git a/kdevplatform/documentation/CMakeLists.txt b/kdevplatform/documentation/CMakeLists.txt --- a/kdevplatform/documentation/CMakeLists.txt +++ b/kdevplatform/documentation/CMakeLists.txt @@ -21,10 +21,12 @@ documentationview.cpp ) -ecm_qt_declare_logging_category(KDevPlatformDocumentation_LIB_SRCS +declare_qt_logging_category(KDevPlatformDocumentation_LIB_SRCS HEADER debug.h IDENTIFIER DOCUMENTATION CATEGORY_NAME "kdevplatform.documentation" + DESCRIPTION "KDevPlatform lib: documentation" + EXPORT KDevPlatformCategories ) ki18n_wrap_ui(KDevPlatformDocumentation_LIB_SRCS documentationfindwidget.ui) diff --git a/kdevplatform/kdevplatform.categories b/kdevplatform/kdevplatform.categories deleted file mode 100644 --- a/kdevplatform/kdevplatform.categories +++ /dev/null @@ -1,16 +0,0 @@ -# KDebugSettings data file -# Format: -# lognamedescription - -# Libraries -kdevplatform.debugger KDevPlatform lib: debugger -kdevplatform.documentation KDevPlatform lib: documentation -kdevplatform.filemanager KDevPlatform lib: filemanager -kdevplatform.language KDevPlatform lib: language -kdevplatform.outputview KDevPlatform lib: outputview -kdevplatform.project KDevPlatform lib: project -kdevplatform.serialization KDevPlatform lib: serialization -kdevplatform.shell KDevPlatform lib: shell -kdevplatform.sublime KDevPlatform lib: sublime -kdevplatform.util KDevPlatform lib: util -kdevplatform.vcs KDevPlatform lib: vcs diff --git a/kdevplatform/language/CMakeLists.txt b/kdevplatform/language/CMakeLists.txt --- a/kdevplatform/language/CMakeLists.txt +++ b/kdevplatform/language/CMakeLists.txt @@ -170,10 +170,12 @@ codegen/archivetemplateloader.cpp ) -ecm_qt_declare_logging_category(KDevPlatformLanguage_LIB_SRCS +declare_qt_logging_category(KDevPlatformLanguage_LIB_SRCS HEADER debug.h IDENTIFIER LANGUAGE CATEGORY_NAME "kdevplatform.language" + DESCRIPTION "KDevPlatform lib: language" + EXPORT KDevPlatformCategories ) ki18n_wrap_ui(KDevPlatformLanguage_LIB_SRCS diff --git a/kdevplatform/outputview/CMakeLists.txt b/kdevplatform/outputview/CMakeLists.txt --- a/kdevplatform/outputview/CMakeLists.txt +++ b/kdevplatform/outputview/CMakeLists.txt @@ -12,10 +12,12 @@ outputjob.cpp outputexecutejob.cpp ) -ecm_qt_declare_logging_category(outputviewinterfaces_LIB_SRCS +declare_qt_logging_category(outputviewinterfaces_LIB_SRCS HEADER debug.h IDENTIFIER OUTPUTVIEW CATEGORY_NAME "kdevplatform.outputview" + DESCRIPTION "KDevPlatform lib: outputview" + EXPORT KDevPlatformCategories ) kdevplatform_add_library(KDevPlatformOutputView SOURCES ${outputviewinterfaces_LIB_SRCS}) target_link_libraries(KDevPlatformOutputView diff --git a/kdevplatform/project/CMakeLists.txt b/kdevplatform/project/CMakeLists.txt --- a/kdevplatform/project/CMakeLists.txt +++ b/kdevplatform/project/CMakeLists.txt @@ -10,7 +10,6 @@ projectbuildsetmodel.cpp projectitemlineedit.cpp helper.cpp - debug.cpp projectproxymodel.cpp abstractfilemanagerplugin.cpp filemanagerlistjob.cpp @@ -23,6 +22,22 @@ widgets/dependencieswidget.cpp ) +declare_qt_logging_category(KDevPlatformProject_LIB_SRCS + HEADER debug_project.h + IDENTIFIER PROJECT + CATEGORY_NAME "kdevplatform.project" + DESCRIPTION "KDevPlatform lib: project" + EXPORT KDevPlatformCategories +) + +declare_qt_logging_category(KDevPlatformProject_LIB_SRCS + HEADER debug_filemanager.h + IDENTIFIER FILEMANAGER + CATEGORY_NAME "kdevplatform.filemanager" + DESCRIPTION "KDevPlatform lib: filemanager" + EXPORT KDevPlatformCategories +) + ki18n_wrap_ui( KDevPlatformProject_LIB_SRCS widgets/dependencieswidget.ui) kdevplatform_add_library(KDevPlatformProject SOURCES ${KDevPlatformProject_LIB_SRCS}) diff --git a/kdevplatform/project/debug.h b/kdevplatform/project/debug.h --- a/kdevplatform/project/debug.h +++ b/kdevplatform/project/debug.h @@ -20,8 +20,7 @@ #ifndef KDEVPLATFORM_PROJECT_DEBUG_H #define KDEVPLATFORM_PROJECT_DEBUG_H -#include -Q_DECLARE_LOGGING_CATEGORY(PROJECT) -Q_DECLARE_LOGGING_CATEGORY(FILEMANAGER) +#include +#include #endif diff --git a/kdevplatform/project/debug.cpp b/kdevplatform/project/debug.cpp deleted file mode 100644 --- a/kdevplatform/project/debug.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * This file is part of KDevelop - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library 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. - */ - -#include "debug.h" - -// TODO: ecm_qt_declare_logging_category only supports one category -// so generate two separate files with a wrapper debug.h, or have code include explicit matching header? -const QtMsgType defaultMsgType = QtInfoMsg; -Q_LOGGING_CATEGORY(PROJECT, "kdevplatform.project", defaultMsgType) -Q_LOGGING_CATEGORY(FILEMANAGER, "kdevplatform.filemanager", defaultMsgType) diff --git a/kdevplatform/serialization/CMakeLists.txt b/kdevplatform/serialization/CMakeLists.txt --- a/kdevplatform/serialization/CMakeLists.txt +++ b/kdevplatform/serialization/CMakeLists.txt @@ -7,10 +7,12 @@ referencecounting.cpp ) -ecm_qt_declare_logging_category(KDevPlatformSerialization_LIB_SRCS +declare_qt_logging_category(KDevPlatformSerialization_LIB_SRCS HEADER debug.h IDENTIFIER SERIALIZATION CATEGORY_NAME "kdevplatform.serialization" + DESCRIPTION "KDevPlatform lib: serialization" + EXPORT KDevPlatformCategories ) kdevplatform_add_library(KDevPlatformSerialization SOURCES ${KDevPlatformSerialization_LIB_SRCS}) diff --git a/kdevplatform/shell/CMakeLists.txt b/kdevplatform/shell/CMakeLists.txt --- a/kdevplatform/shell/CMakeLists.txt +++ b/kdevplatform/shell/CMakeLists.txt @@ -96,10 +96,12 @@ ) endif() -ecm_qt_declare_logging_category(KDevPlatformShell_LIB_SRCS +declare_qt_logging_category(KDevPlatformShell_LIB_SRCS HEADER debug.h IDENTIFIER SHELL CATEGORY_NAME "kdevplatform.shell" + DESCRIPTION "KDevPlatform lib: shell" + EXPORT KDevPlatformCategories ) kconfig_add_kcfg_files(KDevPlatformShell_LIB_SRCS diff --git a/kdevplatform/sublime/CMakeLists.txt b/kdevplatform/sublime/CMakeLists.txt --- a/kdevplatform/sublime/CMakeLists.txt +++ b/kdevplatform/sublime/CMakeLists.txt @@ -28,10 +28,12 @@ idealdockwidget.cpp idealbuttonbarwidget.cpp ) -ecm_qt_declare_logging_category(sublime_LIB_SRCS +declare_qt_logging_category(sublime_LIB_SRCS HEADER debug.h IDENTIFIER SUBLIME CATEGORY_NAME "kdevplatform.sublime" + DESCRIPTION "KDevPlatform lib: sublime" + EXPORT KDevPlatformCategories ) kdevplatform_add_library(KDevPlatformSublime SOURCES ${sublime_LIB_SRCS}) target_link_libraries(KDevPlatformSublime diff --git a/kdevplatform/util/CMakeLists.txt b/kdevplatform/util/CMakeLists.txt --- a/kdevplatform/util/CMakeLists.txt +++ b/kdevplatform/util/CMakeLists.txt @@ -45,10 +45,12 @@ add_subdirectory(tests) endif() -ecm_qt_declare_logging_category(KDevPlatformUtil_LIB_SRCS +declare_qt_logging_category(KDevPlatformUtil_LIB_SRCS HEADER debug.h IDENTIFIER UTIL CATEGORY_NAME "kdevplatform.util" + DESCRIPTION "KDevPlatform lib: util" + EXPORT KDevPlatformCategories ) ki18n_wrap_ui(KDevPlatformUtil_LIB_SRCS ${KDevPlatformUtil_LIB_US}) diff --git a/kdevplatform/vcs/CMakeLists.txt b/kdevplatform/vcs/CMakeLists.txt --- a/kdevplatform/vcs/CMakeLists.txt +++ b/kdevplatform/vcs/CMakeLists.txt @@ -46,10 +46,12 @@ interfaces/ipatchsource.cpp ) -ecm_qt_declare_logging_category(KDevPlatformVcs_LIB_SRCS +declare_qt_logging_category(KDevPlatformVcs_LIB_SRCS HEADER debug.h IDENTIFIER VCS CATEGORY_NAME "kdevplatform.vcs" + DESCRIPTION "KDevPlatform lib: vcs" + EXPORT KDevPlatformCategories ) ki18n_wrap_ui(KDevPlatformVcs_LIB_SRCS ${KDevPlatformVcs_UIS})