summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalUnixMakefileGenerator3.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmLocalUnixMakefileGenerator3.cxx')
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx139
1 files changed, 74 insertions, 65 deletions
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index 919fb74..6caf816 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -3,16 +3,18 @@
#include "cmLocalUnixMakefileGenerator3.h"
#include <algorithm>
+#include <cassert>
#include <cstdio>
#include <sstream>
#include <utility>
#include <cm/memory>
+#include <cm/vector>
+#include <cmext/algorithm>
#include "cmsys/FStream.hxx"
#include "cmsys/Terminal.h"
-#include "cmAlgorithms.h"
#include "cmCustomCommand.h" // IWYU pragma: keep
#include "cmCustomCommandGenerator.h"
#include "cmFileTimeCache.h"
@@ -106,6 +108,13 @@ cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3(
cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3() = default;
+std::string cmLocalUnixMakefileGenerator3::GetConfigName() const
+{
+ auto const& configNames = this->GetConfigNames();
+ assert(configNames.size() == 1);
+ return configNames.front();
+}
+
void cmLocalUnixMakefileGenerator3::Generate()
{
// Record whether some options are enabled to avoid checking many
@@ -121,12 +130,12 @@ void cmLocalUnixMakefileGenerator3::Generate()
// Generate the rule files for each target.
cmGlobalUnixMakefileGenerator3* gg =
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
- for (cmGeneratorTarget* target : this->GetGeneratorTargets()) {
+ for (const auto& target : this->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
std::unique_ptr<cmMakefileTargetGenerator> tg(
- cmMakefileTargetGenerator::New(target));
+ cmMakefileTargetGenerator::New(target.get()));
if (tg) {
tg->WriteRuleFiles();
gg->RecordTargetProgress(tg.get());
@@ -157,15 +166,15 @@ void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath()
void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles(
std::map<std::string, LocalObjectInfo>& localObjectFiles)
{
- for (cmGeneratorTarget* gt : this->GetGeneratorTargets()) {
+ for (const auto& gt : this->GetGeneratorTargets()) {
if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
std::vector<cmSourceFile const*> objectSources;
- gt->GetObjectSources(objectSources, this->ConfigName);
+ gt->GetObjectSources(objectSources, this->GetConfigName());
// Compute full path to object file directory for this target.
std::string dir = cmStrCat(gt->LocalGenerator->GetCurrentBinaryDirectory(),
- '/', this->GetTargetDirectory(gt), '/');
+ '/', this->GetTargetDirectory(gt.get()), '/');
// Compute the name of each object file.
for (cmSourceFile const* sf : objectSources) {
bool hasSourceExtension = true;
@@ -176,7 +185,7 @@ void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles(
}
LocalObjectInfo& info = localObjectFiles[objectName];
info.HasSourceExtension = hasSourceExtension;
- info.emplace_back(gt, sf->GetLanguage());
+ info.emplace_back(gt.get(), sf->GetLanguage());
}
}
}
@@ -352,7 +361,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets(
// for each target we just provide a rule to cd up to the top and do a make
// on the target
std::string localName;
- for (cmGeneratorTarget* target : this->GetGeneratorTargets()) {
+ for (const auto& target : this->GetGeneratorTargets()) {
if ((target->GetType() == cmStateEnums::EXECUTABLE) ||
(target->GetType() == cmStateEnums::STATIC_LIBRARY) ||
(target->GetType() == cmStateEnums::SHARED_LIBRARY) ||
@@ -362,7 +371,8 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets(
emitted.insert(target->GetName());
// for subdirs add a rule to build this specific target by name.
- localName = cmStrCat(this->GetRelativeTargetDirectory(target), "/rule");
+ localName =
+ cmStrCat(this->GetRelativeTargetDirectory(target.get()), "/rule");
commands.clear();
depends.clear();
@@ -383,11 +393,11 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets(
}
// Add a fast rule to build the target
- std::string makefileName =
- cmStrCat(this->GetRelativeTargetDirectory(target), "/build.make");
+ std::string makefileName = cmStrCat(
+ this->GetRelativeTargetDirectory(target.get()), "/build.make");
// make sure the makefile name is suitable for a makefile
std::string makeTargetName =
- cmStrCat(this->GetRelativeTargetDirectory(target), "/build");
+ cmStrCat(this->GetRelativeTargetDirectory(target.get()), "/build");
localName = cmStrCat(target->GetName(), "/fast");
depends.clear();
commands.clear();
@@ -400,9 +410,9 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets(
// Add a local name for the rule to relink the target before
// installation.
- if (target->NeedRelinkBeforeInstall(this->ConfigName)) {
- makeTargetName =
- cmStrCat(this->GetRelativeTargetDirectory(target), "/preinstall");
+ if (target->NeedRelinkBeforeInstall(this->GetConfigName())) {
+ makeTargetName = cmStrCat(
+ this->GetRelativeTargetDirectory(target.get()), "/preinstall");
localName = cmStrCat(target->GetName(), "/preinstall");
depends.clear();
commands.clear();
@@ -613,8 +623,7 @@ void cmLocalUnixMakefileGenerator3::WriteMakeVariables(
this->MaybeConvertWatcomShellCommand(cmSystemTools::GetCMakeCommand());
if (cmakeShellCommand.empty()) {
cmakeShellCommand = this->ConvertToOutputFormat(
- cmSystemTools::CollapseFullPath(cmSystemTools::GetCMakeCommand()),
- cmOutputConverter::SHELL);
+ cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
}
/* clang-format off */
@@ -628,7 +637,7 @@ void cmLocalUnixMakefileGenerator3::WriteMakeVariables(
<< "# The command to remove a file.\n"
<< "RM = "
<< cmakeShellCommand
- << " -E remove -f\n"
+ << " -E rm -f\n"
<< "\n";
makefileStream
<< "# Escaping for special characters.\n"
@@ -638,16 +647,14 @@ void cmLocalUnixMakefileGenerator3::WriteMakeVariables(
<< "# The top-level source directory on which CMake was run.\n"
<< "CMAKE_SOURCE_DIR = "
<< this->ConvertToOutputFormat(
- cmSystemTools::CollapseFullPath(this->GetSourceDirectory()),
- cmOutputConverter::SHELL)
+ this->GetSourceDirectory(), cmOutputConverter::SHELL)
<< "\n"
<< "\n";
makefileStream
<< "# The top-level build directory on which CMake was run.\n"
<< "CMAKE_BINARY_DIR = "
<< this->ConvertToOutputFormat(
- cmSystemTools::CollapseFullPath(this->GetBinaryDirectory()),
- cmOutputConverter::SHELL)
+ this->GetBinaryDirectory(), cmOutputConverter::SHELL)
<< "\n"
<< "\n";
/* clang-format on */
@@ -673,9 +680,15 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsTop(
if (!this->IsNMake() && !this->IsWatcomWMake() &&
!this->BorlandMakeCurlyHack) {
// turn off RCS and SCCS automatic stuff from gmake
- makefileStream
- << "# Remove some rules from gmake that .SUFFIXES does not remove.\n"
- << "SUFFIXES =\n\n";
+ constexpr const char* vcs_rules[] = {
+ "%,v", "RCS/%", "RCS/%,v", "SCCS/s.%", "s.%",
+ };
+ for (auto vcs_rule : vcs_rules) {
+ std::vector<std::string> vcs_depend;
+ vcs_depend.emplace_back(vcs_rule);
+ this->WriteMakeRule(makefileStream, "Disable VCS-based implicit rules.",
+ "%", vcs_depend, no_commands, false);
+ }
}
// Add a fake suffix to keep HP happy. Must be max 32 chars for SGI make.
std::vector<std::string> depends;
@@ -853,7 +866,7 @@ void cmLocalUnixMakefileGenerator3::AppendRuleDepends(
// Add a dependency on the rule file itself unless an option to skip
// it is specifically enabled by the user or project.
if (!this->Makefile->IsOn("CMAKE_SKIP_RULE_DEPENDENCY")) {
- cmAppend(depends, ruleFiles);
+ cm::append(depends, ruleFiles);
}
}
@@ -861,7 +874,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomDepends(
std::vector<std::string>& depends, const std::vector<cmCustomCommand>& ccs)
{
for (cmCustomCommand const& cc : ccs) {
- cmCustomCommandGenerator ccg(cc, this->ConfigName, this);
+ cmCustomCommandGenerator ccg(cc, this->GetConfigName(), this);
this->AppendCustomDepend(depends, ccg);
}
}
@@ -872,7 +885,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomDepend(
for (std::string const& d : ccg.GetDepends()) {
// Lookup the real name of the dependency in case it is a CMake target.
std::string dep;
- if (this->GetRealDependency(d, this->ConfigName, dep)) {
+ if (this->GetRealDependency(d, this->GetConfigName(), dep)) {
depends.push_back(std::move(dep));
}
}
@@ -883,7 +896,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommands(
cmGeneratorTarget* target, std::string const& relative)
{
for (cmCustomCommand const& cc : ccs) {
- cmCustomCommandGenerator ccg(cc, this->ConfigName, this);
+ cmCustomCommandGenerator ccg(cc, this->GetConfigName(), this);
this->AppendCustomCommand(commands, ccg, target, relative, true);
}
}
@@ -962,7 +975,8 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
// Expand rule variables referenced in the given launcher command.
cmRulePlaceholderExpander::RuleVariables vars;
vars.CMTargetName = target->GetName().c_str();
- vars.CMTargetType = cmState::GetTargetTypeName(target->GetType());
+ vars.CMTargetType =
+ cmState::GetTargetTypeName(target->GetType()).c_str();
std::string output;
const std::vector<std::string>& outputs = ccg.GetOutputs();
if (!outputs.empty()) {
@@ -1026,7 +1040,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
this->CreateCDCommand(commands1, dir, relative);
// push back the custom commands
- cmAppend(commands, commands1);
+ cm::append(commands, commands1);
}
void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
@@ -1041,10 +1055,9 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
cleanfile += filename;
}
cleanfile += ".cmake";
- std::string cleanfilePath = cmSystemTools::CollapseFullPath(cleanfile);
- cmsys::ofstream fout(cleanfilePath.c_str());
+ cmsys::ofstream fout(cleanfile.c_str());
if (!fout) {
- cmSystemTools::Error("Could not create " + cleanfilePath);
+ cmSystemTools::Error("Could not create " + cleanfile);
}
if (!files.empty()) {
fout << "file(REMOVE_RECURSE\n";
@@ -1097,18 +1110,16 @@ void cmLocalUnixMakefileGenerator3::AppendDirectoryCleanCommand(
return;
}
- cmLocalGenerator* rootLG =
- this->GetGlobalGenerator()->GetLocalGenerators().at(0);
+ const auto& rootLG = this->GetGlobalGenerator()->GetLocalGenerators().at(0);
std::string const& binaryDir = rootLG->GetCurrentBinaryDirectory();
std::string const& currentBinaryDir = this->GetCurrentBinaryDirectory();
std::string cleanfile =
cmStrCat(currentBinaryDir, "/CMakeFiles/cmake_directory_clean.cmake");
// Write clean script
{
- std::string cleanfilePath = cmSystemTools::CollapseFullPath(cleanfile);
- cmsys::ofstream fout(cleanfilePath.c_str());
+ cmsys::ofstream fout(cleanfile.c_str());
if (!fout) {
- cmSystemTools::Error("Could not create " + cleanfilePath);
+ cmSystemTools::Error("Could not create " + cleanfile);
return;
}
fout << "file(REMOVE_RECURSE\n";
@@ -1179,9 +1190,8 @@ void cmLocalUnixMakefileGenerator3::AppendEcho(
color_name);
if (progress) {
cmd += "--progress-dir=";
- cmd += this->ConvertToOutputFormat(
- cmSystemTools::CollapseFullPath(progress->Dir),
- cmOutputConverter::SHELL);
+ cmd += this->ConvertToOutputFormat(progress->Dir,
+ cmOutputConverter::SHELL);
cmd += " ";
cmd += "--progress-num=";
cmd += progress->Arg;
@@ -1555,8 +1565,8 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
this->WriteDivider(ruleFileStream);
ruleFileStream << "# Targets provided globally by CMake.\n"
<< "\n";
- const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
- for (cmGeneratorTarget* gt : targets) {
+ const auto& targets = this->GetGeneratorTargets();
+ for (const auto& gt : targets) {
if (gt->GetType() == cmStateEnums::GLOBAL_TARGET) {
std::string targetString =
"Special rule for the target " + gt->GetName();
@@ -1568,8 +1578,8 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
text = "Running external command ...";
}
depends.reserve(gt->GetUtilities().size());
- for (BT<std::string> const& u : gt->GetUtilities()) {
- depends.push_back(u.Value);
+ for (BT<std::pair<std::string, bool>> const& u : gt->GetUtilities()) {
+ depends.push_back(u.Value.first);
}
this->AppendEcho(commands, text,
cmLocalUnixMakefileGenerator3::EchoGlobal);
@@ -1577,10 +1587,10 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
// Global targets store their rules in pre- and post-build commands.
this->AppendCustomDepends(depends, gt->GetPreBuildCommands());
this->AppendCustomDepends(depends, gt->GetPostBuildCommands());
- this->AppendCustomCommands(commands, gt->GetPreBuildCommands(), gt,
- this->GetCurrentBinaryDirectory());
- this->AppendCustomCommands(commands, gt->GetPostBuildCommands(), gt,
+ this->AppendCustomCommands(commands, gt->GetPreBuildCommands(), gt.get(),
this->GetCurrentBinaryDirectory());
+ this->AppendCustomCommands(commands, gt->GetPostBuildCommands(),
+ gt.get(), this->GetCurrentBinaryDirectory());
std::string targetName = gt->GetName();
this->WriteMakeRule(ruleFileStream, targetString.c_str(), targetName,
depends, commands, true);
@@ -1621,15 +1631,14 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
{
std::ostringstream progCmd;
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start ";
- progCmd << this->ConvertToOutputFormat(
- cmSystemTools::CollapseFullPath(progressDir), cmOutputConverter::SHELL);
+ progCmd << this->ConvertToOutputFormat(progressDir,
+ cmOutputConverter::SHELL);
std::string progressFile = "/CMakeFiles/progress.marks";
std::string progressFileNameFull = this->ConvertToFullPath(progressFile);
progCmd << " "
- << this->ConvertToOutputFormat(
- cmSystemTools::CollapseFullPath(progressFileNameFull),
- cmOutputConverter::SHELL);
+ << this->ConvertToOutputFormat(progressFileNameFull,
+ cmOutputConverter::SHELL);
commands.push_back(progCmd.str());
}
std::string mf2Dir = "CMakeFiles/Makefile2";
@@ -1639,8 +1648,8 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
{
std::ostringstream progCmd;
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
- progCmd << this->ConvertToOutputFormat(
- cmSystemTools::CollapseFullPath(progressDir), cmOutputConverter::SHELL);
+ progCmd << this->ConvertToOutputFormat(progressDir,
+ cmOutputConverter::SHELL);
progCmd << " 0";
commands.push_back(progCmd.str());
}
@@ -1773,7 +1782,7 @@ private:
const std::string& testDir)
{
// First check if the test directory "starts with" the base directory:
- if (testDir.find(baseDir) != 0) {
+ if (!cmHasPrefix(testDir, baseDir)) {
return false;
}
// If it does, then check that it's either the same string, or that the
@@ -1843,7 +1852,7 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
// Build a list of preprocessor definitions for the target.
std::set<std::string> defines;
- this->GetTargetDefines(target, this->ConfigName, implicitLang.first,
+ this->GetTargetDefines(target, this->GetConfigName(), implicitLang.first,
defines);
if (!defines.empty()) {
/* clang-format off */
@@ -1867,11 +1876,11 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
std::vector<std::string> includes;
this->GetIncludeDirectories(includes, target, implicitLang.first,
- this->ConfigName);
+ this->GetConfigName());
std::string binaryDir = this->GetState()->GetBinaryDirectory();
if (this->Makefile->IsOn("CMAKE_DEPENDS_IN_PROJECT_ONLY")) {
std::string const& sourceDir = this->GetState()->GetSourceDirectory();
- cmEraseIf(includes, ::NotInProjectDir(sourceDir, binaryDir));
+ cm::erase_if(includes, ::NotInProjectDir(sourceDir, binaryDir));
}
for (std::string const& include : includes) {
cmakefileStream << " \""
@@ -1961,18 +1970,18 @@ void cmLocalUnixMakefileGenerator3::WriteDivider(std::ostream& os)
}
void cmLocalUnixMakefileGenerator3::WriteCMakeArgument(std::ostream& os,
- const char* s)
+ const std::string& s)
{
// Write the given string to the stream with escaping to get it back
// into CMake through the lexical scanner.
os << "\"";
- for (const char* c = s; *c; ++c) {
- if (*c == '\\') {
+ for (char c : s) {
+ if (c == '\\') {
os << "\\\\";
- } else if (*c == '"') {
+ } else if (c == '"') {
os << "\\\"";
} else {
- os << *c;
+ os << c;
}
}
os << "\"";