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.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmLocalNinjaGenerator.h"
|
|
|
|
#include "cmCustomCommandGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmGlobalNinjaGenerator.h"
|
|
|
|
#include "cmNinjaTargetGenerator.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmSourceFile.h"
|
|
|
|
#include "cmake.h"
|
2015-04-11 15:15:55 +03:00
|
|
|
#include "cmState.h"
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2015-05-03 17:50:34 +03:00
|
|
|
cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg,
|
2015-05-24 12:50:55 +03:00
|
|
|
cmLocalGenerator* parent,
|
|
|
|
cmState::Snapshot snapshot)
|
2015-07-07 23:37:56 +03:00
|
|
|
: cmLocalCommonGenerator(gg, parent, snapshot)
|
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.
|
|
|
|
this->HomeRelativeOutputPath =
|
|
|
|
this->Convert(this->Makefile->GetCurrentBinaryDirectory(), HOME_OUTPUT);
|
|
|
|
if(this->HomeRelativeOutputPath == ".")
|
|
|
|
{
|
|
|
|
this->HomeRelativeOutputPath = "";
|
|
|
|
}
|
|
|
|
|
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.
|
2015-06-06 15:07:15 +03:00
|
|
|
if(this->Makefile->IsRootMakefile())
|
2013-10-18 14:59:47 +04:00
|
|
|
{
|
|
|
|
this->WriteBuildFileTop();
|
|
|
|
|
2013-11-23 13:49:36 +04:00
|
|
|
this->WritePools(this->GetRulesFileStream());
|
|
|
|
|
2013-10-18 14:59:47 +04:00
|
|
|
const std::string showIncludesPrefix = this->GetMakefile()
|
|
|
|
->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX");
|
|
|
|
if (!showIncludesPrefix.empty())
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(this->GetRulesFileStream(),
|
|
|
|
"localized /showIncludes string");
|
|
|
|
this->GetRulesFileStream()
|
|
|
|
<< "msvc_deps_prefix = " << showIncludesPrefix << "\n\n";
|
|
|
|
}
|
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2012-10-10 23:32:37 +04:00
|
|
|
cmGeneratorTargetsType targets = this->GetMakefile()->GetGeneratorTargets();
|
|
|
|
for(cmGeneratorTargetsType::iterator t = targets.begin();
|
|
|
|
t != targets.end(); ++t)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2013-11-20 15:44:04 +04:00
|
|
|
if (t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY
|
|
|
|
|| t->second->Target->IsImported())
|
2012-10-10 23:32:37 +04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cmNinjaTargetGenerator* tg = cmNinjaTargetGenerator::New(t->second);
|
2011-11-11 09:00:49 +04:00
|
|
|
if(tg)
|
|
|
|
{
|
|
|
|
tg->Generate();
|
|
|
|
// Add the target to "all" if required.
|
|
|
|
if (!this->GetGlobalNinjaGenerator()->IsExcluded(
|
2012-07-18 13:27:49 +04:00
|
|
|
this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0],
|
2012-10-10 23:32:37 +04:00
|
|
|
*t->second->Target))
|
|
|
|
this->GetGlobalNinjaGenerator()->AddDependencyToAll(t->second->Target);
|
2011-11-11 09:00:49 +04:00
|
|
|
delete tg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->WriteCustomCommandBuildStatements();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Picked up from cmLocalUnixMakefileGenerator3. Refactor it.
|
|
|
|
std::string cmLocalNinjaGenerator
|
|
|
|
::GetTargetDirectory(cmTarget const& target) const
|
|
|
|
{
|
|
|
|
std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
|
|
|
|
dir += target.GetName();
|
|
|
|
#if defined(__VMS)
|
|
|
|
dir += "_dir";
|
|
|
|
#else
|
|
|
|
dir += ".dir";
|
|
|
|
#endif
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Non-virtual public methods.
|
|
|
|
|
|
|
|
const cmGlobalNinjaGenerator*
|
|
|
|
cmLocalNinjaGenerator::GetGlobalNinjaGenerator() const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
static_cast<const cmGlobalNinjaGenerator*>(this->GetGlobalGenerator());
|
|
|
|
}
|
|
|
|
|
|
|
|
cmGlobalNinjaGenerator* cmLocalNinjaGenerator::GetGlobalNinjaGenerator()
|
|
|
|
{
|
|
|
|
return static_cast<cmGlobalNinjaGenerator*>(this->GetGlobalGenerator());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Virtual protected methods.
|
|
|
|
|
|
|
|
std::string
|
2014-03-04 22:06:29 +04:00
|
|
|
cmLocalNinjaGenerator::ConvertToLinkReference(std::string const& lib,
|
|
|
|
OutputFormat format)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
return this->Convert(lib, HOME_OUTPUT, format);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
2014-03-04 22:04:02 +04:00
|
|
|
cmLocalNinjaGenerator::ConvertToIncludeReference(std::string const& path,
|
2014-10-10 17:57:07 +04:00
|
|
|
OutputFormat format,
|
|
|
|
bool forceFullPaths)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2014-10-10 17:57:07 +04:00
|
|
|
return this->Convert(path, forceFullPaths? FULL : HOME_OUTPUT, 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);
|
|
|
|
os
|
|
|
|
<< "# Project: " << this->GetMakefile()->GetProjectName() << std::endl
|
|
|
|
<< "# Configuration: " << this->ConfigName << std::endl
|
|
|
|
;
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
}
|
|
|
|
|
2014-10-02 23:21:05 +04:00
|
|
|
void cmLocalNinjaGenerator::WriteNinjaRequiredVersion(std::ostream& os)
|
|
|
|
{
|
|
|
|
// Default required version
|
|
|
|
// Ninja generator uses 'deps' and 'msvc_deps_prefix' introduced in 1.3
|
|
|
|
std::string requiredVersion = "1.3";
|
|
|
|
|
|
|
|
// Ninja generator uses the 'console' pool if available (>= 1.5)
|
|
|
|
std::string usedVersion = this->GetGlobalNinjaGenerator()->ninjaVersion();
|
|
|
|
if(cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
|
|
|
|
usedVersion.c_str(),
|
|
|
|
"1.5") == false)
|
|
|
|
{
|
|
|
|
requiredVersion = "1.5";
|
|
|
|
}
|
|
|
|
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(os,
|
|
|
|
"Minimal version of Ninja required by this file");
|
|
|
|
os
|
|
|
|
<< "ninja_required_version = "
|
|
|
|
<< requiredVersion
|
|
|
|
<< std::endl << std::endl
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2013-11-23 13:49:36 +04:00
|
|
|
void cmLocalNinjaGenerator::WritePools(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
|
2015-04-11 15:15:55 +03:00
|
|
|
const char* jobpools = this->GetCMakeInstance()->GetState()
|
|
|
|
->GetGlobalProperty("JOB_POOLS");
|
2013-11-23 13:49:36 +04:00
|
|
|
if (jobpools)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteComment(os,
|
|
|
|
"Pools defined by global property JOB_POOLS");
|
|
|
|
std::vector<std::string> pools;
|
|
|
|
cmSystemTools::ExpandListArgument(jobpools, pools);
|
|
|
|
for (size_t i = 0; i < pools.size(); ++i)
|
|
|
|
{
|
|
|
|
const std::string pool = pools[i];
|
|
|
|
const std::string::size_type eq = pool.find("=");
|
|
|
|
unsigned int jobs;
|
|
|
|
if (eq != std::string::npos &&
|
|
|
|
sscanf(pool.c_str() + eq, "=%u", &jobs) == 1)
|
|
|
|
{
|
|
|
|
os << "pool " << pool.substr(0, eq) << std::endl;
|
|
|
|
os << " depth = " << jobs << std::endl;
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Invalid pool defined by property 'JOB_POOLS': ",
|
|
|
|
pool.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
void cmLocalNinjaGenerator::WriteNinjaFilesInclusion(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
os
|
|
|
|
<< "# Include auxiliary files.\n"
|
|
|
|
<< "\n"
|
|
|
|
;
|
|
|
|
cmGlobalNinjaGenerator::WriteInclude(os,
|
|
|
|
cmGlobalNinjaGenerator::NINJA_RULES_FILE,
|
|
|
|
"Include rules file.");
|
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
|
2014-03-11 20:37:26 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmLocalNinjaGenerator::ComputeObjectFilenames(
|
|
|
|
std::map<cmSourceFile const*, std::string>& mapping,
|
|
|
|
cmGeneratorTarget const* gt)
|
|
|
|
{
|
|
|
|
for(std::map<cmSourceFile const*, std::string>::iterator
|
|
|
|
si = mapping.begin(); si != mapping.end(); ++si)
|
|
|
|
{
|
|
|
|
cmSourceFile const* sf = si->first;
|
|
|
|
si->second = this->GetObjectFileNameWithoutTarget(*sf,
|
|
|
|
gt->ObjectDirectory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
|
|
|
|
{
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
os
|
|
|
|
<< "# Write statements declared in CMakeLists.txt:" << std::endl
|
2015-05-15 00:47:40 +03:00
|
|
|
<< "# "
|
|
|
|
<< this->Makefile->GetDefinition("CMAKE_CURRENT_LIST_FILE") << std::endl;
|
2015-06-06 15:07:15 +03:00
|
|
|
if(this->Makefile->IsRootMakefile())
|
2011-11-11 09:00:49 +04:00
|
|
|
os << "# Which is the root file." << std::endl;
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
|
2014-03-11 02:32:00 +04:00
|
|
|
std::string cmLocalNinjaGenerator::ConvertToNinjaPath(const std::string& path)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2012-02-19 05:50:53 +04:00
|
|
|
std::string convPath = this->Convert(path, cmLocalGenerator::HOME_OUTPUT);
|
|
|
|
#ifdef _WIN32
|
|
|
|
cmSystemTools::ReplaceString(convPath, "/", "\\");
|
|
|
|
#endif
|
|
|
|
return convPath;
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmLocalNinjaGenerator
|
|
|
|
::AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs)
|
|
|
|
{
|
|
|
|
this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmLocalNinjaGenerator
|
|
|
|
::AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs)
|
|
|
|
{
|
|
|
|
this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs);
|
|
|
|
}
|
|
|
|
|
2014-03-10 23:47:19 +04:00
|
|
|
void cmLocalNinjaGenerator::AppendCustomCommandDeps(
|
|
|
|
cmCustomCommandGenerator const& ccg,
|
|
|
|
cmNinjaDeps &ninjaDeps)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2014-03-10 23:47:19 +04: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;
|
2014-03-11 03:04:11 +04:00
|
|
|
if (this->GetRealDependency(*i, this->GetConfigName(), dep))
|
2014-10-15 16:54:05 +04:00
|
|
|
ninjaDeps.push_back(ConvertToNinjaPath(dep));
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmLocalNinjaGenerator::BuildCommandLine(
|
|
|
|
const std::vector<std::string> &cmdLines)
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
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
|
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
|
2013-11-25 14:17:14 +04:00
|
|
|
{
|
|
|
|
if (li != cmdLines.begin())
|
|
|
|
{
|
|
|
|
cmd << " && ";
|
|
|
|
}
|
|
|
|
else if (cmdLines.size() > 1)
|
|
|
|
{
|
|
|
|
cmd << "cmd.exe /C \"";
|
|
|
|
}
|
|
|
|
cmd << *li;
|
2012-06-06 00:39:42 +04:00
|
|
|
}
|
2013-11-25 14:17:14 +04:00
|
|
|
if (cmdLines.size() > 1)
|
|
|
|
{
|
|
|
|
cmd << "\"";
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
if (li != cmdLines.begin())
|
|
|
|
{
|
|
|
|
cmd << " && ";
|
|
|
|
}
|
2011-11-11 09:00:49 +04: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(
|
|
|
|
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();
|
2014-03-10 21:53:57 +04:00
|
|
|
if (wd.empty())
|
2015-04-16 21:06:54 +03:00
|
|
|
wd = this->GetMakefile()->GetCurrentBinaryDirectory();
|
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
|
|
|
|
std::string cdStr = "cd /D ";
|
|
|
|
#else
|
|
|
|
std::string cdStr = "cd ";
|
|
|
|
#endif
|
|
|
|
cdCmd << cdStr << this->ConvertToOutputFormat(wd, 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 +
|
2014-03-11 03:04:11 +04:00
|
|
|
this->ConvertToOutputFormat(ccg.GetCommand(i), 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-13 17:17:46 +04:00
|
|
|
cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
|
|
|
|
cmCustomCommand const *cc, const cmNinjaDeps& orderOnlyDeps)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
if (this->GetGlobalNinjaGenerator()->SeenCustomCommand(cc))
|
|
|
|
return;
|
|
|
|
|
2014-03-10 23:47:19 +04:00
|
|
|
cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this->Makefile);
|
|
|
|
|
|
|
|
const std::vector<std::string> &outputs = ccg.GetOutputs();
|
2014-11-14 02:54:52 +03:00
|
|
|
const std::vector<std::string> &byproducts = ccg.GetByproducts();
|
|
|
|
cmNinjaDeps ninjaOutputs(outputs.size()+byproducts.size()), ninjaDeps;
|
2011-11-11 09:00:49 +04: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
|
2011-11-11 09:00:49 +04:00
|
|
|
std::transform(outputs.begin(), outputs.end(),
|
|
|
|
ninjaOutputs.begin(), MapToNinjaPath());
|
2014-11-14 02:54:52 +03:00
|
|
|
std::transform(byproducts.begin(), byproducts.end(),
|
|
|
|
ninjaOutputs.begin() + outputs.size(), 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();
|
|
|
|
++i)
|
|
|
|
this->GetGlobalNinjaGenerator()->SeenCustomCommandOutput(*i);
|
|
|
|
|
|
|
|
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(),
|
|
|
|
"Phony custom command for " +
|
|
|
|
ninjaOutputs[0],
|
|
|
|
ninjaOutputs,
|
|
|
|
ninjaDeps,
|
|
|
|
cmNinjaDeps(),
|
|
|
|
orderOnlyDeps,
|
|
|
|
cmNinjaVars());
|
2011-11-11 09:00:49 +04:00
|
|
|
} else {
|
|
|
|
this->GetGlobalNinjaGenerator()->WriteCustomCommandBuild(
|
|
|
|
this->BuildCommandLine(cmdLines),
|
2014-03-10 23:47:19 +04:00
|
|
|
this->ConstructComment(ccg),
|
2011-11-11 09:00:49 +04:00
|
|
|
"Custom command for " + ninjaOutputs[0],
|
2014-11-05 23:42:18 +03:00
|
|
|
cc->GetUsesTerminal(),
|
2011-11-11 09:00:49 +04:00
|
|
|
ninjaOutputs,
|
|
|
|
ninjaDeps,
|
|
|
|
orderOnlyDeps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 17:17:46 +04:00
|
|
|
void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc,
|
2011-11-11 09:00:49 +04:00
|
|
|
cmTarget* target)
|
|
|
|
{
|
|
|
|
this->CustomCommandTargets[cc].insert(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
|
|
|
|
{
|
|
|
|
for (CustomCommandTargetMap::iterator i = this->CustomCommandTargets.begin();
|
|
|
|
i != this->CustomCommandTargets.end(); ++i) {
|
|
|
|
// 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.
|
|
|
|
std::set<cmTarget*>::iterator j = i->second.begin();
|
|
|
|
assert(j != i->second.end());
|
|
|
|
std::vector<std::string> ccTargetDeps;
|
|
|
|
this->AppendTargetDepends(*j, ccTargetDeps);
|
|
|
|
std::sort(ccTargetDeps.begin(), ccTargetDeps.end());
|
|
|
|
++j;
|
|
|
|
|
|
|
|
for (; j != i->second.end(); ++j) {
|
|
|
|
std::vector<std::string> jDeps, depsIntersection;
|
|
|
|
this->AppendTargetDepends(*j, jDeps);
|
|
|
|
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);
|
|
|
|
|
|
|
|
if(!property_value || !*property_value)
|
|
|
|
{
|
|
|
|
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();
|
2013-10-30 01:56:23 +04:00
|
|
|
if(!outputs.empty())
|
|
|
|
{
|
|
|
|
RelativeRoot relative_root =
|
2014-03-10 23:47:19 +04:00
|
|
|
ccg.GetWorkingDirectory().empty() ? START_OUTPUT : NONE;
|
2013-10-30 01:56:23 +04:00
|
|
|
|
2014-03-11 03:04:11 +04:00
|
|
|
output = this->Convert(outputs[0], relative_root, SHELL);
|
2013-10-30 01:56:23 +04:00
|
|
|
}
|
|
|
|
vars.Output = output.c_str();
|
|
|
|
|
|
|
|
std::string launcher;
|
|
|
|
this->ExpandRuleVariables(launcher, vars);
|
|
|
|
if(!launcher.empty())
|
|
|
|
{
|
|
|
|
launcher += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return launcher;
|
|
|
|
}
|