summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmGeneratorTarget.cxx36
-rw-r--r--Source/cmGeneratorTarget.h5
2 files changed, 24 insertions, 17 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index eb4ba90..c6b2718 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -8930,24 +8930,28 @@ bool cmGeneratorTarget::HaveFortranSources(std::string const& config) const
});
}
-bool cmGeneratorTarget::HaveCxx20ModuleSources() const
+bool cmGeneratorTarget::HaveCxx20ModuleSources(std::string* errorMessage) const
{
auto const& fs_names = this->Target->GetAllFileSetNames();
- return std::any_of(fs_names.begin(), fs_names.end(),
- [this](std::string const& name) -> bool {
- auto const* file_set = this->Target->GetFileSet(name);
- if (!file_set) {
- this->Makefile->IssueMessage(
- MessageType::INTERNAL_ERROR,
- cmStrCat("Target \"", this->Target->GetName(),
- "\" is tracked to have file set \"", name,
- "\", but it was not found."));
- return false;
- }
-
- auto const& fs_type = file_set->GetType();
- return fs_type == "CXX_MODULES"_s;
- });
+ return std::any_of(
+ fs_names.begin(), fs_names.end(),
+ [this, errorMessage](std::string const& name) -> bool {
+ auto const* file_set = this->Target->GetFileSet(name);
+ if (!file_set) {
+ auto message = cmStrCat("Target \"", this->Target->GetName(),
+ "\" is tracked to have file set \"", name,
+ "\", but it was not found.");
+ if (errorMessage) {
+ *errorMessage = std::move(message);
+ } else {
+ this->Makefile->IssueMessage(MessageType::INTERNAL_ERROR, message);
+ }
+ return false;
+ }
+
+ auto const& fs_type = file_set->GetType();
+ return fs_type == "CXX_MODULES"_s;
+ });
}
cmGeneratorTarget::Cxx20SupportLevel cmGeneratorTarget::HaveCxxModuleSupport(
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index a32e742..844454f 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -1264,8 +1264,11 @@ public:
*
* This will inspect the target itself to see if C++20 module
* support is expected to work based on its sources.
+ *
+ * If `errorMessage` is given a non-`nullptr`, any error message will be
+ * stored in it, otherwise the error will be reported directly.
*/
- bool HaveCxx20ModuleSources() const;
+ bool HaveCxx20ModuleSources(std::string* errorMessage = nullptr) const;
enum class Cxx20SupportLevel
{