2011-11-11 05:00:49 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
|
|
|
|
Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2013-06-07 18:26:03 +00:00
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmGeneratorExpressionEvaluationFile.h"
|
|
|
|
#include "cmGeneratorTarget.h"
|
2011-11-11 05:00:49 +00:00
|
|
|
#include "cmGlobalNinjaGenerator.h"
|
|
|
|
#include "cmLocalNinjaGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmVersion.h"
|
2015-03-20 20:43:21 +00:00
|
|
|
#include "cmAlgorithms.h"
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2013-03-10 10:36:57 +00:00
|
|
|
#include <algorithm>
|
2014-03-11 16:37:26 +00:00
|
|
|
#include <assert.h>
|
2013-03-10 10:36:57 +00:00
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja";
|
|
|
|
const char* cmGlobalNinjaGenerator::NINJA_RULES_FILE = "rules.ninja";
|
|
|
|
const char* cmGlobalNinjaGenerator::INDENT = " ";
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::Indent(std::ostream& os, int count)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < count; ++i)
|
|
|
|
os << cmGlobalNinjaGenerator::INDENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteDivider(std::ostream& os)
|
|
|
|
{
|
|
|
|
os
|
|
|
|
<< "# ======================================"
|
|
|
|
<< "=======================================\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteComment(std::ostream& os,
|
|
|
|
const std::string& comment)
|
|
|
|
{
|
|
|
|
if (comment.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string replace = comment;
|
|
|
|
std::string::size_type lpos = 0;
|
|
|
|
std::string::size_type rpos;
|
2012-06-10 18:20:29 +00:00
|
|
|
os << "\n#############################################\n";
|
2011-11-11 05:00:49 +00:00
|
|
|
while((rpos = replace.find('\n', lpos)) != std::string::npos)
|
|
|
|
{
|
|
|
|
os << "# " << replace.substr(lpos, rpos - lpos) << "\n";
|
|
|
|
lpos = rpos + 1;
|
|
|
|
}
|
2012-06-10 18:20:29 +00:00
|
|
|
os << "# " << replace.substr(lpos) << "\n\n";
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsIdentChar(char c)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
('a' <= c && c <= 'z') ||
|
|
|
|
('+' <= c && c <= '9') || // +,-./ and numbers
|
|
|
|
('A' <= c && c <= 'Z') ||
|
2012-02-18 19:04:55 +00:00
|
|
|
(c == '_') || (c == '$') || (c == '\\') ||
|
|
|
|
(c == ' ') || (c == ':');
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmGlobalNinjaGenerator::EncodeIdent(const std::string &ident,
|
|
|
|
std::ostream &vars) {
|
|
|
|
if (std::find_if(ident.begin(), ident.end(),
|
|
|
|
std::not1(std::ptr_fun(IsIdentChar))) != ident.end()) {
|
|
|
|
static unsigned VarNum = 0;
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream names;
|
2011-11-11 05:00:49 +00:00
|
|
|
names << "ident" << VarNum++;
|
|
|
|
vars << names.str() << " = " << ident << "\n";
|
|
|
|
return "$" + names.str();
|
|
|
|
} else {
|
2012-02-18 19:04:55 +00:00
|
|
|
std::string result = ident;
|
|
|
|
cmSystemTools::ReplaceString(result, " ", "$ ");
|
|
|
|
cmSystemTools::ReplaceString(result, ":", "$:");
|
|
|
|
return result;
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string &lit)
|
|
|
|
{
|
|
|
|
std::string result = lit;
|
|
|
|
cmSystemTools::ReplaceString(result, "$", "$$");
|
2013-03-09 11:04:16 +00:00
|
|
|
cmSystemTools::ReplaceString(result, "\n", "$\n");
|
2011-11-11 05:00:49 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-02-19 01:50:53 +00:00
|
|
|
std::string cmGlobalNinjaGenerator::EncodePath(const std::string &path)
|
|
|
|
{
|
|
|
|
std::string result = path;
|
|
|
|
#ifdef _WIN32
|
2012-06-05 20:39:42 +00:00
|
|
|
if(UsingMinGW)
|
|
|
|
cmSystemTools::ReplaceString(result, "\\", "/");
|
|
|
|
else
|
|
|
|
cmSystemTools::ReplaceString(result, "/", "\\");
|
2012-02-19 01:50:53 +00:00
|
|
|
#endif
|
|
|
|
return EncodeLiteral(result);
|
|
|
|
}
|
|
|
|
|
2013-10-18 10:59:47 +00:00
|
|
|
std::string cmGlobalNinjaGenerator::EncodeDepfileSpace(const std::string &path)
|
|
|
|
{
|
|
|
|
std::string result = path;
|
|
|
|
cmSystemTools::ReplaceString(result, " ", "\\ ");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
|
|
|
|
const std::string& comment,
|
|
|
|
const std::string& rule,
|
|
|
|
const cmNinjaDeps& outputs,
|
|
|
|
const cmNinjaDeps& explicitDeps,
|
|
|
|
const cmNinjaDeps& implicitDeps,
|
|
|
|
const cmNinjaDeps& orderOnlyDeps,
|
2012-06-05 20:39:42 +00:00
|
|
|
const cmNinjaVars& variables,
|
2012-09-26 08:07:25 +00:00
|
|
|
const std::string& rspfile,
|
2012-06-05 20:39:42 +00:00
|
|
|
int cmdLineLimit)
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
|
|
|
// Make sure there is a rule.
|
|
|
|
if(rule.empty())
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("No rule for WriteBuildStatement! called "
|
|
|
|
"with comment: ",
|
|
|
|
comment.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure there is at least one output file.
|
|
|
|
if(outputs.empty())
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("No output files for WriteBuildStatement! called "
|
|
|
|
"with comment: ",
|
|
|
|
comment.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(os, comment);
|
|
|
|
|
2014-02-08 05:30:18 +00:00
|
|
|
std::string arguments;
|
2011-11-11 05:00:49 +00:00
|
|
|
|
|
|
|
// TODO: Better formatting for when there are multiple input/output files.
|
|
|
|
|
|
|
|
// Write explicit dependencies.
|
|
|
|
for(cmNinjaDeps::const_iterator i = explicitDeps.begin();
|
|
|
|
i != explicitDeps.end();
|
|
|
|
++i)
|
2013-06-07 18:26:03 +00:00
|
|
|
{
|
2014-02-08 05:30:18 +00:00
|
|
|
arguments += " " + EncodeIdent(EncodePath(*i), os);
|
2013-06-07 18:26:03 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
// Write implicit dependencies.
|
|
|
|
if(!implicitDeps.empty())
|
|
|
|
{
|
2014-02-08 05:30:18 +00:00
|
|
|
arguments += " |";
|
2011-11-11 05:00:49 +00:00
|
|
|
for(cmNinjaDeps::const_iterator i = implicitDeps.begin();
|
|
|
|
i != implicitDeps.end();
|
|
|
|
++i)
|
2014-02-08 05:30:18 +00:00
|
|
|
arguments += " " + EncodeIdent(EncodePath(*i), os);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write order-only dependencies.
|
|
|
|
if(!orderOnlyDeps.empty())
|
|
|
|
{
|
2014-02-08 05:30:18 +00:00
|
|
|
arguments += " ||";
|
2011-11-11 05:00:49 +00:00
|
|
|
for(cmNinjaDeps::const_iterator i = orderOnlyDeps.begin();
|
|
|
|
i != orderOnlyDeps.end();
|
|
|
|
++i)
|
2014-02-08 05:30:18 +00:00
|
|
|
arguments += " " + EncodeIdent(EncodePath(*i), os);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
2014-02-08 05:30:18 +00:00
|
|
|
arguments += "\n";
|
2012-06-05 20:39:42 +00:00
|
|
|
|
2014-02-08 05:30:18 +00:00
|
|
|
std::string build;
|
2012-06-05 20:39:42 +00:00
|
|
|
|
|
|
|
// Write outputs files.
|
2014-02-08 05:30:18 +00:00
|
|
|
build += "build";
|
2012-06-05 20:39:42 +00:00
|
|
|
for(cmNinjaDeps::const_iterator i = outputs.begin();
|
2012-07-01 22:01:41 +00:00
|
|
|
i != outputs.end(); ++i)
|
2013-06-07 18:26:03 +00:00
|
|
|
{
|
2014-02-08 05:30:18 +00:00
|
|
|
build += " " + EncodeIdent(EncodePath(*i), os);
|
2015-03-20 20:43:21 +00:00
|
|
|
if (this->ComputingUnknownDependencies)
|
|
|
|
{
|
|
|
|
this->CombinedBuildOutputs.insert( EncodePath(*i) );
|
|
|
|
}
|
2013-06-07 18:26:03 +00:00
|
|
|
}
|
2014-02-08 05:30:18 +00:00
|
|
|
build += ":";
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2012-06-05 20:39:42 +00:00
|
|
|
// Write the rule.
|
2014-02-08 05:30:18 +00:00
|
|
|
build += " " + rule;
|
2012-07-01 22:01:41 +00:00
|
|
|
|
|
|
|
// Write the variables bound to this build statement.
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream variable_assignments;
|
2012-07-01 22:01:41 +00:00
|
|
|
for(cmNinjaVars::const_iterator i = variables.begin();
|
|
|
|
i != variables.end(); ++i)
|
|
|
|
cmGlobalNinjaGenerator::WriteVariable(variable_assignments,
|
|
|
|
i->first, i->second, "", 1);
|
2012-06-05 20:39:42 +00:00
|
|
|
|
|
|
|
// check if a response file rule should be used
|
2014-02-08 05:30:18 +00:00
|
|
|
std::string buildstr = build;
|
2012-09-26 08:07:25 +00:00
|
|
|
std::string assignments = variable_assignments.str();
|
2014-02-08 05:30:18 +00:00
|
|
|
const std::string& args = arguments;
|
2012-07-01 22:01:41 +00:00
|
|
|
if (cmdLineLimit > 0
|
|
|
|
&& args.size() + buildstr.size() + assignments.size()
|
2012-09-26 08:07:25 +00:00
|
|
|
> (size_t) cmdLineLimit) {
|
|
|
|
buildstr += "_RSP_FILE";
|
2014-10-06 20:29:09 +00:00
|
|
|
variable_assignments.str(std::string());
|
2012-09-26 08:07:25 +00:00
|
|
|
cmGlobalNinjaGenerator::WriteVariable(variable_assignments,
|
|
|
|
"RSP_FILE", rspfile, "", 1);
|
|
|
|
assignments += variable_assignments.str();
|
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2012-07-01 22:01:41 +00:00
|
|
|
os << buildstr << args << assignments;
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WritePhonyBuild(std::ostream& os,
|
|
|
|
const std::string& comment,
|
|
|
|
const cmNinjaDeps& outputs,
|
|
|
|
const cmNinjaDeps& explicitDeps,
|
|
|
|
const cmNinjaDeps& implicitDeps,
|
|
|
|
const cmNinjaDeps& orderOnlyDeps,
|
|
|
|
const cmNinjaVars& variables)
|
|
|
|
{
|
2013-06-07 18:25:33 +00:00
|
|
|
this->WriteBuild(os,
|
|
|
|
comment,
|
|
|
|
"phony",
|
|
|
|
outputs,
|
|
|
|
explicitDeps,
|
|
|
|
implicitDeps,
|
|
|
|
orderOnlyDeps,
|
|
|
|
variables);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::AddCustomCommandRule()
|
|
|
|
{
|
|
|
|
this->AddRule("CUSTOM_COMMAND",
|
|
|
|
"$COMMAND",
|
|
|
|
"$DESC",
|
|
|
|
"Rule for running custom commands.",
|
|
|
|
/*depfile*/ "",
|
2013-10-18 10:59:47 +00:00
|
|
|
/*deptype*/ "",
|
2012-06-05 20:39:42 +00:00
|
|
|
/*rspfile*/ "",
|
2012-07-10 07:56:11 +00:00
|
|
|
/*rspcontent*/ "",
|
2014-11-13 23:32:44 +00:00
|
|
|
/*restat*/ "1",
|
2013-10-18 10:59:47 +00:00
|
|
|
/*generator*/ false);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command,
|
|
|
|
const std::string& description,
|
|
|
|
const std::string& comment,
|
2014-11-05 20:42:18 +00:00
|
|
|
bool uses_terminal,
|
2011-11-11 05:00:49 +00:00
|
|
|
const cmNinjaDeps& outputs,
|
|
|
|
const cmNinjaDeps& deps,
|
2013-10-18 10:59:47 +00:00
|
|
|
const cmNinjaDeps& orderOnly)
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2012-06-05 23:36:34 +00:00
|
|
|
std::string cmd = command;
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (cmd.empty())
|
|
|
|
// TODO Shouldn't an empty command be handled by ninja?
|
|
|
|
cmd = "cmd.exe /c";
|
|
|
|
#endif
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
this->AddCustomCommandRule();
|
|
|
|
|
|
|
|
cmNinjaVars vars;
|
2012-06-05 23:36:34 +00:00
|
|
|
vars["COMMAND"] = cmd;
|
2011-11-11 05:00:49 +00:00
|
|
|
vars["DESC"] = EncodeLiteral(description);
|
2014-11-05 20:42:18 +00:00
|
|
|
if (uses_terminal && SupportsConsolePool())
|
|
|
|
{
|
|
|
|
vars["pool"] = "console";
|
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2013-06-07 18:25:33 +00:00
|
|
|
this->WriteBuild(*this->BuildFileStream,
|
|
|
|
comment,
|
|
|
|
"CUSTOM_COMMAND",
|
|
|
|
outputs,
|
|
|
|
deps,
|
|
|
|
cmNinjaDeps(),
|
2013-10-18 10:59:47 +00:00
|
|
|
orderOnly,
|
2013-06-07 18:25:33 +00:00
|
|
|
vars);
|
2014-06-27 20:13:50 +00:00
|
|
|
|
2015-03-20 20:43:21 +00:00
|
|
|
if (this->ComputingUnknownDependencies)
|
2014-06-27 20:13:50 +00:00
|
|
|
{
|
2015-03-20 20:43:21 +00:00
|
|
|
//we need to track every dependency that comes in, since we are trying
|
|
|
|
//to find dependencies that are side effects of build commands
|
|
|
|
for(cmNinjaDeps::const_iterator i = deps.begin(); i != deps.end(); ++i)
|
|
|
|
{
|
|
|
|
this->CombinedCustomCommandExplicitDependencies.insert(EncodePath(*i));
|
|
|
|
}
|
2014-06-27 20:13:50 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
2012-07-10 18:13:01 +00:00
|
|
|
void
|
|
|
|
cmGlobalNinjaGenerator::AddMacOSXContentRule()
|
|
|
|
{
|
|
|
|
cmLocalGenerator *lg = this->LocalGenerators[0];
|
|
|
|
cmMakefile* mfRoot = lg->GetMakefile();
|
|
|
|
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream cmd;
|
2012-07-10 18:13:01 +00:00
|
|
|
cmd << lg->ConvertToOutputFormat(
|
|
|
|
mfRoot->GetRequiredDefinition("CMAKE_COMMAND"),
|
|
|
|
cmLocalGenerator::SHELL)
|
|
|
|
<< " -E copy $in $out";
|
|
|
|
|
|
|
|
this->AddRule("COPY_OSX_CONTENT",
|
|
|
|
cmd.str(),
|
|
|
|
"Copying OS X Content $out",
|
2013-10-18 10:59:47 +00:00
|
|
|
"Rule for copying OS X bundle content file.",
|
2012-07-10 18:13:01 +00:00
|
|
|
/*depfile*/ "",
|
2013-10-18 10:59:47 +00:00
|
|
|
/*deptype*/ "",
|
|
|
|
/*rspfile*/ "",
|
|
|
|
/*rspcontent*/ "",
|
2014-11-13 23:32:44 +00:00
|
|
|
/*restat*/ "",
|
2013-10-18 10:59:47 +00:00
|
|
|
/*generator*/ false);
|
2012-07-10 18:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmGlobalNinjaGenerator::WriteMacOSXContentBuild(const std::string& input,
|
|
|
|
const std::string& output)
|
|
|
|
{
|
|
|
|
this->AddMacOSXContentRule();
|
|
|
|
|
|
|
|
cmNinjaDeps outputs;
|
|
|
|
outputs.push_back(output);
|
|
|
|
cmNinjaDeps deps;
|
|
|
|
deps.push_back(input);
|
|
|
|
cmNinjaVars vars;
|
|
|
|
|
2013-06-07 18:25:33 +00:00
|
|
|
this->WriteBuild(*this->BuildFileStream,
|
|
|
|
"",
|
|
|
|
"COPY_OSX_CONTENT",
|
|
|
|
outputs,
|
|
|
|
deps,
|
|
|
|
cmNinjaDeps(),
|
|
|
|
cmNinjaDeps(),
|
|
|
|
cmNinjaVars());
|
2012-07-10 18:13:01 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
void cmGlobalNinjaGenerator::WriteRule(std::ostream& os,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& command,
|
|
|
|
const std::string& description,
|
|
|
|
const std::string& comment,
|
|
|
|
const std::string& depfile,
|
2013-10-18 10:59:47 +00:00
|
|
|
const std::string& deptype,
|
2012-06-05 20:39:42 +00:00
|
|
|
const std::string& rspfile,
|
2012-07-10 07:56:11 +00:00
|
|
|
const std::string& rspcontent,
|
2014-11-13 23:32:44 +00:00
|
|
|
const std::string& restat,
|
2011-11-11 05:00:49 +00:00
|
|
|
bool generator)
|
|
|
|
{
|
|
|
|
// Make sure the rule has a name.
|
|
|
|
if(name.empty())
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("No name given for WriteRuleStatement! called "
|
|
|
|
"with comment: ",
|
|
|
|
comment.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure a command is given.
|
|
|
|
if(command.empty())
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("No command given for WriteRuleStatement! called "
|
|
|
|
"with comment: ",
|
|
|
|
comment.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(os, comment);
|
|
|
|
|
|
|
|
// Write the rule.
|
|
|
|
os << "rule " << name << "\n";
|
|
|
|
|
|
|
|
// Write the depfile if any.
|
|
|
|
if(!depfile.empty())
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "depfile = " << depfile << "\n";
|
|
|
|
}
|
|
|
|
|
2013-10-18 10:59:47 +00:00
|
|
|
// Write the deptype if any.
|
|
|
|
if (!deptype.empty())
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "deps = " << deptype << "\n";
|
|
|
|
}
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
// Write the command.
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "command = " << command << "\n";
|
|
|
|
|
|
|
|
// Write the description if any.
|
|
|
|
if(!description.empty())
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "description = " << description << "\n";
|
|
|
|
}
|
|
|
|
|
2012-06-05 20:39:42 +00:00
|
|
|
if(!rspfile.empty())
|
|
|
|
{
|
2012-07-10 08:42:24 +00:00
|
|
|
if (rspcontent.empty())
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("No rspfile_content given!", comment.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "rspfile = " << rspfile << "\n";
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "rspfile_content = " << rspcontent << "\n";
|
2012-06-05 20:39:42 +00:00
|
|
|
}
|
|
|
|
|
2014-11-13 23:32:44 +00:00
|
|
|
if(!restat.empty())
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
2014-11-13 23:32:44 +00:00
|
|
|
os << "restat = " << restat << "\n";
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(generator)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "generator = 1\n";
|
|
|
|
}
|
2012-06-10 18:20:29 +00:00
|
|
|
|
|
|
|
os << "\n";
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& value,
|
|
|
|
const std::string& comment,
|
|
|
|
int indent)
|
|
|
|
{
|
|
|
|
// Make sure we have a name.
|
|
|
|
if(name.empty())
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("No name given for WriteVariable! called "
|
|
|
|
"with comment: ",
|
|
|
|
comment.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not add a variable if the value is empty.
|
|
|
|
std::string val = cmSystemTools::TrimWhitespace(value);
|
|
|
|
if(val.empty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(os, comment);
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, indent);
|
|
|
|
os << name << " = " << val << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteInclude(std::ostream& os,
|
|
|
|
const std::string& filename,
|
|
|
|
const std::string& comment)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(os, comment);
|
|
|
|
os << "include " << filename << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteDefault(std::ostream& os,
|
|
|
|
const cmNinjaDeps& targets,
|
|
|
|
const std::string& comment)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(os, comment);
|
|
|
|
os << "default";
|
|
|
|
for(cmNinjaDeps::const_iterator i = targets.begin(); i != targets.end(); ++i)
|
|
|
|
os << " " << *i;
|
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmGlobalNinjaGenerator::cmGlobalNinjaGenerator()
|
|
|
|
: cmGlobalGenerator()
|
|
|
|
, BuildFileStream(0)
|
|
|
|
, RulesFileStream(0)
|
2012-05-09 21:47:37 +00:00
|
|
|
, CompileCommandsStream(0)
|
2011-11-11 05:00:49 +00:00
|
|
|
, Rules()
|
|
|
|
, AllDependencies()
|
2015-03-20 20:43:21 +00:00
|
|
|
, ComputingUnknownDependencies(false)
|
|
|
|
, PolicyCMP0058(cmPolicies::WARN)
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
|
|
|
// // Ninja is not ported to non-Unix OS yet.
|
|
|
|
// this->ForceUnixPaths = true;
|
|
|
|
this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake";
|
|
|
|
}
|
|
|
|
|
2012-06-10 18:20:29 +00:00
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Virtual public methods.
|
|
|
|
|
|
|
|
cmLocalGenerator* cmGlobalNinjaGenerator::CreateLocalGenerator()
|
|
|
|
{
|
|
|
|
cmLocalGenerator* lg = new cmLocalNinjaGenerator;
|
|
|
|
lg->SetGlobalGenerator(this);
|
|
|
|
return lg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator
|
2012-11-19 15:42:24 +00:00
|
|
|
::GetDocumentation(cmDocumentationEntry& entry)
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2012-11-19 15:42:24 +00:00
|
|
|
entry.Name = cmGlobalNinjaGenerator::GetActualName();
|
2011-11-11 05:00:49 +00:00
|
|
|
entry.Brief = "Generates build.ninja files (experimental).";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implemented in all cmGlobaleGenerator sub-classes.
|
|
|
|
// Used in:
|
|
|
|
// Source/cmLocalGenerator.cxx
|
|
|
|
// Source/cmake.cxx
|
|
|
|
void cmGlobalNinjaGenerator::Generate()
|
|
|
|
{
|
|
|
|
this->OpenBuildFileStream();
|
|
|
|
this->OpenRulesFileStream();
|
|
|
|
|
2015-03-20 20:43:21 +00:00
|
|
|
this->PolicyCMP0058 =
|
|
|
|
this->LocalGenerators[0]->GetMakefile()
|
|
|
|
->GetPolicyStatus(cmPolicies::CMP0058);
|
|
|
|
this->ComputingUnknownDependencies =
|
|
|
|
(this->PolicyCMP0058 == cmPolicies::OLD ||
|
|
|
|
this->PolicyCMP0058 == cmPolicies::WARN);
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
this->cmGlobalGenerator::Generate();
|
|
|
|
|
2012-02-05 01:48:08 +00:00
|
|
|
this->WriteAssumedSourceDependencies();
|
2011-11-11 05:00:49 +00:00
|
|
|
this->WriteTargetAliases(*this->BuildFileStream);
|
2013-06-07 18:26:03 +00:00
|
|
|
this->WriteUnknownExplicitDependencies(*this->BuildFileStream);
|
2011-11-11 05:00:49 +00:00
|
|
|
this->WriteBuiltinTargets(*this->BuildFileStream);
|
|
|
|
|
2012-05-16 22:57:09 +00:00
|
|
|
if (cmSystemTools::GetErrorOccuredFlag()) {
|
|
|
|
this->RulesFileStream->setstate(std::ios_base::failbit);
|
|
|
|
this->BuildFileStream->setstate(std::ios_base::failbit);
|
|
|
|
}
|
|
|
|
|
2012-05-09 21:47:37 +00:00
|
|
|
this->CloseCompileCommandsStream();
|
2011-11-11 05:00:49 +00:00
|
|
|
this->CloseRulesFileStream();
|
|
|
|
this->CloseBuildFileStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implemented in all cmGlobaleGenerator sub-classes.
|
|
|
|
// Used in:
|
|
|
|
// Source/cmMakefile.cxx:
|
|
|
|
void cmGlobalNinjaGenerator
|
2013-03-10 10:36:57 +00:00
|
|
|
::EnableLanguage(std::vector<std::string>const& langs,
|
|
|
|
cmMakefile* makefile,
|
2011-11-11 05:00:49 +00:00
|
|
|
bool optional)
|
|
|
|
{
|
2013-03-10 10:36:57 +00:00
|
|
|
if (makefile->IsOn("CMAKE_COMPILER_IS_MINGW"))
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2013-03-09 10:16:39 +00:00
|
|
|
UsingMinGW = true;
|
2013-03-10 10:36:57 +00:00
|
|
|
this->EnableMinGWLanguage(makefile);
|
|
|
|
}
|
|
|
|
if (std::find(langs.begin(), langs.end(), "Fortran") != langs.end())
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("The Ninja generator does not support Fortran yet.");
|
2012-06-08 14:31:54 +00:00
|
|
|
}
|
2013-03-10 10:36:57 +00:00
|
|
|
this->cmGlobalGenerator::EnableLanguage(langs, makefile, optional);
|
2014-09-20 20:37:52 +00:00
|
|
|
for(std::vector<std::string>::const_iterator l = langs.begin();
|
|
|
|
l != langs.end(); ++l)
|
|
|
|
{
|
|
|
|
if(*l == "NONE")
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
this->ResolveLanguageCompiler(*l, makefile, optional);
|
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 20:39:42 +00:00
|
|
|
bool cmGlobalNinjaGenerator::UsingMinGW = false;
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
// Implemented by:
|
|
|
|
// cmGlobalUnixMakefileGenerator3
|
|
|
|
// cmGlobalVisualStudio10Generator
|
|
|
|
// cmGlobalVisualStudio6Generator
|
|
|
|
// cmGlobalVisualStudio7Generator
|
|
|
|
// cmGlobalXCodeGenerator
|
|
|
|
// Called by:
|
|
|
|
// cmGlobalGenerator::Build()
|
2013-11-15 18:33:32 +00:00
|
|
|
void cmGlobalNinjaGenerator
|
|
|
|
::GenerateBuildCommand(std::vector<std::string>& makeCommand,
|
2014-02-24 22:38:55 +00:00
|
|
|
const std::string& makeProgram,
|
2014-02-07 20:40:05 +00:00
|
|
|
const std::string& /*projectName*/,
|
2014-02-24 22:38:30 +00:00
|
|
|
const std::string& /*projectDir*/,
|
2014-02-06 22:31:47 +00:00
|
|
|
const std::string& targetName,
|
2014-02-10 03:48:34 +00:00
|
|
|
const std::string& /*config*/,
|
2013-11-15 18:33:32 +00:00
|
|
|
bool /*fast*/,
|
2015-02-26 10:32:26 +00:00
|
|
|
bool verbose,
|
2013-11-15 18:33:32 +00:00
|
|
|
std::vector<std::string> const& makeOptions)
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2013-11-13 20:12:06 +00:00
|
|
|
makeCommand.push_back(
|
|
|
|
this->SelectMakeProgram(makeProgram)
|
|
|
|
);
|
2013-11-15 18:33:32 +00:00
|
|
|
|
2015-02-26 10:32:26 +00:00
|
|
|
if(verbose)
|
|
|
|
{
|
|
|
|
makeCommand.push_back("-v");
|
|
|
|
}
|
|
|
|
|
2013-11-15 18:33:32 +00:00
|
|
|
makeCommand.insert(makeCommand.end(),
|
|
|
|
makeOptions.begin(), makeOptions.end());
|
2014-02-06 22:31:47 +00:00
|
|
|
if(!targetName.empty())
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2014-02-06 22:31:47 +00:00
|
|
|
if(targetName == "clean")
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2013-11-15 18:33:32 +00:00
|
|
|
makeCommand.push_back("-t");
|
|
|
|
makeCommand.push_back("clean");
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-15 18:33:32 +00:00
|
|
|
makeCommand.push_back(targetName);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Non-virtual public methods.
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::AddRule(const std::string& name,
|
|
|
|
const std::string& command,
|
|
|
|
const std::string& description,
|
|
|
|
const std::string& comment,
|
|
|
|
const std::string& depfile,
|
2013-10-18 10:59:47 +00:00
|
|
|
const std::string& deptype,
|
2012-06-05 20:39:42 +00:00
|
|
|
const std::string& rspfile,
|
2012-07-10 07:56:11 +00:00
|
|
|
const std::string& rspcontent,
|
2014-11-13 23:32:44 +00:00
|
|
|
const std::string& restat,
|
2011-11-11 05:00:49 +00:00
|
|
|
bool generator)
|
|
|
|
{
|
|
|
|
// Do not add the same rule twice.
|
|
|
|
if (this->HasRule(name))
|
2012-06-10 18:20:29 +00:00
|
|
|
{
|
2011-11-11 05:00:49 +00:00
|
|
|
return;
|
2012-06-10 18:20:29 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
|
|
|
|
this->Rules.insert(name);
|
|
|
|
cmGlobalNinjaGenerator::WriteRule(*this->RulesFileStream,
|
|
|
|
name,
|
|
|
|
command,
|
|
|
|
description,
|
|
|
|
comment,
|
|
|
|
depfile,
|
2013-10-18 10:59:47 +00:00
|
|
|
deptype,
|
2012-06-05 20:39:42 +00:00
|
|
|
rspfile,
|
2012-07-10 07:56:11 +00:00
|
|
|
rspcontent,
|
2011-11-11 05:00:49 +00:00
|
|
|
restat,
|
|
|
|
generator);
|
2012-07-02 08:30:29 +00:00
|
|
|
|
2012-07-06 07:46:00 +00:00
|
|
|
this->RuleCmdLength[name] = (int) command.size();
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmGlobalNinjaGenerator::HasRule(const std::string &name)
|
|
|
|
{
|
|
|
|
RulesSetType::const_iterator rule = this->Rules.find(name);
|
|
|
|
return (rule != this->Rules.end());
|
|
|
|
}
|
|
|
|
|
2012-03-13 13:30:23 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Private virtual overrides
|
|
|
|
|
2013-11-12 13:44:08 +00:00
|
|
|
std::string cmGlobalNinjaGenerator::GetEditCacheCommand() const
|
|
|
|
{
|
|
|
|
// Ninja by design does not run interactive tools in the terminal,
|
|
|
|
// so our only choice is cmake-gui.
|
|
|
|
return cmSystemTools::GetCMakeGUICommand();
|
|
|
|
}
|
|
|
|
|
2014-03-12 20:09:20 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmGlobalNinjaGenerator
|
|
|
|
::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const
|
|
|
|
{
|
|
|
|
cmTarget* target = gt->Target;
|
|
|
|
|
|
|
|
// Compute full path to object file directory for this target.
|
2014-03-17 14:27:01 +00:00
|
|
|
std::string dir;
|
|
|
|
dir += gt->Makefile->GetCurrentOutputDirectory();
|
|
|
|
dir += "/";
|
|
|
|
dir += gt->LocalGenerator->GetTargetDirectory(*target);
|
|
|
|
dir += "/";
|
|
|
|
gt->ObjectDirectory = dir;
|
2014-03-12 20:09:20 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Private methods
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::OpenBuildFileStream()
|
|
|
|
{
|
|
|
|
// Compute Ninja's build file path.
|
|
|
|
std::string buildFilePath =
|
|
|
|
this->GetCMakeInstance()->GetHomeOutputDirectory();
|
|
|
|
buildFilePath += "/";
|
|
|
|
buildFilePath += cmGlobalNinjaGenerator::NINJA_BUILD_FILE;
|
|
|
|
|
|
|
|
// Get a stream where to generate things.
|
|
|
|
if (!this->BuildFileStream)
|
|
|
|
{
|
|
|
|
this->BuildFileStream = new cmGeneratedFileStream(buildFilePath.c_str());
|
|
|
|
if (!this->BuildFileStream)
|
|
|
|
{
|
|
|
|
// An error message is generated by the constructor if it cannot
|
|
|
|
// open the file.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the do not edit header.
|
|
|
|
this->WriteDisclaimer(*this->BuildFileStream);
|
|
|
|
|
|
|
|
// Write a comment about this file.
|
|
|
|
*this->BuildFileStream
|
|
|
|
<< "# This file contains all the build statements describing the\n"
|
|
|
|
<< "# compilation DAG.\n\n"
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::CloseBuildFileStream()
|
|
|
|
{
|
|
|
|
if (this->BuildFileStream)
|
|
|
|
{
|
|
|
|
delete this->BuildFileStream;
|
|
|
|
this->BuildFileStream = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Build file stream was not open.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::OpenRulesFileStream()
|
|
|
|
{
|
|
|
|
// Compute Ninja's build file path.
|
|
|
|
std::string rulesFilePath =
|
|
|
|
this->GetCMakeInstance()->GetHomeOutputDirectory();
|
|
|
|
rulesFilePath += "/";
|
|
|
|
rulesFilePath += cmGlobalNinjaGenerator::NINJA_RULES_FILE;
|
|
|
|
|
|
|
|
// Get a stream where to generate things.
|
|
|
|
if (!this->RulesFileStream)
|
|
|
|
{
|
|
|
|
this->RulesFileStream = new cmGeneratedFileStream(rulesFilePath.c_str());
|
|
|
|
if (!this->RulesFileStream)
|
|
|
|
{
|
|
|
|
// An error message is generated by the constructor if it cannot
|
|
|
|
// open the file.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the do not edit header.
|
|
|
|
this->WriteDisclaimer(*this->RulesFileStream);
|
|
|
|
|
|
|
|
// Write comment about this file.
|
|
|
|
*this->RulesFileStream
|
|
|
|
<< "# This file contains all the rules used to get the outputs files\n"
|
|
|
|
<< "# built from the input files.\n"
|
|
|
|
<< "# It is included in the main '" << NINJA_BUILD_FILE << "'.\n\n"
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::CloseRulesFileStream()
|
|
|
|
{
|
|
|
|
if (this->RulesFileStream)
|
|
|
|
{
|
|
|
|
delete this->RulesFileStream;
|
|
|
|
this->RulesFileStream = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Rules file stream was not open.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-09 21:47:37 +00:00
|
|
|
void cmGlobalNinjaGenerator::AddCXXCompileCommand(
|
|
|
|
const std::string &commandLine,
|
|
|
|
const std::string &sourceFile)
|
|
|
|
{
|
|
|
|
// Compute Ninja's build file path.
|
|
|
|
std::string buildFileDir =
|
|
|
|
this->GetCMakeInstance()->GetHomeOutputDirectory();
|
|
|
|
if (!this->CompileCommandsStream)
|
|
|
|
{
|
|
|
|
std::string buildFilePath = buildFileDir + "/compile_commands.json";
|
|
|
|
|
|
|
|
// Get a stream where to generate things.
|
|
|
|
this->CompileCommandsStream =
|
|
|
|
new cmGeneratedFileStream(buildFilePath.c_str());
|
|
|
|
*this->CompileCommandsStream << "[";
|
|
|
|
} else {
|
|
|
|
*this->CompileCommandsStream << "," << std::endl;
|
|
|
|
}
|
|
|
|
|
2012-06-18 17:59:33 +00:00
|
|
|
std::string sourceFileName = sourceFile;
|
|
|
|
if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str()))
|
|
|
|
{
|
|
|
|
sourceFileName = cmSystemTools::CollapseFullPath(
|
2014-10-15 12:54:05 +00:00
|
|
|
sourceFileName,
|
2012-06-18 17:59:33 +00:00
|
|
|
this->GetCMakeInstance()->GetHomeOutputDirectory());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-09 21:47:37 +00:00
|
|
|
*this->CompileCommandsStream << "\n{\n"
|
|
|
|
<< " \"directory\": \""
|
|
|
|
<< cmGlobalGenerator::EscapeJSON(buildFileDir) << "\",\n"
|
|
|
|
<< " \"command\": \""
|
|
|
|
<< cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n"
|
|
|
|
<< " \"file\": \""
|
2012-06-18 17:59:33 +00:00
|
|
|
<< cmGlobalGenerator::EscapeJSON(sourceFileName) << "\"\n"
|
2012-05-09 21:47:37 +00:00
|
|
|
<< "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::CloseCompileCommandsStream()
|
|
|
|
{
|
|
|
|
if (this->CompileCommandsStream)
|
|
|
|
{
|
|
|
|
*this->CompileCommandsStream << "\n]";
|
|
|
|
delete this->CompileCommandsStream;
|
|
|
|
this->CompileCommandsStream = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os)
|
|
|
|
{
|
|
|
|
os
|
|
|
|
<< "# CMAKE generated file: DO NOT EDIT!\n"
|
|
|
|
<< "# Generated by \"" << this->GetName() << "\""
|
|
|
|
<< " Generator, CMake Version "
|
|
|
|
<< cmVersion::GetMajorVersion() << "."
|
|
|
|
<< cmVersion::GetMinorVersion() << "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::AddDependencyToAll(cmTarget* target)
|
|
|
|
{
|
|
|
|
this->AppendTargetOutputs(target, this->AllDependencies);
|
|
|
|
}
|
|
|
|
|
2012-07-10 18:13:01 +00:00
|
|
|
void cmGlobalNinjaGenerator::AddDependencyToAll(const std::string& input)
|
|
|
|
{
|
|
|
|
this->AllDependencies.push_back(input);
|
|
|
|
}
|
|
|
|
|
2012-02-05 01:48:08 +00:00
|
|
|
void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
|
|
|
for (std::map<std::string, std::set<std::string> >::iterator
|
|
|
|
i = this->AssumedSourceDependencies.begin();
|
|
|
|
i != this->AssumedSourceDependencies.end(); ++i) {
|
2012-02-05 01:48:08 +00:00
|
|
|
cmNinjaDeps deps;
|
|
|
|
std::copy(i->second.begin(), i->second.end(), std::back_inserter(deps));
|
2011-11-11 05:00:49 +00:00
|
|
|
WriteCustomCommandBuild(/*command=*/"", /*description=*/"",
|
|
|
|
"Assume dependencies for generated source file.",
|
2014-11-05 20:42:18 +00:00
|
|
|
/*uses_terminal*/false,
|
2012-02-05 01:48:08 +00:00
|
|
|
cmNinjaDeps(1, i->first), deps);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmGlobalNinjaGenerator
|
2013-12-10 14:16:23 +00:00
|
|
|
::AppendTargetOutputs(cmTarget const* target, cmNinjaDeps& outputs)
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2014-02-10 03:48:34 +00:00
|
|
|
std::string configName =
|
|
|
|
target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
2011-11-11 05:00:49 +00:00
|
|
|
cmLocalNinjaGenerator *ng =
|
|
|
|
static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
|
|
|
|
|
2013-07-17 05:01:50 +00:00
|
|
|
// for frameworks, we want the real name, not smple name
|
|
|
|
// frameworks always appear versioned, and the build.ninja
|
|
|
|
// will always attempt to manage symbolic links instead
|
|
|
|
// of letting cmOSXBundleGenerator do it.
|
|
|
|
bool realname = target->IsFrameworkOnApple();
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
switch (target->GetType()) {
|
|
|
|
case cmTarget::EXECUTABLE:
|
|
|
|
case cmTarget::SHARED_LIBRARY:
|
|
|
|
case cmTarget::STATIC_LIBRARY:
|
|
|
|
case cmTarget::MODULE_LIBRARY:
|
|
|
|
outputs.push_back(ng->ConvertToNinjaPath(
|
2014-10-15 12:54:05 +00:00
|
|
|
target->GetFullPath(configName, false, realname)));
|
2011-11-11 05:00:49 +00:00
|
|
|
break;
|
|
|
|
|
2012-03-13 14:05:07 +00:00
|
|
|
case cmTarget::OBJECT_LIBRARY:
|
2011-11-11 05:00:49 +00:00
|
|
|
case cmTarget::UTILITY: {
|
|
|
|
std::string path = ng->ConvertToNinjaPath(
|
|
|
|
target->GetMakefile()->GetStartOutputDirectory());
|
|
|
|
if (path.empty() || path == ".")
|
|
|
|
outputs.push_back(target->GetName());
|
|
|
|
else {
|
|
|
|
path += "/";
|
|
|
|
path += target->GetName();
|
|
|
|
outputs.push_back(path);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case cmTarget::GLOBAL_TARGET:
|
|
|
|
// Always use the target in HOME instead of an unused duplicate in a
|
|
|
|
// subdirectory.
|
|
|
|
outputs.push_back(target->GetName());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmGlobalNinjaGenerator
|
2013-12-10 14:16:23 +00:00
|
|
|
::AppendTargetDepends(cmTarget const* target, cmNinjaDeps& outputs)
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
|
|
|
if (target->GetType() == cmTarget::GLOBAL_TARGET) {
|
|
|
|
// Global targets only depend on other utilities, which may not appear in
|
|
|
|
// the TargetDepends set (e.g. "all").
|
2014-02-10 05:21:34 +00:00
|
|
|
std::set<std::string> const& utils = target->GetUtilities();
|
2012-02-05 01:48:08 +00:00
|
|
|
std::copy(utils.begin(), utils.end(), std::back_inserter(outputs));
|
2011-11-11 05:00:49 +00:00
|
|
|
} else {
|
|
|
|
cmTargetDependSet const& targetDeps =
|
|
|
|
this->GetTargetDirectDepends(*target);
|
|
|
|
for (cmTargetDependSet::const_iterator i = targetDeps.begin();
|
2012-11-02 14:47:40 +00:00
|
|
|
i != targetDeps.end(); ++i)
|
|
|
|
{
|
|
|
|
if ((*i)->GetType() == cmTarget::INTERFACE_LIBRARY)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
this->AppendTargetOutputs(*i, outputs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
|
|
|
|
cmTarget* target) {
|
|
|
|
cmNinjaDeps outputs;
|
|
|
|
this->AppendTargetOutputs(target, outputs);
|
|
|
|
// Mark the target's outputs as ambiguous to ensure that no other target uses
|
|
|
|
// the output as an alias.
|
|
|
|
for (cmNinjaDeps::iterator i = outputs.begin(); i != outputs.end(); ++i)
|
|
|
|
TargetAliases[*i] = 0;
|
|
|
|
|
|
|
|
// Insert the alias into the map. If the alias was already present in the
|
|
|
|
// map and referred to another target, mark it as ambiguous.
|
|
|
|
std::pair<TargetAliasMap::iterator, bool> newAlias =
|
2012-06-14 16:02:20 +00:00
|
|
|
TargetAliases.insert(std::make_pair(alias, target));
|
2011-11-11 05:00:49 +00:00
|
|
|
if (newAlias.second && newAlias.first->second != target)
|
|
|
|
newAlias.first->second = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
os << "# Target aliases.\n\n";
|
|
|
|
|
2013-06-07 18:26:03 +00:00
|
|
|
for (TargetAliasMap::const_iterator i = TargetAliases.begin();
|
2011-11-11 05:00:49 +00:00
|
|
|
i != TargetAliases.end(); ++i) {
|
|
|
|
// Don't write ambiguous aliases.
|
|
|
|
if (!i->second)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cmNinjaDeps deps;
|
|
|
|
this->AppendTargetOutputs(i->second, deps);
|
|
|
|
|
2013-06-07 18:25:33 +00:00
|
|
|
this->WritePhonyBuild(os,
|
|
|
|
"",
|
|
|
|
cmNinjaDeps(1, i->first),
|
|
|
|
deps);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-07 18:26:03 +00:00
|
|
|
void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
|
|
|
|
{
|
2015-03-20 20:43:21 +00:00
|
|
|
if (!this->ComputingUnknownDependencies)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-18 20:24:11 +00:00
|
|
|
// We need to collect the set of known build outputs.
|
|
|
|
// Start with those generated by WriteBuild calls.
|
|
|
|
// No other method needs this so we can take ownership
|
|
|
|
// of the set locally and throw it out when we are done.
|
|
|
|
std::set<std::string> knownDependencies;
|
|
|
|
knownDependencies.swap(this->CombinedBuildOutputs);
|
|
|
|
|
2013-06-07 18:26:03 +00:00
|
|
|
//now write out the unknown explicit dependencies.
|
|
|
|
|
|
|
|
//union the configured files, evaluations files and the CombinedBuildOutputs,
|
|
|
|
//and then difference with CombinedExplicitDependencies to find the explicit
|
|
|
|
//dependencies that we have no rule for
|
|
|
|
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
os << "# Unknown Build Time Dependencies.\n"
|
|
|
|
<< "# Tell Ninja that they may appear as side effects of build rules\n"
|
|
|
|
<< "# otherwise ordered by order-only dependencies.\n\n";
|
|
|
|
|
|
|
|
//get the list of files that cmake itself has generated as a
|
|
|
|
//product of configuration.
|
|
|
|
cmLocalNinjaGenerator *ng =
|
|
|
|
static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
|
|
|
|
|
|
|
|
for (std::vector<cmLocalGenerator *>::const_iterator i =
|
|
|
|
this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i)
|
|
|
|
{
|
|
|
|
//get the vector of files created by this makefile and convert them
|
|
|
|
//to ninja paths, which are all relative in respect to the build directory
|
|
|
|
const std::vector<std::string>& files =
|
|
|
|
(*i)->GetMakefile()->GetOutputFiles();
|
|
|
|
typedef std::vector<std::string>::const_iterator vect_it;
|
|
|
|
for(vect_it j = files.begin(); j != files.end(); ++j)
|
|
|
|
{
|
2014-10-15 12:54:05 +00:00
|
|
|
knownDependencies.insert( ng->ConvertToNinjaPath( *j ) );
|
2013-06-07 18:26:03 +00:00
|
|
|
}
|
2014-06-13 10:11:06 +00:00
|
|
|
//get list files which are implicit dependencies as well and will be phony
|
|
|
|
//for rebuild manifest
|
|
|
|
std::vector<std::string> const& lf = (*i)->GetMakefile()->GetListFiles();
|
|
|
|
typedef std::vector<std::string>::const_iterator vect_it;
|
|
|
|
for(vect_it j = lf.begin(); j != lf.end(); ++j)
|
|
|
|
{
|
2014-10-15 12:54:05 +00:00
|
|
|
knownDependencies.insert( ng->ConvertToNinjaPath( *j ) );
|
2014-06-13 10:11:06 +00:00
|
|
|
}
|
2013-06-07 18:26:03 +00:00
|
|
|
}
|
2014-06-13 10:11:06 +00:00
|
|
|
knownDependencies.insert( "CMakeCache.txt" );
|
2013-06-07 18:26:03 +00:00
|
|
|
|
|
|
|
for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
|
|
|
|
li = this->EvaluationFiles.begin();
|
|
|
|
li != this->EvaluationFiles.end();
|
|
|
|
++li)
|
|
|
|
{
|
|
|
|
//get all the files created by generator expressions and convert them
|
|
|
|
//to ninja paths
|
|
|
|
std::vector<std::string> files = (*li)->GetFiles();
|
|
|
|
typedef std::vector<std::string>::const_iterator vect_it;
|
|
|
|
for(vect_it j = files.begin(); j != files.end(); ++j)
|
|
|
|
{
|
2014-10-15 12:54:05 +00:00
|
|
|
knownDependencies.insert( ng->ConvertToNinjaPath( *j ) );
|
2013-06-07 18:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(TargetAliasMap::const_iterator i= this->TargetAliases.begin();
|
|
|
|
i != this->TargetAliases.end();
|
|
|
|
++i)
|
|
|
|
{
|
2014-10-15 12:54:05 +00:00
|
|
|
knownDependencies.insert( ng->ConvertToNinjaPath(i->first) );
|
2013-06-07 18:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//remove all source files we know will exist.
|
|
|
|
typedef std::map<std::string, std::set<std::string> >::const_iterator map_it;
|
|
|
|
for(map_it i = this->AssumedSourceDependencies.begin();
|
|
|
|
i != this->AssumedSourceDependencies.end();
|
|
|
|
++i)
|
|
|
|
{
|
2014-10-15 12:54:05 +00:00
|
|
|
knownDependencies.insert( ng->ConvertToNinjaPath(i->first) );
|
2013-06-07 18:26:03 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 20:13:50 +00:00
|
|
|
//now we difference with CombinedCustomCommandExplicitDependencies to find
|
2013-07-22 14:32:06 +00:00
|
|
|
//the list of items we know nothing about.
|
2014-06-27 20:13:50 +00:00
|
|
|
//We have encoded all the paths in CombinedCustomCommandExplicitDependencies
|
2013-07-22 14:32:06 +00:00
|
|
|
//and knownDependencies so no matter if unix or windows paths they
|
|
|
|
//should all match now.
|
2013-06-07 18:26:03 +00:00
|
|
|
|
2015-03-18 20:44:05 +00:00
|
|
|
std::vector<std::string> unknownExplicitDepends;
|
2014-06-27 20:13:50 +00:00
|
|
|
this->CombinedCustomCommandExplicitDependencies.erase("all");
|
2013-06-07 18:26:03 +00:00
|
|
|
|
2014-06-27 20:13:50 +00:00
|
|
|
std::set_difference(this->CombinedCustomCommandExplicitDependencies.begin(),
|
|
|
|
this->CombinedCustomCommandExplicitDependencies.end(),
|
2013-06-07 18:26:03 +00:00
|
|
|
knownDependencies.begin(),
|
|
|
|
knownDependencies.end(),
|
2015-03-18 20:44:05 +00:00
|
|
|
std::back_inserter(unknownExplicitDepends));
|
2013-06-07 18:26:03 +00:00
|
|
|
|
2014-10-08 12:49:05 +00:00
|
|
|
std::string const rootBuildDirectory =
|
|
|
|
this->GetCMakeInstance()->GetHomeOutputDirectory();
|
2015-03-20 20:43:21 +00:00
|
|
|
bool const inSourceBuild =
|
|
|
|
(rootBuildDirectory == this->GetCMakeInstance()->GetHomeDirectory());
|
|
|
|
std::vector<std::string> warnExplicitDepends;
|
2013-06-07 18:26:03 +00:00
|
|
|
for (std::vector<std::string>::const_iterator
|
2015-03-18 20:44:05 +00:00
|
|
|
i = unknownExplicitDepends.begin();
|
|
|
|
i != unknownExplicitDepends.end();
|
2013-06-07 18:26:03 +00:00
|
|
|
++i)
|
|
|
|
{
|
2014-10-08 12:49:05 +00:00
|
|
|
//verify the file is in the build directory
|
|
|
|
std::string const absDepPath = cmSystemTools::CollapseFullPath(
|
2014-10-15 12:54:05 +00:00
|
|
|
*i, rootBuildDirectory.c_str());
|
|
|
|
bool const inBuildDir = cmSystemTools::IsSubDirectory(absDepPath,
|
|
|
|
rootBuildDirectory);
|
2014-10-08 12:49:05 +00:00
|
|
|
if(inBuildDir)
|
|
|
|
{
|
|
|
|
cmNinjaDeps deps(1,*i);
|
|
|
|
this->WritePhonyBuild(os,
|
|
|
|
"",
|
|
|
|
deps,
|
2015-03-18 16:51:28 +00:00
|
|
|
cmNinjaDeps());
|
2015-03-20 20:43:21 +00:00
|
|
|
if (this->PolicyCMP0058 == cmPolicies::WARN &&
|
|
|
|
!inSourceBuild && warnExplicitDepends.size() < 10)
|
|
|
|
{
|
|
|
|
warnExplicitDepends.push_back(*i);
|
|
|
|
}
|
2014-10-08 12:49:05 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-20 20:43:21 +00:00
|
|
|
|
|
|
|
if (!warnExplicitDepends.empty())
|
|
|
|
{
|
|
|
|
std::ostringstream w;
|
|
|
|
w <<
|
|
|
|
(this->GetCMakeInstance()->GetPolicies()->
|
|
|
|
GetPolicyWarning(cmPolicies::CMP0058)) << "\n"
|
|
|
|
"This project specifies custom command DEPENDS on files "
|
|
|
|
"in the build tree that are not specified as the OUTPUT or "
|
|
|
|
"BYPRODUCTS of any add_custom_command or add_custom_target:\n"
|
|
|
|
" " << cmJoin(warnExplicitDepends, "\n ") <<
|
|
|
|
"\n"
|
|
|
|
"For compatibility with versions of CMake that did not have "
|
|
|
|
"the BYPRODUCTS option, CMake is generating phony rules for "
|
|
|
|
"such files to convince 'ninja' to build."
|
|
|
|
"\n"
|
|
|
|
"Project authors should add the missing BYPRODUCTS or OUTPUT "
|
|
|
|
"options to the custom commands that produce these files."
|
|
|
|
;
|
|
|
|
this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str());
|
|
|
|
}
|
2013-06-07 18:26:03 +00:00
|
|
|
}
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os)
|
|
|
|
{
|
|
|
|
// Write headers.
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
os << "# Built-in targets\n\n";
|
|
|
|
|
|
|
|
this->WriteTargetAll(os);
|
|
|
|
this->WriteTargetRebuildManifest(os);
|
2012-04-19 14:47:48 +00:00
|
|
|
this->WriteTargetClean(os);
|
2012-04-19 15:07:35 +00:00
|
|
|
this->WriteTargetHelp(os);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteTargetAll(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmNinjaDeps outputs;
|
|
|
|
outputs.push_back("all");
|
|
|
|
|
2013-06-07 18:25:33 +00:00
|
|
|
this->WritePhonyBuild(os,
|
|
|
|
"The main all target.",
|
|
|
|
outputs,
|
|
|
|
this->AllDependencies);
|
2011-11-11 05:00:49 +00:00
|
|
|
|
|
|
|
cmGlobalNinjaGenerator::WriteDefault(os,
|
|
|
|
outputs,
|
|
|
|
"Make the all target the default.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
|
|
|
|
{
|
2012-02-19 03:07:09 +00:00
|
|
|
cmLocalGenerator *lg = this->LocalGenerators[0];
|
|
|
|
cmMakefile* mfRoot = lg->GetMakefile();
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream cmd;
|
2012-02-19 03:07:09 +00:00
|
|
|
cmd << lg->ConvertToOutputFormat(
|
|
|
|
mfRoot->GetRequiredDefinition("CMAKE_COMMAND"),
|
|
|
|
cmLocalGenerator::SHELL)
|
|
|
|
<< " -H"
|
|
|
|
<< lg->ConvertToOutputFormat(mfRoot->GetHomeDirectory(),
|
|
|
|
cmLocalGenerator::SHELL)
|
|
|
|
<< " -B"
|
|
|
|
<< lg->ConvertToOutputFormat(mfRoot->GetHomeOutputDirectory(),
|
|
|
|
cmLocalGenerator::SHELL);
|
2011-11-11 05:00:49 +00:00
|
|
|
WriteRule(*this->RulesFileStream,
|
|
|
|
"RERUN_CMAKE",
|
|
|
|
cmd.str(),
|
|
|
|
"Re-running CMake...",
|
|
|
|
"Rule for re-running cmake.",
|
|
|
|
/*depfile=*/ "",
|
2013-10-18 10:59:47 +00:00
|
|
|
/*deptype=*/ "",
|
2012-06-05 20:39:42 +00:00
|
|
|
/*rspfile=*/ "",
|
2012-07-10 07:56:11 +00:00
|
|
|
/*rspcontent*/ "",
|
2014-11-13 23:32:44 +00:00
|
|
|
/*restat=*/ "",
|
2011-11-11 05:00:49 +00:00
|
|
|
/*generator=*/ true);
|
|
|
|
|
2014-01-21 18:18:40 +00:00
|
|
|
cmLocalNinjaGenerator *ng = static_cast<cmLocalNinjaGenerator *>(lg);
|
|
|
|
|
2014-01-15 21:33:22 +00:00
|
|
|
cmNinjaDeps implicitDeps;
|
2014-01-21 18:18:40 +00:00
|
|
|
for(std::vector<cmLocalGenerator*>::const_iterator i =
|
|
|
|
this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i)
|
|
|
|
{
|
|
|
|
std::vector<std::string> const& lf = (*i)->GetMakefile()->GetListFiles();
|
|
|
|
for(std::vector<std::string>::const_iterator fi = lf.begin();
|
|
|
|
fi != lf.end(); ++fi)
|
|
|
|
{
|
2014-10-15 12:54:05 +00:00
|
|
|
implicitDeps.push_back(ng->ConvertToNinjaPath(*fi));
|
2014-01-21 18:18:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
implicitDeps.push_back("CMakeCache.txt");
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
std::sort(implicitDeps.begin(), implicitDeps.end());
|
|
|
|
implicitDeps.erase(std::unique(implicitDeps.begin(), implicitDeps.end()),
|
|
|
|
implicitDeps.end());
|
|
|
|
|
2014-10-02 19:21:05 +00:00
|
|
|
cmNinjaVars variables;
|
|
|
|
// Use 'console' pool to get non buffered output of the CMake re-run call
|
|
|
|
// Available since Ninja 1.5
|
2014-11-05 20:40:14 +00:00
|
|
|
if(SupportsConsolePool())
|
2014-10-02 19:21:05 +00:00
|
|
|
{
|
|
|
|
variables["pool"] = "console";
|
|
|
|
}
|
|
|
|
|
2013-06-07 18:25:33 +00:00
|
|
|
this->WriteBuild(os,
|
|
|
|
"Re-run CMake if any of its inputs changed.",
|
|
|
|
"RERUN_CMAKE",
|
2014-01-15 21:33:22 +00:00
|
|
|
/*outputs=*/ cmNinjaDeps(1, NINJA_BUILD_FILE),
|
2013-06-07 18:25:33 +00:00
|
|
|
/*explicitDeps=*/ cmNinjaDeps(),
|
|
|
|
implicitDeps,
|
|
|
|
/*orderOnlyDeps=*/ cmNinjaDeps(),
|
2014-10-02 19:21:05 +00:00
|
|
|
variables);
|
2013-06-07 18:25:33 +00:00
|
|
|
|
|
|
|
this->WritePhonyBuild(os,
|
|
|
|
"A missing CMake input file is not an error.",
|
|
|
|
implicitDeps,
|
|
|
|
cmNinjaDeps());
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
2012-04-19 14:47:48 +00:00
|
|
|
|
2012-06-15 10:14:13 +00:00
|
|
|
std::string cmGlobalNinjaGenerator::ninjaCmd() const
|
|
|
|
{
|
|
|
|
cmLocalGenerator* lgen = this->LocalGenerators[0];
|
|
|
|
if (lgen) {
|
|
|
|
return lgen->ConvertToOutputFormat(
|
|
|
|
lgen->GetMakefile()->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"),
|
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
}
|
|
|
|
return "ninja";
|
|
|
|
}
|
|
|
|
|
2014-10-02 19:21:05 +00:00
|
|
|
std::string cmGlobalNinjaGenerator::ninjaVersion() const
|
|
|
|
{
|
|
|
|
std::string version;
|
|
|
|
std::string command = ninjaCmd() + " --version";
|
|
|
|
cmSystemTools::RunSingleCommand(command.c_str(),
|
|
|
|
&version, 0, 0,
|
|
|
|
cmSystemTools::OUTPUT_NONE);
|
|
|
|
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
2014-11-05 20:40:14 +00:00
|
|
|
bool cmGlobalNinjaGenerator::SupportsConsolePool() const
|
|
|
|
{
|
|
|
|
return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
|
|
|
|
ninjaVersion().c_str(), "1.5") == false;
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:47:48 +00:00
|
|
|
void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
|
|
|
|
{
|
|
|
|
WriteRule(*this->RulesFileStream,
|
|
|
|
"CLEAN",
|
2014-03-10 23:04:11 +00:00
|
|
|
ninjaCmd() + " -t clean",
|
2012-04-19 14:47:48 +00:00
|
|
|
"Cleaning all built files...",
|
|
|
|
"Rule for cleaning all built files.",
|
|
|
|
/*depfile=*/ "",
|
2013-10-18 10:59:47 +00:00
|
|
|
/*deptype=*/ "",
|
2012-06-05 20:39:42 +00:00
|
|
|
/*rspfile=*/ "",
|
2012-07-10 07:56:11 +00:00
|
|
|
/*rspcontent*/ "",
|
2014-11-13 23:32:44 +00:00
|
|
|
/*restat=*/ "",
|
2012-04-19 14:47:48 +00:00
|
|
|
/*generator=*/ false);
|
|
|
|
WriteBuild(os,
|
|
|
|
"Clean all the built files.",
|
|
|
|
"CLEAN",
|
|
|
|
/*outputs=*/ cmNinjaDeps(1, "clean"),
|
|
|
|
/*explicitDeps=*/ cmNinjaDeps(),
|
|
|
|
/*implicitDeps=*/ cmNinjaDeps(),
|
|
|
|
/*orderOnlyDeps=*/ cmNinjaDeps(),
|
|
|
|
/*variables=*/ cmNinjaVars());
|
|
|
|
}
|
2012-04-19 15:07:35 +00:00
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteTargetHelp(std::ostream& os)
|
|
|
|
{
|
|
|
|
WriteRule(*this->RulesFileStream,
|
|
|
|
"HELP",
|
2014-03-10 23:04:11 +00:00
|
|
|
ninjaCmd() + " -t targets",
|
2012-04-19 15:07:35 +00:00
|
|
|
"All primary targets available:",
|
|
|
|
"Rule for printing all primary targets available.",
|
|
|
|
/*depfile=*/ "",
|
2013-10-18 10:59:47 +00:00
|
|
|
/*deptype=*/ "",
|
2012-06-05 20:39:42 +00:00
|
|
|
/*rspfile=*/ "",
|
2012-07-10 07:56:11 +00:00
|
|
|
/*rspcontent*/ "",
|
2014-11-13 23:32:44 +00:00
|
|
|
/*restat=*/ "",
|
2012-04-19 15:07:35 +00:00
|
|
|
/*generator=*/ false);
|
|
|
|
WriteBuild(os,
|
|
|
|
"Print all primary targets available.",
|
|
|
|
"HELP",
|
|
|
|
/*outputs=*/ cmNinjaDeps(1, "help"),
|
|
|
|
/*explicitDeps=*/ cmNinjaDeps(),
|
|
|
|
/*implicitDeps=*/ cmNinjaDeps(),
|
|
|
|
/*orderOnlyDeps=*/ cmNinjaDeps(),
|
|
|
|
/*variables=*/ cmNinjaVars());
|
|
|
|
}
|