diff --git a/app_templates/cpp/CMake/cmake_kdevplugin/CMakeLists.txt b/app_templates/cpp/CMake/cmake_kdevplugin/CMakeLists.txt index 4e90afd524..bd3a127b5b 100644 --- a/app_templates/cpp/CMake/cmake_kdevplugin/CMakeLists.txt +++ b/app_templates/cpp/CMake/cmake_kdevplugin/CMakeLists.txt @@ -1,21 +1,25 @@ cmake_minimum_required(VERSION 3.0) project(%{APPNAME}) find_package(ECM "5.14.0" REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMQtDeclareLoggingCategory) include(FeatureSummary) find_package(KDevPlatform 5.2.40 REQUIRED) add_subdirectory(src) # kdebugsettings file -install(FILES %{APPNAMELC}.categories DESTINATION ${KDE_INSTALL_CONFDIR}) +if (ECM_VERSION VERSION_GREATER "5.58.0") + install(FILES %{APPNAMELC}.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) +else() + install(FILES %{APPNAMELC}.categories DESTINATION ${KDE_INSTALL_CONFDIR}) +endif() feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/cmake/modules/KDevelopMacrosInternal.cmake b/cmake/modules/KDevelopMacrosInternal.cmake index 13dd1f8733..c0c67741a6 100644 --- a/cmake/modules/KDevelopMacrosInternal.cmake +++ b/cmake/modules/KDevelopMacrosInternal.cmake @@ -1,302 +1,309 @@ # # KDevelop Private Macros # # The following macros are defined here: # # add_compile_flag_if_supported( [CXX_ONLY]) # add_target_compile_flag_if_supported( ) # declare_qt_logging_category( # TYPE LIBRARY|PLUGIN|APP [IDENTIFIER ] [CATEGORY_BASENAME ] # [HEADER ] [DESCRIPTION ]) # install_qt_logging_categories(TYPE LIBRARY|APP_PLUGIN) # #============================================================================= # Copyright 2018 Friedrich W. H. Kossebau # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # helper method to ensure consistent cache var names function(_varname_for_compile_flag_check_result _varname _flag ) string(REGEX REPLACE "[-=]" "_" _varname ${_flag}) string(TOUPPER ${_varname} _varname) set(_varname "KDEV_HAVE${_varname}" PARENT_SCOPE) endfunction() # add_compile_flag_if_supported( [CXX_ONLY]) # Optional argument CXX_ONLY to set the flag only for C++ code. # # Example: # add_compile_flag_if_supported(-Wsuggest-override CXX_ONLY) function(add_compile_flag_if_supported _flag) _varname_for_compile_flag_check_result(_varname ${_flag}) check_cxx_compiler_flag("${_flag}" "${_varname}") if (${${_varname}}) if("${ARGV1}" STREQUAL "CXX_ONLY") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}" PARENT_SCOPE) else() add_compile_options(${_flag}) endif() endif() endfunction() # add_target_compile_flag_if_supported( ) # # Example: # add_target_compile_flag_if_supported(kdevqtc-qmlsupport PRIVATE "-Wno-suggest-override") function(add_target_compile_flag_if_supported _target _scope _flag) _varname_for_compile_flag_check_result(_varname ${_flag}) check_cxx_compiler_flag("${_flag}" "${_varname}") if (${${_varname}}) target_compile_options(${_target} ${_scope} "${_flag}") endif() endfunction() # helper method # _declare_qt_logging_category( # HEADER IDENTIFIER CATEGORY_NAME # EXPORT DESCRIPTION ) # # Example: # _declare_qt_logging_category(Foo_LIB_SRCS # HEADER debug.h # IDENTIFIER FOO # 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() set(_platformlib_qt_logging_categories_export_name "KDevPlatformCategories") set(_app_plugin_qt_logging_categories_export_name "KDevelopCategories") # declare_qt_logging_category( # TYPE LIBRARY|PLUGIN|APP [IDENTIFIER ] [CATEGORY_BASENAME ] # [HEADER ] [DESCRIPTION ]) # # CATEGORY_BASENAME is unused of TYPE APP. # IDENTIFIER defaults to upper-case CATEGORY_BASENAME . # HEADER defaults to "debug.h" # DESCRIPTION defaults to CATEGORY_BASENAME . # # Example: # declare_qt_logging_category(Foo_LIB_SRCS # TYPE PLUGIN # HEADER foodebug.h # IDENTIFIER FOO # CATEGORY_BASENAME "foo" # ) macro(declare_qt_logging_category sources) set(options ) set(oneValueArgs HEADER IDENTIFIER CATEGORY_BASENAME DESCRIPTION TYPE) set(multiValueArgs) cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if(NOT DEFINED ARGS_TYPE) message(FATAL_ERROR "TYPE needs to be defined when calling declare_qt_logging_category().") endif() if(NOT DEFINED ARGS_IDENTIFIER) if(ARGS_TYPE STREQUAL "LIBRARY" OR ARGS_TYPE STREQUAL "PLUGIN") string(TOUPPER ${ARGS_CATEGORY_BASENAME} ARGS_IDENTIFIER) else() message(FATAL_ERROR "IDENTIFIER needs to be defined when calling declare_qt_logging_category().") endif() endif() if(NOT DEFINED ARGS_CATEGORY_BASENAME) if(ARGS_TYPE STREQUAL "LIBRARY" OR ARGS_TYPE STREQUAL "PLUGIN") message(FATAL_ERROR "CATEGORY_BASENAME needs to be defined when calling declare_qt_logging_category() with TYPE of LIBRARY or PLUGIN.") endif() endif() if(NOT DEFINED ARGS_HEADER) set(ARGS_HEADER debug.h) endif() if(NOT DEFINED ARGS_DESCRIPTION) set(ARGS_DESCRIPTION ${ARGS_CATEGORY_BASENAME}) endif() if(ARGS_TYPE STREQUAL "LIBRARY") _declare_qt_logging_category(${sources} HEADER ${ARGS_HEADER} IDENTIFIER ${ARGS_IDENTIFIER} CATEGORY_NAME "kdevplatform.${ARGS_CATEGORY_BASENAME}" DESCRIPTION "KDevPlatform lib: ${ARGS_DESCRIPTION}" EXPORT ${_platformlib_qt_logging_categories_export_name} ) elseif(ARGS_TYPE STREQUAL "PLUGIN") _declare_qt_logging_category(${sources} HEADER ${ARGS_HEADER} IDENTIFIER ${ARGS_IDENTIFIER} CATEGORY_NAME "kdevelop.plugins.${ARGS_CATEGORY_BASENAME}" DESCRIPTION "KDevelop plugin: ${ARGS_DESCRIPTION}" EXPORT ${_app_plugin_qt_logging_categories_export_name} ) elseif(ARGS_TYPE STREQUAL "APP") _declare_qt_logging_category(${sources} HEADER ${ARGS_HEADER} IDENTIFIER ${ARGS_IDENTIFIER} CATEGORY_NAME "kdevelop.app" DESCRIPTION "KDevelop app" EXPORT ${_app_plugin_qt_logging_categories_export_name} ) else() message(FATAL_ERROR "Unknown \"${ARGS_TYPE}\" with TYPE when calling declare_qt_logging_category().") endif() endmacro() # helper method # _install_qt_logging_categories(EXPORT FILE MACRONAME ) # # 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.categories # ) function(_install_qt_logging_categories) set(options ) set(oneValueArgs FILE EXPORT MACRONAME) 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() if(NOT DEFINED ARGS_MACRONAME) message(FATAL_ERROR "MACRONAME 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 ${ARGS_MACRONAME}(). 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} - ) + if (ECM_VERSION VERSION_GREATER "5.58.0") + install( + FILES "${ARGS_FILE}" + DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR} + ) + else() + install( + FILES "${ARGS_FILE}" + DESTINATION ${KDE_INSTALL_CONFDIR} + ) + endif() endfunction() # install_qt_logging_categories(TYPE LIBRARY|APP_PLUGIN) # # Needs to be called after the last declare_qt_logging_category call for the same TYPE(s). function(install_qt_logging_categories) set(options ) set(oneValueArgs TYPE) set(multiValueArgs) cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if(NOT DEFINED ARGS_TYPE) message(FATAL_ERROR "TYPE needs to be defined when calling install_qt_logging_categories().") endif() if(ARGS_TYPE STREQUAL "LIBRARY") _install_qt_logging_categories( EXPORT ${_platformlib_qt_logging_categories_export_name} FILE kdevplatform.categories MACRONAME install_qt_logging_categories ) elseif(ARGS_TYPE STREQUAL "APP_PLUGIN") _install_qt_logging_categories( EXPORT ${_app_plugin_qt_logging_categories_export_name} FILE kdevelop.categories MACRONAME install_qt_logging_categories ) else() message(FATAL_ERROR "Unknown \"${ARGS_TYPE}\" with TYPE when calling declare_qt_logging_category().") endif() endfunction()