Ninja: Refactor ninja feature detection

Check for features as soon as we know the ninja version.  Save the
results so we do not have to re-compare versions every time.
This commit is contained in:
Brad King 2016-09-21 14:22:41 -04:00
parent f0a23aa3db
commit 0488ae63ea
2 changed files with 18 additions and 6 deletions

View File

@ -473,6 +473,8 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm)
, UsingGCCOnWindows(false) , UsingGCCOnWindows(false)
, ComputingUnknownDependencies(false) , ComputingUnknownDependencies(false)
, PolicyCMP0058(cmPolicies::WARN) , PolicyCMP0058(cmPolicies::WARN)
, NinjaSupportsConsolePool(false)
, NinjaSupportsImplicitOuts(false)
{ {
#ifdef _WIN32 #ifdef _WIN32
cm->GetState()->SetWindowsShell(true); cm->GetState()->SetWindowsShell(true);
@ -558,9 +560,20 @@ void cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf)
cmSystemTools::RunSingleCommand(command, &version, CM_NULLPTR, CM_NULLPTR, cmSystemTools::RunSingleCommand(command, &version, CM_NULLPTR, CM_NULLPTR,
CM_NULLPTR, cmSystemTools::OUTPUT_NONE); CM_NULLPTR, cmSystemTools::OUTPUT_NONE);
this->NinjaVersion = cmSystemTools::TrimWhitespace(version); this->NinjaVersion = cmSystemTools::TrimWhitespace(version);
this->CheckNinjaFeatures();
} }
} }
void cmGlobalNinjaGenerator::CheckNinjaFeatures()
{
this->NinjaSupportsConsolePool = !cmSystemTools::VersionCompare(
cmSystemTools::OP_LESS, this->NinjaVersion.c_str(),
RequiredNinjaVersionForConsolePool().c_str());
this->NinjaSupportsImplicitOuts = !cmSystemTools::VersionCompare(
cmSystemTools::OP_LESS, this->NinjaVersion.c_str(),
this->RequiredNinjaVersionForImplicitOuts().c_str());
}
bool cmGlobalNinjaGenerator::CheckLanguages( bool cmGlobalNinjaGenerator::CheckLanguages(
std::vector<std::string> const& languages, cmMakefile* mf) const std::vector<std::string> const& languages, cmMakefile* mf) const
{ {
@ -1311,16 +1324,12 @@ std::string cmGlobalNinjaGenerator::ninjaCmd() const
bool cmGlobalNinjaGenerator::SupportsConsolePool() const bool cmGlobalNinjaGenerator::SupportsConsolePool() const
{ {
return !cmSystemTools::VersionCompare( return this->NinjaSupportsConsolePool;
cmSystemTools::OP_LESS, this->NinjaVersion.c_str(),
RequiredNinjaVersionForConsolePool().c_str());
} }
bool cmGlobalNinjaGenerator::SupportsImplicitOuts() const bool cmGlobalNinjaGenerator::SupportsImplicitOuts() const
{ {
return !cmSystemTools::VersionCompare( return this->NinjaSupportsImplicitOuts;
cmSystemTools::OP_LESS, this->NinjaVersion.c_str(),
this->RequiredNinjaVersionForImplicitOuts().c_str());
} }
void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)

View File

@ -355,6 +355,7 @@ protected:
private: private:
std::string GetEditCacheCommand() const CM_OVERRIDE; std::string GetEditCacheCommand() const CM_OVERRIDE;
void FindMakeProgram(cmMakefile* mf) CM_OVERRIDE; void FindMakeProgram(cmMakefile* mf) CM_OVERRIDE;
void CheckNinjaFeatures();
bool CheckLanguages(std::vector<std::string> const& languages, bool CheckLanguages(std::vector<std::string> const& languages,
cmMakefile* mf) const CM_OVERRIDE; cmMakefile* mf) const CM_OVERRIDE;
@ -441,6 +442,8 @@ private:
std::string NinjaCommand; std::string NinjaCommand;
std::string NinjaVersion; std::string NinjaVersion;
bool NinjaSupportsConsolePool;
bool NinjaSupportsImplicitOuts;
private: private:
void InitOutputPathPrefix(); void InitOutputPathPrefix();