summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefileTargetGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmMakefileTargetGenerator.cxx')
-rw-r--r--Source/cmMakefileTargetGenerator.cxx143
1 files changed, 55 insertions, 88 deletions
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index 4918bf6..e87f81b 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -218,15 +218,12 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
}
}
- std::string currentBinDir =
- this->LocalGenerator->GetCurrentBinaryDirectory();
-
// Look for ISPC extra object files generated by this target
auto ispcAdditionalObjs =
this->GeneratorTarget->GetGeneratedISPCObjects(this->GetConfigName());
for (std::string const& ispcObj : ispcAdditionalObjs) {
- this->CleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
- currentBinDir, ispcObj));
+ this->CleanFiles.insert(
+ this->LocalGenerator->MaybeRelativeToCurBinDir(ispcObj));
}
// add custom commands to the clean rules?
@@ -251,14 +248,12 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
const std::vector<std::string>& outputs = ccg.GetOutputs();
for (std::string const& output : outputs) {
this->CleanFiles.insert(
- this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir,
- output));
+ this->LocalGenerator->MaybeRelativeToCurBinDir(output));
}
const std::vector<std::string>& byproducts = ccg.GetByproducts();
for (std::string const& byproduct : byproducts) {
this->CleanFiles.insert(
- this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir,
- byproduct));
+ this->LocalGenerator->MaybeRelativeToCurBinDir(byproduct));
}
}
}
@@ -279,8 +274,7 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
const std::vector<std::string>& byproducts = beg.GetByproducts();
for (std::string const& byproduct : byproducts) {
this->CleanFiles.insert(
- this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir,
- byproduct));
+ this->LocalGenerator->MaybeRelativeToCurBinDir(byproduct));
}
}
}
@@ -327,8 +321,7 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
<< "# Include any dependencies generated for this target.\n"
<< this->GlobalGenerator->IncludeDirective << " " << root
<< cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(), dependFileNameFull))
+ this->LocalGenerator->MaybeRelativeToTopBinDir(dependFileNameFull))
<< "\n";
std::string depsUseCompiler = "CMAKE_DEPENDS_USE_COMPILER";
@@ -336,14 +329,14 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
this->Makefile->IsOn(depsUseCompiler)) {
std::string compilerDependFile =
cmStrCat(this->TargetBuildDirectoryFull, "/compiler_depend.make");
- *this->BuildFileStream
- << "# Include any dependencies generated by the "
- "compiler for this target.\n"
- << this->GlobalGenerator->IncludeDirective << " " << root
- << cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(), compilerDependFile))
- << "\n\n";
+ *this->BuildFileStream << "# Include any dependencies generated by the "
+ "compiler for this target.\n"
+ << this->GlobalGenerator->IncludeDirective << " "
+ << root
+ << cmSystemTools::ConvertToOutputPath(
+ this->LocalGenerator->MaybeRelativeToTopBinDir(
+ compilerDependFile))
+ << "\n\n";
// Write an empty dependency file.
cmGeneratedFileStream depFileStream(
@@ -399,8 +392,7 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
<< "# Include the progress variables for this target.\n"
<< this->GlobalGenerator->IncludeDirective << " " << root
<< cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(),
+ this->LocalGenerator->MaybeRelativeToTopBinDir(
this->ProgressFileNameFull))
<< "\n\n";
}
@@ -423,8 +415,8 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
<< "# Include the compile flags for this target's objects.\n"
<< this->GlobalGenerator->IncludeDirective << " " << root
<< cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(), this->FlagFileNameFull))
+ this->LocalGenerator->MaybeRelativeToTopBinDir(
+ this->FlagFileNameFull))
<< "\n\n";
}
@@ -491,10 +483,8 @@ void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()(
std::string output =
cmStrCat(macdir, '/', cmSystemTools::GetFilenameName(input));
this->Generator->CleanFiles.insert(
- this->Generator->LocalGenerator->MaybeConvertToRelativePath(
- this->Generator->LocalGenerator->GetCurrentBinaryDirectory(), output));
- output = this->Generator->LocalGenerator->MaybeConvertToRelativePath(
- this->Generator->LocalGenerator->GetBinaryDirectory(), output);
+ this->Generator->LocalGenerator->MaybeRelativeToCurBinDir(output));
+ output = this->Generator->LocalGenerator->MaybeRelativeToTopBinDir(output);
// Create a rule to copy the content into the bundle.
std::vector<std::string> depends;
@@ -663,7 +653,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
cmProp ispcSuffixProp =
this->GeneratorTarget->GetProperty("ISPC_HEADER_SUFFIX");
- assert(ispcSuffixProp != nullptr);
+ assert(ispcSuffixProp);
std::string directory = this->GeneratorTarget->GetObjectDirectory(config);
if (cmProp prop =
@@ -797,15 +787,12 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
}
targetOutPathReal = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathReal),
+ this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathReal),
cmOutputConverter::SHELL);
targetOutPathPDB = this->LocalGenerator->ConvertToOutputFormat(
targetFullPathPDB, cmOutputConverter::SHELL);
targetOutPathCompilePDB = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(),
- targetFullPathCompilePDB),
+ this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathCompilePDB),
cmOutputConverter::SHELL);
if (this->LocalGenerator->IsMinGWMake() &&
@@ -834,14 +821,12 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
vars.Object = shellObj.c_str();
std::string objectDir = this->GeneratorTarget->GetSupportDirectory();
objectDir = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), objectDir),
+ this->LocalGenerator->MaybeRelativeToCurBinDir(objectDir),
cmOutputConverter::SHELL);
vars.ObjectDir = objectDir.c_str();
std::string objectFileDir = cmSystemTools::GetFilenamePath(obj);
objectFileDir = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), objectFileDir),
+ this->LocalGenerator->MaybeRelativeToCurBinDir(objectFileDir),
cmOutputConverter::SHELL);
vars.ObjectFileDir = objectFileDir.c_str();
vars.Flags = flags.c_str();
@@ -854,7 +839,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
vars.Defines = definesString.c_str();
std::string includesString = this->LocalGenerator->GetIncludeFlags(
- includes, this->GeneratorTarget, lang, true, false, config);
+ includes, this->GeneratorTarget, lang, config);
this->LocalGenerator->AppendFlags(includesString,
"$(" + lang + "_INCLUDES)");
vars.Includes = includesString.c_str();
@@ -865,8 +850,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
if (compilerGenerateDeps) {
dependencyTarget = this->LocalGenerator->EscapeForShell(
this->LocalGenerator->ConvertToMakefilePath(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(), relativeObj)));
+ this->LocalGenerator->MaybeRelativeToTopBinDir(relativeObj)));
vars.DependencyTarget = dependencyTarget.c_str();
auto depFile = cmStrCat(obj, ".d");
@@ -875,8 +859,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
vars.DependencyFile = shellDependencyFile.c_str();
this->CleanFiles.insert(depFile);
- dependencyTimestamp = this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(),
+ dependencyTimestamp = this->LocalGenerator->MaybeRelativeToTopBinDir(
cmStrCat(this->TargetBuildDirectoryFull, "/compiler_depend.ts"));
}
@@ -926,8 +909,11 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
compileCommand, vars);
std::string workingDirectory =
this->LocalGenerator->GetCurrentBinaryDirectory();
- compileCommand.replace(compileCommand.find(langFlags), langFlags.size(),
- this->GetFlags(lang, this->GetConfigName()));
+ std::string::size_type lfPos = compileCommand.find(langFlags);
+ if (lfPos != std::string::npos) {
+ compileCommand.replace(lfPos, langFlags.size(),
+ this->GetFlags(lang, this->GetConfigName()));
+ }
std::string langDefines = std::string("$(") + lang + "_DEFINES)";
std::string::size_type ldPos = compileCommand.find(langDefines);
if (ldPos != std::string::npos) {
@@ -1302,12 +1288,11 @@ bool cmMakefileTargetGenerator::WriteMakeRule(
// For multiple outputs, make the extra ones depend on the first one.
std::vector<std::string> const output_depends(1, outputs[0]);
- std::string binDir = this->LocalGenerator->GetBinaryDirectory();
for (std::string const& output : cmMakeRange(outputs).advance(1)) {
// Touch the extra output so "make" knows that it was updated,
// but only if the output was actually created.
std::string const out = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->MaybeConvertToRelativePath(binDir, output),
+ this->LocalGenerator->MaybeRelativeToTopBinDir(output),
cmOutputConverter::SHELL);
std::vector<std::string> output_commands;
@@ -1515,14 +1500,12 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule(
const std::string objectDir = this->GeneratorTarget->ObjectDirectory;
const std::string relObjectDir =
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), objectDir);
+ this->LocalGenerator->MaybeRelativeToCurBinDir(objectDir);
// Construct a list of files associated with this executable that
// may need to be cleaned.
std::vector<std::string> cleanFiles;
- cleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), output));
+ cleanFiles.push_back(this->LocalGenerator->MaybeRelativeToCurBinDir(output));
std::string profiles;
std::vector<std::string> fatbinaryDepends;
@@ -1547,8 +1530,7 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule(
// generate it only on the first invocation to reduce overhead.
if (fatbinaryDepends.size() == 1) {
std::string registerFileRel =
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), registerFile);
+ this->LocalGenerator->MaybeRelativeToCurBinDir(registerFile);
registerFileCmd =
cmStrCat(" --register-link-binaries=", registerFileRel);
cleanFiles.push_back(registerFileRel);
@@ -1572,8 +1554,7 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule(
const std::string fatbinaryOutput =
cmStrCat(objectDir, "cmake_cuda_fatbin.h");
const std::string fatbinaryOutputRel =
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), fatbinaryOutput);
+ this->LocalGenerator->MaybeRelativeToCurBinDir(fatbinaryOutput);
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
fatbinaryOutputRel, fatbinaryDepends,
@@ -1640,8 +1621,7 @@ void cmMakefileTargetGenerator::GenerateCustomRuleFile(
if (!ccg.GetCC().GetDepfile().empty()) {
// Add dependency over timestamp file for dependencies management
auto dependTimestamp = cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(),
+ this->LocalGenerator->MaybeRelativeToTopBinDir(
cmStrCat(this->TargetBuildDirectoryFull, "/compiler_depend.ts")));
depends.push_back(dependTimestamp);
@@ -1743,11 +1723,8 @@ void cmMakefileTargetGenerator::WriteObjectsVariable(
<< this->GeneratorTarget->GetName() << "\n"
<< variableNameExternal << " =";
/* clang-format on */
- std::string currentBinDir =
- this->LocalGenerator->GetCurrentBinaryDirectory();
for (std::string const& obj : this->ExternalObjects) {
- object =
- this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, obj);
+ object = this->LocalGenerator->MaybeRelativeToCurBinDir(obj);
*this->BuildFileStream << " " << lineContinue;
*this->BuildFileStream
<< cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(
@@ -1775,7 +1752,8 @@ public:
{
// Construct the name of the next object.
this->NextObject = this->OutputConverter->ConvertToOutputFormat(
- this->MaybeConvertToRelativePath(obj), cmOutputConverter::RESPONSE);
+ this->OutputConverter->MaybeRelativeToCurBinDir(obj),
+ cmOutputConverter::RESPONSE);
// Roll over to next string if the limit will be exceeded.
if (this->LengthLimit != std::string::npos &&
@@ -1796,15 +1774,6 @@ public:
void Done() { this->Strings.push_back(this->CurrentString); }
private:
- std::string MaybeConvertToRelativePath(std::string const& obj)
- {
- if (!this->StateDir.ContainsBoth(this->StateDir.GetCurrentBinary(), obj)) {
- return obj;
- }
- return cmSystemTools::ForceToRelativePath(
- this->StateDir.GetCurrentBinary(), obj);
- }
-
std::vector<std::string>& Strings;
cmOutputConverter* OutputConverter;
cmStateDirectory StateDir;
@@ -1847,8 +1816,8 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule(
this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
std::string buildTargetRuleName =
cmStrCat(dir, relink ? "/preinstall" : "/build");
- buildTargetRuleName = this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(), buildTargetRuleName);
+ buildTargetRuleName =
+ this->LocalGenerator->MaybeRelativeToTopBinDir(buildTargetRuleName);
// Build the list of target outputs to drive.
std::vector<std::string> depends;
@@ -1985,13 +1954,12 @@ void cmMakefileTargetGenerator::CreateLinkScript(
}
// Create the makefile command to invoke the link script.
- std::string link_command = cmStrCat(
- "$(CMAKE_COMMAND) -E cmake_link_script ",
- this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), linkScriptName),
- cmOutputConverter::SHELL),
- " --verbose=$(VERBOSE)");
+ std::string link_command =
+ cmStrCat("$(CMAKE_COMMAND) -E cmake_link_script ",
+ this->LocalGenerator->ConvertToOutputFormat(
+ this->LocalGenerator->MaybeRelativeToCurBinDir(linkScriptName),
+ cmOutputConverter::SHELL),
+ " --verbose=$(VERBOSE)");
makefile_commands.push_back(std::move(link_command));
makefile_depends.push_back(std::move(linkScriptName));
}
@@ -2058,7 +2026,8 @@ std::string cmMakefileTargetGenerator::CreateResponseFile(
// Create the response file.
std::string responseFileNameFull =
cmStrCat(this->TargetBuildDirectoryFull, '/', name);
- cmGeneratedFileStream responseStream(responseFileNameFull);
+ cmGeneratedFileStream responseStream(
+ responseFileNameFull, false, this->GlobalGenerator->GetMakefileEncoding());
responseStream.SetCopyIfDifferent(true);
responseStream << options << "\n";
@@ -2195,8 +2164,8 @@ void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags,
lang, this->GetConfigName());
std::string includeFlags = this->LocalGenerator->GetIncludeFlags(
- includes, this->GeneratorTarget, lang, false, useResponseFile,
- this->GetConfigName());
+ includes, this->GeneratorTarget, lang, this->GetConfigName(),
+ useResponseFile);
if (includeFlags.empty()) {
return;
}
@@ -2232,14 +2201,12 @@ void cmMakefileTargetGenerator::GenDefFile(
this->LocalGenerator->ConvertToOutputFormat(cmd, cmOutputConverter::SHELL),
" -E __create_def ",
this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), mdi->DefFile),
+ this->LocalGenerator->MaybeRelativeToCurBinDir(mdi->DefFile),
cmOutputConverter::SHELL),
' ');
std::string objlist_file = mdi->DefFile + ".objs";
cmd += this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->MaybeConvertToRelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), objlist_file),
+ this->LocalGenerator->MaybeRelativeToCurBinDir(objlist_file),
cmOutputConverter::SHELL);
cmProp nm_executable = this->Makefile->GetDefinition("CMAKE_NM");
if (cmNonempty(nm_executable)) {