cmake/Source/cmLocalGhsMultiGenerator.cxx

81 lines
2.5 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. */
2015-08-17 11:37:30 +02:00
#include "cmLocalGhsMultiGenerator.h"
2016-07-09 11:21:54 +02:00
2020-02-01 23:06:01 +01:00
#include <utility>
2021-09-14 00:13:48 +02:00
#include <vector>
2020-08-30 11:54:41 +02:00
2015-08-17 11:37:30 +02:00
#include "cmGeneratorTarget.h"
#include "cmGhsMultiTargetGenerator.h"
2019-11-11 23:01:05 +01:00
#include "cmGlobalGenerator.h"
#include "cmSourceFile.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2019-11-11 23:01:05 +01:00
#include "cmSystemTools.h"
2015-08-17 11:37:30 +02:00
cmLocalGhsMultiGenerator::cmLocalGhsMultiGenerator(cmGlobalGenerator* gg,
2015-11-17 17:22:37 +01:00
cmMakefile* mf)
: cmLocalGenerator(gg, mf)
2015-08-17 11:37:30 +02:00
{
}
2019-11-11 23:01:05 +01:00
cmLocalGhsMultiGenerator::~cmLocalGhsMultiGenerator() = default;
std::string cmLocalGhsMultiGenerator::GetTargetDirectory(
cmGeneratorTarget const* target) const
2016-07-09 11:21:54 +02:00
{
2020-02-01 23:06:01 +01:00
std::string dir = cmStrCat(target->GetName(), ".dir");
2019-11-11 23:01:05 +01:00
return dir;
}
2015-08-17 11:37:30 +02:00
void cmLocalGhsMultiGenerator::Generate()
{
2021-09-14 00:13:48 +02:00
for (cmGeneratorTarget* gt :
this->GlobalGenerator->GetLocalGeneratorTargetsInOrder(this)) {
if (!gt->IsInBuildSystem()) {
continue;
2019-11-11 23:01:05 +01:00
}
2021-09-14 00:13:48 +02:00
cmGhsMultiTargetGenerator tg(gt);
tg.Generate();
2019-11-11 23:01:05 +01:00
}
}
void cmLocalGhsMultiGenerator::ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
cmGeneratorTarget const* gt)
{
2020-02-01 23:06:01 +01:00
std::string dir_max = cmStrCat(this->GetCurrentBinaryDirectory(), '/',
this->GetTargetDirectory(gt), '/');
2019-11-11 23:01:05 +01:00
// Count the number of object files with each name. Note that
// filesystem may not be case sensitive.
std::map<std::string, int> counts;
for (auto const& si : mapping) {
cmSourceFile const* sf = si.first;
2020-02-01 23:06:01 +01:00
std::string objectNameLower = cmStrCat(
cmSystemTools::LowerCase(
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())),
this->GlobalGenerator->GetLanguageOutputExtension(*sf));
2019-11-11 23:01:05 +01:00
counts[objectNameLower] += 1;
}
// For all source files producing duplicate names we need unique
// object name computation.
for (auto& si : mapping) {
cmSourceFile const* sf = si.first;
2020-02-01 23:06:01 +01:00
std::string objectName = cmStrCat(
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()),
this->GlobalGenerator->GetLanguageOutputExtension(*sf));
2015-08-17 11:37:30 +02:00
2019-11-11 23:01:05 +01:00
if (counts[cmSystemTools::LowerCase(objectName)] > 1) {
const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
bool keptSourceExtension;
objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max,
&keptSourceExtension);
cmsys::SystemTools::ReplaceString(objectName, "/", "_");
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
si.second = objectName;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}