123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173 |
- #include "cmExtraEclipseCDT4Generator.h"
- #include "cmsys/RegularExpression.hxx"
- #include <algorithm>
- #include <assert.h>
- #include <sstream>
- #include <stdio.h>
- #include <utility>
- #include "cmGeneratedFileStream.h"
- #include "cmGeneratorExpression.h"
- #include "cmGeneratorTarget.h"
- #include "cmGlobalGenerator.h"
- #include "cmLocalGenerator.h"
- #include "cmMakefile.h"
- #include "cmSourceFile.h"
- #include "cmSourceGroup.h"
- #include "cmState.h"
- #include "cmStateTypes.h"
- #include "cmSystemTools.h"
- #include "cmXMLWriter.h"
- #include "cmake.h"
- static void AppendAttribute(cmXMLWriter& xml, const char* keyval)
- {
- xml.StartElement("attribute");
- xml.Attribute("key", keyval);
- xml.Attribute("value", keyval);
- xml.EndElement();
- }
- template <typename T>
- void AppendDictionary(cmXMLWriter& xml, const char* key, T const& value)
- {
- xml.StartElement("dictionary");
- xml.Element("key", key);
- xml.Element("value", value);
- xml.EndElement();
- }
- cmExtraEclipseCDT4Generator::cmExtraEclipseCDT4Generator()
- : cmExternalMakefileProjectGenerator()
- {
- this->SupportsVirtualFolders = true;
- this->GenerateLinkedResources = true;
- this->SupportsGmakeErrorParser = true;
- this->SupportsMachO64Parser = true;
- this->CEnabled = false;
- this->CXXEnabled = false;
- }
- cmExternalMakefileProjectGeneratorFactory*
- cmExtraEclipseCDT4Generator::GetFactory()
- {
- static cmExternalMakefileProjectGeneratorSimpleFactory<
- cmExtraEclipseCDT4Generator>
- factory("Eclipse CDT4", "Generates Eclipse CDT 4.0 project files.");
- if (factory.GetSupportedGlobalGenerators().empty()) {
- #if defined(_WIN32)
- factory.AddSupportedGlobalGenerator("NMake Makefiles");
- factory.AddSupportedGlobalGenerator("MinGW Makefiles");
- #endif
- factory.AddSupportedGlobalGenerator("Ninja");
- factory.AddSupportedGlobalGenerator("Unix Makefiles");
- }
- return &factory;
- }
- void cmExtraEclipseCDT4Generator::EnableLanguage(
- std::vector<std::string> const& languages, cmMakefile* ,
- bool )
- {
- for (std::string const& l : languages) {
- if (l == "CXX") {
- this->Natures.insert("org.eclipse.cdt.core.ccnature");
- this->Natures.insert("org.eclipse.cdt.core.cnature");
- this->CXXEnabled = true;
- } else if (l == "C") {
- this->Natures.insert("org.eclipse.cdt.core.cnature");
- this->CEnabled = true;
- } else if (l == "Java") {
- this->Natures.insert("org.eclipse.jdt.core.javanature");
- }
- }
- }
- void cmExtraEclipseCDT4Generator::Generate()
- {
- cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
- const cmMakefile* mf = lg->GetMakefile();
- std::string eclipseVersion = mf->GetSafeDefinition("CMAKE_ECLIPSE_VERSION");
- cmsys::RegularExpression regex(".*([0-9]+\\.[0-9]+).*");
- if (regex.find(eclipseVersion.c_str())) {
- unsigned int majorVersion = 0;
- unsigned int minorVersion = 0;
- int res =
- sscanf(regex.match(1).c_str(), "%u.%u", &majorVersion, &minorVersion);
- if (res == 2) {
- int version = majorVersion * 1000 + minorVersion;
- if (version < 3006)
- {
- this->SupportsVirtualFolders = false;
- this->SupportsMachO64Parser = false;
- }
- if (version < 3007)
- {
- this->SupportsGmakeErrorParser = false;
- }
- }
- }
-
- this->HomeDirectory = lg->GetSourceDirectory();
- this->HomeOutputDirectory = lg->GetBinaryDirectory();
- this->GenerateLinkedResources =
- mf->IsOn("CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES");
- this->IsOutOfSourceBuild =
- (this->HomeDirectory != this->HomeOutputDirectory);
- this->GenerateSourceProject =
- (this->IsOutOfSourceBuild &&
- mf->IsOn("CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT"));
- if (!this->GenerateSourceProject &&
- (mf->IsOn("ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT"))) {
- mf->IssueMessage(
- cmake::WARNING,
- "ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT is set to TRUE, "
- "but this variable is not supported anymore since CMake 2.8.7.\n"
- "Enable CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT instead.");
- }
- if (cmSystemTools::IsSubDirectory(this->HomeOutputDirectory,
- this->HomeDirectory)) {
- mf->IssueMessage(cmake::WARNING,
- "The build directory is a subdirectory "
- "of the source directory.\n"
- "This is not supported well by Eclipse. It is strongly "
- "recommended to use a build directory which is a "
- "sibling of the source directory.");
- }
-
-
-
- if (this->GenerateSourceProject) {
-
- this->CreateSourceProjectFile();
- }
-
- this->CreateProjectFile();
-
- this->CreateCProjectFile();
- }
- void cmExtraEclipseCDT4Generator::CreateSourceProjectFile()
- {
- assert(this->HomeDirectory != this->HomeOutputDirectory);
-
- cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
- std::string name =
- this->GenerateProjectName(lg->GetProjectName(), "Source",
- this->GetPathBasename(this->HomeDirectory));
- const std::string filename = this->HomeDirectory + "/.project";
- cmGeneratedFileStream fout(filename.c_str());
- if (!fout) {
- return;
- }
- cmXMLWriter xml(fout);
- xml.StartDocument("UTF-8");
- xml.StartElement("projectDescription");
- xml.Element("name", name);
- xml.Element("comment", "");
- xml.Element("projects", "");
- xml.Element("buildSpec", "");
- xml.Element("natures", "");
- xml.StartElement("linkedResources");
- if (this->SupportsVirtualFolders) {
- this->CreateLinksToSubprojects(xml, this->HomeDirectory);
- this->SrcLinkedResources.clear();
- }
- xml.EndElement();
- xml.EndElement();
- xml.EndDocument();
- }
- void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out,
- const char* envVar,
- cmLocalGenerator* lg)
- {
- cmMakefile* mf = lg->GetMakefile();
-
-
- std::string envVarValue;
- const bool envVarSet = cmSystemTools::GetEnv(envVar, envVarValue);
- std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_";
- cacheEntryName += envVar;
- const char* cacheValue =
- lg->GetState()->GetInitializedCacheValue(cacheEntryName);
-
- std::string valueToUse;
- if (!envVarSet && cacheValue == nullptr) {
-
- valueToUse.clear();
- } else if (envVarSet && cacheValue == nullptr) {
-
-
- valueToUse = envVarValue;
- mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
- cacheEntryName.c_str(), cmStateEnums::STRING, true);
- mf->GetCMakeInstance()->SaveCache(lg->GetBinaryDirectory());
- } else if (!envVarSet && cacheValue != nullptr) {
-
- valueToUse = cacheValue;
- } else {
-
-
-
-
-
- valueToUse = cacheValue;
- if (valueToUse.find(envVarValue) == std::string::npos) {
- valueToUse = envVarValue;
- mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
- cacheEntryName.c_str(), cmStateEnums::STRING,
- true);
- mf->GetCMakeInstance()->SaveCache(lg->GetBinaryDirectory());
- }
- }
- if (!valueToUse.empty()) {
- out << envVar << "=" << valueToUse << "|";
- }
- }
- void cmExtraEclipseCDT4Generator::CreateProjectFile()
- {
- cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
- cmMakefile* mf = lg->GetMakefile();
- const std::string filename = this->HomeOutputDirectory + "/.project";
- cmGeneratedFileStream fout(filename.c_str());
- if (!fout) {
- return;
- }
- std::string compilerId = mf->GetSafeDefinition("CMAKE_C_COMPILER_ID");
- if (compilerId.empty())
- {
- compilerId = mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID");
- }
- cmXMLWriter xml(fout);
- xml.StartDocument("UTF-8");
- xml.StartElement("projectDescription");
- xml.Element("name", this->GenerateProjectName(
- lg->GetProjectName(),
- mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
- this->GetPathBasename(this->HomeOutputDirectory)));
- xml.Element("comment", "");
- xml.Element("projects", "");
- xml.StartElement("buildSpec");
- xml.StartElement("buildCommand");
- xml.Element("name", "org.eclipse.cdt.make.core.makeBuilder");
- xml.Element("triggers", "clean,full,incremental,");
- xml.StartElement("arguments");
-
- AppendDictionary(xml, "org.eclipse.cdt.make.core.cleanBuildTarget", "clean");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.enableCleanBuild", "true");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.append_environment",
- "true");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.stopOnError", "true");
-
- AppendDictionary(xml, "org.eclipse.cdt.make.core.enabledIncrementalBuild",
- "true");
- AppendDictionary(
- xml, "org.eclipse.cdt.make.core.build.command",
- this->GetEclipsePath(mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM")));
- AppendDictionary(xml, "org.eclipse.cdt.make.core.contents",
- "org.eclipse.cdt.make.core.activeConfigSettings");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.build.target.inc", "all");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.build.arguments",
- mf->GetSafeDefinition("CMAKE_ECLIPSE_MAKE_ARGUMENTS"));
- AppendDictionary(xml, "org.eclipse.cdt.make.core.buildLocation",
- this->GetEclipsePath(this->HomeOutputDirectory));
- AppendDictionary(xml, "org.eclipse.cdt.make.core.useDefaultBuildCmd",
- "false");
-
- std::ostringstream environment;
- environment << "VERBOSE=1|CMAKE_NO_VERBOSE=1|";
-
-
- if (compilerId == "MSVC") {
- AddEnvVar(environment, "PATH", lg);
- AddEnvVar(environment, "INCLUDE", lg);
- AddEnvVar(environment, "LIB", lg);
- AddEnvVar(environment, "LIBPATH", lg);
- } else if (compilerId == "Intel") {
-
-
-
- AddEnvVar(environment, "INTEL_LICENSE_FILE", lg);
- }
- AppendDictionary(xml, "org.eclipse.cdt.make.core.environment",
- environment.str());
- AppendDictionary(xml, "org.eclipse.cdt.make.core.enableFullBuild", "true");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.build.target.auto", "all");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.enableAutoBuild", "false");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.build.target.clean",
- "clean");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.fullBuildTarget", "all");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.buildArguments", "");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.build.location",
- this->GetEclipsePath(this->HomeOutputDirectory));
- AppendDictionary(xml, "org.eclipse.cdt.make.core.autoBuildTarget", "all");
-
- std::ostringstream errorOutputParser;
- if (compilerId == "MSVC") {
- errorOutputParser << "org.eclipse.cdt.core.VCErrorParser;";
- } else if (compilerId == "Intel") {
- errorOutputParser << "org.eclipse.cdt.core.ICCErrorParser;";
- }
- if (this->SupportsGmakeErrorParser) {
- errorOutputParser << "org.eclipse.cdt.core.GmakeErrorParser;";
- } else {
- errorOutputParser << "org.eclipse.cdt.core.MakeErrorParser;";
- }
- errorOutputParser << "org.eclipse.cdt.core.GCCErrorParser;"
- "org.eclipse.cdt.core.GASErrorParser;"
- "org.eclipse.cdt.core.GLDErrorParser;";
- AppendDictionary(xml, "org.eclipse.cdt.core.errorOutputParser",
- errorOutputParser.str());
- xml.EndElement();
- xml.EndElement();
- xml.StartElement("buildCommand");
- xml.Element("name", "org.eclipse.cdt.make.core.ScannerConfigBuilder");
- xml.StartElement("arguments");
- xml.EndElement();
- xml.EndElement();
- xml.EndElement();
-
- xml.StartElement("natures");
- xml.Element("nature", "org.eclipse.cdt.make.core.makeNature");
- xml.Element("nature", "org.eclipse.cdt.make.core.ScannerConfigNature");
- ;
- for (std::string const& n : this->Natures) {
- xml.Element("nature", n);
- }
- if (const char* extraNaturesProp =
- mf->GetState()->GetGlobalProperty("ECLIPSE_EXTRA_NATURES")) {
- std::vector<std::string> extraNatures;
- cmSystemTools::ExpandListArgument(extraNaturesProp, extraNatures);
- for (std::string const& n : extraNatures) {
- xml.Element("nature", n);
- }
- }
- xml.EndElement();
- xml.StartElement("linkedResources");
-
- if (this->IsOutOfSourceBuild) {
-
-
-
-
-
- std::string sourceLinkedResourceName = "[Source directory]";
- std::string linkSourceDirectory =
- this->GetEclipsePath(lg->GetCurrentSourceDirectory());
-
- if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory,
- linkSourceDirectory)) {
- this->AppendLinkedResource(xml, sourceLinkedResourceName,
- this->GetEclipsePath(linkSourceDirectory),
- LinkToFolder);
- this->SrcLinkedResources.push_back(std::move(sourceLinkedResourceName));
- }
- }
- if (this->SupportsVirtualFolders) {
- this->CreateLinksToSubprojects(xml, this->HomeOutputDirectory);
- this->CreateLinksForTargets(xml);
- }
- xml.EndElement();
- xml.EndElement();
- }
- void cmExtraEclipseCDT4Generator::WriteGroups(
- std::vector<cmSourceGroup> const& sourceGroups, std::string& linkName,
- cmXMLWriter& xml)
- {
- for (cmSourceGroup const& sg : sourceGroups) {
- std::string linkName3 = linkName;
- linkName3 += "/";
- linkName3 += sg.GetFullName();
- std::replace(linkName3.begin(), linkName3.end(), '\\', '/');
- this->AppendLinkedResource(xml, linkName3, "virtual:/virtual",
- VirtualFolder);
- std::vector<cmSourceGroup> const& children = sg.GetGroupChildren();
- if (!children.empty()) {
- this->WriteGroups(children, linkName, xml);
- }
- std::vector<const cmSourceFile*> sFiles = sg.GetSourceFiles();
- for (cmSourceFile const* file : sFiles) {
- std::string const& fullPath = file->GetFullPath();
- if (!cmSystemTools::FileIsDirectory(fullPath)) {
- std::string linkName4 = linkName3;
- linkName4 += "/";
- linkName4 += cmSystemTools::GetFilenameName(fullPath);
- this->AppendLinkedResource(xml, linkName4,
- this->GetEclipsePath(fullPath), LinkToFile);
- }
- }
- }
- }
- void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
- {
- std::string linkName = "[Targets]";
- this->AppendLinkedResource(xml, linkName, "virtual:/virtual", VirtualFolder);
- for (cmLocalGenerator* lg : this->GlobalGenerator->GetLocalGenerators()) {
- cmMakefile* makefile = lg->GetMakefile();
- const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
- for (cmGeneratorTarget* target : targets) {
- std::string linkName2 = linkName;
- linkName2 += "/";
- switch (target->GetType()) {
- case cmStateEnums::EXECUTABLE:
- case cmStateEnums::STATIC_LIBRARY:
- case cmStateEnums::SHARED_LIBRARY:
- case cmStateEnums::MODULE_LIBRARY:
- case cmStateEnums::OBJECT_LIBRARY: {
- const char* prefix =
- (target->GetType() == cmStateEnums::EXECUTABLE ? "[exe] "
- : "[lib] ");
- linkName2 += prefix;
- linkName2 += target->GetName();
- this->AppendLinkedResource(xml, linkName2, "virtual:/virtual",
- VirtualFolder);
- if (!this->GenerateLinkedResources) {
- break;
- }
- std::vector<cmSourceGroup> sourceGroups =
- makefile->GetSourceGroups();
-
- cmGeneratorTarget* gt = const_cast<cmGeneratorTarget*>(target);
- std::vector<cmSourceFile*> files;
- gt->GetSourceFiles(files,
- makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
- for (cmSourceFile* sf : files) {
-
- std::string const& source = sf->GetFullPath();
- cmSourceGroup* sourceGroup =
- makefile->FindSourceGroup(source, sourceGroups);
- sourceGroup->AssignSource(sf);
- }
- this->WriteGroups(sourceGroups, linkName2, xml);
- } break;
-
- default:
- break;
- }
- }
- }
- }
- void cmExtraEclipseCDT4Generator::CreateLinksToSubprojects(
- cmXMLWriter& xml, const std::string& baseDir)
- {
- if (!this->GenerateLinkedResources) {
- return;
- }
-
-
- this->AppendLinkedResource(xml, "[Subprojects]", "virtual:/virtual",
- VirtualFolder);
- for (auto const& it : this->GlobalGenerator->GetProjectMap()) {
- std::string linkSourceDirectory =
- this->GetEclipsePath(it.second[0]->GetCurrentSourceDirectory());
-
-
- if ((baseDir != linkSourceDirectory) &&
- !cmSystemTools::IsSubDirectory(baseDir, linkSourceDirectory)) {
- std::string linkName = "[Subprojects]/";
- linkName += it.first;
- this->AppendLinkedResource(xml, linkName,
- this->GetEclipsePath(linkSourceDirectory),
- LinkToFolder);
-
-
- }
- }
- }
- void cmExtraEclipseCDT4Generator::AppendIncludeDirectories(
- cmXMLWriter& xml, const std::vector<std::string>& includeDirs,
- std::set<std::string>& emittedDirs)
- {
- for (std::string const& inc : includeDirs) {
- if (!inc.empty()) {
- std::string dir = cmSystemTools::CollapseFullPath(inc);
-
-
-
- cmsys::RegularExpression frameworkRx("(.+/Frameworks)/.+\\.framework/");
- if (frameworkRx.find(dir.c_str())) {
- dir = frameworkRx.match(1);
- }
- if (emittedDirs.find(dir) == emittedDirs.end()) {
- emittedDirs.insert(dir);
- xml.StartElement("pathentry");
- xml.Attribute("include",
- cmExtraEclipseCDT4Generator::GetEclipsePath(dir));
- xml.Attribute("kind", "inc");
- xml.Attribute("path", "");
- xml.Attribute("system", "true");
- xml.EndElement();
- }
- }
- }
- }
- void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
- {
- std::set<std::string> emmited;
- cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
- const cmMakefile* mf = lg->GetMakefile();
- const std::string filename = this->HomeOutputDirectory + "/.cproject";
- cmGeneratedFileStream fout(filename.c_str());
- if (!fout) {
- return;
- }
- cmXMLWriter xml(fout);
-
- xml.StartDocument("UTF-8");
- xml.ProcessingInstruction("fileVersion", "4.0.0");
- xml.StartElement("cproject");
- xml.StartElement("storageModule");
- xml.Attribute("moduleId", "org.eclipse.cdt.core.settings");
- xml.StartElement("cconfiguration");
- xml.Attribute("id", "org.eclipse.cdt.core.default.config.1");
-
- xml.StartElement("storageModule");
- xml.Attribute("buildSystemId",
- "org.eclipse.cdt.core.defaultConfigDataProvider");
- xml.Attribute("id", "org.eclipse.cdt.core.default.config.1");
- xml.Attribute("moduleId", "org.eclipse.cdt.core.settings");
- xml.Attribute("name", "Configuration");
- xml.Element("externalSettings");
- xml.StartElement("extensions");
-
- std::string executableFormat =
- mf->GetSafeDefinition("CMAKE_EXECUTABLE_FORMAT");
- if (executableFormat == "ELF") {
- xml.StartElement("extension");
- xml.Attribute("id", "org.eclipse.cdt.core.ELF");
- xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
- xml.EndElement();
- xml.StartElement("extension");
- xml.Attribute("id", "org.eclipse.cdt.core.GNU_ELF");
- xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
- AppendAttribute(xml, "addr2line");
- AppendAttribute(xml, "c++filt");
- xml.EndElement();
- } else {
- std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
- if (systemName == "CYGWIN") {
- xml.StartElement("extension");
- xml.Attribute("id", "org.eclipse.cdt.core.Cygwin_PE");
- xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
- AppendAttribute(xml, "addr2line");
- AppendAttribute(xml, "c++filt");
- AppendAttribute(xml, "cygpath");
- AppendAttribute(xml, "nm");
- xml.EndElement();
- } else if (systemName == "Windows") {
- xml.StartElement("extension");
- xml.Attribute("id", "org.eclipse.cdt.core.PE");
- xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
- xml.EndElement();
- } else if (systemName == "Darwin") {
- xml.StartElement("extension");
- xml.Attribute("id", this->SupportsMachO64Parser
- ? "org.eclipse.cdt.core.MachO64"
- : "org.eclipse.cdt.core.MachO");
- xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
- AppendAttribute(xml, "c++filt");
- xml.EndElement();
- } else {
-
- xml.Element("error_toolchain_type");
- }
- }
- xml.EndElement();
- xml.EndElement();
-
- xml.StartElement("storageModule");
- xml.Attribute("moduleId", "org.eclipse.cdt.core.language.mapping");
- xml.Element("project-mappings");
- xml.EndElement();
-
- xml.StartElement("storageModule");
- xml.Attribute("moduleId", "org.eclipse.cdt.core.externalSettings");
- xml.EndElement();
-
- xml.StartElement("storageModule");
- xml.Attribute("moduleId", "org.eclipse.cdt.core.pathentry");
-
-
-
- std::string excludeFromOut;
-
-
-
- if (this->GenerateLinkedResources) {
- xml.StartElement("pathentry");
- xml.Attribute("kind", "src");
- xml.Attribute("path", "[Subprojects]");
- xml.EndElement();
- }
- for (std::string const& p : this->SrcLinkedResources) {
- xml.StartElement("pathentry");
- xml.Attribute("kind", "src");
- xml.Attribute("path", p);
- xml.EndElement();
-
-
- if (!cmSystemTools::FileIsDirectory(
- std::string(this->HomeOutputDirectory + "/" + p))) {
- excludeFromOut += p + "/|";
- }
- }
- excludeFromOut += "**/CMakeFiles/";
- xml.StartElement("pathentry");
- xml.Attribute("excluding", excludeFromOut);
- xml.Attribute("kind", "out");
- xml.Attribute("path", "");
- xml.EndElement();
-
- emmited.clear();
- for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
- if (const char* cdefs =
- lgen->GetMakefile()->GetProperty("COMPILE_DEFINITIONS")) {
-
- std::vector<std::string> defs;
- cmGeneratorExpression::Split(cdefs, defs);
- for (std::string const& d : defs) {
- if (cmGeneratorExpression::Find(d) != std::string::npos) {
- continue;
- }
- std::string::size_type equals = d.find('=', 0);
- std::string::size_type enddef = d.length();
- std::string def;
- std::string val;
- if (equals != std::string::npos && equals < enddef) {
-
- def = d.substr(0, equals);
- val = d.substr(equals + 1, enddef - equals + 1);
- } else {
-
- def = d;
- }
-
- if (emmited.find(def) == emmited.end()) {
- emmited.insert(def);
- xml.StartElement("pathentry");
- xml.Attribute("kind", "mac");
- xml.Attribute("name", def);
- xml.Attribute("path", "");
- xml.Attribute("value", val);
- xml.EndElement();
- }
- }
- }
- }
-
- const char* cDefs =
- mf->GetDefinition("CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS");
- if (this->CEnabled && cDefs) {
-
- std::vector<std::string> defs;
- cmSystemTools::ExpandListArgument(cDefs, defs, true);
-
- if ((defs.size() % 2) == 0) {
- std::vector<std::string>::const_iterator di = defs.begin();
- while (di != defs.end()) {
- std::string def = *di;
- ++di;
- std::string val;
- if (di != defs.end()) {
- val = *di;
- ++di;
- }
-
- if (emmited.find(def) == emmited.end()) {
- emmited.insert(def);
- xml.StartElement("pathentry");
- xml.Attribute("kind", "mac");
- xml.Attribute("name", def);
- xml.Attribute("path", "");
- xml.Attribute("value", val);
- xml.EndElement();
- }
- }
- }
- }
-
- const char* cxxDefs =
- mf->GetDefinition("CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS");
- if (this->CXXEnabled && cxxDefs) {
-
- std::vector<std::string> defs;
- cmSystemTools::ExpandListArgument(cxxDefs, defs, true);
-
- if ((defs.size() % 2) == 0) {
- std::vector<std::string>::const_iterator di = defs.begin();
- while (di != defs.end()) {
- std::string def = *di;
- ++di;
- std::string val;
- if (di != defs.end()) {
- val = *di;
- ++di;
- }
-
- if (emmited.find(def) == emmited.end()) {
- emmited.insert(def);
- xml.StartElement("pathentry");
- xml.Attribute("kind", "mac");
- xml.Attribute("name", def);
- xml.Attribute("path", "");
- xml.Attribute("value", val);
- xml.EndElement();
- }
- }
- }
- }
-
- emmited.clear();
- for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
- const std::vector<cmGeneratorTarget*>& targets =
- lgen->GetGeneratorTargets();
- for (cmGeneratorTarget* target : targets) {
- std::vector<std::string> includeDirs;
- std::string config = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
- lgen->GetIncludeDirectories(includeDirs, target, "C", config);
- this->AppendIncludeDirectories(xml, includeDirs, emmited);
- }
- }
-
-
-
- std::string compiler = mf->GetSafeDefinition("CMAKE_C_COMPILER");
- if (this->CEnabled && !compiler.empty()) {
- std::string systemIncludeDirs =
- mf->GetSafeDefinition("CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
- std::vector<std::string> dirs;
- cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
- this->AppendIncludeDirectories(xml, dirs, emmited);
- }
- compiler = mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
- if (this->CXXEnabled && !compiler.empty()) {
- std::string systemIncludeDirs =
- mf->GetSafeDefinition("CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
- std::vector<std::string> dirs;
- cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
- this->AppendIncludeDirectories(xml, dirs, emmited);
- }
- xml.EndElement();
-
- xml.StartElement("storageModule");
- xml.Attribute("moduleId", "org.eclipse.cdt.make.core.buildtargets");
- xml.StartElement("buildTargets");
- emmited.clear();
- const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
- const std::string makeArgs =
- mf->GetSafeDefinition("CMAKE_ECLIPSE_MAKE_ARGUMENTS");
- cmGlobalGenerator* generator =
- const_cast<cmGlobalGenerator*>(this->GlobalGenerator);
- std::string allTarget;
- std::string cleanTarget;
- if (generator->GetAllTargetName()) {
- allTarget = generator->GetAllTargetName();
- }
- if (generator->GetCleanTargetName()) {
- cleanTarget = generator->GetCleanTargetName();
- }
-
-
- for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
- const std::vector<cmGeneratorTarget*>& targets =
- lgen->GetGeneratorTargets();
- std::string subdir = lgen->ConvertToRelativePath(
- this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory());
- if (subdir == ".") {
- subdir.clear();
- }
- for (cmGeneratorTarget* target : targets) {
- std::string targetName = target->GetName();
- switch (target->GetType()) {
- case cmStateEnums::GLOBAL_TARGET: {
-
-
- if (subdir.empty()) {
- this->AppendTarget(xml, targetName, make, makeArgs, subdir, ": ");
- }
- } break;
- case cmStateEnums::UTILITY:
-
-
- if (((targetName.find("Nightly") == 0) &&
- (targetName != "Nightly")) ||
- ((targetName.find("Continuous") == 0) &&
- (targetName != "Continuous")) ||
- ((targetName.find("Experimental") == 0) &&
- (targetName != "Experimental"))) {
- break;
- }
- this->AppendTarget(xml, targetName, make, makeArgs, subdir, ": ");
- break;
- case cmStateEnums::EXECUTABLE:
- case cmStateEnums::STATIC_LIBRARY:
- case cmStateEnums::SHARED_LIBRARY:
- case cmStateEnums::MODULE_LIBRARY:
- case cmStateEnums::OBJECT_LIBRARY: {
- const char* prefix =
- (target->GetType() == cmStateEnums::EXECUTABLE ? "[exe] "
- : "[lib] ");
- this->AppendTarget(xml, targetName, make, makeArgs, subdir, prefix);
- std::string fastTarget = targetName;
- fastTarget += "/fast";
- this->AppendTarget(xml, fastTarget, make, makeArgs, subdir, prefix);
-
- if (this->SupportsVirtualFolders) {
- std::string virtDir = "[Targets]/";
- virtDir += prefix;
- virtDir += targetName;
- std::string buildArgs = "-C \"";
- buildArgs += lgen->GetBinaryDirectory();
- buildArgs += "\" ";
- buildArgs += makeArgs;
- this->AppendTarget(xml, "Build", make, buildArgs, virtDir, "",
- targetName.c_str());
- std::string cleanArgs = "-E chdir \"";
- cleanArgs += lgen->GetCurrentBinaryDirectory();
- cleanArgs += "\" \"";
- cleanArgs += cmSystemTools::GetCMakeCommand();
- cleanArgs += "\" -P \"";
- cmGeneratorTarget* gt = target;
- cleanArgs += lgen->GetTargetDirectory(gt);
- cleanArgs += "/cmake_clean.cmake\"";
- this->AppendTarget(xml, "Clean", cmSystemTools::GetCMakeCommand(),
- cleanArgs, virtDir, "", "");
- }
- } break;
- default:
- break;
- }
- }
-
- if (!allTarget.empty()) {
- this->AppendTarget(xml, allTarget, make, makeArgs, subdir, ": ");
- }
- if (!cleanTarget.empty()) {
- this->AppendTarget(xml, cleanTarget, make, makeArgs, subdir, ": ");
- }
-
-
- std::vector<std::string> objectFileTargets;
- lg->GetIndividualFileTargets(objectFileTargets);
- for (std::string const& f : objectFileTargets) {
- const char* prefix = "[obj] ";
- if (f[f.length() - 1] == 's') {
- prefix = "[to asm] ";
- } else if (f[f.length() - 1] == 'i') {
- prefix = "[pre] ";
- }
- this->AppendTarget(xml, f, make, makeArgs, subdir, prefix);
- }
- }
- xml.EndElement();
- xml.EndElement();
- this->AppendStorageScanners(xml, *mf);
- xml.EndElement();
- xml.EndElement();
- xml.StartElement("storageModule");
- xml.Attribute("moduleId", "cdtBuildSystem");
- xml.Attribute("version", "4.0.0");
- xml.StartElement("project");
- xml.Attribute("id", std::string(lg->GetProjectName()) + ".null.1");
- xml.Attribute("name", lg->GetProjectName());
- xml.EndElement();
- xml.EndElement();
- xml.EndElement();
- }
- std::string cmExtraEclipseCDT4Generator::GetEclipsePath(
- const std::string& path)
- {
- #if defined(__CYGWIN__)
- std::string cmd = "cygpath -m " + path;
- std::string out;
- if (!cmSystemTools::RunSingleCommand(cmd.c_str(), &out, &out)) {
- return path;
- } else {
- out.erase(out.find_last_of('\n'));
- return out;
- }
- #else
- return path;
- #endif
- }
- std::string cmExtraEclipseCDT4Generator::GetPathBasename(
- const std::string& path)
- {
- std::string outputBasename = path;
- while (!outputBasename.empty() &&
- (outputBasename[outputBasename.size() - 1] == '/' ||
- outputBasename[outputBasename.size() - 1] == '\\')) {
- outputBasename.resize(outputBasename.size() - 1);
- }
- std::string::size_type loc = outputBasename.find_last_of("/\\");
- if (loc != std::string::npos) {
- outputBasename = outputBasename.substr(loc + 1);
- }
- return outputBasename;
- }
- std::string cmExtraEclipseCDT4Generator::GenerateProjectName(
- const std::string& name, const std::string& type, const std::string& path)
- {
- return name + (type.empty() ? "" : "-") + type + "@" + path;
- }
- void cmExtraEclipseCDT4Generator::AppendStorageScanners(
- cmXMLWriter& xml, const cmMakefile& makefile)
- {
-
- std::string make = makefile.GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
- std::string compiler = makefile.GetSafeDefinition("CMAKE_C_COMPILER");
- std::string arg1 = makefile.GetSafeDefinition("CMAKE_C_COMPILER_ARG1");
- if (compiler.empty()) {
- compiler = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER");
- arg1 = makefile.GetSafeDefinition("CMAKE_CXX_COMPILER_ARG1");
- }
- if (compiler.empty())
- {
- compiler = "gcc";
- }
-
- std::string compilerArgs =
- "-E -P -v -dD ${plugin_state_location}/${specs_file}";
- if (!arg1.empty()) {
- arg1 += " ";
- compilerArgs = arg1 + compilerArgs;
- }
- xml.StartElement("storageModule");
- xml.Attribute("moduleId", "scannerConfiguration");
- xml.StartElement("autodiscovery");
- xml.Attribute("enabled", "true");
- xml.Attribute("problemReportingEnabled", "true");
- xml.Attribute("selectedProfileId",
- "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile");
- xml.EndElement();
- cmExtraEclipseCDT4Generator::AppendScannerProfile(
- xml, "org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile", true,
- "", true, "specsFile", compilerArgs, compiler, true, true);
- cmExtraEclipseCDT4Generator::AppendScannerProfile(
- xml, "org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile", true, "",
- true, "makefileGenerator", "-f ${project_name}_scd.mk", make, true, true);
- xml.EndElement();
- }
- void cmExtraEclipseCDT4Generator::AppendTarget(
- cmXMLWriter& xml, const std::string& target, const std::string& make,
- const std::string& makeArgs, const std::string& path, const char* prefix,
- const char* makeTarget)
- {
- xml.StartElement("target");
- xml.Attribute("name", prefix + target);
- xml.Attribute("path", path);
- xml.Attribute("targetID", "org.eclipse.cdt.make.MakeTargetBuilder");
- xml.Element("buildCommand",
- cmExtraEclipseCDT4Generator::GetEclipsePath(make));
- xml.Element("buildArguments", makeArgs);
- xml.Element("buildTarget", makeTarget ? makeTarget : target.c_str());
- xml.Element("stopOnError", "true");
- xml.Element("useDefaultCommand", "false");
- xml.EndElement();
- }
- void cmExtraEclipseCDT4Generator::AppendScannerProfile(
- cmXMLWriter& xml, const std::string& profileID, bool openActionEnabled,
- const std::string& openActionFilePath, bool pParserEnabled,
- const std::string& scannerInfoProviderID,
- const std::string& runActionArguments, const std::string& runActionCommand,
- bool runActionUseDefault, bool sipParserEnabled)
- {
- xml.StartElement("profile");
- xml.Attribute("id", profileID);
- xml.StartElement("buildOutputProvider");
- xml.StartElement("openAction");
- xml.Attribute("enabled", openActionEnabled ? "true" : "false");
- xml.Attribute("filePath", openActionFilePath);
- xml.EndElement();
- xml.StartElement("parser");
- xml.Attribute("enabled", pParserEnabled ? "true" : "false");
- xml.EndElement();
- xml.EndElement();
- xml.StartElement("scannerInfoProvider");
- xml.Attribute("id", scannerInfoProviderID);
- xml.StartElement("runAction");
- xml.Attribute("arguments", runActionArguments);
- xml.Attribute("command", runActionCommand);
- xml.Attribute("useDefault", runActionUseDefault ? "true" : "false");
- xml.EndElement();
- xml.StartElement("parser");
- xml.Attribute("enabled", sipParserEnabled ? "true" : "false");
- xml.EndElement();
- xml.EndElement();
- xml.EndElement();
- }
- void cmExtraEclipseCDT4Generator::AppendLinkedResource(cmXMLWriter& xml,
- const std::string& name,
- const std::string& path,
- LinkType linkType)
- {
- const char* locationTag = "location";
- int typeTag = 2;
- if (linkType == VirtualFolder)
- {
- locationTag = "locationURI";
- }
- if (linkType == LinkToFile) {
- typeTag = 1;
- }
- xml.StartElement("link");
- xml.Element("name", name);
- xml.Element("type", typeTag);
- xml.Element(locationTag, path);
- xml.EndElement();
- }
|