diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 07310a8eb..affc0fda5 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -71,6 +71,13 @@ void cmExtraEclipseCDT4Generator //---------------------------------------------------------------------------- void cmExtraEclipseCDT4Generator::Generate() { + const cmMakefile* mf + = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile(); + + // TODO: Decide if these are local or member variables + this->HomeDirectory = mf->GetHomeDirectory(); + this->HomeOutputDirectory = mf->GetHomeOutputDirectory(); + // create a .project file this->CreateProjectFile(); @@ -83,10 +90,11 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const { const cmMakefile* mf = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile(); + // set up the project name: -Source@ + std::string name = this->GenerateProjectName(mf->GetProjectName(), "Source", + this->GetPathBasename(this->HomeDirectory)); - const std::string homeDirectory(mf->GetHomeDirectory()); - const std::string homeOutputDirectory(mf->GetHomeOutputDirectory()); - const std::string filename = homeOutputDirectory + "/.project"; + const std::string filename = this->HomeOutputDirectory + "/.project"; cmGeneratedFileStream fout(filename.c_str()); if (!fout) @@ -97,7 +105,11 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const fout << "\n" "\n" - "\t" << this->GetPathBasename(homeOutputDirectory) << "\n" + "\t" << + this->GenerateProjectName(mf->GetProjectName(), + mf->GetDefinition("CMAKE_BUILD_TYPE"), + this->GetPathBasename(this->HomeOutputDirectory)) + << "\n" "\t\n" "\t\n" "\t\n" @@ -154,7 +166,7 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const "\t\t\t\t\n" "\t\t\t\t\torg.eclipse.cdt.make.core.buildLocation\n" "\t\t\t\t\t" - << this->GetEclipsePath(homeOutputDirectory) << "\n" + << this->GetEclipsePath(this->HomeOutputDirectory) << "\n" "\t\t\t\t\n" "\t\t\t\t\n" "\t\t\t\t\torg.eclipse.cdt.make.core.useDefaultBuildCmd\n" @@ -222,7 +234,7 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const "\t\t\t\t\n" "\t\t\t\t\torg.eclipse.cdt.make.core.build.location\n" "\t\t\t\t\t" - << this->GetEclipsePath(homeOutputDirectory) << "\n" + << this->GetEclipsePath(this->HomeOutputDirectory) << "\n" "\t\t\t\t\n" "\t\t\t\t\n" "\t\t\t\t\torg.eclipse.cdt.make.core.autoBuildTarget\n" @@ -273,7 +285,7 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const // TODO: refactor this // create linked resources - if (homeDirectory != homeOutputDirectory) + if (this->HomeDirectory != this->HomeOutputDirectory) { fout << "\t\n"; // for each sub project create a linked resource to the source dir @@ -285,7 +297,7 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const { std::string linkSourceDirectory =this->GetEclipsePath( it->second[0]->GetMakefile()->GetStartDirectory()); - if (!cmSystemTools::IsSubDirectory(homeOutputDirectory.c_str(), + if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(), linkSourceDirectory.c_str())) { fout << @@ -302,7 +314,7 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const // for EXECUTABLE_OUTPUT_PATH when not in binary dir std::string output_path = mf->GetDefinition("EXECUTABLE_OUTPUT_PATH"); if (!cmSystemTools::IsSubDirectory(output_path.c_str(), - homeOutputDirectory.c_str())) + this->HomeOutputDirectory.c_str())) { std::string name = this->GetPathBasename(output_path); while (this->GlobalGenerator->GetProjectMap().find(name) @@ -325,7 +337,7 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() const { output_path = mf->GetDefinition("LIBRARY_OUTPUT_PATH"); if (!cmSystemTools::IsSubDirectory(output_path.c_str(), - homeOutputDirectory.c_str())) + this->HomeOutputDirectory.c_str())) { std::string name = this->GetPathBasename(output_path); while (this->GlobalGenerator->GetProjectMap().find(name) @@ -358,8 +370,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const const cmMakefile* mf = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile(); - const std::string homeOutputDirectory(mf->GetHomeOutputDirectory()); - const std::string filename = homeOutputDirectory + "/.cproject"; + const std::string filename = this->HomeOutputDirectory + "/.cproject"; cmGeneratedFileStream fout(filename.c_str()); if (!fout) @@ -471,7 +482,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const // exlude source directory from output search path // - only if not named the same as an output directory if (!cmSystemTools::FileIsDirectory( - std::string(homeOutputDirectory + "/" + it->first).c_str())) + std::string(this->HomeOutputDirectory + "/" + it->first).c_str())) { exclude_from_out += it->first + "/|"; } @@ -485,7 +496,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const // but check it doesn't conflict with other linked resources names std::string output_path = mf->GetDefinition("EXECUTABLE_OUTPUT_PATH"); if (!cmSystemTools::IsSubDirectory(output_path.c_str(), - homeOutputDirectory.c_str())) + this->HomeOutputDirectory.c_str())) { std::string name = this->GetPathBasename(output_path); while (this->GlobalGenerator->GetProjectMap().find(name) @@ -500,7 +511,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const { output_path = mf->GetDefinition("LIBRARY_OUTPUT_PATH"); if (!cmSystemTools::IsSubDirectory(output_path.c_str(), - homeOutputDirectory.c_str())) + this->HomeOutputDirectory.c_str())) { std::string name = this->GetPathBasename(output_path); while (this->GlobalGenerator->GetProjectMap().find(name) @@ -751,6 +762,14 @@ cmExtraEclipseCDT4Generator::GetPathBasename(const std::string& path) return outputBasename; } +std::string +cmExtraEclipseCDT4Generator::GenerateProjectName(const std::string& name, + const std::string& type, + const std::string& path) +{ + return name + (type.empty() ? "" : "-") + type + "@" + path; +} + //---------------------------------------------------------------------------- // Helper functions //---------------------------------------------------------------------------- diff --git a/Source/cmExtraEclipseCDT4Generator.h b/Source/cmExtraEclipseCDT4Generator.h index 4ed720fb5..d025c89ce 100644 --- a/Source/cmExtraEclipseCDT4Generator.h +++ b/Source/cmExtraEclipseCDT4Generator.h @@ -76,6 +76,11 @@ private: // Extract basename. static std::string GetPathBasename(const std::string& path); + // Generate the project name as: -@ + static std::string GenerateProjectName(const std::string& name, + const std::string& type, + const std::string& path); + // Helper functions static void AppendStorageScanners(cmGeneratedFileStream& fout); static void AppendTarget (cmGeneratedFileStream& fout, @@ -91,6 +96,10 @@ private: const std::string& runActionCommand, bool runActionUseDefault, bool sipParserEnabled); + + std::string HomeDirectory; + std::string HomeOutputDirectory; + }; #endif