Merge topic 'ninja-version-refactor'

a3c5ca96 cmGlobalNinjaGenerator: Save 'ninja' version very early
ed67f405 cmGlobalNinjaGenerator: Save path to 'ninja' tool very early
This commit is contained in:
Brad King 2015-11-06 14:58:09 -05:00 committed by CMake Topic Stage
commit 5bd78b0e99
2 changed files with 26 additions and 19 deletions

View File

@ -548,11 +548,11 @@ void cmGlobalNinjaGenerator::Generate()
{ {
// Check minimum Ninja version. // Check minimum Ninja version.
if (cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, if (cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
CurrentNinjaVersion().c_str(), this->NinjaVersion.c_str(),
RequiredNinjaVersion().c_str())) RequiredNinjaVersion().c_str()))
{ {
std::ostringstream msg; std::ostringstream msg;
msg << "The detected version of Ninja (" << this->CurrentNinjaVersion(); msg << "The detected version of Ninja (" << this->NinjaVersion;
msg << ") is less than the version of Ninja required by CMake ("; msg << ") is less than the version of Ninja required by CMake (";
msg << this->RequiredNinjaVersion() << ")."; msg << this->RequiredNinjaVersion() << ").";
this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, msg.str()); this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, msg.str());
@ -585,6 +585,23 @@ void cmGlobalNinjaGenerator::Generate()
this->CloseBuildFileStream(); this->CloseBuildFileStream();
} }
void cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf)
{
this->cmGlobalGenerator::FindMakeProgram(mf);
if (const char* ninjaCommand = mf->GetDefinition("CMAKE_MAKE_PROGRAM"))
{
this->NinjaCommand = ninjaCommand;
std::vector<std::string> command;
command.push_back(this->NinjaCommand);
command.push_back("--version");
std::string version;
cmSystemTools::RunSingleCommand(command,
&version, 0, 0, 0,
cmSystemTools::OUTPUT_NONE);
this->NinjaVersion = cmSystemTools::TrimWhitespace(version);
}
}
void cmGlobalNinjaGenerator void cmGlobalNinjaGenerator
::EnableLanguage(std::vector<std::string>const& langs, ::EnableLanguage(std::vector<std::string>const& langs,
cmMakefile* mf, cmMakefile* mf,
@ -1260,28 +1277,16 @@ std::string cmGlobalNinjaGenerator::ninjaCmd() const
{ {
cmLocalGenerator* lgen = this->LocalGenerators[0]; cmLocalGenerator* lgen = this->LocalGenerators[0];
if (lgen) { if (lgen) {
return lgen->ConvertToOutputFormat( return lgen->ConvertToOutputFormat(this->NinjaCommand,
lgen->GetMakefile()->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"), cmLocalGenerator::SHELL);
cmLocalGenerator::SHELL);
} }
return "ninja"; return "ninja";
} }
std::string cmGlobalNinjaGenerator::CurrentNinjaVersion() const
{
std::string version;
std::string command = ninjaCmd() + " --version";
cmSystemTools::RunSingleCommand(command.c_str(),
&version, 0, 0, 0,
cmSystemTools::OUTPUT_NONE);
return cmSystemTools::TrimWhitespace(version);
}
bool cmGlobalNinjaGenerator::SupportsConsolePool() const bool cmGlobalNinjaGenerator::SupportsConsolePool() const
{ {
return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
CurrentNinjaVersion().c_str(), this->NinjaVersion.c_str(),
RequiredNinjaVersionForConsolePool().c_str()) == false; RequiredNinjaVersionForConsolePool().c_str()) == false;
} }

View File

@ -305,7 +305,6 @@ public:
virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const; virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
std::string CurrentNinjaVersion() const;
// Ninja generator uses 'deps' and 'msvc_deps_prefix' introduced in 1.3 // Ninja generator uses 'deps' and 'msvc_deps_prefix' introduced in 1.3
static std::string RequiredNinjaVersion() { return "1.3"; } static std::string RequiredNinjaVersion() { return "1.3"; }
static std::string RequiredNinjaVersionForConsolePool() { return "1.5"; } static std::string RequiredNinjaVersionForConsolePool() { return "1.5"; }
@ -320,7 +319,7 @@ protected:
private: private:
virtual std::string GetEditCacheCommand() const; virtual std::string GetEditCacheCommand() const;
virtual void FindMakeProgram(cmMakefile* mf);
void OpenBuildFileStream(); void OpenBuildFileStream();
void CloseBuildFileStream(); void CloseBuildFileStream();
@ -392,6 +391,9 @@ private:
typedef std::map<std::string, cmGeneratorTarget*> TargetAliasMap; typedef std::map<std::string, cmGeneratorTarget*> TargetAliasMap;
TargetAliasMap TargetAliases; TargetAliasMap TargetAliases;
std::string NinjaCommand;
std::string NinjaVersion;
}; };
#endif // ! cmGlobalNinjaGenerator_h #endif // ! cmGlobalNinjaGenerator_h