Merge topic 'SourceGroupsForEclipse'
66bd543
Eclipse: fix #12417, don't create wrong src pathentries70de8bd
Eclipse: detect number of CPUs, set CMAKE_ECLIPSE_MAKE_ARGUMENTS accordigly117f2b8
Eclipse: add Build and Clean targets to targetsc3f30bd
Eclipse: move code for generating links to targets into separate functioncef6bd9
Eclipse: move code for generating links to projects into separate functionb6d4de7
Eclipse: add virtual folder for each target
This commit is contained in:
commit
4701843974
|
@ -54,8 +54,20 @@ ENDFUNCTION()
|
|||
|
||||
_FIND_ECLIPSE_VERSION()
|
||||
|
||||
# Try to find out how many CPUs we have and set the -j argument for make accordingly
|
||||
SET(_CMAKE_ECLIPSE_INITIAL_MAKE_ARGS "")
|
||||
|
||||
INCLUDE(ProcessorCount)
|
||||
PROCESSORCOUNT(_CMAKE_ECLIPSE_PROCESSOR_COUNT)
|
||||
|
||||
# Only set -j if we are under UNIX and if the make-tool used actually has "make" in the name
|
||||
# (we may also get here in the future e.g. for ninja)
|
||||
IF("${_CMAKE_ECLIPSE_PROCESSOR_COUNT}" GREATER 1 AND UNIX AND "${CMAKE_MAKE_PROGRAM}" MATCHES make)
|
||||
SET(_CMAKE_ECLIPSE_INITIAL_MAKE_ARGS "-j${_CMAKE_ECLIPSE_PROCESSOR_COUNT}")
|
||||
ENDIF()
|
||||
|
||||
# This variable is used by the Eclipse generator and appended to the make invocation commands.
|
||||
SET(CMAKE_ECLIPSE_MAKE_ARGUMENTS "" CACHE STRING "Additional command line arguments when Eclipse invokes make. Enter e.g. -j<some_number> to get parallel builds")
|
||||
SET(CMAKE_ECLIPSE_MAKE_ARGUMENTS "${_CMAKE_ECLIPSE_INITIAL_MAKE_ARGS}" CACHE STRING "Additional command line arguments when Eclipse invokes make. Enter e.g. -j<some_number> to get parallel builds")
|
||||
|
||||
# This variable is used by the Eclipse generator in out-of-source builds only.
|
||||
SET(ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT FALSE CACHE BOOL "If enabled, CMake will generate a source project for Eclipse in CMAKE_SOURCE_DIR")
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "cmMakefile.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmSourceFile.h"
|
||||
|
||||
#include "cmSystemTools.h"
|
||||
#include <stdlib.h>
|
||||
|
@ -414,7 +415,8 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
|
|||
linkSourceDirectory.c_str()))
|
||||
{
|
||||
this->AppendLinkedResource(fout, sourceLinkedResourceName,
|
||||
this->GetEclipsePath(linkSourceDirectory));
|
||||
this->GetEclipsePath(linkSourceDirectory),
|
||||
LinkToFolder);
|
||||
this->SrcLinkedResources.push_back(sourceLinkedResourceName);
|
||||
}
|
||||
|
||||
|
@ -422,31 +424,9 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
|
|||
|
||||
if (this->SupportsVirtualFolders)
|
||||
{
|
||||
// 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", true);
|
||||
this->CreateLinksToSubprojects(fout);
|
||||
|
||||
for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::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);
|
||||
}
|
||||
}
|
||||
this->CreateLinksForTargets(fout);
|
||||
}
|
||||
|
||||
// I'm not sure this makes too much sense. There can be different
|
||||
|
@ -466,6 +446,123 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
|
|||
fout << "</projectDescription>\n";
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmExtraEclipseCDT4Generator::CreateLinksForTargets(
|
||||
cmGeneratedFileStream& fout)
|
||||
{
|
||||
std::string linkName = "[Targets]";
|
||||
this->AppendLinkedResource(fout, linkName, "virtual:/virtual",VirtualFolder);
|
||||
|
||||
for (std::vector<cmLocalGenerator*>::const_iterator
|
||||
lgIt = this->GlobalGenerator->GetLocalGenerators().begin();
|
||||
lgIt != this->GlobalGenerator->GetLocalGenerators().end();
|
||||
++lgIt)
|
||||
{
|
||||
cmMakefile* makefile = (*lgIt)->GetMakefile();
|
||||
const cmTargets& targets = makefile->GetTargets();
|
||||
|
||||
for(cmTargets::const_iterator ti=targets.begin(); ti!=targets.end();++ti)
|
||||
{
|
||||
std::string linkName2 = linkName;
|
||||
linkName2 += "/";
|
||||
switch(ti->second.GetType())
|
||||
{
|
||||
case cmTarget::EXECUTABLE:
|
||||
case cmTarget::STATIC_LIBRARY:
|
||||
case cmTarget::SHARED_LIBRARY:
|
||||
case cmTarget::MODULE_LIBRARY:
|
||||
{
|
||||
const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ?
|
||||
"[exe] " : "[lib] ");
|
||||
linkName2 += prefix;
|
||||
linkName2 += ti->first;
|
||||
this->AppendLinkedResource(fout, linkName2, "virtual:/virtual",
|
||||
VirtualFolder);
|
||||
std::vector<cmSourceGroup> sourceGroups=makefile->GetSourceGroups();
|
||||
// get the files from the source lists then add them to the groups
|
||||
cmTarget* tgt = const_cast<cmTarget*>(&ti->second);
|
||||
std::vector<cmSourceFile*>const & files = tgt->GetSourceFiles();
|
||||
for(std::vector<cmSourceFile*>::const_iterator sfIt = files.begin();
|
||||
sfIt != files.end();
|
||||
sfIt++)
|
||||
{
|
||||
// Add the file to the list of sources.
|
||||
std::string source = (*sfIt)->GetFullPath();
|
||||
cmSourceGroup& sourceGroup =
|
||||
makefile->FindSourceGroup(source.c_str(), sourceGroups);
|
||||
sourceGroup.AssignSource(*sfIt);
|
||||
}
|
||||
|
||||
for(std::vector<cmSourceGroup>::iterator sgIt = sourceGroups.begin();
|
||||
sgIt != sourceGroups.end();
|
||||
++sgIt)
|
||||
{
|
||||
std::string linkName3 = linkName2;
|
||||
linkName3 += "/";
|
||||
linkName3 += sgIt->GetFullName();
|
||||
this->AppendLinkedResource(fout, linkName3, "virtual:/virtual",
|
||||
VirtualFolder);
|
||||
|
||||
std::vector<const cmSourceFile*> sFiles = sgIt->GetSourceFiles();
|
||||
for(std::vector<const cmSourceFile*>::const_iterator fileIt =
|
||||
sFiles.begin();
|
||||
fileIt != sFiles.end();
|
||||
++fileIt)
|
||||
{
|
||||
std::string linkName4 = linkName3;
|
||||
linkName4 += "/";
|
||||
linkName4 +=
|
||||
cmSystemTools::GetFilenameName((*fileIt)->GetFullPath());
|
||||
this->AppendLinkedResource(fout, linkName4,
|
||||
(*fileIt)->GetFullPath(), LinkToFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
// ignore all others:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmExtraEclipseCDT4Generator::CreateLinksToSubprojects(
|
||||
cmGeneratedFileStream& fout)
|
||||
{
|
||||
// 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", VirtualFolder);
|
||||
|
||||
for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::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),
|
||||
LinkToFolder
|
||||
);
|
||||
this->SrcLinkedResources.push_back(it->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmExtraEclipseCDT4Generator::AppendIncludeDirectories(
|
||||
cmGeneratedFileStream& fout,
|
||||
|
@ -598,6 +695,18 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
|
|||
// - make it type 'src'
|
||||
// - and exclude it from type 'out'
|
||||
std::string excludeFromOut;
|
||||
/* I don't know what the pathentry kind="src" are good for, e.g. autocompletion
|
||||
* works also without them. Done wrong, the indexer complains, see #12417
|
||||
* and #12213.
|
||||
* The CDT documentation is very terse on that:
|
||||
* "CDT_SOURCE: Entry kind constant describing a path entry identifying a
|
||||
* folder containing source code to be compiled."
|
||||
* Also on the cdt-dev list didn't bring any information:
|
||||
* http://web.archiveorange.com/archive/v/B4NlJDNIpYoOS1SbxFNy
|
||||
* So I'm disabling them for now, hoping that somebody will report if something
|
||||
* is not workging anymore.
|
||||
* Alex */
|
||||
#ifdef DO_CREATE_SRC_PATH_ENTRIES
|
||||
for (std::vector<std::string>::const_iterator
|
||||
it = this->SrcLinkedResources.begin();
|
||||
it != this->SrcLinkedResources.end();
|
||||
|
@ -614,6 +723,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
|
|||
excludeFromOut += this->EscapeForXML(*it) + "/|";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
excludeFromOut += "**/CMakeFiles/";
|
||||
fout << "<pathentry excluding=\"" << excludeFromOut
|
||||
<< "\" kind=\"out\" path=\"\"/>\n";
|
||||
|
@ -791,6 +901,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
|
|||
const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
|
||||
const std::string makeArgs = mf->GetSafeDefinition(
|
||||
"CMAKE_ECLIPSE_MAKE_ARGUMENTS");
|
||||
const std::string cmake = mf->GetRequiredDefinition("CMAKE_COMMAND");
|
||||
|
||||
cmGlobalGenerator* generator
|
||||
= const_cast<cmGlobalGenerator*>(this->GlobalGenerator);
|
||||
|
||||
|
@ -879,6 +991,25 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
|
|||
std::string fastTarget = ti->first;
|
||||
fastTarget += "/fast";
|
||||
this->AppendTarget(fout, fastTarget, make, makeArgs, subdir, prefix);
|
||||
|
||||
// Add Build and Clean targets in the virtual folder of targets:
|
||||
if (this->SupportsVirtualFolders)
|
||||
{
|
||||
std::string virtDir = "[Targets]/";
|
||||
virtDir += prefix;
|
||||
virtDir += ti->first;
|
||||
this->AppendTarget(fout, "Build", make, makeArgs, virtDir, "",
|
||||
ti->first.c_str());
|
||||
|
||||
std::string cleanArgs = "-E chdir \"";
|
||||
cleanArgs += makefile->GetCurrentOutputDirectory();
|
||||
cleanArgs += "\" \"";
|
||||
cleanArgs += cmake;
|
||||
cleanArgs += "\" -P \"";
|
||||
cleanArgs += (*it)->GetTargetDirectory(ti->second);
|
||||
cleanArgs += "/cmake_clean.cmake\"";
|
||||
this->AppendTarget(fout, "Clean", cmake, cleanArgs, virtDir, "", "");
|
||||
}
|
||||
}
|
||||
break;
|
||||
// ignore these:
|
||||
|
@ -1063,9 +1194,17 @@ void cmExtraEclipseCDT4Generator::AppendTarget(cmGeneratedFileStream& fout,
|
|||
const std::string& make,
|
||||
const std::string& makeArgs,
|
||||
const std::string& path,
|
||||
const char* prefix)
|
||||
const char* prefix,
|
||||
const char* makeTarget
|
||||
)
|
||||
{
|
||||
std::string targetXml = cmExtraEclipseCDT4Generator::EscapeForXML(target);
|
||||
std::string makeTargetXml = targetXml;
|
||||
if (makeTarget != NULL)
|
||||
{
|
||||
makeTargetXml = cmExtraEclipseCDT4Generator::EscapeForXML(makeTarget);
|
||||
}
|
||||
cmExtraEclipseCDT4Generator::EscapeForXML(target);
|
||||
std::string pathXml = cmExtraEclipseCDT4Generator::EscapeForXML(path);
|
||||
fout <<
|
||||
"<target name=\"" << prefix << targetXml << "\""
|
||||
|
@ -1075,7 +1214,7 @@ void cmExtraEclipseCDT4Generator::AppendTarget(cmGeneratedFileStream& fout,
|
|||
<< cmExtraEclipseCDT4Generator::GetEclipsePath(make)
|
||||
<< "</buildCommand>\n"
|
||||
"<buildArguments>" << makeArgs << "</buildArguments>\n"
|
||||
"<buildTarget>" << targetXml << "</buildTarget>\n"
|
||||
"<buildTarget>" << makeTargetXml << "</buildTarget>\n"
|
||||
"<stopOnError>true</stopOnError>\n"
|
||||
"<useDefaultCommand>false</useDefaultCommand>\n"
|
||||
"</target>\n"
|
||||
|
@ -1115,20 +1254,25 @@ void cmExtraEclipseCDT4Generator
|
|||
::AppendLinkedResource (cmGeneratedFileStream& fout,
|
||||
const std::string& name,
|
||||
const std::string& path,
|
||||
bool isVirtualFolder)
|
||||
LinkType linkType)
|
||||
{
|
||||
const char* locationTag = "location";
|
||||
if (isVirtualFolder) // ... and not a linked folder
|
||||
const char* typeTag = "2";
|
||||
if (linkType == VirtualFolder) // ... and not a linked folder
|
||||
{
|
||||
locationTag = "locationURI";
|
||||
}
|
||||
if (linkType == LinkToFile)
|
||||
{
|
||||
typeTag = "1";
|
||||
}
|
||||
|
||||
fout <<
|
||||
"\t\t<link>\n"
|
||||
"\t\t\t<name>"
|
||||
<< cmExtraEclipseCDT4Generator::EscapeForXML(name)
|
||||
<< "</name>\n"
|
||||
"\t\t\t<type>2</type>\n"
|
||||
"\t\t\t<type>" << typeTag << "</type>\n"
|
||||
"\t\t\t<" << locationTag << ">"
|
||||
<< cmExtraEclipseCDT4Generator::EscapeForXML(path)
|
||||
<< "</" << locationTag << ">\n"
|
||||
|
@ -1177,7 +1321,7 @@ bool cmExtraEclipseCDT4Generator
|
|||
else
|
||||
{
|
||||
this->AppendLinkedResource(fout, name,
|
||||
this->GetEclipsePath(outputPath));
|
||||
this->GetEclipsePath(outputPath), LinkToFolder);
|
||||
this->OutLinkedResources.push_back(name);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ class cmGeneratedFileStream;
|
|||
class cmExtraEclipseCDT4Generator : public cmExternalMakefileProjectGenerator
|
||||
{
|
||||
public:
|
||||
enum LinkType {VirtualFolder, LinkToFolder, LinkToFile };
|
||||
|
||||
cmExtraEclipseCDT4Generator();
|
||||
|
||||
static cmExternalMakefileProjectGenerator* New() {
|
||||
|
@ -73,7 +75,8 @@ private:
|
|||
const std::string& make,
|
||||
const std::string& makeArguments,
|
||||
const std::string& path,
|
||||
const char* prefix = "");
|
||||
const char* prefix = "",
|
||||
const char* makeTarget = NULL);
|
||||
static void AppendScannerProfile (cmGeneratedFileStream& fout,
|
||||
const std::string& profileID,
|
||||
bool openActionEnabled,
|
||||
|
@ -88,7 +91,7 @@ private:
|
|||
static void AppendLinkedResource (cmGeneratedFileStream& fout,
|
||||
const std::string& name,
|
||||
const std::string& path,
|
||||
bool isVirtualFolder = false);
|
||||
LinkType linkType);
|
||||
|
||||
bool AppendOutLinkedResource(cmGeneratedFileStream& fout,
|
||||
const std::string& defname,
|
||||
|
@ -101,6 +104,9 @@ private:
|
|||
static void AddEnvVar(cmGeneratedFileStream& fout, const char* envVar,
|
||||
cmMakefile* mf);
|
||||
|
||||
void CreateLinksToSubprojects(cmGeneratedFileStream& fout);
|
||||
void CreateLinksForTargets(cmGeneratedFileStream& fout);
|
||||
|
||||
std::vector<std::string> SrcLinkedResources;
|
||||
std::vector<std::string> OutLinkedResources;
|
||||
std::string HomeDirectory;
|
||||
|
|
Loading…
Reference in New Issue