2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2011-11-11 09:00:49 +04:00
|
|
|
#include "cmLocalNinjaGenerator.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmCustomCommand.h"
|
2011-11-11 09:00:49 +04:00
|
|
|
#include "cmCustomCommandGenerator.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmGeneratorTarget.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
2011-11-11 09:00:49 +04:00
|
|
|
#include "cmGlobalNinjaGenerator.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmMakefile.h"
|
2011-11-11 09:00:49 +04:00
|
|
|
#include "cmNinjaTargetGenerator.h"
|
|
|
|
#include "cmSourceFile.h"
|
2015-04-11 15:15:55 +03:00
|
|
|
#include "cmState.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmSystemTools.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmake.h"
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <algorithm>
|
2011-11-11 09:00:49 +04:00
|
|
|
#include <assert.h>
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <iterator>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <utility>
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2015-05-03 17:50:34 +03:00
|
|
|
cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg,
|
2015-08-02 12:41:51 +03:00
|
|
|
cmMakefile* mf)
|
2016-08-27 19:32:49 +03:00
|
|
|
: cmLocalCommonGenerator(gg, mf, mf->GetState()->GetBinaryDirectory())
|
2011-11-11 09:00:49 +04:00
|
|
|
, HomeRelativeOutputPath("")
|
|
|
|
{
|
2012-02-20 01:38:10 +04:00
|
|
|
this->TargetImplib = "$TARGET_IMPLIB";
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Virtual public methods.
|
|
|
|
|
|
|
|
cmLocalNinjaGenerator::~cmLocalNinjaGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmLocalNinjaGenerator::Generate()
|
|
|
|
{
|
2015-05-30 20:12:38 +03:00
|
|
|
// Compute the path to use when referencing the current output
|
|
|
|
// directory from the top output directory.
|
2016-08-27 14:44:56 +03:00
|
|
|
this->HomeRelativeOutputPath = this->ConvertToRelativePath(
|
2016-09-07 00:02:23 +03:00
|
|
|
this->GetBinaryDirectory(), this->GetCurrentBinaryDirectory());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->HomeRelativeOutputPath == ".") {
|
2015-05-30 20:12:38 +03:00
|
|
|
this->HomeRelativeOutputPath = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-30 20:12:38 +03:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
this->SetConfigName();
|
|
|
|
|
|
|
|
this->WriteProcessedMakefile(this->GetBuildFileStream());
|
2012-06-10 22:20:29 +04:00
|
|
|
#ifdef NINJA_GEN_VERBOSE_FILES
|
2011-11-11 09:00:49 +04:00
|
|
|
this->WriteProcessedMakefile(this->GetRulesFileStream());
|
2012-06-10 22:20:29 +04:00
|
|
|
#endif
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2013-10-18 14:59:47 +04:00
|
|
|
// We do that only once for the top CMakeLists.txt file.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsRootMakefile()) {
|
2013-10-18 14:59:47 +04:00
|
|
|
this->WriteBuildFileTop();
|
|
|
|
|
2013-11-23 13:49:36 +04:00
|
|
|
this->WritePools(this->GetRulesFileStream());
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string showIncludesPrefix =
|
|
|
|
this->GetMakefile()->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX");
|
|
|
|
if (!showIncludesPrefix.empty()) {
|
2013-10-18 14:59:47 +04:00
|
|
|
cmGlobalNinjaGenerator::WriteComment(this->GetRulesFileStream(),
|
|
|
|
"localized /showIncludes string");
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GetRulesFileStream() << "msvc_deps_prefix = " << showIncludesPrefix
|
|
|
|
<< "\n\n";
|
2013-10-18 14:59:47 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2015-10-18 17:53:00 +03:00
|
|
|
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
|
|
|
|
t != targets.end(); ++t) {
|
|
|
|
if ((*t)->GetType() == cmState::INTERFACE_LIBRARY) {
|
2012-10-10 23:32:37 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-18 17:53:00 +03:00
|
|
|
cmNinjaTargetGenerator* tg = cmNinjaTargetGenerator::New(*t);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tg) {
|
2011-11-11 09:00:49 +04:00
|
|
|
tg->Generate();
|
|
|
|
// Add the target to "all" if required.
|
|
|
|
if (!this->GetGlobalNinjaGenerator()->IsExcluded(
|
2016-06-10 19:36:24 +03:00
|
|
|
this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0], *t)) {
|
2015-10-19 00:13:50 +03:00
|
|
|
this->GetGlobalNinjaGenerator()->AddDependencyToAll(*t);
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
delete tg;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
this->WriteCustomCommandBuildStatements();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Picked up from cmLocalUnixMakefileGenerator3. Refactor it.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmLocalNinjaGenerator::GetTargetDirectory(
|
|
|
|
cmGeneratorTarget const* target) const
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
|
2015-10-09 23:27:46 +03:00
|
|
|
dir += target->GetName();
|
2011-11-11 09:00:49 +04:00
|
|
|
#if defined(__VMS)
|
|
|
|
dir += "_dir";
|
|
|
|
#else
|
|
|
|
dir += ".dir";
|
|
|
|
#endif
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Non-virtual public methods.
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmGlobalNinjaGenerator* cmLocalNinjaGenerator::GetGlobalNinjaGenerator()
|
|
|
|
const
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
return static_cast<const cmGlobalNinjaGenerator*>(
|
|
|
|
this->GetGlobalGenerator());
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmGlobalNinjaGenerator* cmLocalNinjaGenerator::GetGlobalNinjaGenerator()
|
|
|
|
{
|
|
|
|
return static_cast<cmGlobalNinjaGenerator*>(this->GetGlobalGenerator());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Virtual protected methods.
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmLocalNinjaGenerator::ConvertToLinkReference(
|
2016-05-20 00:11:40 +03:00
|
|
|
std::string const& lib, cmOutputConverter::OutputFormat format)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2016-05-14 02:18:20 +03:00
|
|
|
std::string path = this->GetGlobalNinjaGenerator()->ConvertToNinjaPath(lib);
|
|
|
|
return this->ConvertToOutputFormat(path, format);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmLocalNinjaGenerator::ConvertToIncludeReference(
|
2016-05-20 00:11:40 +03:00
|
|
|
std::string const& path, cmOutputConverter::OutputFormat format,
|
|
|
|
bool forceFullPaths)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2016-08-27 14:44:57 +03:00
|
|
|
if (forceFullPaths) {
|
2016-08-27 14:44:57 +03:00
|
|
|
return this->ConvertToOutputFormat(cmSystemTools::CollapseFullPath(path),
|
|
|
|
format);
|
2016-08-27 14:44:57 +03:00
|
|
|
}
|
2016-08-27 19:20:37 +03:00
|
|
|
return this->ConvertToOutputFormat(
|
|
|
|
this->ConvertToRelativePath(this->GetBinaryDirectory(), path), format);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Private methods.
|
|
|
|
|
|
|
|
cmGeneratedFileStream& cmLocalNinjaGenerator::GetBuildFileStream() const
|
|
|
|
{
|
|
|
|
return *this->GetGlobalNinjaGenerator()->GetBuildFileStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
cmGeneratedFileStream& cmLocalNinjaGenerator::GetRulesFileStream() const
|
|
|
|
{
|
|
|
|
return *this->GetGlobalNinjaGenerator()->GetRulesFileStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
const cmake* cmLocalNinjaGenerator::GetCMakeInstance() const
|
|
|
|
{
|
|
|
|
return this->GetGlobalGenerator()->GetCMakeInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
cmake* cmLocalNinjaGenerator::GetCMakeInstance()
|
|
|
|
{
|
|
|
|
return this->GetGlobalGenerator()->GetCMakeInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmLocalNinjaGenerator::WriteBuildFileTop()
|
|
|
|
{
|
|
|
|
// For the build file.
|
|
|
|
this->WriteProjectHeader(this->GetBuildFileStream());
|
2014-10-02 23:21:05 +04:00
|
|
|
this->WriteNinjaRequiredVersion(this->GetBuildFileStream());
|
2011-11-11 09:00:49 +04:00
|
|
|
this->WriteNinjaFilesInclusion(this->GetBuildFileStream());
|
|
|
|
|
|
|
|
// For the rule file.
|
|
|
|
this->WriteProjectHeader(this->GetRulesFileStream());
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmLocalNinjaGenerator::WriteProjectHeader(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
2016-05-16 17:34:04 +03:00
|
|
|
os << "# Project: " << this->GetProjectName() << std::endl
|
|
|
|
<< "# Configuration: " << this->ConfigName << std::endl;
|
2011-11-11 09:00:49 +04:00
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
}
|
|
|
|
|
2014-10-02 23:21:05 +04:00
|
|
|
void cmLocalNinjaGenerator::WriteNinjaRequiredVersion(std::ostream& os)
|
|
|
|
{
|
|
|
|
// Default required version
|
2015-08-08 23:04:08 +03:00
|
|
|
std::string requiredVersion =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GetGlobalNinjaGenerator()->RequiredNinjaVersion();
|
2014-10-02 23:21:05 +04:00
|
|
|
|
|
|
|
// Ninja generator uses the 'console' pool if available (>= 1.5)
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->GetGlobalNinjaGenerator()->SupportsConsolePool()) {
|
2015-08-08 23:04:08 +03:00
|
|
|
requiredVersion =
|
|
|
|
this->GetGlobalNinjaGenerator()->RequiredNinjaVersionForConsolePool();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-02 23:21:05 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGlobalNinjaGenerator::WriteComment(
|
|
|
|
os, "Minimal version of Ninja required by this file");
|
|
|
|
os << "ninja_required_version = " << requiredVersion << std::endl
|
|
|
|
<< std::endl;
|
2014-10-02 23:21:05 +04:00
|
|
|
}
|
|
|
|
|
2013-11-23 13:49:36 +04:00
|
|
|
void cmLocalNinjaGenerator::WritePools(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* jobpools =
|
|
|
|
this->GetCMakeInstance()->GetState()->GetGlobalProperty("JOB_POOLS");
|
|
|
|
if (jobpools) {
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(
|
|
|
|
os, "Pools defined by global property JOB_POOLS");
|
2013-11-23 13:49:36 +04:00
|
|
|
std::vector<std::string> pools;
|
|
|
|
cmSystemTools::ExpandListArgument(jobpools, pools);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 0; i < pools.size(); ++i) {
|
2013-11-23 13:49:36 +04:00
|
|
|
const std::string pool = pools[i];
|
2016-05-24 22:24:10 +03:00
|
|
|
const std::string::size_type eq = pool.find('=');
|
2013-11-23 13:49:36 +04:00
|
|
|
unsigned int jobs;
|
|
|
|
if (eq != std::string::npos &&
|
2016-05-16 17:34:04 +03:00
|
|
|
sscanf(pool.c_str() + eq, "=%u", &jobs) == 1) {
|
2013-11-23 13:49:36 +04:00
|
|
|
os << "pool " << pool.substr(0, eq) << std::endl;
|
|
|
|
os << " depth = " << jobs << std::endl;
|
|
|
|
os << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-11-23 13:49:36 +04:00
|
|
|
cmSystemTools::Error("Invalid pool defined by property 'JOB_POOLS': ",
|
|
|
|
pool.c_str());
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-23 13:49:36 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
void cmLocalNinjaGenerator::WriteNinjaFilesInclusion(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
2016-05-16 17:34:04 +03:00
|
|
|
os << "# Include auxiliary files.\n"
|
|
|
|
<< "\n";
|
2016-05-14 02:18:20 +03:00
|
|
|
cmGlobalNinjaGenerator* ng = this->GetGlobalNinjaGenerator();
|
|
|
|
std::string const ninjaRulesFile =
|
|
|
|
ng->NinjaOutputPath(cmGlobalNinjaGenerator::NINJA_RULES_FILE);
|
|
|
|
std::string const rulesFilePath =
|
|
|
|
ng->EncodeIdent(ng->EncodePath(ninjaRulesFile), os);
|
|
|
|
cmGlobalNinjaGenerator::WriteInclude(os, rulesFilePath,
|
|
|
|
"Include rules file.");
|
2011-11-11 09:00:49 +04:00
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
|
2014-03-11 20:37:26 +04:00
|
|
|
void cmLocalNinjaGenerator::ComputeObjectFilenames(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::map<cmSourceFile const*, std::string>& mapping,
|
|
|
|
cmGeneratorTarget const* gt)
|
2014-03-11 20:37:26 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<cmSourceFile const*, std::string>::iterator si =
|
|
|
|
mapping.begin();
|
|
|
|
si != mapping.end(); ++si) {
|
2014-03-11 20:37:26 +04:00
|
|
|
cmSourceFile const* sf = si->first;
|
2016-05-16 17:34:04 +03:00
|
|
|
si->second =
|
|
|
|
this->GetObjectFileNameWithoutTarget(*sf, gt->ObjectDirectory);
|
|
|
|
}
|
2014-03-11 20:37:26 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
2016-05-16 17:34:04 +03:00
|
|
|
os << "# Write statements declared in CMakeLists.txt:" << std::endl
|
|
|
|
<< "# " << this->Makefile->GetDefinition("CMAKE_CURRENT_LIST_FILE")
|
|
|
|
<< std::endl;
|
2016-06-10 19:36:24 +03:00
|
|
|
if (this->IsRootMakefile()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
os << "# Which is the root file." << std::endl;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalNinjaGenerator::AppendTargetOutputs(cmGeneratorTarget* target,
|
|
|
|
cmNinjaDeps& outputs)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs);
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalNinjaGenerator::AppendTargetDepends(cmGeneratorTarget* target,
|
|
|
|
cmNinjaDeps& outputs)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs);
|
|
|
|
}
|
|
|
|
|
2014-03-10 23:47:19 +04:00
|
|
|
void cmLocalNinjaGenerator::AppendCustomCommandDeps(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCustomCommandGenerator const& ccg, cmNinjaDeps& ninjaDeps)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::vector<std::string>& deps = ccg.GetDepends();
|
2011-11-11 09:00:49 +04:00
|
|
|
for (std::vector<std::string>::const_iterator i = deps.begin();
|
|
|
|
i != deps.end(); ++i) {
|
|
|
|
std::string dep;
|
2016-06-10 19:36:24 +03:00
|
|
|
if (this->GetRealDependency(*i, this->GetConfigName(), dep)) {
|
2015-09-25 20:26:44 +03:00
|
|
|
ninjaDeps.push_back(
|
|
|
|
this->GetGlobalNinjaGenerator()->ConvertToNinjaPath(dep));
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmLocalNinjaGenerator::BuildCommandLine(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::vector<std::string>& cmdLines)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
// If we have no commands but we need to build a command anyway, use ":".
|
|
|
|
// This happens when building a POST_BUILD value for link targets that
|
|
|
|
// don't use POST_BUILD.
|
2016-06-10 19:36:24 +03:00
|
|
|
if (cmdLines.empty()) {
|
2012-02-18 11:07:11 +04:00
|
|
|
#ifdef _WIN32
|
2012-07-02 02:01:41 +04:00
|
|
|
return "cd .";
|
2012-02-18 11:07:11 +04:00
|
|
|
#else
|
2011-11-11 09:00:49 +04:00
|
|
|
return ":";
|
2012-02-18 11:07:11 +04:00
|
|
|
#endif
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream cmd;
|
2011-11-11 09:00:49 +04:00
|
|
|
for (std::vector<std::string>::const_iterator li = cmdLines.begin();
|
2013-11-25 14:17:14 +04:00
|
|
|
li != cmdLines.end(); ++li)
|
2012-06-06 00:39:42 +04:00
|
|
|
#ifdef _WIN32
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (li != cmdLines.begin()) {
|
2013-11-25 14:17:14 +04:00
|
|
|
cmd << " && ";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmdLines.size() > 1) {
|
2013-11-25 14:17:14 +04:00
|
|
|
cmd << "cmd.exe /C \"";
|
2012-06-06 00:39:42 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
cmd << *li;
|
|
|
|
}
|
|
|
|
if (cmdLines.size() > 1) {
|
2013-11-25 14:17:14 +04:00
|
|
|
cmd << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-25 14:17:14 +04:00
|
|
|
#else
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (li != cmdLines.begin()) {
|
2013-11-25 14:17:14 +04:00
|
|
|
cmd << " && ";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
cmd << *li;
|
|
|
|
}
|
2013-11-25 14:17:14 +04:00
|
|
|
#endif
|
2011-11-11 09:00:49 +04:00
|
|
|
return cmd.str();
|
|
|
|
}
|
|
|
|
|
2014-03-10 23:47:19 +04:00
|
|
|
void cmLocalNinjaGenerator::AppendCustomCommandLines(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCustomCommandGenerator const& ccg, std::vector<std::string>& cmdLines)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
if (ccg.GetNumberOfCommands() > 0) {
|
2014-03-10 23:47:19 +04:00
|
|
|
std::string wd = ccg.GetWorkingDirectory();
|
2016-06-10 19:36:24 +03:00
|
|
|
if (wd.empty()) {
|
2015-09-25 01:13:20 +03:00
|
|
|
wd = this->GetCurrentBinaryDirectory();
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2012-02-19 06:46:37 +04:00
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream cdCmd;
|
2013-04-18 21:57:39 +04:00
|
|
|
#ifdef _WIN32
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cdStr = "cd /D ";
|
2013-04-18 21:57:39 +04:00
|
|
|
#else
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cdStr = "cd ";
|
2013-04-18 21:57:39 +04:00
|
|
|
#endif
|
2016-05-20 00:11:40 +03:00
|
|
|
cdCmd << cdStr
|
|
|
|
<< this->ConvertToOutputFormat(wd, cmOutputConverter::SHELL);
|
2011-11-11 09:00:49 +04:00
|
|
|
cmdLines.push_back(cdCmd.str());
|
|
|
|
}
|
2013-10-30 01:56:23 +04:00
|
|
|
|
2014-03-10 23:47:19 +04:00
|
|
|
std::string launcher = this->MakeCustomLauncher(ccg);
|
2013-10-30 01:56:23 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
for (unsigned i = 0; i != ccg.GetNumberOfCommands(); ++i) {
|
2013-10-30 01:56:23 +04:00
|
|
|
cmdLines.push_back(launcher +
|
2016-05-20 00:11:40 +03:00
|
|
|
this->ConvertToOutputFormat(ccg.GetCommand(i),
|
|
|
|
cmOutputConverter::SHELL));
|
2013-10-30 01:56:23 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
std::string& cmd = cmdLines.back();
|
|
|
|
ccg.AppendArguments(i, cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
|
|
|
|
cmCustomCommand const* cc, const cmNinjaDeps& orderOnlyDeps)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2016-06-10 19:36:24 +03:00
|
|
|
if (this->GetGlobalNinjaGenerator()->SeenCustomCommand(cc)) {
|
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
|
|
|
|
2015-07-25 18:52:10 +03:00
|
|
|
cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this);
|
2014-03-10 23:47:19 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::vector<std::string>& outputs = ccg.GetOutputs();
|
|
|
|
const std::vector<std::string>& byproducts = ccg.GetByproducts();
|
|
|
|
cmNinjaDeps ninjaOutputs(outputs.size() + byproducts.size()), ninjaDeps;
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2015-11-19 23:13:11 +03:00
|
|
|
bool symbolic = false;
|
|
|
|
for (std::vector<std::string>::const_iterator o = outputs.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
!symbolic && o != outputs.end(); ++o) {
|
|
|
|
if (cmSourceFile* sf = this->Makefile->GetSource(*o)) {
|
2015-11-19 23:13:11 +03:00
|
|
|
symbolic = sf->GetPropertyAsBool("SYMBOLIC");
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-11-19 23:13:11 +03:00
|
|
|
|
2014-11-14 02:54:52 +03:00
|
|
|
#if 0
|
|
|
|
#error TODO: Once CC in an ExternalProject target must provide the \
|
|
|
|
file of each imported target that has an add_dependencies pointing \
|
|
|
|
at us. How to know which ExternalProject step actually provides it?
|
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
std::transform(outputs.begin(), outputs.end(), ninjaOutputs.begin(),
|
2015-09-25 20:26:44 +03:00
|
|
|
this->GetGlobalNinjaGenerator()->MapToNinjaPath());
|
2014-11-14 02:54:52 +03:00
|
|
|
std::transform(byproducts.begin(), byproducts.end(),
|
2015-09-25 20:26:44 +03:00
|
|
|
ninjaOutputs.begin() + outputs.size(),
|
|
|
|
this->GetGlobalNinjaGenerator()->MapToNinjaPath());
|
2014-03-10 23:47:19 +04:00
|
|
|
this->AppendCustomCommandDeps(ccg, ninjaDeps);
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
for (cmNinjaDeps::iterator i = ninjaOutputs.begin(); i != ninjaOutputs.end();
|
2016-06-10 19:36:24 +03:00
|
|
|
++i) {
|
2011-11-11 09:00:49 +04:00
|
|
|
this->GetGlobalNinjaGenerator()->SeenCustomCommandOutput(*i);
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
std::vector<std::string> cmdLines;
|
2014-03-10 23:47:19 +04:00
|
|
|
this->AppendCustomCommandLines(ccg, cmdLines);
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
if (cmdLines.empty()) {
|
2013-06-07 22:25:33 +04:00
|
|
|
this->GetGlobalNinjaGenerator()->WritePhonyBuild(
|
|
|
|
this->GetBuildFileStream(),
|
2016-05-16 17:34:04 +03:00
|
|
|
"Phony custom command for " + ninjaOutputs[0], ninjaOutputs, ninjaDeps,
|
|
|
|
cmNinjaDeps(), orderOnlyDeps, cmNinjaVars());
|
2011-11-11 09:00:49 +04:00
|
|
|
} else {
|
|
|
|
this->GetGlobalNinjaGenerator()->WriteCustomCommandBuild(
|
2016-05-16 17:34:04 +03:00
|
|
|
this->BuildCommandLine(cmdLines), this->ConstructComment(ccg),
|
2016-08-05 15:39:31 +03:00
|
|
|
"Custom command for " + ninjaOutputs[0], cc->GetDepfile(),
|
|
|
|
cc->GetUsesTerminal(),
|
2016-05-16 17:34:04 +03:00
|
|
|
/*restat*/ !symbolic || !byproducts.empty(), ninjaOutputs, ninjaDeps,
|
2011-11-11 09:00:49 +04:00
|
|
|
orderOnlyDeps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 17:17:46 +04:00
|
|
|
void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc,
|
2015-10-19 00:13:50 +03:00
|
|
|
cmGeneratorTarget* target)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2016-02-10 22:08:48 +03:00
|
|
|
CustomCommandTargetMap::value_type v(cc, std::set<cmGeneratorTarget*>());
|
2016-05-16 17:34:04 +03:00
|
|
|
std::pair<CustomCommandTargetMap::iterator, bool> ins =
|
|
|
|
this->CustomCommandTargets.insert(v);
|
|
|
|
if (ins.second) {
|
2016-02-10 22:08:48 +03:00
|
|
|
this->CustomCommands.push_back(cc);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-02-10 22:08:48 +03:00
|
|
|
ins.first->second.insert(target);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
|
|
|
|
{
|
2016-02-10 22:08:48 +03:00
|
|
|
for (std::vector<cmCustomCommand const*>::iterator vi =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CustomCommands.begin();
|
|
|
|
vi != this->CustomCommands.end(); ++vi) {
|
2016-02-10 22:08:48 +03:00
|
|
|
CustomCommandTargetMap::iterator i = this->CustomCommandTargets.find(*vi);
|
|
|
|
assert(i != this->CustomCommandTargets.end());
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// A custom command may appear on multiple targets. However, some build
|
|
|
|
// systems exist where the target dependencies on some of the targets are
|
|
|
|
// overspecified, leading to a dependency cycle. If we assume all target
|
|
|
|
// dependencies are a superset of the true target dependencies for this
|
|
|
|
// custom command, we can take the set intersection of all target
|
|
|
|
// dependencies to obtain a correct dependency list.
|
|
|
|
//
|
|
|
|
// FIXME: This won't work in certain obscure scenarios involving indirect
|
|
|
|
// dependencies.
|
2015-10-19 00:13:50 +03:00
|
|
|
std::set<cmGeneratorTarget*>::iterator j = i->second.begin();
|
2011-11-11 09:00:49 +04:00
|
|
|
assert(j != i->second.end());
|
|
|
|
std::vector<std::string> ccTargetDeps;
|
2016-07-20 16:32:32 +03:00
|
|
|
this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j,
|
|
|
|
ccTargetDeps);
|
2011-11-11 09:00:49 +04:00
|
|
|
std::sort(ccTargetDeps.begin(), ccTargetDeps.end());
|
|
|
|
++j;
|
|
|
|
|
|
|
|
for (; j != i->second.end(); ++j) {
|
|
|
|
std::vector<std::string> jDeps, depsIntersection;
|
2016-07-20 16:32:32 +03:00
|
|
|
this->GetGlobalNinjaGenerator()->AppendTargetDependsClosure(*j, jDeps);
|
2011-11-11 09:00:49 +04:00
|
|
|
std::sort(jDeps.begin(), jDeps.end());
|
|
|
|
std::set_intersection(ccTargetDeps.begin(), ccTargetDeps.end(),
|
|
|
|
jDeps.begin(), jDeps.end(),
|
|
|
|
std::back_inserter(depsIntersection));
|
|
|
|
ccTargetDeps = depsIntersection;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->WriteCustomCommandBuildStatement(i->first, ccTargetDeps);
|
|
|
|
}
|
|
|
|
}
|
2013-10-30 01:56:23 +04:00
|
|
|
|
|
|
|
std::string cmLocalNinjaGenerator::MakeCustomLauncher(
|
2014-03-10 23:47:19 +04:00
|
|
|
cmCustomCommandGenerator const& ccg)
|
2013-10-30 01:56:23 +04:00
|
|
|
{
|
|
|
|
const char* property = "RULE_LAUNCH_CUSTOM";
|
|
|
|
const char* property_value = this->Makefile->GetProperty(property);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!property_value || !*property_value) {
|
2013-10-30 01:56:23 +04:00
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expand rules in the empty string. It may insert the launcher and
|
|
|
|
// perform replacements.
|
|
|
|
RuleVariables vars;
|
|
|
|
vars.RuleLauncher = property;
|
|
|
|
std::string output;
|
2014-03-10 23:47:19 +04:00
|
|
|
const std::vector<std::string>& outputs = ccg.GetOutputs();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!outputs.empty()) {
|
2016-08-27 14:44:54 +03:00
|
|
|
if (ccg.GetWorkingDirectory().empty()) {
|
2016-08-27 19:52:40 +03:00
|
|
|
output = this->ConvertToOutputFormat(
|
|
|
|
this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(),
|
|
|
|
outputs[0]),
|
|
|
|
cmOutputConverter::SHELL);
|
2016-08-27 14:44:54 +03:00
|
|
|
} else {
|
2016-08-27 14:44:55 +03:00
|
|
|
output =
|
|
|
|
this->ConvertToOutputFormat(outputs[0], cmOutputConverter::SHELL);
|
2016-08-27 14:44:54 +03:00
|
|
|
}
|
2013-10-30 01:56:23 +04:00
|
|
|
}
|
|
|
|
vars.Output = output.c_str();
|
|
|
|
|
|
|
|
std::string launcher;
|
|
|
|
this->ExpandRuleVariables(launcher, vars);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!launcher.empty()) {
|
2013-10-30 01:56:23 +04:00
|
|
|
launcher += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return launcher;
|
|
|
|
}
|