From 724b5491ef63adb9ce39958f06e0d7ff0d444832 Mon Sep 17 00:00:00 2001 From: Fred Baksik Date: Wed, 16 Mar 2022 16:24:59 -0400 Subject: GHS: Rearrange project files in binary directory The top level project and the target projects are all in the same directory so they are easier to find and looks nicer in the GUI. All of the ancillary project files are located in the target subdirectory. --- Source/cmGhsMultiTargetGenerator.cxx | 36 ++++++++++++++++++++++-------------- Source/cmGlobalGhsMultiGenerator.cxx | 24 ++++++------------------ 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index a2d64aa..a7796c9 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -107,12 +107,6 @@ void cmGhsMultiTargetGenerator::Generate() return; } - // Tell the global generator the name of the project file - this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME", - this->Name); - this->GeneratorTarget->Target->SetProperty( - "GENERATOR_FILE_NAME_EXT", GhsMultiGpj::GetGpjTag(this->TagType)); - this->GenerateTarget(); } @@ -121,7 +115,14 @@ void cmGhsMultiTargetGenerator::GenerateTarget() // Open the target file in copy-if-different mode. std::string fproj = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/', - this->Name, cmGlobalGhsMultiGenerator::FILE_EXTENSION); + this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), + '/', this->Name, cmGlobalGhsMultiGenerator::FILE_EXTENSION); + + // Tell the global generator the name of the project file + this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME", fproj); + this->GeneratorTarget->Target->SetProperty( + "GENERATOR_FILE_NAME_EXT", GhsMultiGpj::GetGpjTag(this->TagType)); + cmGeneratedFileStream fout(fproj); fout.SetCopyIfDifferent(true); @@ -155,10 +156,16 @@ void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout, { std::string outpath; + /* Determine paths from the target project file to where the output artifacts + * need to be located. + */ if (this->TagType != GhsMultiGpj::SUBPROJECT) { // set target binary file destination - outpath = this->GeneratorTarget->GetDirectory(config); - outpath = this->LocalGenerator->MaybeRelativeToCurBinDir(outpath); + std::string binpath = cmStrCat( + this->LocalGenerator->GetCurrentBinaryDirectory(), '/', + this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget)); + outpath = cmSystemTools::RelativePath( + binpath, this->GeneratorTarget->GetDirectory(config)); /* clang-format off */ fout << " :binDirRelative=\"" << outpath << "\"\n" " -o \"" << this->TargetNameReal << "\"\n"; @@ -166,7 +173,7 @@ void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout, } // set target object file destination - outpath = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); + outpath = "."; fout << " :outputDirRelative=\"" << outpath << "\"\n"; } @@ -576,11 +583,12 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) // Open the filestream in copy-if-different mode. std::string gname = sg; cmsys::SystemTools::ReplaceString(gname, "\\", "_"); - std::string lpath = cmStrCat( - this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), '/', - gname, cmGlobalGhsMultiGenerator::FILE_EXTENSION); + std::string lpath = + cmStrCat(gname, cmGlobalGhsMultiGenerator::FILE_EXTENSION); std::string fpath = cmStrCat( - this->LocalGenerator->GetCurrentBinaryDirectory(), '/', lpath); + this->LocalGenerator->GetCurrentBinaryDirectory(), '/', + this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), '/', + lpath); cmGeneratedFileStream* f = new cmGeneratedFileStream(fpath); f->SetCopyIfDifferent(true); gfiles.push_back(f); diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index ca05076..fee438d 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -328,8 +328,7 @@ void cmGlobalGhsMultiGenerator::WriteSubProjects(std::ostream& fout) target->GetName() != this->GetInstallTargetName())) { continue; } - fout << "CMakeFiles/" << target->GetName() + ".tgt" + FILE_EXTENSION - << " [Project]\n"; + fout << target->GetName() + ".tgt" + FILE_EXTENSION << " [Project]\n"; } } @@ -337,33 +336,22 @@ void cmGlobalGhsMultiGenerator::WriteProjectLine( std::ostream& fout, cmGeneratorTarget const* target, std::string& rootBinaryDir) { - cmValue projName = target->GetProperty("GENERATOR_FILE_NAME"); + cmValue projFile = target->GetProperty("GENERATOR_FILE_NAME"); cmValue projType = target->GetProperty("GENERATOR_FILE_NAME_EXT"); /* If either value is not valid then this particular target is an * unsupported target type and should be skipped. */ - if (projName && projType) { - cmLocalGenerator* lg = target->GetLocalGenerator(); - std::string dir = lg->GetCurrentBinaryDirectory(); - dir = cmSystemTools::ForceToRelativePath(rootBinaryDir, dir); - if (dir == ".") { - dir.clear(); - } else { - if (dir.back() != '/') { - dir += "/"; - } - } + if (projFile && projType) { + std::string path = cmSystemTools::RelativePath(rootBinaryDir, projFile); - std::string projFile = dir + *projName + FILE_EXTENSION; - fout << projFile; + fout << path; fout << ' ' << *projType << '\n'; } } void cmGlobalGhsMultiGenerator::WriteTargets(cmLocalGenerator* root) { - std::string rootBinaryDir = - cmStrCat(root->GetCurrentBinaryDirectory(), "/CMakeFiles"); + std::string rootBinaryDir = root->GetCurrentBinaryDirectory(); // All known targets for (cmGeneratorTarget const* target : this->ProjectTargets) { -- cgit v0.12