From b6bfa7eeb29937fbed44153518abfa4f28b9aa62 Mon Sep 17 00:00:00 2001 From: Fred Baksik Date: Mon, 8 Apr 2019 09:55:34 -0400 Subject: GHS: Support add_dependencies() command -- use references to list target dependencies --- Source/cmGhsMultiTargetGenerator.cxx | 42 +++++++----- Source/cmGlobalGhsMultiGenerator.cxx | 121 +++++++++++++++++++---------------- Source/cmGlobalGhsMultiGenerator.h | 19 +++--- 3 files changed, 102 insertions(+), 80 deletions(-) diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 725c4b4..51d08cb 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -109,12 +109,12 @@ void cmGhsMultiTargetGenerator::Generate() void cmGhsMultiTargetGenerator::GenerateTarget() { - // Open the filestream in copy-if-different mode. - std::string fname = this->LocalGenerator->GetCurrentBinaryDirectory(); - fname += "/"; - fname += this->Name; - fname += cmGlobalGhsMultiGenerator::FILE_EXTENSION; - cmGeneratedFileStream fout(fname); + // Open the target file in copy-if-different mode. + std::string fproj = this->LocalGenerator->GetCurrentBinaryDirectory(); + fproj += "/"; + fproj += this->Name; + fproj += cmGlobalGhsMultiGenerator::FILE_EXTENSION; + cmGeneratedFileStream fout(fproj); fout.SetCopyIfDifferent(true); this->GetGlobalGenerator()->WriteFileHeader(fout); @@ -132,9 +132,23 @@ void cmGhsMultiTargetGenerator::GenerateTarget() this->WriteTargetLinkLine(fout, this->ConfigName); this->WriteBuildEvents(fout); } - this->WriteSources(fout); this->WriteReferences(fout); + this->WriteSources(fout); + fout.Close(); + + // Open the target ref file in copy-if-different mode. + std::string fname = this->LocalGenerator->GetCurrentBinaryDirectory(); + fname += "/"; + fname += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); + fname += "/"; + fname += this->Name + "_REF" + cmGlobalGhsMultiGenerator::FILE_EXTENSION; + cmGeneratedFileStream fref(fname); + fref.SetCopyIfDifferent(true); + this->GetGlobalGenerator()->WriteFileHeader(fref); + GhsMultiGpj::WriteGpjTag(GhsMultiGpj::REFERENCE, fref); + fref << " :reference=" << fproj << std::endl; + fref.Close(); } cmGlobalGhsMultiGenerator* cmGhsMultiTargetGenerator::GetGlobalGenerator() @@ -489,7 +503,7 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) /* list of known groups and the order they are displayed in a project file */ const std::vector standardGroups = { - "Header Files", "Source Files", "CMake Rules", + "CMake Rules", "Header Files", "Source Files", "Object Files", "Object Libraries", "Resources" }; @@ -667,7 +681,7 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) fname += std::to_string(cmdcount++) + "_"; fname += (sf->GetLocation()).GetName(); fname += this->CmdWindowsShell ? ".bat" : ".sh"; - cmGeneratedFileStream f(fname.c_str()); + cmGeneratedFileStream f(fname); f.SetCopyIfDifferent(true); this->WriteCustomCommandsHelper(f, ccg); f.Close(); @@ -727,11 +741,8 @@ void cmGhsMultiTargetGenerator::WriteObjectLangOverride( void cmGhsMultiTargetGenerator::WriteReferences(std::ostream& fout) { - // This only applies to INTEGRITY Applications - if (this->TagType != GhsMultiGpj::INTERGRITY_APPLICATION) { - return; - } - + // FIXME - compare unordered to ordered projects + // also needs transitive build order deps! // Get the targets that this one depends upon cmTargetDependSet unordered = this->GetGlobalGenerator()->GetTargetDirectDepends(this->GeneratorTarget); @@ -748,9 +759,6 @@ void cmGhsMultiTargetGenerator::WriteReferences(std::ostream& fout) fout << outpath; fout << " "; GhsMultiGpj::WriteGpjTag(GhsMultiGpj::REFERENCE, fout); - - // Tell the global generator that a reference project needs to be created - t->Target->SetProperty("GHS_REFERENCE_PROJECT", "ON"); } } diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 2180770..f212efc 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -322,7 +322,7 @@ void cmGlobalGhsMultiGenerator::WriteCustomTargetBOD(std::ostream& fout) } void cmGlobalGhsMultiGenerator::WriteTopLevelProject( - std::ostream& fout, std::string& ename, cmLocalGenerator* root, + std::ostream& fout, cmLocalGenerator* root, std::vector& generators) { WriteFileHeader(fout); @@ -355,64 +355,80 @@ void cmGlobalGhsMultiGenerator::WriteTopLevelProject( fout << "\"" << this->OsDir << "\"" << std::endl; } - WriteSubProjects(fout, ename, root, generators); + WriteSubProjects(fout, root, generators); } void cmGlobalGhsMultiGenerator::WriteSubProjects( - std::ostream& fout, std::string& ename, cmLocalGenerator* root, + std::ostream& fout, cmLocalGenerator* root, std::vector& generators) { - this->ExcludedTargets.clear(); + this->DefaultTargets.clear(); + this->ProjectTargets.clear(); // Collect all targets under this root generator and the transitive // closure of their dependencies. + // FIXME -- what is correct list or is it build order TargetDependSet projectTargets; TargetDependSet originalTargets; this->GetTargetSets(projectTargets, originalTargets, root, generators); OrderedTargetDependSet orderedProjectTargets(projectTargets, ""); - // write out all the targets for ALL target + // determine the targets for ALL target std::string rootBinaryDir = root->GetCurrentBinaryDirectory(); for (cmGeneratorTarget const* target : orderedProjectTargets) { if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } - if (cmSystemTools::IsOn(target->GetProperty("EXCLUDE_FROM_ALL"))) { - this->ExcludedTargets.push_back(target); - continue; + this->ProjectTargets.push_back(target); + if (!cmSystemTools::IsOn(target->GetProperty("EXCLUDE_FROM_ALL"))) { + this->DefaultTargets.push_back(target); } - this->WriteProjectLine(fout, target, root, rootBinaryDir); - } - if (!this->ExcludedTargets.empty()) { - fout << "{nobuild} " << ename << " [Project]" << std::endl; } + + fout << root->GetProjectName() << ".default" << FILE_EXTENSION + << " [Project]" << std::endl; + fout << "{nobuild} " << root->GetProjectName() << ".target" << FILE_EXTENSION + << " [Project]" << std::endl; + fout << "{nobuild} " << root->GetProjectName() << ".project" + << FILE_EXTENSION << " [Project]" << std::endl; } -void cmGlobalGhsMultiGenerator::WriteExcludedProjects( +void cmGlobalGhsMultiGenerator::WriteDefaultProject( std::ostream& fout, cmLocalGenerator* root, std::vector& generators) { - // write out all the excluded targets + // write out all the targets for this project + WriteFileHeader(fout); + GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, fout); std::string rootBinaryDir = root->GetCurrentBinaryDirectory(); - for (cmGeneratorTarget const* target : this->ExcludedTargets) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { - continue; - } - this->WriteProjectLine(fout, target, root, rootBinaryDir); + for (cmGeneratorTarget const* target : this->DefaultTargets) { + this->WriteProjectLine(fout, target, root, rootBinaryDir, false); + } +} + +void cmGlobalGhsMultiGenerator::WriteTargetProjects( + std::ostream& fout, cmLocalGenerator* root, + std::vector& generators, bool proj) +{ + // write out all the targets for this project + WriteFileHeader(fout); + GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, fout); + std::string rootBinaryDir = root->GetCurrentBinaryDirectory(); + for (cmGeneratorTarget const* target : this->ProjectTargets) { + this->WriteProjectLine(fout, target, root, rootBinaryDir, proj); } - this->ExcludedTargets.clear(); } void cmGlobalGhsMultiGenerator::WriteProjectLine( std::ostream& fout, cmGeneratorTarget const* target, cmLocalGenerator* root, - std::string& rootBinaryDir) + std::string& rootBinaryDir, bool proj) { const char* projName = target->GetProperty("GENERATOR_FILE_NAME"); const char* projType = target->GetProperty("GENERATOR_FILE_NAME_EXT"); if (projName && projType) { cmLocalGenerator* lg = target->GetLocalGenerator(); std::string dir = lg->GetCurrentBinaryDirectory(); - dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir.c_str()); + dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir); if (dir == ".") { dir.clear(); } else { @@ -424,23 +440,6 @@ void cmGlobalGhsMultiGenerator::WriteProjectLine( std::string projFile = dir + projName + FILE_EXTENSION; fout << projFile; fout << " " << projType << std::endl; - - if (cmSystemTools::IsOn(target->GetProperty("GHS_REFERENCE_PROJECT"))) { - // create reference project - std::string fname = dir; - fname += target->GetName(); - fname += "REF"; - fname += FILE_EXTENSION; - - cmGeneratedFileStream fref(fname); - fref.SetCopyIfDifferent(true); - - this->WriteFileHeader(fref); - GhsMultiGpj::WriteGpjTag(GhsMultiGpj::REFERENCE, fref); - fref << " :reference=" << projFile << std::endl; - - fref.Close(); - } } } @@ -468,7 +467,7 @@ void cmGlobalGhsMultiGenerator::Generate() // create custom target BOD file fname = this->GetCMakeInstance()->GetHomeOutputDirectory() + "/CMakeFiles/custom_target.bod"; - cmGeneratedFileStream ftarget(fname.c_str()); + cmGeneratedFileStream ftarget(fname); ftarget.SetCopyIfDifferent(true); this->WriteFileHeader(ftarget); this->WriteCustomTargetBOD(ftarget); @@ -479,7 +478,6 @@ void cmGlobalGhsMultiGenerator::OutputTopLevelProject( cmLocalGenerator* root, std::vector& generators) { std::string fname; - std::string ename; if (generators.empty()) { return; @@ -495,24 +493,37 @@ void cmGlobalGhsMultiGenerator::OutputTopLevelProject( fname += ".top"; fname += FILE_EXTENSION; - ename = root->GetProjectName(); - ename += ".nobuild"; - ename += FILE_EXTENSION; - cmGeneratedFileStream top(fname); top.SetCopyIfDifferent(true); - this->WriteTopLevelProject(top, ename, root, generators); + this->WriteTopLevelProject(top, root, generators); top.Close(); - if (!this->ExcludedTargets.empty()) { - ename = root->GetCurrentBinaryDirectory() + "/" + ename; - cmGeneratedFileStream exclude(ename); - exclude.SetCopyIfDifferent(true); - WriteFileHeader(exclude); - GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, exclude); - this->WriteExcludedProjects(exclude, root, generators); - exclude.Close(); - } + fname = root->GetCurrentBinaryDirectory() + "/"; + fname += root->GetProjectName(); + fname += ".target"; + fname += FILE_EXTENSION; + cmGeneratedFileStream target(fname); + target.SetCopyIfDifferent(true); + this->WriteTargetProjects(target, root, generators, false); + target.Close(); + + fname = root->GetCurrentBinaryDirectory() + "/"; + fname += root->GetProjectName(); + fname += ".project"; + fname += FILE_EXTENSION; + cmGeneratedFileStream project(fname); + project.SetCopyIfDifferent(true); + this->WriteTargetProjects(project, root, generators, true); + project.Close(); + + fname = root->GetCurrentBinaryDirectory() + "/"; + fname += root->GetProjectName(); + fname += ".default"; + fname += FILE_EXTENSION; + cmGeneratedFileStream default_targets(fname); + default_targets.SetCopyIfDifferent(true); + this->WriteDefaultProject(default_targets, root, generators); + default_targets.Close(); } std::vector diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h index a987205..5027a7c 100644 --- a/Source/cmGlobalGhsMultiGenerator.h +++ b/Source/cmGlobalGhsMultiGenerator.h @@ -111,18 +111,20 @@ private: /* top-level project */ void OutputTopLevelProject(cmLocalGenerator* root, std::vector& generators); - void WriteTopLevelProject(std::ostream& fout, std::string& ename, - cmLocalGenerator* root, + void WriteTopLevelProject(std::ostream& fout, cmLocalGenerator* root, std::vector& generators); void WriteMacros(std::ostream& fout); void WriteHighLevelDirectives(cmLocalGenerator* root, std::ostream& fout); - void WriteSubProjects(std::ostream& fout, std::string& ename, - cmLocalGenerator* root, + void WriteSubProjects(std::ostream& fout, cmLocalGenerator* root, std::vector& generators); - void WriteExcludedProjects(std::ostream& fout, cmLocalGenerator* root, - std::vector& generators); + void WriteTargetProjects(std::ostream& fout, cmLocalGenerator* root, + std::vector& generators, + bool proj); + void WriteDefaultProject(std::ostream& fout, cmLocalGenerator* root, + std::vector& generators); void WriteProjectLine(std::ostream& fout, cmGeneratorTarget const* target, - cmLocalGenerator* root, std::string& rootBinaryDir); + cmLocalGenerator* root, std::string& rootBinaryDir, + bool proj); void WriteCustomRuleBOD(std::ostream& fout); void WriteCustomTargetBOD(std::ostream& fout); @@ -131,7 +133,8 @@ private: std::string OsDir; static const char* DEFAULT_BUILD_PROGRAM; static const char* DEFAULT_TOOLSET_ROOT; - std::vector ExcludedTargets; + std::vector DefaultTargets; + std::vector ProjectTargets; }; class cmGlobalGhsMultiGenerator::OrderedTargetDependSet -- cgit v0.12