ENH: patch from Miguel part 2: if ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT is
true, then the generator additionally generates eclipse project files in the source dir, since this is the only way to get cvs/svn working with eclipse This is off by default and the user has to enable it explicitely. If cmake can't write there it still continues. Alex
This commit is contained in:
parent
87ae93362c
commit
a2fadc80fa
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmExtraEclipseCDT4Generator
|
cmExtraEclipseCDT4Generator
|
||||||
|
@ -78,6 +79,20 @@ void cmExtraEclipseCDT4Generator::Generate()
|
||||||
this->HomeDirectory = mf->GetHomeDirectory();
|
this->HomeDirectory = mf->GetHomeDirectory();
|
||||||
this->HomeOutputDirectory = mf->GetHomeOutputDirectory();
|
this->HomeOutputDirectory = mf->GetHomeOutputDirectory();
|
||||||
|
|
||||||
|
this->IsOutOfSourceBuild = (this->HomeDirectory!=this->HomeOutputDirectory);
|
||||||
|
|
||||||
|
this->GenerateSourceProject = (this->IsOutOfSourceBuild &&
|
||||||
|
mf->IsOn("ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT"));
|
||||||
|
|
||||||
|
// NOTE: This is not good, since it pollutes the source tree. However,
|
||||||
|
// Eclipse doesn't allow CVS/SVN to work when the .project is not in
|
||||||
|
// the cvs/svn root directory. Hence, this is provided as an option.
|
||||||
|
if (this->GenerateSourceProject)
|
||||||
|
{
|
||||||
|
// create .project file in the source tree
|
||||||
|
this->CreateSourceProjectFile();
|
||||||
|
}
|
||||||
|
|
||||||
// create a .project file
|
// create a .project file
|
||||||
this->CreateProjectFile();
|
this->CreateProjectFile();
|
||||||
|
|
||||||
|
@ -85,14 +100,43 @@ void cmExtraEclipseCDT4Generator::Generate()
|
||||||
this->CreateCProjectFile();
|
this->CreateCProjectFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmExtraEclipseCDT4Generator::CreateSourceProjectFile() const
|
||||||
|
{
|
||||||
|
assert(this->HomeDirectory != this->HomeOutputDirectory);
|
||||||
|
|
||||||
|
// set up the project name: <project>-Source@<baseSourcePathName>
|
||||||
|
const cmMakefile* mf
|
||||||
|
= this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
|
||||||
|
std::string name = this->GenerateProjectName(mf->GetProjectName(), "Source",
|
||||||
|
this->GetPathBasename(this->HomeDirectory));
|
||||||
|
|
||||||
|
const std::string filename = this->HomeDirectory + "/.project";
|
||||||
|
cmGeneratedFileStream fout(filename.c_str());
|
||||||
|
if (!fout)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fout <<
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||||
|
"<projectDescription>\n"
|
||||||
|
"\t<name>" << name << "</name>\n"
|
||||||
|
"\t<comment></comment>\n"
|
||||||
|
"\t<projects>\n"
|
||||||
|
"\t</projects>\n"
|
||||||
|
"\t<buildSpec>\n"
|
||||||
|
"\t</buildSpec>\n"
|
||||||
|
"\t<natures>\n"
|
||||||
|
"\t</natures>\n"
|
||||||
|
"</projectDescription>\n"
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmExtraEclipseCDT4Generator::CreateProjectFile() const
|
void cmExtraEclipseCDT4Generator::CreateProjectFile()
|
||||||
{
|
{
|
||||||
const cmMakefile* mf
|
const cmMakefile* mf
|
||||||
= this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
|
= this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
|
||||||
// set up the project name: <project>-Source@<baseSourcePathName>
|
|
||||||
std::string name = this->GenerateProjectName(mf->GetProjectName(), "Source",
|
|
||||||
this->GetPathBasename(this->HomeDirectory));
|
|
||||||
|
|
||||||
const std::string filename = this->HomeOutputDirectory + "/.project";
|
const std::string filename = this->HomeOutputDirectory + "/.project";
|
||||||
|
|
||||||
|
@ -285,7 +329,7 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const
|
||||||
|
|
||||||
// TODO: refactor this
|
// TODO: refactor this
|
||||||
// create linked resources
|
// create linked resources
|
||||||
if (this->HomeDirectory != this->HomeOutputDirectory)
|
if (this->IsOutOfSourceBuild)
|
||||||
{
|
{
|
||||||
fout << "\t<linkedResources>\n";
|
fout << "\t<linkedResources>\n";
|
||||||
// for each sub project create a linked resource to the source dir
|
// for each sub project create a linked resource to the source dir
|
||||||
|
@ -297,18 +341,13 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const
|
||||||
{
|
{
|
||||||
std::string linkSourceDirectory =this->GetEclipsePath(
|
std::string linkSourceDirectory =this->GetEclipsePath(
|
||||||
it->second[0]->GetMakefile()->GetStartDirectory());
|
it->second[0]->GetMakefile()->GetStartDirectory());
|
||||||
|
// .project dir can't be subdir of a linked resource dir
|
||||||
if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(),
|
if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(),
|
||||||
linkSourceDirectory.c_str()))
|
linkSourceDirectory.c_str()))
|
||||||
{
|
{
|
||||||
fout <<
|
this->AppendLinkedResource(fout, it->first,
|
||||||
"\t\t<link>\n"
|
this->GetEclipsePath(linkSourceDirectory));
|
||||||
"\t\t\t<name>" << it->first << "</name>\n"
|
this->SrcLinkedResources.push_back(it->first);
|
||||||
"\t\t\t<type>2</type>\n"
|
|
||||||
"\t\t\t<location>"
|
|
||||||
<< this->GetEclipsePath(linkSourceDirectory)
|
|
||||||
<< "</location>\n"
|
|
||||||
"\t\t</link>\n"
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for EXECUTABLE_OUTPUT_PATH when not in binary dir
|
// for EXECUTABLE_OUTPUT_PATH when not in binary dir
|
||||||
|
@ -317,20 +356,16 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const
|
||||||
this->HomeOutputDirectory.c_str()))
|
this->HomeOutputDirectory.c_str()))
|
||||||
{
|
{
|
||||||
std::string name = this->GetPathBasename(output_path);
|
std::string name = this->GetPathBasename(output_path);
|
||||||
|
|
||||||
|
// make sure linked resource name is unique
|
||||||
while (this->GlobalGenerator->GetProjectMap().find(name)
|
while (this->GlobalGenerator->GetProjectMap().find(name)
|
||||||
!= this->GlobalGenerator->GetProjectMap().end())
|
!= this->GlobalGenerator->GetProjectMap().end())
|
||||||
{
|
{
|
||||||
name += "_";
|
name += "_";
|
||||||
}
|
}
|
||||||
fout <<
|
this->AppendLinkedResource(fout, name,
|
||||||
"\t\t<link>\n"
|
this->GetEclipsePath(output_path));
|
||||||
"\t\t\t<name>" << name << "</name>\n"
|
this->OutLinkedResources.push_back(name);
|
||||||
"\t\t\t<type>2</type>\n"
|
|
||||||
"\t\t\t<location>"
|
|
||||||
<< this->GetEclipsePath(output_path)
|
|
||||||
<< "</location>\n"
|
|
||||||
"\t\t</link>\n"
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
// for LIBRARY_OUTPUT_PATH when not in binary dir
|
// for LIBRARY_OUTPUT_PATH when not in binary dir
|
||||||
if (output_path != mf->GetDefinition("LIBRARY_OUTPUT_PATH"))
|
if (output_path != mf->GetDefinition("LIBRARY_OUTPUT_PATH"))
|
||||||
|
@ -340,20 +375,16 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const
|
||||||
this->HomeOutputDirectory.c_str()))
|
this->HomeOutputDirectory.c_str()))
|
||||||
{
|
{
|
||||||
std::string name = this->GetPathBasename(output_path);
|
std::string name = this->GetPathBasename(output_path);
|
||||||
|
|
||||||
|
// make sure linked resource name is unique
|
||||||
while (this->GlobalGenerator->GetProjectMap().find(name)
|
while (this->GlobalGenerator->GetProjectMap().find(name)
|
||||||
!= this->GlobalGenerator->GetProjectMap().end())
|
!= this->GlobalGenerator->GetProjectMap().end())
|
||||||
{
|
{
|
||||||
name += "_";
|
name += "_";
|
||||||
}
|
}
|
||||||
fout <<
|
this->AppendLinkedResource(fout, name,
|
||||||
"\t\t<link>\n"
|
this->GetEclipsePath(output_path));
|
||||||
"\t\t\t<name>" << name << "</name>\n"
|
this->OutLinkedResources.push_back(name);
|
||||||
"\t\t\t<type>2</type>\n"
|
|
||||||
"\t\t\t<location>"
|
|
||||||
<< this->GetEclipsePath(output_path)
|
|
||||||
<< "</location>\n"
|
|
||||||
"\t\t</link>\n"
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fout << "\t</linkedResources>\n";
|
fout << "\t</linkedResources>\n";
|
||||||
|
@ -472,19 +503,19 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
|
||||||
// - make it type 'src'
|
// - make it type 'src'
|
||||||
// - and exclude it from type 'out'
|
// - and exclude it from type 'out'
|
||||||
std::string exclude_from_out;
|
std::string exclude_from_out;
|
||||||
for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
|
for (std::vector<std::string>::const_iterator
|
||||||
it = this->GlobalGenerator->GetProjectMap().begin();
|
it = this->SrcLinkedResources.begin();
|
||||||
it != this->GlobalGenerator->GetProjectMap().end();
|
it != this->SrcLinkedResources.end();
|
||||||
++it)
|
++it)
|
||||||
{
|
{
|
||||||
fout << "<pathentry kind=\"src\" path=\"" << it->first << "\"/>\n";
|
fout << "<pathentry kind=\"src\" path=\"" << *it << "\"/>\n";
|
||||||
|
|
||||||
// exlude source directory from output search path
|
// exlude source directory from output search path
|
||||||
// - only if not named the same as an output directory
|
// - only if not named the same as an output directory
|
||||||
if (!cmSystemTools::FileIsDirectory(
|
if (!cmSystemTools::FileIsDirectory(
|
||||||
std::string(this->HomeOutputDirectory + "/" + it->first).c_str()))
|
std::string(this->HomeOutputDirectory + "/" + *it).c_str()))
|
||||||
{
|
{
|
||||||
exclude_from_out += it->first + "/|";
|
exclude_from_out += *it + "/|";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exclude_from_out += "**/CMakeFiles/";
|
exclude_from_out += "**/CMakeFiles/";
|
||||||
|
@ -494,33 +525,12 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
|
||||||
// - if it is a subdir of homeOutputDirectory, there is no need to add it
|
// - if it is a subdir of homeOutputDirectory, there is no need to add it
|
||||||
// - if it is not then create a linked resource and add the linked name
|
// - if it is not then create a linked resource and add the linked name
|
||||||
// but check it doesn't conflict with other linked resources names
|
// but check it doesn't conflict with other linked resources names
|
||||||
std::string output_path = mf->GetDefinition("EXECUTABLE_OUTPUT_PATH");
|
for (std::vector<std::string>::const_iterator
|
||||||
if (!cmSystemTools::IsSubDirectory(output_path.c_str(),
|
it = this->OutLinkedResources.begin();
|
||||||
this->HomeOutputDirectory.c_str()))
|
it != this->OutLinkedResources.end();
|
||||||
|
++it)
|
||||||
{
|
{
|
||||||
std::string name = this->GetPathBasename(output_path);
|
fout << "<pathentry kind=\"out\" path=\"" << *it << "\"/>\n";
|
||||||
while (this->GlobalGenerator->GetProjectMap().find(name)
|
|
||||||
!= this->GlobalGenerator->GetProjectMap().end())
|
|
||||||
{
|
|
||||||
name += "_";
|
|
||||||
}
|
|
||||||
fout << "<pathentry kind=\"out\" path=\"" << name << "\"/>\n";
|
|
||||||
}
|
|
||||||
// for LIBRARY_OUTPUT_PATH when not in binary dir
|
|
||||||
if (output_path != mf->GetDefinition("LIBRARY_OUTPUT_PATH"))
|
|
||||||
{
|
|
||||||
output_path = mf->GetDefinition("LIBRARY_OUTPUT_PATH");
|
|
||||||
if (!cmSystemTools::IsSubDirectory(output_path.c_str(),
|
|
||||||
this->HomeOutputDirectory.c_str()))
|
|
||||||
{
|
|
||||||
std::string name = this->GetPathBasename(output_path);
|
|
||||||
while (this->GlobalGenerator->GetProjectMap().find(name)
|
|
||||||
!= this->GlobalGenerator->GetProjectMap().end())
|
|
||||||
{
|
|
||||||
name += "_";
|
|
||||||
}
|
|
||||||
fout << "<pathentry kind=\"out\" path=\"" << name << "\"/>\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add pre-processor definitions to allow eclipse to gray out sections
|
// add pre-processor definitions to allow eclipse to gray out sections
|
||||||
|
@ -843,3 +853,19 @@ void cmExtraEclipseCDT4Generator
|
||||||
"</profile>\n"
|
"</profile>\n"
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmExtraEclipseCDT4Generator
|
||||||
|
::AppendLinkedResource (cmGeneratedFileStream& fout,
|
||||||
|
const std::string& name,
|
||||||
|
const std::string& path)
|
||||||
|
{
|
||||||
|
fout <<
|
||||||
|
"\t\t<link>\n"
|
||||||
|
"\t\t\t<name>" << name << "</name>\n"
|
||||||
|
"\t\t\t<type>2</type>\n"
|
||||||
|
"\t\t\t<location>"
|
||||||
|
<< path
|
||||||
|
<< "</location>\n"
|
||||||
|
"\t\t</link>\n"
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
|
@ -52,8 +52,11 @@ public:
|
||||||
virtual void Generate();
|
virtual void Generate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// create .project file in the source tree
|
||||||
|
void CreateSourceProjectFile() const;
|
||||||
|
|
||||||
// create .project file
|
// create .project file
|
||||||
void CreateProjectFile() const;
|
void CreateProjectFile();
|
||||||
|
|
||||||
// create .cproject file
|
// create .cproject file
|
||||||
void CreateCProjectFile() const;
|
void CreateCProjectFile() const;
|
||||||
|
@ -97,8 +100,16 @@ private:
|
||||||
bool runActionUseDefault,
|
bool runActionUseDefault,
|
||||||
bool sipParserEnabled);
|
bool sipParserEnabled);
|
||||||
|
|
||||||
|
static void AppendLinkedResource (cmGeneratedFileStream& fout,
|
||||||
|
const std::string& name,
|
||||||
|
const std::string& path);
|
||||||
|
|
||||||
|
std::vector<std::string> SrcLinkedResources;
|
||||||
|
std::vector<std::string> OutLinkedResources;
|
||||||
std::string HomeDirectory;
|
std::string HomeDirectory;
|
||||||
std::string HomeOutputDirectory;
|
std::string HomeOutputDirectory;
|
||||||
|
bool IsOutOfSourceBuild;
|
||||||
|
bool GenerateSourceProject;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue