From e8a97e075aa571b31287b23c80fcbadf892ce5c0 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 13 Feb 2011 01:15:11 +0100 Subject: [PATCH] Eclipse projects: created one linked resource for each subproject Now a virtual folder "Subprojects" is created, and in this virtual folder is a linked resource for each project(). This can be considered a fix for #11657 Alex --- Source/cmExtraEclipseCDT4Generator.cxx | 73 +++++++++++++++++++------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index eb7864712..c4ea42514 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -102,7 +102,7 @@ void cmExtraEclipseCDT4Generator::CreateSourceProjectFile() const fout << "\n" "\n" - "\t" << name << "\n" + "\t" << this->EscapeForXML(name) << "\n" "\t\n" "\t\n" "\t\n" @@ -376,11 +376,10 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() "\t\n" ; - // TODO: refactor this + fout << "\t\n"; // create linked resources if (this->IsOutOfSourceBuild) { - fout << "\t\n"; // create a linked resource to CMAKE_SOURCE_DIR // (this is not done anymore for each project because of // http://public.kitware.com/Bug/view.php?id=9978 and because I found it @@ -399,18 +398,48 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() this->SrcLinkedResources.push_back(sourceLinkedResourceName); } - // for EXECUTABLE_OUTPUT_PATH when not in binary dir - this->AppendOutLinkedResource(fout, - mf->GetSafeDefinition("CMAKE_RUNTIME_OUTPUT_DIRECTORY"), - mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH")); - // for LIBRARY_OUTPUT_PATH when not in binary dir - this->AppendOutLinkedResource(fout, - mf->GetSafeDefinition("CMAKE_LIBRARY_OUTPUT_DIRECTORY"), - mf->GetSafeDefinition("LIBRARY_OUTPUT_PATH")); - - fout << "\t\n"; } + // for each sub project create a linked resource to the source dir + // - only if it is an out-of-source build + this->AppendLinkedResource(fout, "[Subprojects]", + "virtual:/virtual"); + + for (std::map >::const_iterator + it = this->GlobalGenerator->GetProjectMap().begin(); + it != this->GlobalGenerator->GetProjectMap().end(); + ++it) + { + std::string linkSourceDirectory = this->GetEclipsePath( + it->second[0]->GetMakefile()->GetStartDirectory()); + // a linked resource must not point to a parent directory of .project or + // .project itself + if ((this->HomeOutputDirectory != linkSourceDirectory) && + !cmSystemTools::IsSubDirectory(this->HomeOutputDirectory.c_str(), + linkSourceDirectory.c_str())) + { + std::string linkName = "[Subprojects]/"; + linkName += it->first; + this->AppendLinkedResource(fout, linkName, + this->GetEclipsePath(linkSourceDirectory)); + this->SrcLinkedResources.push_back(it->first); + } + } + + // I'm not sure this makes too much sense. There can be different + // output directories in different subdirs, so we would need more of them. + + // for EXECUTABLE_OUTPUT_PATH when not in binary dir + this->AppendOutLinkedResource(fout, + mf->GetSafeDefinition("CMAKE_RUNTIME_OUTPUT_DIRECTORY"), + mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH")); + // for LIBRARY_OUTPUT_PATH when not in binary dir + this->AppendOutLinkedResource(fout, + mf->GetSafeDefinition("CMAKE_LIBRARY_OUTPUT_DIRECTORY"), + mf->GetSafeDefinition("LIBRARY_OUTPUT_PATH")); + + fout << "\t\n"; + fout << "\n"; } @@ -551,14 +580,15 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const it != this->SrcLinkedResources.end(); ++it) { - fout << "\n"; + fout << "EscapeForXML(*it) + << "\"/>\n"; // exlude source directory from output search path // - only if not named the same as an output directory if (!cmSystemTools::FileIsDirectory( std::string(this->HomeOutputDirectory + "/" + *it).c_str())) { - excludeFromOut += *it + "/|"; + excludeFromOut += this->EscapeForXML(*it) + "/|"; } } excludeFromOut += "**/CMakeFiles/"; @@ -573,7 +603,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const it != this->OutLinkedResources.end(); ++it) { - fout << "\n"; + fout << "EscapeForXML(*it) + << "\"/>\n"; } // add pre-processor definitions to allow eclipse to gray out sections @@ -1055,11 +1086,13 @@ void cmExtraEclipseCDT4Generator { fout << "\t\t\n" - "\t\t\t" << name << "\n" + "\t\t\t" + << cmExtraEclipseCDT4Generator::EscapeForXML(name) + << "\n" "\t\t\t2\n" - "\t\t\t" - << path - << "\n" + "\t\t\t" + << cmExtraEclipseCDT4Generator::EscapeForXML(path) + << "\n" "\t\t\n" ; }