From fb66a14da2a79780d67dd6b704a049f664208565 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Tue, 25 Nov 2025 15:32:25 -0500 Subject: [PATCH] cmExportFileGenerator: Allow other message types Export generators sometimes need to issue errors, and we had an existing API for that. However, in the future, it will be useful to issue non-fatal diagnostics as well. Rework the API to allow specifying the type of diagnostic to issue. --- Source/cmExportBuildFileGenerator.cxx | 8 +++----- Source/cmExportBuildFileGenerator.h | 3 ++- Source/cmExportFileGenerator.h | 9 ++++++++- Source/cmExportInstallFileGenerator.cxx | 6 +++--- Source/cmExportInstallFileGenerator.h | 3 ++- Source/cmExportTryCompileFileGenerator.cxx | 23 +++++++++++++++++++--- Source/cmExportTryCompileFileGenerator.h | 3 ++- 7 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 332a6c1d90..ee12b1d254 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -16,7 +16,6 @@ #include "cmList.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" -#include "cmMessageType.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmTarget.h" @@ -242,12 +241,11 @@ void cmExportBuildFileGenerator::ComplainAboutDuplicateTarget( this->ReportError(e.str()); } -void cmExportBuildFileGenerator::ReportError( - std::string const& errorMessage) const +void cmExportBuildFileGenerator::IssueMessage(MessageType type, + std::string const& message) const { this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage( - MessageType::FATAL_ERROR, errorMessage, - this->LG->GetMakefile()->GetBacktrace()); + type, message, this->LG->GetMakefile()->GetBacktrace()); } std::string cmExportBuildFileGenerator::InstallNameDir( diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h index 6b30815b9c..575d8e2149 100644 --- a/Source/cmExportBuildFileGenerator.h +++ b/Source/cmExportBuildFileGenerator.h @@ -86,7 +86,8 @@ protected: void ComplainAboutDuplicateTarget( std::string const& targetName) const override; - void ReportError(std::string const& errorMessage) const override; + void IssueMessage(MessageType type, + std::string const& message) const override; /** Fill in properties indicating built file locations. */ void SetImportLocationProperty(std::string const& config, diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index bae6b504a5..f53cba7529 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -13,6 +13,7 @@ #include #include "cmGeneratorExpression.h" +#include "cmMessageType.h" class cmExportSet; class cmGeneratorTarget; @@ -120,7 +121,13 @@ protected: cmGeneratorExpression::PreprocessContext preprocessRule, ImportPropertyMap& properties); - virtual void ReportError(std::string const& errorMessage) const = 0; + virtual void IssueMessage(MessageType type, + std::string const& message) const = 0; + + void ReportError(std::string const& errorMessage) const + { + this->IssueMessage(MessageType::FATAL_ERROR, errorMessage); + } struct ExportInfo { diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index db78ba7862..26ddaad089 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -335,11 +335,11 @@ void cmExportInstallFileGenerator::ComplainAboutDuplicateTarget( this->ReportError(e.str()); } -void cmExportInstallFileGenerator::ReportError( - std::string const& errorMessage) const +void cmExportInstallFileGenerator::IssueMessage( + MessageType type, std::string const& message) const { this->IEGen->GetLocalGenerator()->GetCMakeInstance()->IssueMessage( - MessageType::FATAL_ERROR, errorMessage, + type, message, this->IEGen->GetLocalGenerator()->GetMakefile()->GetBacktrace()); } diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h index 79dff1d243..60115640f8 100644 --- a/Source/cmExportInstallFileGenerator.h +++ b/Source/cmExportInstallFileGenerator.h @@ -94,7 +94,8 @@ protected: ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override; - void ReportError(std::string const& errorMessage) const override; + void IssueMessage(MessageType type, + std::string const& message) const override; /** Generate a per-configuration file for the targets. */ virtual bool GenerateImportFileConfig(std::string const& config); diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index 456e6b9453..9843bf7ecf 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -6,6 +6,7 @@ #include #include +#include #include "cmFileSet.h" #include "cmGenExContext.h" @@ -16,6 +17,7 @@ #include "cmList.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" @@ -31,10 +33,25 @@ cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator( gg->CreateImportedGenerationObjects(mf, targets, this->Exports); } -void cmExportTryCompileFileGenerator::ReportError( - std::string const& errorMessage) const +void cmExportTryCompileFileGenerator::IssueMessage( + MessageType type, std::string const& message) const { - cmSystemTools::Error(errorMessage); + switch (type) { + case MessageType::FATAL_ERROR: + case MessageType::AUTHOR_ERROR: + case MessageType::INTERNAL_ERROR: + case MessageType::DEPRECATION_ERROR: + cmSystemTools::Error(message); + break; + case MessageType::WARNING: + case MessageType::AUTHOR_WARNING: + case MessageType::DEPRECATION_WARNING: + cmSystemTools::Message(cmStrCat("CMake Warning: "_s, message), + "Warning"); + break; + default: + cmSystemTools::Message(message); + } } bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os) diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h index d9a8361381..00231ba6ff 100644 --- a/Source/cmExportTryCompileFileGenerator.h +++ b/Source/cmExportTryCompileFileGenerator.h @@ -30,7 +30,8 @@ protected: // Implement virtual methods from the superclass. void ComplainAboutDuplicateTarget( std::string const& /*targetName*/) const override {}; - void ReportError(std::string const& errorMessage) const override; + void IssueMessage(MessageType type, + std::string const& message) const override; bool GenerateMainFile(std::ostream& os) override;