SublimeText2 Gen: Improved use of define, include flags from CMAKE_C(XX)_FLAGS

Both define and include flags from CMAKE_C(XX)_FLAGS are now included in
SublimeClang options.

Include directories are now used with absolute paths instead of relative
paths since CMake generated build trees cannot be moved anyway.
This commit is contained in:
Morné Chamberlain 2012-11-04 16:15:04 +02:00
parent cc84072156
commit 90bcb77956
2 changed files with 26 additions and 19 deletions

View File

@ -182,8 +182,9 @@ void cmExtraSublimeTextGenerator
// It appears that a relative path to the sublime-project file doesn't // It appears that a relative path to the sublime-project file doesn't
// always work. So we use ${folder:${project_path:<project_filename>}} // always work. So we use ${folder:${project_path:<project_filename>}}
// that SublimeClang will expand to the correct path // that SublimeClang will expand to the correct path
fout << "\t\"-I${folder:${project_path:" << mf->GetProjectName() << // fout << "\t\"-I${folder:${project_path:" << mf->GetProjectName() <<
".sublime-project}}/" << relative << "\""; // ".sublime-project}}/" << relative << "\"";
fout << "\t\"-I" << includeDir << "\"";
stringSetIter++; stringSetIter++;
if ((stringSetIter != includeDirs.end()) || (!defines.empty())) if ((stringSetIter != includeDirs.end()) || (!defines.empty()))
{ {
@ -309,27 +310,28 @@ void cmExtraSublimeTextGenerator::
} }
void cmExtraSublimeTextGenerator:: void cmExtraSublimeTextGenerator::
ExtractDefines(const char* value, bool check, ExtractFlags(const char* value, const std::string& flag,
std::set<std::string> &defines) std::set<std::string> &defines)
{ {
std::string::size_type flagLength = flag.length();
std::vector<std::string> defs; std::vector<std::string> defs;
cmSystemTools::ExpandListArgument(value, defs); cmSystemTools::ExpandListArgument(value, defs);
for(std::vector<std::string>::const_iterator di = defs.begin(); for(std::vector<std::string>::const_iterator di = defs.begin();
di != defs.end(); ++di) di != defs.end(); ++di)
{ {
cmXMLSafe safedef(di->c_str()); cmXMLSafe safedef(di->c_str());
if (check) std::string safedefString = safedef.str();
if ((flagLength == 0) || ((safedefString.length() >= flagLength) &&
(safedefString.substr(0, flagLength) == flag)))
{ {
std::string safedefString = safedef.str(); if (flagLength > 0)
if ((safedefString.length() >= 2) &&
(safedefString.substr(0, 2) == "-D"))
{ {
defines.insert(safedefString.substr(2)); defines.insert(safedefString.substr(flagLength));
}
else
{
defines.insert(safedefString);
} }
}
else
{
defines.insert(safedef.str());
} }
} }
} }
@ -351,13 +353,15 @@ 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); ExtractFlags(cdefs.c_str(), "", defines);
// Get compiler definitions from CMAKE_CXX_FLAGS and CMAKE_C_FLAGS as // Get compiler definitions from CMAKE_CXX_FLAGS and CMAKE_C_FLAGS as
// well, in case the user set those flags directly // well, in case the user set those flags directly
std::string cflags = makefile->GetSafeDefinition("CMAKE_CXX_FLAGS"); std::string cflags = makefile->GetSafeDefinition("CMAKE_CXX_FLAGS");
ExtractDefines(cflags.c_str(), true, defines); ExtractFlags(cflags.c_str(), "-D", defines);
ExtractFlags(cflags.c_str(), "-I", includeDirs);
cflags = makefile->GetSafeDefinition("CMAKE_C_FLAGS"); cflags = makefile->GetSafeDefinition("CMAKE_C_FLAGS");
ExtractDefines(cflags.c_str(), true, defines); ExtractFlags(cflags.c_str(), "-D", defines);
ExtractFlags(cflags.c_str(), "-D", includeDirs);
// 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

@ -69,9 +69,12 @@ 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, * Extracts compile flags from a variable.
std::set<std::string> &defines); * flag would typically be "-D" or "-I"
*/
void ExtractFlags(const char* value, const std::string& flag,
std::set<std::string> &defines);
}; };
#endif #endif