Define flags in CMAKE_C(XX)_FLAGS are now included in SublimeClang settings.

Changed the the SublimeText2 generator name to Sublime Text 2.

Fixed a minor issue where if the build directory was outside of the source
directory an unnecessary folder_exclude_pattern was generated in the
Sublime Text 2 project file.
This commit is contained in:
Morné Chamberlain 2012-10-18 22:54:19 +02:00
parent d022d4ec78
commit 8670cbe166
2 changed files with 44 additions and 19 deletions

View File

@ -117,8 +117,13 @@ void cmExtraSublimeTextGenerator
cmSystemTools::RelativePath(lgs[0]->GetMakefile()->GetHomeDirectory(), cmSystemTools::RelativePath(lgs[0]->GetMakefile()->GetHomeDirectory(),
lgs[0]->GetMakefile()-> lgs[0]->GetMakefile()->
GetHomeOutputDirectory()); GetHomeOutputDirectory());
fout << ",\n\t\t\t\"folder_exclude_patterns\": [\"" << if ((!outputRelativeToSourceRoot.empty()) &&
outputRelativeToSourceRoot << "\"]"; ((outputRelativeToSourceRoot.length() < 3) ||
(outputRelativeToSourceRoot.substr(0, 3) != "../")))
{
fout << ",\n\t\t\t\"folder_exclude_patterns\": [\"" <<
outputRelativeToSourceRoot << "\"]";
}
} }
else else
{ {
@ -303,7 +308,32 @@ void cmExtraSublimeTextGenerator::
} }
} }
// Generate the build_system entry for one target void cmExtraSublimeTextGenerator::
ExtractDefines(const char* value, bool check,
std::set<std::string> &defines)
{
std::vector<std::string> defs;
cmSystemTools::ExpandListArgument(value, defs);
for(std::vector<std::string>::const_iterator di = defs.begin();
di != defs.end(); ++di)
{
cmXMLSafe safedef(di->c_str());
if (check)
{
std::string safedefString = safedef.str();
if ((safedefString.length() >= 2) &&
(safedefString.substr(0, 2) == "-D"))
{
defines.insert(safedefString.substr(2));
}
}
else
{
defines.insert(safedef.str());
}
}
}
void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout, void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
const char* targetName, const char* targetName,
cmTarget* target, cmTarget* target,
@ -321,20 +351,13 @@ void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
cmGeneratorTarget *gtgt = this->GlobalGenerator cmGeneratorTarget *gtgt = this->GlobalGenerator
->GetGeneratorTarget(target); ->GetGeneratorTarget(target);
std::string cdefs = gtgt->GetCompileDefinitions(); std::string cdefs = gtgt->GetCompileDefinitions();
ExtractDefines(cdefs.c_str(), false, defines);
if(!cdefs.empty()) // Get compiler definitions from CMAKE_CXX_FLAGS and CMAKE_C_FLAGS as
{ // well, in case the user set those flags directly
// Expand the list. std::string cflags = makefile->GetSafeDefinition("CMAKE_CXX_FLAGS");
std::vector<std::string> defs; ExtractDefines(cflags.c_str(), true, defines);
cmSystemTools::ExpandListArgument(cdefs.c_str(), defs); cflags = makefile->GetSafeDefinition("CMAKE_C_FLAGS");
for(std::vector<std::string>::const_iterator di = defs.begin(); ExtractDefines(cflags.c_str(), true, defines);
di != defs.end(); ++di)
{
cmXMLSafe safedef(di->c_str());
defines.insert(safedef.str());
}
}
// the include directories for this target // the include directories for this target
std::vector<std::string> includes; std::vector<std::string> includes;
target->GetMakefile()->GetLocalGenerator()-> target->GetMakefile()->GetLocalGenerator()->

View File

@ -31,7 +31,7 @@ public:
virtual const char* GetName() const virtual const char* GetName() const
{ return cmExtraSublimeTextGenerator::GetActualName();} { return cmExtraSublimeTextGenerator::GetActualName();}
static const char* GetActualName() static const char* GetActualName()
{ return "SublimeText2";} { return "Sublime Text 2";}
static cmExternalMakefileProjectGenerator* New() static cmExternalMakefileProjectGenerator* New()
{ return new cmExtraSublimeTextGenerator; } { return new cmExtraSublimeTextGenerator; }
/** Get the documentation entry for this generator. */ /** Get the documentation entry for this generator. */
@ -69,7 +69,9 @@ private:
const char* compiler, const char* compiler,
std::set<std::string>& includeDirs, std::set<std::string>& includeDirs,
std::set<std::string>& defines, bool firstTarget); std::set<std::string>& defines, bool firstTarget);
/** Extracts -D compile flags from a variable */
void ExtractDefines(const char* value, bool check,
std::set<std::string> &defines);
}; };
#endif #endif