cmGlobalGenerator: give context about module queries

Some queries are merely investigating support in order to change
behavior. Let the method know so that any internal errors can be skipped
over.
This commit is contained in:
Ben Boeckel
2023-10-31 13:09:36 -04:00
committed by Brad King
parent 889aa0354a
commit 1f507580a1
5 changed files with 22 additions and 8 deletions

View File

@@ -9190,7 +9190,8 @@ void cmGeneratorTarget::CheckCxxModuleStatus(std::string const& config) const
// If the generator doesn't support modules at all, error that we have
// sources that require the support.
if (!this->GetGlobalGenerator()->CheckCxxModuleSupport()) {
if (!this->GetGlobalGenerator()->CheckCxxModuleSupport(
cmGlobalGenerator::CxxModuleSupportQuery::Expected)) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat(
@@ -9248,7 +9249,8 @@ bool cmGeneratorTarget::NeedCxxModuleSupport(std::string const& lang,
return false;
}
return this->HaveCxxModuleSupport(config) == Cxx20SupportLevel::Supported &&
this->GetGlobalGenerator()->CheckCxxModuleSupport();
this->GetGlobalGenerator()->CheckCxxModuleSupport(
cmGlobalGenerator::CxxModuleSupportQuery::Inspect);
}
bool cmGeneratorTarget::NeedDyndep(std::string const& lang,
@@ -9304,7 +9306,8 @@ bool cmGeneratorTarget::NeedDyndepForSource(std::string const& lang,
break;
}
bool haveGeneratorSupport =
this->GetGlobalGenerator()->CheckCxxModuleSupport();
this->GetGlobalGenerator()->CheckCxxModuleSupport(
cmGlobalGenerator::CxxModuleSupportQuery::Inspect);
auto const sfProp = sf->GetProperty("CXX_SCAN_FOR_MODULES");
if (sfProp.IsSet()) {
return sfProp.IsOn();

View File

@@ -156,7 +156,17 @@ public:
virtual bool InspectConfigTypeVariables() { return true; }
virtual bool CheckCxxModuleSupport() { return false; }
enum class CxxModuleSupportQuery
{
// Support is expected at the call site.
Expected,
// The call site is querying for support and handles problems by itself.
Inspect,
};
virtual bool CheckCxxModuleSupport(CxxModuleSupportQuery /*query*/)
{
return false;
}
virtual bool IsGNUMakeJobServerAware() const { return false; }

View File

@@ -882,13 +882,14 @@ bool cmGlobalNinjaGenerator::CheckLanguages(
return true;
}
bool cmGlobalNinjaGenerator::CheckCxxModuleSupport()
bool cmGlobalNinjaGenerator::CheckCxxModuleSupport(CxxModuleSupportQuery query)
{
if (this->NinjaSupportsDyndepsCxx) {
return true;
}
bool const diagnose = !this->DiagnosedCxxModuleNinjaSupport &&
!this->CMakeInstance->GetIsInTryCompile();
!this->CMakeInstance->GetIsInTryCompile() &&
query == CxxModuleSupportQuery::Expected;
if (diagnose) {
std::ostringstream e;
/* clang-format off */

View File

@@ -475,7 +475,7 @@ public:
bool IsSingleConfigUtility(cmGeneratorTarget const* target) const;
bool CheckCxxModuleSupport() override;
bool CheckCxxModuleSupport(CxxModuleSupportQuery query) override;
protected:
void Generate() override;

View File

@@ -48,7 +48,7 @@ public:
const char* GetAndroidApplicationTypeRevision() const override;
bool CheckCxxModuleSupport() override
bool CheckCxxModuleSupport(CxxModuleSupportQuery /*query*/) override
{
return this->SupportsCxxModuleDyndep();
}