try_compile: Tolerate compile features from non-enabled languages

Do not copy the list of enabled languages from the outer generator.
It is populated as languages are enabled inside the test project.

Fixes: #27684
This commit is contained in:
Joseph Snyder
2026-05-26 20:17:27 -04:00
committed by Brad King
parent bbab63839b
commit 243462fafe
7 changed files with 15 additions and 25 deletions
+1 -10
View File
@@ -2573,8 +2573,7 @@ std::unique_ptr<cmLocalGenerator> cmGlobalGenerator::CreateLocalGenerator(
return cm::make_unique<cmLocalGenerator>(this, mf);
}
void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator* gen,
cmMakefile* mf)
void cmGlobalGenerator::SetupTryCompile(cmGlobalGenerator* gen, cmMakefile* mf)
{
this->SetConfiguredFilesPath(gen);
this->TryCompileOuterMakefile = mf;
@@ -2582,15 +2581,7 @@ void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator* gen,
gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
this->GetCMakeInstance()->AddCacheEntry(
"CMAKE_MAKE_PROGRAM", make, "make program", cmStateEnums::FILEPATH);
// copy the enabled languages
this->GetCMakeInstance()->GetState()->SetEnabledLanguages(
gen->GetCMakeInstance()->GetState()->GetEnabledLanguages());
this->LanguagesReadyForTryCompile = gen->LanguagesReadyForTryCompile;
this->ExtensionToLanguage = gen->ExtensionToLanguage;
this->IgnoreExtensions = gen->IgnoreExtensions;
this->LanguageToOutputExtension = gen->LanguageToOutputExtension;
this->LanguageToLinkerPreference = gen->LanguageToLinkerPreference;
this->OutputExtensions = gen->OutputExtensions;
}
void cmGlobalGenerator::SetConfiguredFilesPath(cmGlobalGenerator* gen)
+1 -7
View File
@@ -240,11 +240,7 @@ public:
void ResolveLanguageCompiler(std::string const& lang, cmMakefile* mf,
bool optional) const;
/**
* Try to determine system information, get it from another generator
*/
void EnableLanguagesFromGenerator(cmGlobalGenerator* gen, cmMakefile* mf);
void SetupTryCompile(cmGlobalGenerator* gen, cmMakefile* mf);
/**
* Try running cmake and building a file. This is used for dynamically
* loaded commands, not as part of the usual build process.
@@ -870,8 +866,6 @@ private:
std::map<cmGeneratorTarget const*, size_t> TargetOrderIndex;
cmMakefile* TryCompileOuterMakefile;
// If you add a new map here, make sure it is copied
// in EnableLanguagesFromGenerator
std::map<std::string, bool> IgnoreExtensions;
std::set<std::string> LanguagesReadyForTryCompile;
std::set<std::string> LanguagesInProgress;
+1 -2
View File
@@ -3347,8 +3347,7 @@ int cmMakefile::TryCompile(std::string const& srcdir,
cm.SetCacheArgs(*cmakeArgs);
}
// to save time we pass the EnableLanguage info directly
cm.GetGlobalGenerator()->EnableLanguagesFromGenerator(
this->GetGlobalGenerator(), this);
cm.GetGlobalGenerator()->SetupTryCompile(this->GetGlobalGenerator(), this);
for (unsigned dc = 1; dc < cmDiagnostics::CategoryCount; ++dc) {
auto const category = static_cast<cmDiagnosticCategory>(dc);
if (this->GetDiagnosticAction(category) == cmDiagnostics::Ignore) {
-5
View File
@@ -390,11 +390,6 @@ std::vector<std::string> cmState::GetEnabledLanguages() const
return this->EnabledLanguages;
}
void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
{
this->EnabledLanguages = langs;
}
void cmState::ClearEnabledLanguages()
{
this->EnabledLanguages.clear();
-1
View File
@@ -159,7 +159,6 @@ public:
void SetLanguageEnabled(std::string const& l);
bool GetLanguageEnabled(std::string const& l) const;
std::vector<std::string> GetEnabledLanguages() const;
void SetEnabledLanguages(std::vector<std::string> const& langs);
void ClearEnabledLanguages();
bool GetIsGeneratorMultiConfig() const;
@@ -0,0 +1,11 @@
enable_language (C CXX)
include(CheckSourceCompiles)
add_library(cxx_iface INTERFACE IMPORTED)
target_compile_features(cxx_iface INTERFACE cxx_std_11)
set(CMAKE_REQUIRED_LIBRARIES cxx_iface)
check_source_compiles(C "int main() {return 0;}" SHOULD_BUILD)
if(NOT SHOULD_BUILD)
message(SEND_ERROR "Test fail for valid C source.")
endif()
@@ -3,6 +3,7 @@ include(RunCMake)
run_cmake(NotEnabledLanguage)
run_cmake(NonExistentLanguage)
run_cmake(UnknownArgument)
run_cmake(MultipleLanguages)
run_cmake(CheckCSourceCompiles)
run_cmake(CheckCXXSourceCompiles)