Index: modules/ECMQtDeclareLoggingCategory.cmake =================================================================== --- modules/ECMQtDeclareLoggingCategory.cmake +++ modules/ECMQtDeclareLoggingCategory.cmake @@ -15,10 +15,10 @@ # Critical|Fatal>]) # # 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, which will be added to ```` (either a target or a +# list of source files). These will provide a QLoggingCategory category that +# can be referred to from C++ code using ````, and from the logging +# configuration using ````. # # If ```` is not absolute, it will be taken relative to the current # binary directory. @@ -129,7 +129,11 @@ 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}) + else() + set(sources "${${sources_var}}") + list(APPEND sources "${cpp_filename}") + set(${sources_var} "${sources}" PARENT_SCOPE) + endif() endfunction()