2011-11-11 09:00:49 +04: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.
|
|
|
|
============================================================================*/
|
2016-04-29 16:40:20 +03:00
|
|
|
#include "cmGlobalNinjaGenerator.h"
|
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2013-06-07 22:26:03 +04:00
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmGeneratorExpressionEvaluationFile.h"
|
|
|
|
#include "cmGeneratorTarget.h"
|
2011-11-11 09:00:49 +04:00
|
|
|
#include "cmLocalNinjaGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmVersion.h"
|
|
|
|
|
2013-03-10 14:36:57 +04:00
|
|
|
#include <algorithm>
|
2014-03-11 20:37:26 +04:00
|
|
|
#include <assert.h>
|
2015-05-18 20:31:11 +03:00
|
|
|
#include <ctype.h>
|
2013-03-10 14:36:57 +04:00
|
|
|
|
2011-11-11 09:00:49 +04: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)
|
|
|
|
{
|
2016-06-10 19:36:24 +03:00
|
|
|
for (int i = 0; i < count; ++i) {
|
2011-11-11 09:00:49 +04:00
|
|
|
os << cmGlobalNinjaGenerator::INDENT;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteDivider(std::ostream& os)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
os << "# ======================================"
|
|
|
|
<< "=======================================\n";
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteComment(std::ostream& os,
|
|
|
|
const std::string& comment)
|
|
|
|
{
|
2016-06-10 19:36:24 +03:00
|
|
|
if (comment.empty()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
return;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
std::string::size_type lpos = 0;
|
|
|
|
std::string::size_type rpos;
|
2012-06-10 22:20:29 +04:00
|
|
|
os << "\n#############################################\n";
|
2016-05-26 23:21:15 +03:00
|
|
|
while ((rpos = comment.find('\n', lpos)) != std::string::npos) {
|
|
|
|
os << "# " << comment.substr(lpos, rpos - lpos) << "\n";
|
2011-11-11 09:00:49 +04:00
|
|
|
lpos = rpos + 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-05-26 23:21:15 +03:00
|
|
|
os << "# " << comment.substr(lpos) << "\n\n";
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-18 20:31:11 +03:00
|
|
|
std::string cmGlobalNinjaGenerator::EncodeRuleName(std::string const& name)
|
|
|
|
{
|
|
|
|
// Ninja rule names must match "[a-zA-Z0-9_.-]+". Use ".xx" to encode
|
|
|
|
// "." and all invalid characters as hexadecimal.
|
|
|
|
std::string encoded;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::const_iterator i = name.begin(); i != name.end(); ++i) {
|
|
|
|
if (isalnum(*i) || *i == '_' || *i == '-') {
|
2015-05-18 20:31:11 +03:00
|
|
|
encoded += *i;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-05-18 20:31:11 +03:00
|
|
|
char buf[16];
|
|
|
|
sprintf(buf, ".%02x", static_cast<unsigned int>(*i));
|
|
|
|
encoded += buf;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-18 20:31:11 +03:00
|
|
|
return encoded;
|
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
static bool IsIdentChar(char c)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
return ('a' <= c && c <= 'z') ||
|
|
|
|
('+' <= c && c <= '9') || // +,-./ and numbers
|
|
|
|
('A' <= c && c <= 'Z') || (c == '_') || (c == '$') || (c == '\\') ||
|
2012-02-18 23:04:55 +04:00
|
|
|
(c == ' ') || (c == ':');
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmGlobalNinjaGenerator::EncodeIdent(const std::string& ident,
|
|
|
|
std::ostream& vars)
|
|
|
|
{
|
2011-11-11 09:00:49 +04:00
|
|
|
if (std::find_if(ident.begin(), ident.end(),
|
|
|
|
std::not1(std::ptr_fun(IsIdentChar))) != ident.end()) {
|
|
|
|
static unsigned VarNum = 0;
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream names;
|
2011-11-11 09:00:49 +04:00
|
|
|
names << "ident" << VarNum++;
|
|
|
|
vars << names.str() << " = " << ident << "\n";
|
|
|
|
return "$" + names.str();
|
|
|
|
} else {
|
2012-02-18 23:04:55 +04:00
|
|
|
std::string result = ident;
|
|
|
|
cmSystemTools::ReplaceString(result, " ", "$ ");
|
|
|
|
cmSystemTools::ReplaceString(result, ":", "$:");
|
|
|
|
return result;
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string& lit)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
std::string result = lit;
|
|
|
|
cmSystemTools::ReplaceString(result, "$", "$$");
|
2013-03-09 15:04:16 +04:00
|
|
|
cmSystemTools::ReplaceString(result, "\n", "$\n");
|
2011-11-11 09:00:49 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmGlobalNinjaGenerator::EncodePath(const std::string& path)
|
2012-02-19 05:50:53 +04:00
|
|
|
{
|
|
|
|
std::string result = path;
|
|
|
|
#ifdef _WIN32
|
2015-05-07 01:45:01 +03:00
|
|
|
if (this->IsGCCOnWindows())
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(result.begin(), result.end(), '\\', '/');
|
2012-06-06 00:39:42 +04:00
|
|
|
else
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(result.begin(), result.end(), '/', '\\');
|
2012-02-19 05:50:53 +04:00
|
|
|
#endif
|
|
|
|
return EncodeLiteral(result);
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmGlobalNinjaGenerator::EncodeDepfileSpace(const std::string& path)
|
2013-10-18 14:59:47 +04:00
|
|
|
{
|
|
|
|
std::string result = path;
|
|
|
|
cmSystemTools::ReplaceString(result, " ", "\\ ");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03: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,
|
|
|
|
const cmNinjaVars& variables, const std::string& rspfile, int cmdLineLimit,
|
|
|
|
bool* usedResponseFile)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
// Make sure there is a rule.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (rule.empty()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmSystemTools::Error("No rule for WriteBuildStatement! called "
|
|
|
|
"with comment: ",
|
|
|
|
comment.c_str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// Make sure there is at least one output file.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (outputs.empty()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmSystemTools::Error("No output files for WriteBuildStatement! called "
|
|
|
|
"with comment: ",
|
|
|
|
comment.c_str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(os, comment);
|
|
|
|
|
2014-02-08 09:30:18 +04:00
|
|
|
std::string arguments;
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// TODO: Better formatting for when there are multiple input/output files.
|
|
|
|
|
|
|
|
// Write explicit dependencies.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmNinjaDeps::const_iterator i = explicitDeps.begin();
|
|
|
|
i != explicitDeps.end(); ++i) {
|
2014-02-08 09:30:18 +04:00
|
|
|
arguments += " " + EncodeIdent(EncodePath(*i), os);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-06-07 22:26:03 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// Write implicit dependencies.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!implicitDeps.empty()) {
|
2014-02-08 09:30:18 +04:00
|
|
|
arguments += " |";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmNinjaDeps::const_iterator i = implicitDeps.begin();
|
2016-06-10 19:36:24 +03:00
|
|
|
i != implicitDeps.end(); ++i) {
|
2014-02-08 09:30:18 +04:00
|
|
|
arguments += " " + EncodeIdent(EncodePath(*i), os);
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// Write order-only dependencies.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!orderOnlyDeps.empty()) {
|
2014-02-08 09:30:18 +04:00
|
|
|
arguments += " ||";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmNinjaDeps::const_iterator i = orderOnlyDeps.begin();
|
2016-06-10 19:36:24 +03:00
|
|
|
i != orderOnlyDeps.end(); ++i) {
|
2014-02-08 09:30:18 +04:00
|
|
|
arguments += " " + EncodeIdent(EncodePath(*i), os);
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2014-02-08 09:30:18 +04:00
|
|
|
arguments += "\n";
|
2012-06-06 00:39:42 +04:00
|
|
|
|
2014-02-08 09:30:18 +04:00
|
|
|
std::string build;
|
2012-06-06 00:39:42 +04:00
|
|
|
|
|
|
|
// Write outputs files.
|
2014-02-08 09:30:18 +04:00
|
|
|
build += "build";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmNinjaDeps::const_iterator i = outputs.begin(); i != outputs.end();
|
|
|
|
++i) {
|
2014-02-08 09:30:18 +04:00
|
|
|
build += " " + EncodeIdent(EncodePath(*i), os);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ComputingUnknownDependencies) {
|
|
|
|
this->CombinedBuildOutputs.insert(EncodePath(*i));
|
2013-06-07 22:26:03 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-08 09:30:18 +04:00
|
|
|
build += ":";
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2012-06-06 00:39:42 +04:00
|
|
|
// Write the rule.
|
2014-02-08 09:30:18 +04:00
|
|
|
build += " " + rule;
|
2012-07-02 02:01:41 +04:00
|
|
|
|
|
|
|
// Write the variables bound to this build statement.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream variable_assignments;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmNinjaVars::const_iterator i = variables.begin(); i != variables.end();
|
2016-06-10 19:36:24 +03:00
|
|
|
++i) {
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGlobalNinjaGenerator::WriteVariable(variable_assignments, i->first,
|
|
|
|
i->second, "", 1);
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2012-06-06 00:39:42 +04:00
|
|
|
|
|
|
|
// check if a response file rule should be used
|
2014-02-08 09:30:18 +04:00
|
|
|
std::string buildstr = build;
|
2012-09-26 12:07:25 +04:00
|
|
|
std::string assignments = variable_assignments.str();
|
2014-02-08 09:30:18 +04:00
|
|
|
const std::string& args = arguments;
|
2015-05-18 20:31:11 +03:00
|
|
|
bool useResponseFile = false;
|
2016-04-06 13:55:15 +03:00
|
|
|
if (cmdLineLimit < 0 ||
|
|
|
|
(cmdLineLimit > 0 &&
|
2016-05-16 17:34:04 +03:00
|
|
|
(args.size() + buildstr.size() + assignments.size()) >
|
|
|
|
static_cast<size_t>(cmdLineLimit))) {
|
2014-10-07 00:29:09 +04:00
|
|
|
variable_assignments.str(std::string());
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGlobalNinjaGenerator::WriteVariable(variable_assignments, "RSP_FILE",
|
|
|
|
rspfile, "", 1);
|
2012-09-26 12:07:25 +04:00
|
|
|
assignments += variable_assignments.str();
|
2015-05-18 20:31:11 +03:00
|
|
|
useResponseFile = true;
|
2012-09-26 12:07:25 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (usedResponseFile) {
|
2015-05-18 20:31:11 +03:00
|
|
|
*usedResponseFile = useResponseFile;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2012-07-02 02:01:41 +04:00
|
|
|
os << buildstr << args << assignments;
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03: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)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteBuild(os, comment, "phony", outputs, explicitDeps, implicitDeps,
|
|
|
|
orderOnlyDeps, variables);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::AddCustomCommandRule()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
this->AddRule("CUSTOM_COMMAND", "$COMMAND", "$DESC",
|
2011-11-11 09:00:49 +04:00
|
|
|
"Rule for running custom commands.",
|
|
|
|
/*depfile*/ "",
|
2013-10-18 14:59:47 +04:00
|
|
|
/*deptype*/ "",
|
2012-06-06 00:39:42 +04:00
|
|
|
/*rspfile*/ "",
|
2012-07-10 11:56:11 +04:00
|
|
|
/*rspcontent*/ "",
|
2015-11-19 22:47:36 +03:00
|
|
|
/*restat*/ "", // bound on each build statement as needed
|
2013-10-18 14:59:47 +04:00
|
|
|
/*generator*/ false);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
|
|
|
|
const std::string& command, const std::string& description,
|
|
|
|
const std::string& comment, bool uses_terminal, bool restat,
|
|
|
|
const cmNinjaDeps& outputs, const cmNinjaDeps& deps,
|
|
|
|
const cmNinjaDeps& orderOnly)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2012-06-06 03:36:34 +04:00
|
|
|
std::string cmd = command;
|
|
|
|
#ifdef _WIN32
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmd.empty())
|
|
|
|
// TODO Shouldn't an empty command be handled by ninja?
|
|
|
|
cmd = "cmd.exe /c";
|
2012-06-06 03:36:34 +04:00
|
|
|
#endif
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
this->AddCustomCommandRule();
|
|
|
|
|
|
|
|
cmNinjaVars vars;
|
2012-06-06 03:36:34 +04:00
|
|
|
vars["COMMAND"] = cmd;
|
2011-11-11 09:00:49 +04:00
|
|
|
vars["DESC"] = EncodeLiteral(description);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (restat) {
|
2015-11-19 23:09:40 +03:00
|
|
|
vars["restat"] = "1";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (uses_terminal && SupportsConsolePool()) {
|
2014-11-05 23:42:18 +03:00
|
|
|
vars["pool"] = "console";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteBuild(*this->BuildFileStream, comment, "CUSTOM_COMMAND", outputs,
|
|
|
|
deps, cmNinjaDeps(), orderOnly, vars);
|
|
|
|
|
|
|
|
if (this->ComputingUnknownDependencies) {
|
|
|
|
// 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) {
|
2015-03-20 23:43:21 +03:00
|
|
|
this->CombinedCustomCommandExplicitDependencies.insert(EncodePath(*i));
|
2014-06-28 00:13:50 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalNinjaGenerator::AddMacOSXContentRule()
|
2012-07-10 22:13:01 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalGenerator* lg = this->LocalGenerators[0];
|
2012-07-10 22:13:01 +04:00
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream cmd;
|
2015-05-20 16:10:52 +03:00
|
|
|
cmd << lg->ConvertToOutputFormat(cmSystemTools::GetCMakeCommand(),
|
2016-05-20 00:11:40 +03:00
|
|
|
cmOutputConverter::SHELL)
|
2012-07-10 22:13:01 +04:00
|
|
|
<< " -E copy $in $out";
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->AddRule("COPY_OSX_CONTENT", cmd.str(), "Copying OS X Content $out",
|
2013-10-18 14:59:47 +04:00
|
|
|
"Rule for copying OS X bundle content file.",
|
2012-07-10 22:13:01 +04:00
|
|
|
/*depfile*/ "",
|
2013-10-18 14:59:47 +04:00
|
|
|
/*deptype*/ "",
|
|
|
|
/*rspfile*/ "",
|
|
|
|
/*rspcontent*/ "",
|
2014-11-14 02:32:44 +03:00
|
|
|
/*restat*/ "",
|
2013-10-18 14:59:47 +04:00
|
|
|
/*generator*/ false);
|
2012-07-10 22:13:01 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalNinjaGenerator::WriteMacOSXContentBuild(const std::string& input,
|
|
|
|
const std::string& output)
|
2012-07-10 22:13:01 +04:00
|
|
|
{
|
|
|
|
this->AddMacOSXContentRule();
|
|
|
|
|
|
|
|
cmNinjaDeps outputs;
|
|
|
|
outputs.push_back(output);
|
|
|
|
cmNinjaDeps deps;
|
|
|
|
deps.push_back(input);
|
|
|
|
cmNinjaVars vars;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteBuild(*this->BuildFileStream, "", "COPY_OSX_CONTENT", outputs,
|
|
|
|
deps, cmNinjaDeps(), cmNinjaDeps(), cmNinjaVars());
|
2012-07-10 22:13:01 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03: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, const std::string& deptype,
|
|
|
|
const std::string& rspfile, const std::string& rspcontent,
|
|
|
|
const std::string& restat, bool generator)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
// Make sure the rule has a name.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (name.empty()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmSystemTools::Error("No name given for WriteRuleStatement! called "
|
|
|
|
"with comment: ",
|
|
|
|
comment.c_str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// Make sure a command is given.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (command.empty()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmSystemTools::Error("No command given for WriteRuleStatement! called "
|
|
|
|
"with comment: ",
|
|
|
|
comment.c_str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(os, comment);
|
|
|
|
|
|
|
|
// Write the rule.
|
|
|
|
os << "rule " << name << "\n";
|
|
|
|
|
|
|
|
// Write the depfile if any.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!depfile.empty()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "depfile = " << depfile << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2013-10-18 14:59:47 +04:00
|
|
|
// Write the deptype if any.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!deptype.empty()) {
|
2013-10-18 14:59:47 +04:00
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "deps = " << deptype << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-18 14:59:47 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// Write the command.
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "command = " << command << "\n";
|
|
|
|
|
|
|
|
// Write the description if any.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!description.empty()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "description = " << description << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!rspfile.empty()) {
|
|
|
|
if (rspcontent.empty()) {
|
2012-07-10 12:42:24 +04:00
|
|
|
cmSystemTools::Error("No rspfile_content given!", comment.c_str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-07-10 12:42:24 +04:00
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "rspfile = " << rspfile << "\n";
|
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "rspfile_content = " << rspcontent << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-06-06 00:39:42 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!restat.empty()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
2014-11-14 02:32:44 +03:00
|
|
|
os << "restat = " << restat << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (generator) {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmGlobalNinjaGenerator::Indent(os, 1);
|
|
|
|
os << "generator = 1\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-06-10 22:20:29 +04:00
|
|
|
|
|
|
|
os << "\n";
|
2011-11-11 09:00:49 +04: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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (name.empty()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmSystemTools::Error("No name given for WriteVariable! called "
|
|
|
|
"with comment: ",
|
|
|
|
comment.c_str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// Do not add a variable if the value is empty.
|
|
|
|
std::string val = cmSystemTools::TrimWhitespace(value);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (val.empty()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
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";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmNinjaDeps::const_iterator i = targets.begin(); i != targets.end();
|
2016-06-10 19:36:24 +03:00
|
|
|
++i) {
|
2011-11-11 09:00:49 +04:00
|
|
|
os << " " << *i;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
|
2015-05-24 12:31:14 +03:00
|
|
|
cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm)
|
2015-07-07 23:37:56 +03:00
|
|
|
: cmGlobalCommonGenerator(cm)
|
2016-06-27 23:44:16 +03:00
|
|
|
, BuildFileStream(CM_NULLPTR)
|
|
|
|
, RulesFileStream(CM_NULLPTR)
|
|
|
|
, CompileCommandsStream(CM_NULLPTR)
|
2011-11-11 09:00:49 +04:00
|
|
|
, Rules()
|
|
|
|
, AllDependencies()
|
2015-05-07 01:45:01 +03:00
|
|
|
, UsingGCCOnWindows(false)
|
2015-03-20 23:43:21 +03:00
|
|
|
, ComputingUnknownDependencies(false)
|
|
|
|
, PolicyCMP0058(cmPolicies::WARN)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2015-05-04 23:40:11 +03:00
|
|
|
#ifdef _WIN32
|
2015-05-24 12:46:30 +03:00
|
|
|
cm->GetState()->SetWindowsShell(true);
|
2015-05-04 23:40:11 +03:00
|
|
|
#endif
|
2011-11-11 09:00:49 +04:00
|
|
|
// // Ninja is not ported to non-Unix OS yet.
|
|
|
|
// this->ForceUnixPaths = true;
|
|
|
|
this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Virtual public methods.
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalGenerator* cmGlobalNinjaGenerator::CreateLocalGenerator(cmMakefile* mf)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2015-08-02 12:41:51 +03:00
|
|
|
return new cmLocalNinjaGenerator(this, mf);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalNinjaGenerator::GetDocumentation(cmDocumentationEntry& entry)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2012-11-19 19:42:24 +04:00
|
|
|
entry.Name = cmGlobalNinjaGenerator::GetActualName();
|
2015-04-14 20:14:50 +03:00
|
|
|
entry.Brief = "Generates build.ninja files.";
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implemented in all cmGlobaleGenerator sub-classes.
|
|
|
|
// Used in:
|
|
|
|
// Source/cmLocalGenerator.cxx
|
|
|
|
// Source/cmake.cxx
|
|
|
|
void cmGlobalNinjaGenerator::Generate()
|
|
|
|
{
|
2015-08-09 20:51:35 +03:00
|
|
|
// Check minimum Ninja version.
|
|
|
|
if (cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
|
2015-11-03 00:31:27 +03:00
|
|
|
this->NinjaVersion.c_str(),
|
2016-05-16 17:34:04 +03:00
|
|
|
RequiredNinjaVersion().c_str())) {
|
2015-08-09 20:51:35 +03:00
|
|
|
std::ostringstream msg;
|
2015-11-03 00:31:27 +03:00
|
|
|
msg << "The detected version of Ninja (" << this->NinjaVersion;
|
2015-08-09 20:51:35 +03:00
|
|
|
msg << ") is less than the version of Ninja required by CMake (";
|
|
|
|
msg << this->RequiredNinjaVersion() << ").";
|
|
|
|
this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, msg.str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
this->OpenBuildFileStream();
|
|
|
|
this->OpenRulesFileStream();
|
|
|
|
|
2016-07-20 16:32:32 +03:00
|
|
|
this->TargetDependsClosures.clear();
|
|
|
|
|
2016-05-14 02:18:20 +03:00
|
|
|
this->InitOutputPathPrefix();
|
2016-05-14 02:18:20 +03:00
|
|
|
this->TargetAll = this->NinjaOutputPath("all");
|
|
|
|
this->CMakeCacheFile = this->NinjaOutputPath("CMakeCache.txt");
|
2016-05-14 00:42:02 +03:00
|
|
|
|
2015-03-20 23:43:21 +03:00
|
|
|
this->PolicyCMP0058 =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerators[0]->GetMakefile()->GetPolicyStatus(
|
|
|
|
cmPolicies::CMP0058);
|
2015-03-20 23:43:21 +03:00
|
|
|
this->ComputingUnknownDependencies =
|
|
|
|
(this->PolicyCMP0058 == cmPolicies::OLD ||
|
|
|
|
this->PolicyCMP0058 == cmPolicies::WARN);
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
this->cmGlobalGenerator::Generate();
|
|
|
|
|
2012-02-05 05:48:08 +04:00
|
|
|
this->WriteAssumedSourceDependencies();
|
2011-11-11 09:00:49 +04:00
|
|
|
this->WriteTargetAliases(*this->BuildFileStream);
|
2016-03-11 18:26:29 +03:00
|
|
|
this->WriteFolderTargets(*this->BuildFileStream);
|
2013-06-07 22:26:03 +04:00
|
|
|
this->WriteUnknownExplicitDependencies(*this->BuildFileStream);
|
2011-11-11 09:00:49 +04:00
|
|
|
this->WriteBuiltinTargets(*this->BuildFileStream);
|
|
|
|
|
2012-05-17 02:57:09 +04:00
|
|
|
if (cmSystemTools::GetErrorOccuredFlag()) {
|
2016-06-14 00:04:16 +03:00
|
|
|
this->RulesFileStream->setstate(std::ios::failbit);
|
|
|
|
this->BuildFileStream->setstate(std::ios::failbit);
|
2012-05-17 02:57:09 +04:00
|
|
|
}
|
|
|
|
|
2012-05-10 01:47:37 +04:00
|
|
|
this->CloseCompileCommandsStream();
|
2011-11-11 09:00:49 +04:00
|
|
|
this->CloseRulesFileStream();
|
|
|
|
this->CloseBuildFileStream();
|
|
|
|
}
|
|
|
|
|
2015-11-03 00:27:31 +03:00
|
|
|
void cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf)
|
|
|
|
{
|
|
|
|
this->cmGlobalGenerator::FindMakeProgram(mf);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* ninjaCommand = mf->GetDefinition("CMAKE_MAKE_PROGRAM")) {
|
2015-11-03 00:27:31 +03:00
|
|
|
this->NinjaCommand = ninjaCommand;
|
2015-11-03 00:31:27 +03:00
|
|
|
std::vector<std::string> command;
|
|
|
|
command.push_back(this->NinjaCommand);
|
|
|
|
command.push_back("--version");
|
|
|
|
std::string version;
|
2016-06-27 23:44:16 +03:00
|
|
|
cmSystemTools::RunSingleCommand(command, &version, CM_NULLPTR, CM_NULLPTR,
|
|
|
|
CM_NULLPTR, cmSystemTools::OUTPUT_NONE);
|
2015-11-03 00:31:27 +03:00
|
|
|
this->NinjaVersion = cmSystemTools::TrimWhitespace(version);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-11-03 00:27:31 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalNinjaGenerator::EnableLanguage(
|
|
|
|
std::vector<std::string> const& langs, cmMakefile* mf, bool optional)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (std::find(langs.begin(), langs.end(), "Fortran") != langs.end()) {
|
2013-03-10 14:36:57 +04:00
|
|
|
cmSystemTools::Error("The Ninja generator does not support Fortran yet.");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-07 21:01:58 +03:00
|
|
|
this->cmGlobalGenerator::EnableLanguage(langs, mf, optional);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator l = langs.begin();
|
|
|
|
l != langs.end(); ++l) {
|
|
|
|
if (*l == "NONE") {
|
2014-09-21 00:37:52 +04:00
|
|
|
continue;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->ResolveLanguageCompiler(*l, mf, optional);
|
|
|
|
}
|
2015-05-07 21:01:58 +03:00
|
|
|
#ifdef _WIN32
|
2016-08-04 16:41:10 +03:00
|
|
|
if (strcmp(mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID"), "MSVC") != 0 &&
|
|
|
|
strcmp(mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID"), "MSVC") != 0 &&
|
|
|
|
(mf->IsOn("CMAKE_COMPILER_IS_MINGW") ||
|
|
|
|
strcmp(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"), "GNU") == 0 ||
|
|
|
|
strcmp(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"), "GNU") == 0 ||
|
|
|
|
strcmp(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"), "Clang") == 0 ||
|
|
|
|
strcmp(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"), "Clang") == 0)) {
|
2015-05-07 01:45:01 +03:00
|
|
|
this->UsingGCCOnWindows = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-07 21:01:58 +03:00
|
|
|
#endif
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implemented by:
|
|
|
|
// cmGlobalUnixMakefileGenerator3
|
2015-03-24 08:12:55 +03:00
|
|
|
// cmGlobalGhsMultiGenerator
|
2011-11-11 09:00:49 +04:00
|
|
|
// cmGlobalVisualStudio10Generator
|
|
|
|
// cmGlobalVisualStudio7Generator
|
|
|
|
// cmGlobalXCodeGenerator
|
|
|
|
// Called by:
|
|
|
|
// cmGlobalGenerator::Build()
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalNinjaGenerator::GenerateBuildCommand(
|
|
|
|
std::vector<std::string>& makeCommand, const std::string& makeProgram,
|
|
|
|
const std::string& /*projectName*/, const std::string& /*projectDir*/,
|
|
|
|
const std::string& targetName, const std::string& /*config*/, bool /*fast*/,
|
|
|
|
bool verbose, std::vector<std::string> const& makeOptions)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
makeCommand.push_back(this->SelectMakeProgram(makeProgram));
|
2013-11-15 22:33:32 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (verbose) {
|
2015-02-26 13:32:26 +03:00
|
|
|
makeCommand.push_back("-v");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-26 13:32:26 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
makeCommand.insert(makeCommand.end(), makeOptions.begin(),
|
|
|
|
makeOptions.end());
|
|
|
|
if (!targetName.empty()) {
|
|
|
|
if (targetName == "clean") {
|
2013-11-15 22:33:32 +04:00
|
|
|
makeCommand.push_back("-t");
|
|
|
|
makeCommand.push_back("clean");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-11-15 22:33:32 +04:00
|
|
|
makeCommand.push_back(targetName);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Non-virtual public methods.
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalNinjaGenerator::AddRule(
|
|
|
|
const std::string& name, const std::string& command,
|
|
|
|
const std::string& description, const std::string& comment,
|
|
|
|
const std::string& depfile, const std::string& deptype,
|
|
|
|
const std::string& rspfile, const std::string& rspcontent,
|
|
|
|
const std::string& restat, bool generator)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
// Do not add the same rule twice.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->HasRule(name)) {
|
2011-11-11 09:00:49 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
this->Rules.insert(name);
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGlobalNinjaGenerator::WriteRule(*this->RulesFileStream, name, command,
|
|
|
|
description, comment, depfile, deptype,
|
|
|
|
rspfile, rspcontent, restat, generator);
|
|
|
|
|
|
|
|
this->RuleCmdLength[name] = (int)command.size();
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmGlobalNinjaGenerator::HasRule(const std::string& name)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
RulesSetType::const_iterator rule = this->Rules.find(name);
|
|
|
|
return (rule != this->Rules.end());
|
|
|
|
}
|
|
|
|
|
2012-03-13 17:30:23 +04:00
|
|
|
// Private virtual overrides
|
|
|
|
|
2013-11-12 17:44:08 +04: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();
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalNinjaGenerator::ComputeTargetObjectDirectory(
|
|
|
|
cmGeneratorTarget* gt) const
|
2014-03-13 00:09:20 +04:00
|
|
|
{
|
|
|
|
// Compute full path to object file directory for this target.
|
2014-03-17 18:27:01 +04:00
|
|
|
std::string dir;
|
2015-10-21 20:59:12 +03:00
|
|
|
dir += gt->LocalGenerator->GetCurrentBinaryDirectory();
|
2014-03-17 18:27:01 +04:00
|
|
|
dir += "/";
|
2015-10-09 23:27:46 +03:00
|
|
|
dir += gt->LocalGenerator->GetTargetDirectory(gt);
|
2014-03-17 18:27:01 +04:00
|
|
|
dir += "/";
|
|
|
|
gt->ObjectDirectory = dir;
|
2014-03-13 00:09:20 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04: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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->BuildFileStream) {
|
2011-11-11 09:00:49 +04:00
|
|
|
this->BuildFileStream = new cmGeneratedFileStream(buildFilePath.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->BuildFileStream) {
|
2011-11-11 09:00:49 +04:00
|
|
|
// An error message is generated by the constructor if it cannot
|
|
|
|
// open the file.
|
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// 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"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "# compilation DAG.\n\n";
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::CloseBuildFileStream()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->BuildFileStream) {
|
2011-11-11 09:00:49 +04:00
|
|
|
delete this->BuildFileStream;
|
2016-06-27 23:44:16 +03:00
|
|
|
this->BuildFileStream = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmSystemTools::Error("Build file stream was not open.");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->RulesFileStream) {
|
2011-11-11 09:00:49 +04:00
|
|
|
this->RulesFileStream = new cmGeneratedFileStream(rulesFilePath.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->RulesFileStream) {
|
2011-11-11 09:00:49 +04:00
|
|
|
// An error message is generated by the constructor if it cannot
|
|
|
|
// open the file.
|
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// Write the do not edit header.
|
|
|
|
this->WriteDisclaimer(*this->RulesFileStream);
|
|
|
|
|
|
|
|
// Write comment about this file.
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2011-11-11 09:00:49 +04:00
|
|
|
*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"
|
|
|
|
;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::CloseRulesFileStream()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->RulesFileStream) {
|
2011-11-11 09:00:49 +04:00
|
|
|
delete this->RulesFileStream;
|
2016-06-27 23:44:16 +03:00
|
|
|
this->RulesFileStream = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2011-11-11 09:00:49 +04:00
|
|
|
cmSystemTools::Error("Rules file stream was not open.");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2016-05-14 02:18:20 +03:00
|
|
|
static void EnsureTrailingSlash(std::string& path)
|
|
|
|
{
|
|
|
|
if (path.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::string::value_type last = path[path.size() - 1];
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (last != '\\') {
|
|
|
|
path += '\\';
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (last != '/') {
|
|
|
|
path += '/';
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-09-25 20:26:44 +03:00
|
|
|
std::string cmGlobalNinjaGenerator::ConvertToNinjaPath(const std::string& path)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalNinjaGenerator* ng =
|
|
|
|
static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]);
|
2015-09-25 20:26:44 +03:00
|
|
|
std::string convPath = ng->Convert(path, cmOutputConverter::HOME_OUTPUT);
|
2016-05-14 02:18:20 +03:00
|
|
|
convPath = this->NinjaOutputPath(convPath);
|
2015-09-25 20:26:44 +03:00
|
|
|
#ifdef _WIN32
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(convPath.begin(), convPath.end(), '/', '\\');
|
2015-09-25 20:26:44 +03:00
|
|
|
#endif
|
|
|
|
return convPath;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmGlobalNinjaGenerator::ConvertToNinjaFolderRule(
|
|
|
|
const std::string& path)
|
2016-03-11 18:26:29 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalNinjaGenerator* ng =
|
|
|
|
static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]);
|
|
|
|
std::string convPath = ng->Convert(path + "/all", cmOutputConverter::HOME);
|
2016-05-14 02:18:20 +03:00
|
|
|
convPath = this->NinjaOutputPath(convPath);
|
2016-03-11 18:26:29 +03:00
|
|
|
#ifdef _WIN32
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(convPath.begin(), convPath.end(), '/', '\\');
|
2016-03-11 18:26:29 +03:00
|
|
|
#endif
|
|
|
|
return convPath;
|
|
|
|
}
|
|
|
|
|
2012-05-10 01:47:37 +04:00
|
|
|
void cmGlobalNinjaGenerator::AddCXXCompileCommand(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& commandLine, const std::string& sourceFile)
|
2012-05-10 01:47:37 +04:00
|
|
|
{
|
|
|
|
// Compute Ninja's build file path.
|
|
|
|
std::string buildFileDir =
|
|
|
|
this->GetCMakeInstance()->GetHomeOutputDirectory();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->CompileCommandsStream) {
|
2012-05-10 01:47:37 +04:00
|
|
|
std::string buildFilePath = buildFileDir + "/compile_commands.json";
|
|
|
|
|
|
|
|
// Get a stream where to generate things.
|
|
|
|
this->CompileCommandsStream =
|
|
|
|
new cmGeneratedFileStream(buildFilePath.c_str());
|
|
|
|
*this->CompileCommandsStream << "[";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-05-10 01:47:37 +04:00
|
|
|
*this->CompileCommandsStream << "," << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-10 01:47:37 +04:00
|
|
|
|
2012-06-18 21:59:33 +04:00
|
|
|
std::string sourceFileName = sourceFile;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str())) {
|
2012-06-18 21:59:33 +04:00
|
|
|
sourceFileName = cmSystemTools::CollapseFullPath(
|
2016-05-16 17:34:04 +03:00
|
|
|
sourceFileName, this->GetCMakeInstance()->GetHomeOutputDirectory());
|
|
|
|
}
|
2012-06-18 21:59:33 +04:00
|
|
|
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2012-05-10 01:47:37 +04:00
|
|
|
*this->CompileCommandsStream << "\n{\n"
|
|
|
|
<< " \"directory\": \""
|
|
|
|
<< cmGlobalGenerator::EscapeJSON(buildFileDir) << "\",\n"
|
|
|
|
<< " \"command\": \""
|
|
|
|
<< cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n"
|
|
|
|
<< " \"file\": \""
|
2012-06-18 21:59:33 +04:00
|
|
|
<< cmGlobalGenerator::EscapeJSON(sourceFileName) << "\"\n"
|
2012-05-10 01:47:37 +04:00
|
|
|
<< "}";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2012-05-10 01:47:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::CloseCompileCommandsStream()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CompileCommandsStream) {
|
2012-05-10 01:47:37 +04:00
|
|
|
*this->CompileCommandsStream << "\n]";
|
|
|
|
delete this->CompileCommandsStream;
|
2016-06-27 23:44:16 +03:00
|
|
|
this->CompileCommandsStream = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-10 01:47:37 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
os << "# CMAKE generated file: DO NOT EDIT!\n"
|
|
|
|
<< "# Generated by \"" << this->GetName() << "\""
|
|
|
|
<< " Generator, CMake Version " << cmVersion::GetMajorVersion() << "."
|
|
|
|
<< cmVersion::GetMinorVersion() << "\n\n";
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2015-10-19 00:13:50 +03:00
|
|
|
void cmGlobalNinjaGenerator::AddDependencyToAll(cmGeneratorTarget* target)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
this->AppendTargetOutputs(target, this->AllDependencies);
|
|
|
|
}
|
|
|
|
|
2012-07-10 22:13:01 +04:00
|
|
|
void cmGlobalNinjaGenerator::AddDependencyToAll(const std::string& input)
|
|
|
|
{
|
|
|
|
this->AllDependencies.push_back(input);
|
|
|
|
}
|
|
|
|
|
2012-02-05 05:48:08 +04:00
|
|
|
void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, std::set<std::string> >::iterator i =
|
|
|
|
this->AssumedSourceDependencies.begin();
|
2011-11-11 09:00:49 +04:00
|
|
|
i != this->AssumedSourceDependencies.end(); ++i) {
|
2012-02-05 05:48:08 +04:00
|
|
|
cmNinjaDeps deps;
|
|
|
|
std::copy(i->second.begin(), i->second.end(), std::back_inserter(deps));
|
2011-11-11 09:00:49 +04:00
|
|
|
WriteCustomCommandBuild(/*command=*/"", /*description=*/"",
|
|
|
|
"Assume dependencies for generated source file.",
|
2016-05-16 17:34:04 +03:00
|
|
|
/*uses_terminal*/ false,
|
|
|
|
/*restat*/ true, cmNinjaDeps(1, i->first), deps);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalNinjaGenerator::AppendTargetOutputs(
|
|
|
|
cmGeneratorTarget const* target, cmNinjaDeps& outputs)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2014-02-10 07:48:34 +04:00
|
|
|
std::string configName =
|
2015-10-19 00:13:50 +03:00
|
|
|
target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
2015-10-10 00:57:17 +03:00
|
|
|
|
2013-07-17 09:01:50 +04: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.
|
2015-10-19 00:13:50 +03:00
|
|
|
bool realname = target->IsFrameworkOnApple();
|
2013-07-17 09:01:50 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
switch (target->GetType()) {
|
2016-05-16 17:34:04 +03:00
|
|
|
case cmState::EXECUTABLE:
|
|
|
|
case cmState::SHARED_LIBRARY:
|
|
|
|
case cmState::STATIC_LIBRARY:
|
|
|
|
case cmState::MODULE_LIBRARY: {
|
|
|
|
outputs.push_back(this->ConvertToNinjaPath(
|
|
|
|
target->GetFullPath(configName, false, realname)));
|
|
|
|
break;
|
2012-10-06 20:30:43 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
case cmState::OBJECT_LIBRARY:
|
2016-08-05 21:58:16 +03:00
|
|
|
case cmState::GLOBAL_TARGET:
|
2016-05-16 17:34:04 +03:00
|
|
|
case cmState::UTILITY: {
|
2016-05-16 22:30:53 +03:00
|
|
|
std::string path =
|
|
|
|
target->GetLocalGenerator()->GetCurrentBinaryDirectory() +
|
|
|
|
std::string("/") + target->GetName();
|
|
|
|
outputs.push_back(this->ConvertToNinjaPath(path));
|
2016-05-16 17:34:04 +03:00
|
|
|
break;
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
default:
|
|
|
|
return;
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalNinjaGenerator::AppendTargetDepends(
|
|
|
|
cmGeneratorTarget const* target, cmNinjaDeps& outputs)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2015-10-08 01:21:51 +03:00
|
|
|
if (target->GetType() == cmState::GLOBAL_TARGET) {
|
2016-08-05 22:55:32 +03:00
|
|
|
// These depend only on other CMake-provided targets, e.g. "all".
|
2015-10-23 02:01:46 +03:00
|
|
|
std::set<std::string> const& utils = target->GetUtilities();
|
2016-08-05 22:55:32 +03:00
|
|
|
for (std::set<std::string>::const_iterator i = utils.begin();
|
|
|
|
i != utils.end(); ++i) {
|
|
|
|
std::string d =
|
|
|
|
target->GetLocalGenerator()->GetCurrentBinaryDirectory() +
|
|
|
|
std::string("/") + *i;
|
|
|
|
outputs.push_back(this->ConvertToNinjaPath(d));
|
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
} else {
|
2016-02-12 16:45:09 +03:00
|
|
|
cmNinjaDeps outs;
|
2015-10-19 00:13:50 +03:00
|
|
|
cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(target);
|
2011-11-11 09:00:49 +04:00
|
|
|
for (cmTargetDependSet::const_iterator i = targetDeps.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
i != targetDeps.end(); ++i) {
|
|
|
|
if ((*i)->GetType() == cmState::INTERFACE_LIBRARY) {
|
2012-11-02 18:47:40 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-02-12 16:45:09 +03:00
|
|
|
this->AppendTargetOutputs(*i, outs);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
2016-02-12 16:45:09 +03:00
|
|
|
std::sort(outs.begin(), outs.end());
|
|
|
|
outputs.insert(outputs.end(), outs.begin(), outs.end());
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:32:32 +03:00
|
|
|
void cmGlobalNinjaGenerator::AppendTargetDependsClosure(
|
|
|
|
cmGeneratorTarget const* target, cmNinjaDeps& outputs)
|
|
|
|
{
|
|
|
|
TargetDependsClosureMap::iterator i =
|
|
|
|
this->TargetDependsClosures.find(target);
|
|
|
|
if (i == this->TargetDependsClosures.end()) {
|
|
|
|
TargetDependsClosureMap::value_type e(
|
|
|
|
target, std::set<cmGeneratorTarget const*>());
|
|
|
|
i = this->TargetDependsClosures.insert(e).first;
|
|
|
|
this->ComputeTargetDependsClosure(target, i->second);
|
|
|
|
}
|
|
|
|
std::set<cmGeneratorTarget const*> const& targets = i->second;
|
|
|
|
cmNinjaDeps outs;
|
|
|
|
for (std::set<cmGeneratorTarget const*>::const_iterator ti = targets.begin();
|
|
|
|
ti != targets.end(); ++ti) {
|
|
|
|
this->AppendTargetOutputs(*ti, outs);
|
|
|
|
}
|
|
|
|
std::sort(outs.begin(), outs.end());
|
|
|
|
outputs.insert(outputs.end(), outs.begin(), outs.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::ComputeTargetDependsClosure(
|
|
|
|
cmGeneratorTarget const* target, std::set<cmGeneratorTarget const*>& depends)
|
|
|
|
{
|
|
|
|
cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(target);
|
|
|
|
for (cmTargetDependSet::const_iterator i = targetDeps.begin();
|
|
|
|
i != targetDeps.end(); ++i) {
|
|
|
|
if ((*i)->GetType() == cmState::INTERFACE_LIBRARY) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (depends.insert(*i).second) {
|
|
|
|
this->ComputeTargetDependsClosure(*i, depends);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorTarget* target)
|
|
|
|
{
|
2016-05-14 02:18:20 +03:00
|
|
|
std::string buildAlias = this->NinjaOutputPath(alias);
|
2011-11-11 09:00:49 +04:00
|
|
|
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.
|
2016-06-10 19:36:24 +03:00
|
|
|
for (cmNinjaDeps::iterator i = outputs.begin(); i != outputs.end(); ++i) {
|
2016-06-27 23:44:16 +03:00
|
|
|
TargetAliases[*i] = CM_NULLPTR;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// 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 =
|
2016-05-14 02:18:20 +03:00
|
|
|
TargetAliases.insert(std::make_pair(buildAlias, target));
|
2016-06-10 19:36:24 +03:00
|
|
|
if (newAlias.second && newAlias.first->second != target) {
|
2016-06-27 23:44:16 +03:00
|
|
|
newAlias.first->second = CM_NULLPTR;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
os << "# Target aliases.\n\n";
|
|
|
|
|
2013-06-07 22:26:03 +04:00
|
|
|
for (TargetAliasMap::const_iterator i = TargetAliases.begin();
|
2011-11-11 09:00:49 +04:00
|
|
|
i != TargetAliases.end(); ++i) {
|
|
|
|
// Don't write ambiguous aliases.
|
2016-06-10 19:36:24 +03:00
|
|
|
if (!i->second) {
|
2011-11-11 09:00:49 +04:00
|
|
|
continue;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
cmNinjaDeps deps;
|
|
|
|
this->AppendTargetOutputs(i->second, deps);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WritePhonyBuild(os, "", cmNinjaDeps(1, i->first), deps);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-11 18:26:29 +03:00
|
|
|
void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
os << "# Folder targets.\n\n";
|
|
|
|
|
|
|
|
std::map<std::string, cmNinjaDeps> targetsPerFolder;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmLocalGenerator*>::const_iterator lgi =
|
|
|
|
this->LocalGenerators.begin();
|
|
|
|
lgi != this->LocalGenerators.end(); ++lgi) {
|
2016-03-11 18:26:29 +03:00
|
|
|
cmLocalGenerator const* lg = *lgi;
|
|
|
|
const std::string currentSourceFolder(
|
|
|
|
lg->GetStateSnapshot().GetDirectory().GetCurrentSource());
|
|
|
|
// The directory-level rule should depend on the target-level rules
|
|
|
|
// for all targets in the directory.
|
|
|
|
targetsPerFolder[currentSourceFolder] = cmNinjaDeps();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::const_iterator ti =
|
|
|
|
lg->GetGeneratorTargets().begin();
|
|
|
|
ti != lg->GetGeneratorTargets().end(); ++ti) {
|
2016-03-11 18:26:29 +03:00
|
|
|
cmGeneratorTarget const* gt = *ti;
|
|
|
|
cmState::TargetType const type = gt->GetType();
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((type == cmState::EXECUTABLE || type == cmState::STATIC_LIBRARY ||
|
|
|
|
type == cmState::SHARED_LIBRARY ||
|
|
|
|
type == cmState::MODULE_LIBRARY ||
|
|
|
|
type == cmState::OBJECT_LIBRARY || type == cmState::UTILITY) &&
|
|
|
|
!gt->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
|
2016-03-11 18:26:29 +03:00
|
|
|
targetsPerFolder[currentSourceFolder].push_back(gt->GetName());
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-03-11 18:26:29 +03:00
|
|
|
|
|
|
|
// The directory-level rule should depend on the directory-level
|
|
|
|
// rules of the subdirectories.
|
|
|
|
std::vector<cmState::Snapshot> const& children =
|
|
|
|
lg->GetStateSnapshot().GetChildren();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmState::Snapshot>::const_iterator stateIt =
|
|
|
|
children.begin();
|
|
|
|
stateIt != children.end(); ++stateIt) {
|
2016-03-11 18:26:29 +03:00
|
|
|
targetsPerFolder[currentSourceFolder].push_back(
|
|
|
|
this->ConvertToNinjaFolderRule(
|
|
|
|
stateIt->GetDirectory().GetCurrentSource()));
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-03-11 18:26:29 +03:00
|
|
|
|
|
|
|
std::string const rootSourceDir =
|
|
|
|
this->LocalGenerators[0]->GetSourceDirectory();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, cmNinjaDeps>::const_iterator it =
|
|
|
|
targetsPerFolder.begin();
|
|
|
|
it != targetsPerFolder.end(); ++it) {
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
2016-03-11 18:26:29 +03:00
|
|
|
std::string const& currentSourceDir = it->first;
|
|
|
|
|
|
|
|
// Do not generate a rule for the root source dir.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (rootSourceDir.length() >= currentSourceDir.length()) {
|
2016-03-11 18:26:29 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-03-11 18:26:29 +03:00
|
|
|
|
|
|
|
std::string const comment = "Folder: " + currentSourceDir;
|
|
|
|
cmNinjaDeps output(1);
|
|
|
|
output.push_back(this->ConvertToNinjaFolderRule(currentSourceDir));
|
|
|
|
|
|
|
|
this->WritePhonyBuild(os, comment, output, it->second);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-03-11 18:26:29 +03:00
|
|
|
}
|
|
|
|
|
2013-06-07 22:26:03 +04:00
|
|
|
void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->ComputingUnknownDependencies) {
|
2015-03-20 23:43:21 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-03-20 23:43:21 +03:00
|
|
|
|
2015-03-18 23:24:11 +03: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);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// now write out the unknown explicit dependencies.
|
2013-06-07 22:26:03 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// 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
|
2013-06-07 22:26:03 +04:00
|
|
|
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2013-06-07 22:26:03 +04:00
|
|
|
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";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2013-06-07 22:26:03 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// get the list of files that cmake itself has generated as a
|
|
|
|
// product of configuration.
|
2013-06-07 22:26:03 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
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
|
2013-06-07 22:26:03 +04:00
|
|
|
const std::vector<std::string>& files =
|
2016-05-16 17:34:04 +03:00
|
|
|
(*i)->GetMakefile()->GetOutputFiles();
|
2013-06-07 22:26:03 +04:00
|
|
|
typedef std::vector<std::string>::const_iterator vect_it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (vect_it j = files.begin(); j != files.end(); ++j) {
|
|
|
|
knownDependencies.insert(this->ConvertToNinjaPath(*j));
|
|
|
|
}
|
|
|
|
// get list files which are implicit dependencies as well and will be phony
|
|
|
|
// for rebuild manifest
|
2014-06-13 14:11:06 +04:00
|
|
|
std::vector<std::string> const& lf = (*i)->GetMakefile()->GetListFiles();
|
|
|
|
typedef std::vector<std::string>::const_iterator vect_it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (vect_it j = lf.begin(); j != lf.end(); ++j) {
|
|
|
|
knownDependencies.insert(this->ConvertToNinjaPath(*j));
|
|
|
|
}
|
2015-08-01 13:05:13 +03:00
|
|
|
std::vector<cmGeneratorExpressionEvaluationFile*> const& ef =
|
2016-05-16 17:34:04 +03:00
|
|
|
(*i)->GetMakefile()->GetEvaluationFiles();
|
|
|
|
for (std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator li =
|
|
|
|
ef.begin();
|
|
|
|
li != ef.end(); ++li) {
|
|
|
|
// get all the files created by generator expressions and convert them
|
|
|
|
// to ninja paths
|
2015-08-01 13:05:13 +03:00
|
|
|
std::vector<std::string> evaluationFiles = (*li)->GetFiles();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (vect_it j = evaluationFiles.begin(); j != evaluationFiles.end();
|
|
|
|
++j) {
|
|
|
|
knownDependencies.insert(this->ConvertToNinjaPath(*j));
|
2013-06-07 22:26:03 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-05-14 00:44:25 +03:00
|
|
|
knownDependencies.insert(this->CMakeCacheFile);
|
2013-06-07 22:26:03 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (TargetAliasMap::const_iterator i = this->TargetAliases.begin();
|
|
|
|
i != this->TargetAliases.end(); ++i) {
|
|
|
|
knownDependencies.insert(this->ConvertToNinjaPath(i->first));
|
|
|
|
}
|
2013-06-07 22:26:03 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// remove all source files we know will exist.
|
2013-06-07 22:26:03 +04:00
|
|
|
typedef std::map<std::string, std::set<std::string> >::const_iterator map_it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (map_it i = this->AssumedSourceDependencies.begin();
|
|
|
|
i != this->AssumedSourceDependencies.end(); ++i) {
|
|
|
|
knownDependencies.insert(this->ConvertToNinjaPath(i->first));
|
|
|
|
}
|
2013-06-07 22:26:03 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// now we difference with CombinedCustomCommandExplicitDependencies to find
|
|
|
|
// the list of items we know nothing about.
|
|
|
|
// We have encoded all the paths in CombinedCustomCommandExplicitDependencies
|
|
|
|
// and knownDependencies so no matter if unix or windows paths they
|
|
|
|
// should all match now.
|
2013-06-07 22:26:03 +04:00
|
|
|
|
2015-03-18 23:44:05 +03:00
|
|
|
std::vector<std::string> unknownExplicitDepends;
|
2016-05-14 00:42:02 +03:00
|
|
|
this->CombinedCustomCommandExplicitDependencies.erase(this->TargetAll);
|
2013-06-07 22:26:03 +04:00
|
|
|
|
2014-06-28 00:13:50 +04:00
|
|
|
std::set_difference(this->CombinedCustomCommandExplicitDependencies.begin(),
|
|
|
|
this->CombinedCustomCommandExplicitDependencies.end(),
|
2016-05-16 17:34:04 +03:00
|
|
|
knownDependencies.begin(), knownDependencies.end(),
|
2015-03-18 23:44:05 +03:00
|
|
|
std::back_inserter(unknownExplicitDepends));
|
2013-06-07 22:26:03 +04:00
|
|
|
|
2014-10-08 16:49:05 +04:00
|
|
|
std::string const rootBuildDirectory =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GetCMakeInstance()->GetHomeOutputDirectory();
|
2015-03-20 23:43:21 +03:00
|
|
|
bool const inSourceBuild =
|
|
|
|
(rootBuildDirectory == this->GetCMakeInstance()->GetHomeDirectory());
|
|
|
|
std::vector<std::string> warnExplicitDepends;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator i =
|
|
|
|
unknownExplicitDepends.begin();
|
|
|
|
i != unknownExplicitDepends.end(); ++i) {
|
|
|
|
// verify the file is in the build directory
|
|
|
|
std::string const absDepPath =
|
|
|
|
cmSystemTools::CollapseFullPath(*i, rootBuildDirectory.c_str());
|
|
|
|
bool const inBuildDir =
|
|
|
|
cmSystemTools::IsSubDirectory(absDepPath, rootBuildDirectory);
|
|
|
|
if (inBuildDir) {
|
|
|
|
cmNinjaDeps deps(1, *i);
|
|
|
|
this->WritePhonyBuild(os, "", deps, cmNinjaDeps());
|
|
|
|
if (this->PolicyCMP0058 == cmPolicies::WARN && !inSourceBuild &&
|
|
|
|
warnExplicitDepends.size() < 10) {
|
2015-03-20 23:43:21 +03:00
|
|
|
warnExplicitDepends.push_back(*i);
|
2014-10-08 16:49:05 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
}
|
2015-03-20 23:43:21 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!warnExplicitDepends.empty()) {
|
2015-03-20 23:43:21 +03:00
|
|
|
std::ostringstream w;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2015-05-03 11:12:10 +03:00
|
|
|
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0058) << "\n"
|
2015-03-20 23:43:21 +03:00
|
|
|
"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."
|
|
|
|
;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2015-03-20 23:43:21 +03:00
|
|
|
this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-06-07 22:26:03 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04: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 18:47:48 +04:00
|
|
|
this->WriteTargetClean(os);
|
2012-04-19 19:07:35 +04:00
|
|
|
this->WriteTargetHelp(os);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteTargetAll(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmNinjaDeps outputs;
|
2016-05-14 00:42:02 +03:00
|
|
|
outputs.push_back(this->TargetAll);
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WritePhonyBuild(os, "The main all target.", outputs,
|
2013-06-07 22:25:33 +04:00
|
|
|
this->AllDependencies);
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2016-05-14 02:18:20 +03:00
|
|
|
if (!this->HasOutputPathPrefix()) {
|
|
|
|
cmGlobalNinjaGenerator::WriteDefault(os, outputs,
|
|
|
|
"Make the all target the default.");
|
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalGenerator* lg = this->LocalGenerators[0];
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream cmd;
|
2015-05-20 16:10:52 +03:00
|
|
|
cmd << lg->ConvertToOutputFormat(cmSystemTools::GetCMakeCommand(),
|
2016-05-20 00:11:40 +03:00
|
|
|
cmOutputConverter::SHELL)
|
2012-02-19 07:07:09 +04:00
|
|
|
<< " -H"
|
2015-10-07 02:17:48 +03:00
|
|
|
<< lg->ConvertToOutputFormat(lg->GetSourceDirectory(),
|
2016-05-20 00:11:40 +03:00
|
|
|
cmOutputConverter::SHELL)
|
2012-02-19 07:07:09 +04:00
|
|
|
<< " -B"
|
2015-10-07 02:17:48 +03:00
|
|
|
<< lg->ConvertToOutputFormat(lg->GetBinaryDirectory(),
|
2016-05-20 00:11:40 +03:00
|
|
|
cmOutputConverter::SHELL);
|
2016-05-16 17:34:04 +03:00
|
|
|
WriteRule(*this->RulesFileStream, "RERUN_CMAKE", cmd.str(),
|
|
|
|
"Re-running CMake...", "Rule for re-running cmake.",
|
|
|
|
/*depfile=*/"",
|
|
|
|
/*deptype=*/"",
|
|
|
|
/*rspfile=*/"",
|
2012-07-10 11:56:11 +04:00
|
|
|
/*rspcontent*/ "",
|
2016-05-16 17:34:04 +03:00
|
|
|
/*restat=*/"",
|
|
|
|
/*generator=*/true);
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2014-01-16 01:33:22 +04:00
|
|
|
cmNinjaDeps implicitDeps;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmLocalGenerator*>::const_iterator i =
|
|
|
|
this->LocalGenerators.begin();
|
|
|
|
i != this->LocalGenerators.end(); ++i) {
|
2014-01-21 22:18:40 +04:00
|
|
|
std::vector<std::string> const& lf = (*i)->GetMakefile()->GetListFiles();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator fi = lf.begin();
|
|
|
|
fi != lf.end(); ++fi) {
|
2015-09-25 20:26:44 +03:00
|
|
|
implicitDeps.push_back(this->ConvertToNinjaPath(*fi));
|
2014-01-21 22:18:40 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-05-14 00:44:25 +03:00
|
|
|
implicitDeps.push_back(this->CMakeCacheFile);
|
2014-01-21 22:18:40 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
std::sort(implicitDeps.begin(), implicitDeps.end());
|
|
|
|
implicitDeps.erase(std::unique(implicitDeps.begin(), implicitDeps.end()),
|
|
|
|
implicitDeps.end());
|
|
|
|
|
2014-10-02 23:21:05 +04:00
|
|
|
cmNinjaVars variables;
|
|
|
|
// Use 'console' pool to get non buffered output of the CMake re-run call
|
|
|
|
// Available since Ninja 1.5
|
2016-05-16 17:34:04 +03:00
|
|
|
if (SupportsConsolePool()) {
|
2014-10-02 23:21:05 +04:00
|
|
|
variables["pool"] = "console";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-02 23:21:05 +04:00
|
|
|
|
2016-05-14 02:18:20 +03:00
|
|
|
std::string const ninjaBuildFile = this->NinjaOutputPath(NINJA_BUILD_FILE);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteBuild(os, "Re-run CMake if any of its inputs changed.",
|
2013-06-07 22:25:33 +04:00
|
|
|
"RERUN_CMAKE",
|
2016-05-14 02:18:20 +03:00
|
|
|
/*outputs=*/cmNinjaDeps(1, ninjaBuildFile),
|
2016-05-16 17:34:04 +03:00
|
|
|
/*explicitDeps=*/cmNinjaDeps(), implicitDeps,
|
|
|
|
/*orderOnlyDeps=*/cmNinjaDeps(), variables);
|
|
|
|
|
|
|
|
this->WritePhonyBuild(os, "A missing CMake input file is not an error.",
|
|
|
|
implicitDeps, cmNinjaDeps());
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
2012-04-19 18:47:48 +04:00
|
|
|
|
2012-06-15 14:14:13 +04:00
|
|
|
std::string cmGlobalNinjaGenerator::ninjaCmd() const
|
|
|
|
{
|
|
|
|
cmLocalGenerator* lgen = this->LocalGenerators[0];
|
|
|
|
if (lgen) {
|
2015-11-03 00:27:31 +03:00
|
|
|
return lgen->ConvertToOutputFormat(this->NinjaCommand,
|
2016-05-20 00:11:40 +03:00
|
|
|
cmOutputConverter::SHELL);
|
2012-06-15 14:14:13 +04:00
|
|
|
}
|
|
|
|
return "ninja";
|
|
|
|
}
|
|
|
|
|
2014-11-05 23:40:14 +03:00
|
|
|
bool cmGlobalNinjaGenerator::SupportsConsolePool() const
|
|
|
|
{
|
2016-06-02 00:29:53 +03:00
|
|
|
return !cmSystemTools::VersionCompare(
|
|
|
|
cmSystemTools::OP_LESS, this->NinjaVersion.c_str(),
|
|
|
|
RequiredNinjaVersionForConsolePool().c_str());
|
2014-11-05 23:40:14 +03:00
|
|
|
}
|
|
|
|
|
2012-04-19 18:47:48 +04:00
|
|
|
void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
WriteRule(*this->RulesFileStream, "CLEAN", ninjaCmd() + " -t clean",
|
2012-04-19 18:47:48 +04:00
|
|
|
"Cleaning all built files...",
|
|
|
|
"Rule for cleaning all built files.",
|
2016-05-16 17:34:04 +03:00
|
|
|
/*depfile=*/"",
|
|
|
|
/*deptype=*/"",
|
|
|
|
/*rspfile=*/"",
|
2012-07-10 11:56:11 +04:00
|
|
|
/*rspcontent*/ "",
|
2016-05-16 17:34:04 +03:00
|
|
|
/*restat=*/"",
|
|
|
|
/*generator=*/false);
|
|
|
|
WriteBuild(os, "Clean all the built files.", "CLEAN",
|
2016-05-14 02:18:20 +03:00
|
|
|
/*outputs=*/cmNinjaDeps(1, this->NinjaOutputPath("clean")),
|
2016-05-16 17:34:04 +03:00
|
|
|
/*explicitDeps=*/cmNinjaDeps(),
|
|
|
|
/*implicitDeps=*/cmNinjaDeps(),
|
|
|
|
/*orderOnlyDeps=*/cmNinjaDeps(),
|
|
|
|
/*variables=*/cmNinjaVars());
|
2012-04-19 18:47:48 +04:00
|
|
|
}
|
2012-04-19 19:07:35 +04:00
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::WriteTargetHelp(std::ostream& os)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
WriteRule(*this->RulesFileStream, "HELP", ninjaCmd() + " -t targets",
|
2012-04-19 19:07:35 +04:00
|
|
|
"All primary targets available:",
|
|
|
|
"Rule for printing all primary targets available.",
|
2016-05-16 17:34:04 +03:00
|
|
|
/*depfile=*/"",
|
|
|
|
/*deptype=*/"",
|
|
|
|
/*rspfile=*/"",
|
2012-07-10 11:56:11 +04:00
|
|
|
/*rspcontent*/ "",
|
2016-05-16 17:34:04 +03:00
|
|
|
/*restat=*/"",
|
|
|
|
/*generator=*/false);
|
|
|
|
WriteBuild(os, "Print all primary targets available.", "HELP",
|
2016-05-14 02:18:20 +03:00
|
|
|
/*outputs=*/cmNinjaDeps(1, this->NinjaOutputPath("help")),
|
2016-05-16 17:34:04 +03:00
|
|
|
/*explicitDeps=*/cmNinjaDeps(),
|
|
|
|
/*implicitDeps=*/cmNinjaDeps(),
|
|
|
|
/*orderOnlyDeps=*/cmNinjaDeps(),
|
|
|
|
/*variables=*/cmNinjaVars());
|
2012-04-19 19:07:35 +04:00
|
|
|
}
|
2016-05-14 02:18:20 +03:00
|
|
|
|
2016-05-14 02:18:20 +03:00
|
|
|
void cmGlobalNinjaGenerator::InitOutputPathPrefix()
|
|
|
|
{
|
|
|
|
this->OutputPathPrefix =
|
|
|
|
this->LocalGenerators[0]->GetMakefile()->GetSafeDefinition(
|
|
|
|
"CMAKE_NINJA_OUTPUT_PATH_PREFIX");
|
|
|
|
EnsureTrailingSlash(this->OutputPathPrefix);
|
|
|
|
}
|
|
|
|
|
2016-05-14 02:18:20 +03:00
|
|
|
std::string cmGlobalNinjaGenerator::NinjaOutputPath(std::string const& path)
|
|
|
|
{
|
2016-05-14 02:18:20 +03:00
|
|
|
if (!this->HasOutputPathPrefix() || cmSystemTools::FileIsFullPath(path)) {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
return this->OutputPathPrefix + path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalNinjaGenerator::StripNinjaOutputPathPrefixAsSuffix(
|
|
|
|
std::string& path)
|
|
|
|
{
|
|
|
|
if (path.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EnsureTrailingSlash(path);
|
|
|
|
cmStripSuffixIfExists(path, this->OutputPathPrefix);
|
2016-05-14 02:18:20 +03:00
|
|
|
}
|