Makefile,Ninja: De-duplicate ComputeObjectFilenames method

Move the method implementation up to `cmLocalCommonGenerator`
to avoid duplicating it in each generator.
This commit is contained in:
Brad King 2018-01-29 10:20:47 -05:00
parent 92cd3d0677
commit 79f22e8408
6 changed files with 21 additions and 38 deletions

View File

@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmLocalCommonGenerator.h"
#include <utility>
#include <vector>
#include "cmGeneratorTarget.h"
@ -76,3 +77,17 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags(
return flags;
}
void cmLocalCommonGenerator::ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
cmGeneratorTarget const* gt)
{
// Determine if these object files should use a custom extension
char const* custom_ext = gt->GetCustomObjectExtension();
for (auto& si : mapping) {
cmSourceFile const* sf = si.first;
bool keptSourceExtension;
si.second = this->GetObjectFileNameWithoutTarget(
*sf, gt->ObjectDirectory, &keptSourceExtension, custom_ext);
}
}

View File

@ -5,6 +5,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
#include <string>
#include "cmLocalGenerator.h"
@ -12,6 +13,7 @@
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmMakefile;
class cmSourceFile;
/** \class cmLocalCommonGenerator
* \brief Common infrastructure for Makefile and Ninja local generators.
@ -30,6 +32,10 @@ public:
std::string GetTargetFortranFlags(cmGeneratorTarget const* target,
std::string const& config) override;
void ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
cmGeneratorTarget const* gt = nullptr) override;
protected:
std::string WorkingDirectory;

View File

@ -246,20 +246,6 @@ void cmLocalNinjaGenerator::WriteNinjaFilesInclusion(std::ostream& os)
os << "\n";
}
void cmLocalNinjaGenerator::ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
cmGeneratorTarget const* gt)
{
// Determine if these object files should use a custom extension
char const* custom_ext = gt->GetCustomObjectExtension();
for (auto& si : mapping) {
cmSourceFile const* sf = si.first;
bool keptSourceExtension;
si.second = this->GetObjectFileNameWithoutTarget(
*sf, gt->ObjectDirectory, &keptSourceExtension, custom_ext);
}
}
void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
{
cmGlobalNinjaGenerator::WriteDivider(os);

View File

@ -23,7 +23,6 @@ class cmGlobalGenerator;
class cmGlobalNinjaGenerator;
class cmMakefile;
class cmRulePlaceholderExpander;
class cmSourceFile;
class cmake;
/**
@ -74,10 +73,6 @@ public:
void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
cmNinjaDeps& ninjaDeps);
void ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
cmGeneratorTarget const* gt = nullptr) override;
protected:
std::string ConvertToIncludeReference(
std::string const& path,

View File

@ -150,20 +150,6 @@ void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath()
}
}
void cmLocalUnixMakefileGenerator3::ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
cmGeneratorTarget const* gt)
{
// Determine if these object files should use a custom extension
char const* custom_ext = gt->GetCustomObjectExtension();
for (auto& si : mapping) {
cmSourceFile const* sf = si.first;
bool keptSourceExtension;
si.second = this->GetObjectFileNameWithoutTarget(
*sf, gt->ObjectDirectory, &keptSourceExtension, custom_ext);
}
}
void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles(
std::map<std::string, LocalObjectInfo>& localObjectFiles)
{

View File

@ -19,7 +19,6 @@ class cmCustomCommandGenerator;
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmMakefile;
class cmSourceFile;
/** \class cmLocalUnixMakefileGenerator3
* \brief Write a LocalUnix makefiles.
@ -252,10 +251,6 @@ protected:
private:
std::string MaybeConvertWatcomShellCommand(std::string const& cmd);
void ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
cmGeneratorTarget const* gt = nullptr) override;
friend class cmMakefileTargetGenerator;
friend class cmMakefileExecutableTargetGenerator;
friend class cmMakefileLibraryTargetGenerator;