From 3ee63fed9cb6e063e3ac0fc0d9763fafd85df7e2 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Thu, 28 Jan 2021 20:55:37 +0100 Subject: ecm_qt_declare_logging_category: support target arg to append source file to --- modules/ECMQtDeclareLoggingCategory.cmake | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'modules/ECMQtDeclareLoggingCategory.cmake') diff --git a/modules/ECMQtDeclareLoggingCategory.cmake b/modules/ECMQtDeclareLoggingCategory.cmake index 720a5013..a6562333 100644 --- a/modules/ECMQtDeclareLoggingCategory.cmake +++ b/modules/ECMQtDeclareLoggingCategory.cmake @@ -12,7 +12,7 @@ # # :: # -# ecm_qt_declare_logging_category( +# ecm_qt_declare_logging_category( # HEADER # IDENTIFIER # CATEGORY_NAME @@ -23,11 +23,15 @@ # ) # # A header file, ````, will be generated along with a corresponding -# source file, which will be added to ````. These will provide a -# QLoggingCategory category that can be referred to from C++ code using -# ````, and from the logging configuration using +# source file. These will provide a QLoggingCategory category that can be referred +# to from C++ code using ````, and from the logging configuration using # ````. # +# The generated source file will be added to the variable with the name +# ````. If the given argument is a target though, instead both the +# generated header file and the generated source file will be added to the target as +# private sources (since 5.80). +# # If ```` is not absolute, it will be taken relative to the current # binary directory. # @@ -265,9 +269,13 @@ function(ecm_qt_declare_logging_category sources_var) configure_file("${_ECM_QT_DECLARE_LOGGING_CATEGORY_TEMPLATE_CPP}" "${cpp_filename}") configure_file("${_ECM_QT_DECLARE_LOGGING_CATEGORY_TEMPLATE_H}" "${ARG_HEADER}") - set(sources "${${sources_var}}") - list(APPEND sources "${cpp_filename}") - set(${sources_var} "${sources}" PARENT_SCOPE) + if(TARGET ${sources_var}) + target_sources(${sources_var} PRIVATE ${cpp_filename} "${ARG_HEADER}") + else() + set(sources "${${sources_var}}") + list(APPEND sources "${cpp_filename}") + set(${sources_var} "${sources}" PARENT_SCOPE) + endif() # note data in global properties if (ARG_EXPORT) -- cgit v1.2.1