BUG: Fix VS IDE project order

Our implementation of the feature to pull in dependent targets in VS
solution files for subprojects caused the order of project files in the
solution to be arbitrary (based on pointer value in the representation).
Target ordering in solution files is important to prevent unnecessary
changing of the files and because the VS IDE selects the first project
listed as the default active target.  This change restores lexicographic
order by target name.
This commit is contained in:
Brad King 2009-01-21 16:39:43 -05:00
parent 36c228814b
commit 00ca96ae7c
3 changed files with 52 additions and 26 deletions

View File

@ -115,7 +115,9 @@ void cmGlobalVisualStudio71Generator
this->GetTargetSets(projectTargets,
originalTargets,
root, generators);
this->WriteTargetsToSolution(fout, root, projectTargets, originalTargets);
OrderedTargetDependSet orderedProjectTargets(projectTargets);
this->WriteTargetsToSolution(fout, root, orderedProjectTargets,
originalTargets);
// Write out the configurations information for the solution
fout << "Global\n";
// Write out the configurations for the solution
@ -123,7 +125,7 @@ void cmGlobalVisualStudio71Generator
fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
<< ") = postSolution\n";
// Write out the configurations for all the targets in the project
this->WriteTargetConfigurations(fout, root, projectTargets);
this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
fout << "\tEndGlobalSection\n";
// Write the footer for the SLN file
this->WriteSLNFooter(fout);

View File

@ -253,15 +253,7 @@ void cmGlobalVisualStudio7Generator::AddAllBuildDepends(
cmTarget* t = const_cast<cmTarget*>(*ot);
if(!this->IsExcluded(root, *t))
{
if (t->GetType() == cmTarget::UTILITY ||
t->GetType() == cmTarget::GLOBAL_TARGET)
{
target->AddUtility(t->GetName());
}
else
{
target->AddLinkLibrary(t->GetName(),cmTarget::GENERAL);
}
target->AddUtility(t->GetName());
}
}
}
@ -269,14 +261,14 @@ void cmGlobalVisualStudio7Generator::AddAllBuildDepends(
void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
std::ostream& fout,
cmLocalGenerator* root,
cmGlobalGenerator::TargetDependSet& projectTargets)
OrderedTargetDependSet const& projectTargets)
{
// loop over again and write out configurations for each target
// in the solution
for(cmGlobalGenerator::TargetDependSet::iterator tt =
for(OrderedTargetDependSet::const_iterator tt =
projectTargets.begin(); tt != projectTargets.end(); ++tt)
{
cmTarget* target = const_cast<cmTarget*>(*tt);
cmTarget* target = *tt;
if (strncmp(target->GetName(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
{
cmCustomCommand cc = target->GetPostBuildCommands()[0];
@ -304,16 +296,16 @@ void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
std::ostream& fout,
cmLocalGenerator* root,
cmGlobalGenerator::TargetDependSet& projectTargets,
OrderedTargetDependSet const& projectTargets,
cmGlobalGenerator::TargetDependSet& originalTargets
)
{
std::string rootdir = root->GetMakefile()->GetStartOutputDirectory();
rootdir += "/";
for(cmGlobalGenerator::TargetDependSet::iterator tt =
for(OrderedTargetDependSet::const_iterator tt =
projectTargets.begin(); tt != projectTargets.end(); ++tt)
{
cmTarget* target = const_cast<cmTarget*>(*tt);
cmTarget* target = *tt;
cmMakefile* mf = target->GetMakefile();
// look for the all_build rule and add depends to all
// of the original targets (none that were "pulled" into this project)
@ -370,13 +362,13 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
void cmGlobalVisualStudio7Generator::WriteTargetDepends(
std::ostream& fout,
cmGlobalGenerator::TargetDependSet& projectTargets
OrderedTargetDependSet const& projectTargets
)
{
for(cmGlobalGenerator::TargetDependSet::iterator tt =
for(OrderedTargetDependSet::const_iterator tt =
projectTargets.begin(); tt != projectTargets.end(); ++tt)
{
cmTarget* target = const_cast<cmTarget*>(*tt);
cmTarget* target = *tt;
cmMakefile* mf = target->GetMakefile();
if (strncmp(target->GetName(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
{
@ -434,7 +426,9 @@ void cmGlobalVisualStudio7Generator
this->GetTargetSets(projectTargets,
originalTargets,
root, generators);
this->WriteTargetsToSolution(fout, root, projectTargets, originalTargets);
OrderedTargetDependSet orderedProjectTargets(projectTargets);
this->WriteTargetsToSolution(fout, root, orderedProjectTargets,
originalTargets);
// Write out the configurations information for the solution
fout << "Global\n"
<< "\tGlobalSection(SolutionConfiguration) = preSolution\n";
@ -449,12 +443,12 @@ void cmGlobalVisualStudio7Generator
fout << "\tEndGlobalSection\n";
// Write out project(target) depends
fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
this->WriteTargetDepends(fout, projectTargets);
this->WriteTargetDepends(fout, orderedProjectTargets);
fout << "\tEndGlobalSection\n";
// Write out the configurations for all the targets in the project
fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
this->WriteTargetConfigurations(fout, root, projectTargets);
this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
fout << "\tEndGlobalSection\n";
// Write the footer for the SLN file
@ -730,6 +724,25 @@ bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project,
return true;
}
//----------------------------------------------------------------------------
bool
cmGlobalVisualStudio7Generator::TargetCompare
::operator()(cmTarget const* l, cmTarget const* r)
{
return strcmp(l->GetName(), r->GetName()) < 0;
}
//----------------------------------------------------------------------------
cmGlobalVisualStudio7Generator::OrderedTargetDependSet
::OrderedTargetDependSet(cmGlobalGenerator::TargetDependSet const& targets)
{
for(cmGlobalGenerator::TargetDependSet::const_iterator ti =
targets.begin(); ti != targets.end(); ++ti)
{
this->insert(*ti);
}
}
//----------------------------------------------------------------------------
static cmVS7FlagTable cmVS7ExtraFlagTable[] =
{

View File

@ -97,6 +97,11 @@ public:
///! What is the configurations directory variable called?
virtual const char* GetCMakeCFGInitDirectory() { return "$(OutDir)"; }
struct TargetCompare
{
bool operator()(cmTarget const* l, cmTarget const* r);
};
protected:
static cmVS7FlagTable const* GetExtraFlagTableVS7();
virtual void OutputSLNFile(cmLocalGenerator* root,
@ -114,18 +119,24 @@ protected:
virtual void WriteSLNHeader(std::ostream& fout);
virtual void AddPlatformDefinitions(cmMakefile* mf);
class OrderedTargetDependSet: public std::set<cmTarget*, TargetCompare>
{
public:
OrderedTargetDependSet(cmGlobalGenerator::TargetDependSet const&);
};
virtual void WriteTargetsToSolution(
std::ostream& fout,
cmLocalGenerator* root,
cmGlobalGenerator::TargetDependSet& projectTargets,
OrderedTargetDependSet const& projectTargets,
cmGlobalGenerator::TargetDependSet& originalTargets);
virtual void WriteTargetDepends(
std::ostream& fout,
cmGlobalGenerator::TargetDependSet& projectTargets);
OrderedTargetDependSet const& projectTargets);
virtual void WriteTargetConfigurations(
std::ostream& fout,
cmLocalGenerator* root,
cmGlobalGenerator::TargetDependSet& projectTargets);
OrderedTargetDependSet const& projectTargets);
void AddAllBuildDepends(cmLocalGenerator* root,
cmTarget* target,