From 73092b2213495e06ef2ecfbf5fcca850874d6c88 Mon Sep 17 00:00:00 2001 From: Fred Baksik Date: Sat, 5 Jan 2019 11:01:22 -0500 Subject: GHS: Add support for object libraries --- Source/cmGhsMultiTargetGenerator.cxx | 111 ++++++++--------------------------- Source/cmGhsMultiTargetGenerator.h | 9 +-- Source/cmLocalGhsMultiGenerator.cxx | 42 +++++++++++++ Source/cmLocalGhsMultiGenerator.h | 4 ++ 4 files changed, 70 insertions(+), 96 deletions(-) diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 5e6224f..72f308a 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -76,10 +76,15 @@ void cmGhsMultiTargetGenerator::Generate() return; } case cmStateEnums::OBJECT_LIBRARY: { - std::string msg = "add_library( OBJECT ...) not supported: "; - msg += this->Name; - cmSystemTools::Message(msg.c_str()); - return; + std::string targetName; + std::string targetNameSO; + std::string targetNameImport; + std::string targetNamePDB; + this->GeneratorTarget->GetLibraryNames( + targetName, targetNameSO, this->TargetNameReal, targetNameImport, + targetNamePDB, this->ConfigName); + this->TagType = GhsMultiGpj::SUBPROJECT; + break; } case cmStateEnums::MODULE_LIBRARY: { std::string msg = "add_library( MODULE ...) not supported: "; @@ -151,11 +156,13 @@ void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout, std::string outpath; std::string rootpath = this->LocalGenerator->GetCurrentBinaryDirectory(); - // set target binary file destination - outpath = this->GeneratorTarget->GetDirectory(config); - outpath = this->LocalGenerator->ConvertToRelativePath(rootpath, outpath); - fout << " :binDirRelative=\"" << outpath << "\"" << std::endl; - fout << " -o \"" << this->TargetNameReal << "\"" << std::endl; + if (this->TagType != GhsMultiGpj::SUBPROJECT) { + // set target binary file destination + outpath = this->GeneratorTarget->GetDirectory(config); + outpath = this->LocalGenerator->ConvertToRelativePath(rootpath, outpath); + fout << " :binDirRelative=\"" << outpath << "\"" << std::endl; + fout << " -o \"" << this->TargetNameReal << "\"" << std::endl; + } // set target object file destination outpath = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); @@ -360,52 +367,6 @@ void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper( } } -std::map -cmGhsMultiTargetGenerator::GetObjectNames( - std::vector* const objectSources, - cmLocalGhsMultiGenerator* const localGhsMultiGenerator, - cmGeneratorTarget* const generatorTarget) -{ - std::map> filenameToSource; - std::map sourceToFilename; - for (std::vector::const_iterator sf = objectSources->begin(); - sf != objectSources->end(); ++sf) { - const std::string filename = - cmSystemTools::GetFilenameName((*sf)->GetFullPath()); - const std::string lower_filename = cmSystemTools::LowerCase(filename); - filenameToSource[lower_filename].push_back(*sf); - sourceToFilename[*sf] = lower_filename; - } - - std::vector duplicateSources; - for (std::map>::const_iterator - msvSourceI = filenameToSource.begin(); - msvSourceI != filenameToSource.end(); ++msvSourceI) { - if (msvSourceI->second.size() > 1) { - duplicateSources.insert(duplicateSources.end(), - msvSourceI->second.begin(), - msvSourceI->second.end()); - } - } - - std::map objectNamesCorrected; - - for (std::vector::const_iterator sf = - duplicateSources.begin(); - sf != duplicateSources.end(); ++sf) { - std::string const longestObjectDirectory( - cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory( - localGhsMultiGenerator, generatorTarget, *sf)); - std::string objFilenameName = - localGhsMultiGenerator->GetObjectFileNameWithoutTarget( - **sf, longestObjectDirectory); - cmsys::SystemTools::ReplaceString(objFilenameName, "/", "_"); - objectNamesCorrected[*sf] = objFilenameName; - } - - return objectNamesCorrected; -} - void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) { /* vector of all sources for this target */ @@ -473,11 +434,6 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) }); } - /* get all the object names for these sources */ - std::map objectNames = - cmGhsMultiTargetGenerator::GetObjectNames(&sources, this->LocalGenerator, - this->GeneratorTarget); - /* list of open project files */ std::vector gfiles; @@ -537,10 +493,13 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) if ("ld" != si->GetExtension() && "int" != si->GetExtension() && "bsp" != si->GetExtension()) { this->WriteObjectLangOverride(*fout, si); - if (objectNames.end() != objectNames.find(si)) { - *fout << " -o \"" << objectNames.find(si)->second << "\"" - << std::endl; - } + } + /* to avoid clutter in the gui only print out the objectName if it has + * been renamed */ + std::string objectName = this->GeneratorTarget->GetObjectName(si); + if (!objectName.empty() && + this->GeneratorTarget->HasExplicitObjectName(si)) { + *fout << " -o " << objectName << std::endl; } } } @@ -563,30 +522,6 @@ void cmGhsMultiTargetGenerator::WriteObjectLangOverride( } } -std::string cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory( - cmLocalGhsMultiGenerator const* localGhsMultiGenerator, - cmGeneratorTarget* const generatorTarget, cmSourceFile* const sourceFile) -{ - std::string dir_max; - dir_max += - localGhsMultiGenerator->GetMakefile()->GetCurrentBinaryDirectory(); - dir_max += "/"; - dir_max += generatorTarget->Target->GetName(); - dir_max += "/"; - std::vector sourceGroups( - localGhsMultiGenerator->GetMakefile()->GetSourceGroups()); - std::string const& sourceFullPath = sourceFile->GetFullPath(); - cmSourceGroup* sourceGroup = - localGhsMultiGenerator->GetMakefile()->FindSourceGroup(sourceFullPath, - sourceGroups); - std::string const& sgPath = sourceGroup->GetFullName(); - dir_max += sgPath; - dir_max += "/Objs/libs/"; - dir_max += generatorTarget->Target->GetName(); - dir_max += "/"; - return dir_max; -} - bool cmGhsMultiTargetGenerator::DetermineIfTargetGroup( const cmGeneratorTarget* target) { diff --git a/Source/cmGhsMultiTargetGenerator.h b/Source/cmGhsMultiTargetGenerator.h index 5d67112..c713cc4 100644 --- a/Source/cmGhsMultiTargetGenerator.h +++ b/Source/cmGhsMultiTargetGenerator.h @@ -52,17 +52,10 @@ private: std::ostream& fout, std::vector const& commandsSet, cmTarget::CustomCommandType commandType); void WriteSources(std::ostream& fout_proj); - static std::map GetObjectNames( - std::vector* objectSources, - cmLocalGhsMultiGenerator* localGhsMultiGenerator, - cmGeneratorTarget* generatorTarget); + static void WriteObjectLangOverride(std::ostream& fout, const cmSourceFile* sourceFile); - static std::string ComputeLongestObjectDirectory( - cmLocalGhsMultiGenerator const* localGhsMultiGenerator, - cmGeneratorTarget* generatorTarget, cmSourceFile* const sourceFile); - static bool DetermineIfTargetGroup(const cmGeneratorTarget* target); bool DetermineIfDynamicDownload(std::string const& config, const std::string& language); diff --git a/Source/cmLocalGhsMultiGenerator.cxx b/Source/cmLocalGhsMultiGenerator.cxx index b539a1c..125e8b5 100644 --- a/Source/cmLocalGhsMultiGenerator.cxx +++ b/Source/cmLocalGhsMultiGenerator.cxx @@ -7,6 +7,7 @@ #include "cmGhsMultiTargetGenerator.h" #include "cmGlobalGhsMultiGenerator.h" #include "cmMakefile.h" +#include "cmSourceFile.h" cmLocalGhsMultiGenerator::cmLocalGhsMultiGenerator(cmGlobalGenerator* gg, cmMakefile* mf) @@ -56,3 +57,44 @@ void cmLocalGhsMultiGenerator::Generate() } } } + +void cmLocalGhsMultiGenerator::ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const* gt) +{ + std::string dir_max; + dir_max += this->GetCurrentBinaryDirectory(); + dir_max += "/"; + dir_max += this->GetTargetDirectory(gt); + dir_max += "/"; + + // Count the number of object files with each name. Note that + // filesystem may not be case sensitive. + std::map counts; + + for (auto const& si : mapping) { + cmSourceFile const* sf = si.first; + std::string objectNameLower = cmSystemTools::LowerCase( + cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())); + objectNameLower += this->GlobalGenerator->GetLanguageOutputExtension(*sf); + 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; + std::string objectName = + cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()); + objectName += this->GlobalGenerator->GetLanguageOutputExtension(*sf); + + if (counts[cmSystemTools::LowerCase(objectName)] > 1) { + const_cast(gt)->AddExplicitObjectName(sf); + bool keptSourceExtension; + objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max, + &keptSourceExtension); + cmsys::SystemTools::ReplaceString(objectName, "/", "_"); + } + si.second = objectName; + } +} diff --git a/Source/cmLocalGhsMultiGenerator.h b/Source/cmLocalGhsMultiGenerator.h index 1f55420..d5bec42 100644 --- a/Source/cmLocalGhsMultiGenerator.h +++ b/Source/cmLocalGhsMultiGenerator.h @@ -28,6 +28,10 @@ public: std::string GetTargetDirectory( cmGeneratorTarget const* target) const override; + void ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const* gt = nullptr) override; + private: void GenerateTargetsDepthFirst(cmGeneratorTarget* target, std::vector& remaining); -- cgit v0.12