Major improvement of the generated targets in Eclipse.

Before this change all targets were displayed in the top level directory of
the project. Now the targets are displayed in the correct directory.
The targets "clean" and "all" are now created in every subdirectory.
Also now the targets for just compiling one file, preprocessing one file,
assembling one file are are created for Eclipse.
Additionally all targets get a prefix now in eclipse, so that they are
sorted in a way which makes sense (global targets first, then executable and
libraries, then object files, then preprocessed, then assembly). Also
this prefix gives the user a hint what the target is, i.e. whether it's a
library or an executable or something else.

Alex
This commit is contained in:
Alexander Neundorf 2009-09-16 18:01:23 -04:00
parent 229b67a249
commit 298de4374b
4 changed files with 102 additions and 14 deletions

View File

@ -689,15 +689,16 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
cmGlobalGenerator* generator cmGlobalGenerator* generator
= const_cast<cmGlobalGenerator*>(this->GlobalGenerator); = const_cast<cmGlobalGenerator*>(this->GlobalGenerator);
std::string allTarget;
std::string cleanTarget;
if (generator->GetAllTargetName()) if (generator->GetAllTargetName())
{ {
emmited.insert(generator->GetAllTargetName()); allTarget = generator->GetAllTargetName();
this->AppendTarget(fout, generator->GetAllTargetName(), make);
} }
if (generator->GetCleanTargetName()) if (generator->GetCleanTargetName())
{ {
emmited.insert(generator->GetCleanTargetName()); cleanTarget = generator->GetCleanTargetName();
this->AppendTarget(fout, generator->GetCleanTargetName(), make);
} }
// add all executable and library targets and some of the GLOBAL // add all executable and library targets and some of the GLOBAL
@ -709,6 +710,13 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
{ {
const cmTargets& targets = (*it)->GetMakefile()->GetTargets(); const cmTargets& targets = (*it)->GetMakefile()->GetTargets();
cmMakefile* makefile=(*it)->GetMakefile(); cmMakefile* makefile=(*it)->GetMakefile();
std::string subdir = (*it)->Convert(makefile->GetCurrentOutputDirectory(),
cmLocalGenerator::HOME_OUTPUT);
if (subdir == ".")
{
subdir = "";
}
for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end(); ++ti) for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end(); ++ti)
{ {
switch(ti->second.GetType()) switch(ti->second.GetType())
@ -718,8 +726,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
bool insertTarget = false; bool insertTarget = false;
// Only add the global targets from CMAKE_BINARY_DIR, // Only add the global targets from CMAKE_BINARY_DIR,
// not from the subdirs // not from the subdirs
if (strcmp(makefile->GetStartOutputDirectory(), if (subdir.empty())
makefile->GetHomeOutputDirectory())==0)
{ {
insertTarget = true; insertTarget = true;
// only add the "edit_cache" target if it's not ccmake, because // only add the "edit_cache" target if it's not ccmake, because
@ -735,7 +742,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
} }
if (insertTarget) if (insertTarget)
{ {
this->AppendTarget(fout, ti->first, make); this->AppendTarget(fout, ti->first, make, subdir, ": ");
} }
} }
break; break;
@ -750,17 +757,19 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
break; break;
} }
this->AppendTarget(fout, ti->first, make); this->AppendTarget(fout, ti->first, make, subdir, ": ");
break; break;
case cmTarget::EXECUTABLE: case cmTarget::EXECUTABLE:
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
case cmTarget::SHARED_LIBRARY: case cmTarget::SHARED_LIBRARY:
case cmTarget::MODULE_LIBRARY: case cmTarget::MODULE_LIBRARY:
{ {
this->AppendTarget(fout, ti->first, make); const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ?
"[exe] " : "[lib] ");
this->AppendTarget(fout, ti->first, make, subdir, prefix);
std::string fastTarget = ti->first; std::string fastTarget = ti->first;
fastTarget += "/fast"; fastTarget += "/fast";
this->AppendTarget(fout, fastTarget, make); this->AppendTarget(fout, fastTarget, make, subdir, prefix);
} }
break; break;
// ignore these: // ignore these:
@ -771,7 +780,38 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
break; break;
} }
} }
// insert the all and clean targets in every subdir
if (!allTarget.empty())
{
this->AppendTarget(fout, allTarget, make, subdir, ": ");
} }
if (!cleanTarget.empty())
{
this->AppendTarget(fout, cleanTarget, make, subdir, ": ");
}
//insert rules for compiling, preprocessing and assembling individual files
cmLocalUnixMakefileGenerator3* lumg=(cmLocalUnixMakefileGenerator3*)*it;
std::vector<std::string> objectFileTargets;
lumg->GetIndividualFileTargets(objectFileTargets);
for(std::vector<std::string>::const_iterator fit=objectFileTargets.begin();
fit != objectFileTargets.end();
++fit)
{
const char* prefix = "[obj] ";
if ((*fit)[fit->length()-1] == 's')
{
prefix = "[to asm] ";
}
else if ((*fit)[fit->length()-1] == 'i')
{
prefix = "[pre] ";
}
this->AppendTarget(fout, *fit, make, subdir, prefix);
}
}
fout << "</buildTargets>\n" fout << "</buildTargets>\n"
"</storageModule>\n" "</storageModule>\n"
; ;
@ -924,13 +964,23 @@ void cmExtraEclipseCDT4Generator
fout << "</storageModule>\n"; fout << "</storageModule>\n";
} }
// The prefix is prepended before the actual name of the target. The purpose
// of that is to sort the targets in the view of Eclipse, so that at first
// the global/utility/all/clean targets appear ": ", then the executable
// targets "[exe] ", then the libraries "[lib]", then the rules for the
// object files "[obj]", then for preprocessing only "[pre] " and
// finally the assembly files "[to asm] ". Note the "to" in "to asm",
// without it, "asm" would be the first targets in the list, with the "to"
// they are the last targets, which makes more sense.
void cmExtraEclipseCDT4Generator::AppendTarget(cmGeneratedFileStream& fout, void cmExtraEclipseCDT4Generator::AppendTarget(cmGeneratedFileStream& fout,
const std::string& target, const std::string& target,
const std::string& make) const std::string& make,
const std::string& path,
const char* prefix)
{ {
fout << fout <<
"<target name=\"" << target << "\"" "<target name=\"" << prefix << target << "\""
" path=\"\"" " path=\"" << path.c_str() << "\""
" targetID=\"org.eclipse.cdt.make.MakeTargetBuilder\">\n" " targetID=\"org.eclipse.cdt.make.MakeTargetBuilder\">\n"
"<buildCommand>" "<buildCommand>"
<< cmExtraEclipseCDT4Generator::GetEclipsePath(make) << cmExtraEclipseCDT4Generator::GetEclipsePath(make)

View File

@ -91,7 +91,9 @@ private:
const cmMakefile& makefile); const cmMakefile& makefile);
static void AppendTarget (cmGeneratedFileStream& fout, static void AppendTarget (cmGeneratedFileStream& fout,
const std::string& target, const std::string& target,
const std::string& make); const std::string& make,
const std::string& path,
const char* prefix = "");
static void AppendScannerProfile (cmGeneratedFileStream& fout, static void AppendScannerProfile (cmGeneratedFileStream& fout,
const std::string& profileID, const std::string& profileID,
bool openActionEnabled, bool openActionEnabled,

View File

@ -151,6 +151,30 @@ void cmLocalUnixMakefileGenerator3::Generate()
this->WriteDirectoryInformationFile(); this->WriteDirectoryInformationFile();
} }
//----------------------------------------------------------------------------
void cmLocalUnixMakefileGenerator3::GetIndividualFileTargets
(std::vector<std::string>& targets)
{
for (std::map<cmStdString, LocalObjectInfo>::iterator lo =
this->LocalObjectFiles.begin();
lo != this->LocalObjectFiles.end(); ++lo)
{
targets.push_back(lo->first);
std::string::size_type dot_pos = lo->first.rfind(".");
std::string base = lo->first.substr(0, dot_pos);
if(lo->second.HasPreprocessRule)
{
targets.push_back(base + ".i");
}
if(lo->second.HasAssembleRule)
{
targets.push_back(base + ".s");
}
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalUnixMakefileGenerator3::WriteLocalMakefile() void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
{ {
@ -228,12 +252,14 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
this->WriteObjectConvenienceRule( this->WriteObjectConvenienceRule(
ruleFileStream, "target to preprocess a source file", ruleFileStream, "target to preprocess a source file",
(base + ".i").c_str(), lo->second); (base + ".i").c_str(), lo->second);
lo->second.HasPreprocessRule = true;
} }
if(do_assembly_rules) if(do_assembly_rules)
{ {
this->WriteObjectConvenienceRule( this->WriteObjectConvenienceRule(
ruleFileStream, "target to generate assembly for a file", ruleFileStream, "target to generate assembly for a file",
(base + ".s").c_str(), lo->second); (base + ".s").c_str(), lo->second);
lo->second.HasAssembleRule = true;
} }
} }
} }

View File

@ -246,6 +246,10 @@ public:
struct LocalObjectInfo: public std::vector<LocalObjectEntry> struct LocalObjectInfo: public std::vector<LocalObjectEntry>
{ {
bool HasSourceExtension; bool HasSourceExtension;
bool HasPreprocessRule;
bool HasAssembleRule;
LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false),
HasAssembleRule(false) {}
}; };
std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles() std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles()
{ return this->LocalObjectFiles;} { return this->LocalObjectFiles;}
@ -266,6 +270,12 @@ public:
// Get the directories into which the .o files will go for this target // Get the directories into which the .o files will go for this target
void GetTargetObjectFileDirectories(cmTarget* target, void GetTargetObjectFileDirectories(cmTarget* target,
std::vector<std::string>& dirs); std::vector<std::string>& dirs);
// Fill the vector with the target names for the object files,
// preprocessed files and assembly files. Currently only used by the
// Eclipse generator.
void GetIndividualFileTargets(std::vector<std::string>& targets);
protected: protected:
void WriteLocalMakefile(); void WriteLocalMakefile();