cmake/Source/cmMakefileUtilityTargetGenerator.cxx

115 lines
3.9 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmMakefileUtilityTargetGenerator.h"
2017-04-14 19:02:05 +02:00
#include <ostream>
#include <string>
#include <vector>
#include "cmGeneratedFileStream.h"
2016-10-30 18:24:19 +01:00
#include "cmGeneratorTarget.h"
#include "cmGlobalUnixMakefileGenerator3.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
2016-10-30 18:24:19 +01:00
#include "cmOSXBundleGenerator.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
2016-07-09 11:21:54 +02:00
cmMakefileUtilityTargetGenerator::cmMakefileUtilityTargetGenerator(
cmGeneratorTarget* target)
: cmMakefileTargetGenerator(target)
{
this->CustomCommandDriver = OnUtility;
2016-07-09 11:21:54 +02:00
this->OSXBundleGenerator =
new cmOSXBundleGenerator(target, this->ConfigName);
2012-08-04 10:26:08 +03:00
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
}
2016-07-09 11:21:54 +02:00
cmMakefileUtilityTargetGenerator::~cmMakefileUtilityTargetGenerator()
2012-08-04 10:26:08 +03:00
{
delete this->OSXBundleGenerator;
}
void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
{
this->CreateRuleFile();
2016-07-09 11:21:54 +02:00
*this->BuildFileStream << "# Utility rule file for "
<< this->GeneratorTarget->GetName() << ".\n\n";
2016-07-09 11:21:54 +02:00
if (!this->NoRuleMessages) {
const char* root = (this->Makefile->IsOn("CMAKE_MAKE_INCLUDE_FROM_ROOT")
? "$(CMAKE_BINARY_DIR)/"
: "");
2012-02-18 12:40:36 +02:00
// Include the progress variables for the target.
*this->BuildFileStream
<< "# Include the progress variables for this target.\n"
2015-08-17 11:37:30 +02:00
<< this->GlobalGenerator->IncludeDirective << " " << root
2016-10-30 18:24:19 +01:00
<< cmSystemTools::ConvertToOutputPath(
this->LocalGenerator
2017-04-14 19:02:05 +02:00
->MaybeConvertToRelativePath(
2016-10-30 18:24:19 +01:00
this->LocalGenerator->GetBinaryDirectory(),
this->ProgressFileNameFull)
.c_str())
2012-02-18 12:40:36 +02:00
<< "\n\n";
2016-07-09 11:21:54 +02:00
}
2012-02-18 12:40:36 +02:00
// write the custom commands for this target
this->WriteTargetBuildRules();
// Collect the commands and dependencies.
std::vector<std::string> commands;
std::vector<std::string> depends;
// Utility targets store their rules in pre- and post-build commands.
2016-07-09 11:21:54 +02:00
this->LocalGenerator->AppendCustomDepends(
depends, this->GeneratorTarget->GetPreBuildCommands());
2016-07-09 11:21:54 +02:00
this->LocalGenerator->AppendCustomDepends(
depends, this->GeneratorTarget->GetPostBuildCommands());
2016-07-09 11:21:54 +02:00
this->LocalGenerator->AppendCustomCommands(
commands, this->GeneratorTarget->GetPreBuildCommands(),
2016-10-30 18:24:19 +01:00
this->GeneratorTarget, this->LocalGenerator->GetBinaryDirectory());
// Depend on all custom command outputs for sources
this->DriveCustomCommands(depends);
2016-07-09 11:21:54 +02:00
this->LocalGenerator->AppendCustomCommands(
commands, this->GeneratorTarget->GetPostBuildCommands(),
2016-10-30 18:24:19 +01:00
this->GeneratorTarget, this->LocalGenerator->GetBinaryDirectory());
// Add dependencies on targets that must be built first.
this->AppendTargetDepends(depends);
// Add a dependency on the rule file itself.
this->LocalGenerator->AppendRuleDepend(depends,
this->BuildFileNameFull.c_str());
// If the rule is empty add the special empty rule dependency needed
// by some make tools.
2016-07-09 11:21:54 +02:00
if (depends.empty() && commands.empty()) {
std::string hack = this->GlobalGenerator->GetEmptyRuleHackDepends();
2016-07-09 11:21:54 +02:00
if (!hack.empty()) {
depends.push_back(hack);
}
2016-07-09 11:21:54 +02:00
}
// Write the rule.
2016-10-30 18:24:19 +01:00
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
2016-03-13 13:35:51 +01:00
this->GeneratorTarget->GetName(),
depends, commands, true);
// Write the main driver rule to build everything in this target.
2016-03-13 13:35:51 +01:00
this->WriteTargetDriverRule(this->GeneratorTarget->GetName(), false);
// Write clean target
this->WriteTargetCleanRules();
// Write the dependency generation rule. This must be done last so
// that multiple output pair information is available.
this->WriteTargetDependRules();
// close the streams
this->CloseFileStreams();
}