SublimeText 2 Gen: Set the sublimeclang_options_script property.
The sublimeclang_options_script property is now set in the project file. It is set to execute a python script that reads the JSON options file to get options per source file. Python must be installed and in the path for this feature to work from Sublime Text.
This commit is contained in:
parent
44c2eee896
commit
089d9ccdce
|
@ -161,7 +161,11 @@ void cmExtraSublimeTextGenerator
|
||||||
std::string projectName = mf->GetProjectName();
|
std::string projectName = mf->GetProjectName();
|
||||||
std::string sublimeClangOptionsFilename = outputDir+"/";
|
std::string sublimeClangOptionsFilename = outputDir+"/";
|
||||||
sublimeClangOptionsFilename += projectName + ".sublimeclang-options";
|
sublimeClangOptionsFilename += projectName + ".sublimeclang-options";
|
||||||
fout << "\t\"sublimeclang_options_file\": \"" << sublimeClangOptionsFilename
|
std::string sublimeClangOptionsScriptFilename = outputDir + "/"
|
||||||
|
+ projectName + "_sublimeclang_options_script.py";
|
||||||
|
fout << "\t\"sublimeclang_options_script\": \"python "
|
||||||
|
<< sublimeClangOptionsScriptFilename << " "
|
||||||
|
<< sublimeClangOptionsFilename
|
||||||
<< "\"\n\t";
|
<< "\"\n\t";
|
||||||
// End of the settings section
|
// End of the settings section
|
||||||
fout << "}\n";
|
fout << "}\n";
|
||||||
|
@ -171,8 +175,30 @@ void cmExtraSublimeTextGenerator
|
||||||
|
|
||||||
this->WriteSublimeClangOptionsFile(sourceFileFlags,
|
this->WriteSublimeClangOptionsFile(sourceFileFlags,
|
||||||
sublimeClangOptionsFilename);
|
sublimeClangOptionsFilename);
|
||||||
|
this->WriteSublimeClangOptionsScript(sublimeClangOptionsScriptFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmExtraSublimeTextGenerator::
|
||||||
|
WriteSublimeClangOptionsScript(const std::string& filename)
|
||||||
|
{
|
||||||
|
cmGeneratedFileStream fout(filename.c_str());
|
||||||
|
if(!fout)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fout << "import json\n";
|
||||||
|
fout << "import sys\n\n\n";
|
||||||
|
fout << "if len(sys.argv) < 2:\n";
|
||||||
|
fout << " sys.exit(1)\n";
|
||||||
|
fout << "data = None\n";
|
||||||
|
fout << "with open(sys.argv[1]) as f:\n";
|
||||||
|
fout << " data = json.load(f)\n";
|
||||||
|
fout << "if data is not None:\n";
|
||||||
|
fout << " for arg in data.get(sys.argv[2], []):\n";
|
||||||
|
fout << " print arg\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void cmExtraSublimeTextGenerator::
|
void cmExtraSublimeTextGenerator::
|
||||||
WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
|
WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
|
||||||
const std::string& filename)
|
const std::string& filename)
|
||||||
|
@ -351,6 +377,7 @@ void cmExtraSublimeTextGenerator::
|
||||||
this->ComputeDefines(*iter, lg, target, gtgt);
|
this->ComputeDefines(*iter, lg, target, gtgt);
|
||||||
flags.clear();
|
flags.clear();
|
||||||
cmsys::RegularExpression flagRegex;
|
cmsys::RegularExpression flagRegex;
|
||||||
|
// Regular expression to extract compiler flags from a string
|
||||||
// https://gist.github.com/3944250
|
// https://gist.github.com/3944250
|
||||||
const char* regexString =
|
const char* regexString =
|
||||||
"(^|[ ])-[DIOUWfgs][^= ]+(=\\\"[^\"]+\\\"|=[^\"][^ ]+)?";
|
"(^|[ ])-[DIOUWfgs][^= ]+(=\\\"[^\"]+\\\"|=[^\"][^ ]+)?";
|
||||||
|
|
|
@ -48,6 +48,7 @@ private:
|
||||||
|
|
||||||
void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
|
void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
|
||||||
const std::string& filename);
|
const std::string& filename);
|
||||||
|
void WriteSublimeClangOptionsScript(const std::string& filename);
|
||||||
void WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
|
void WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
|
||||||
const std::string& filename);
|
const std::string& filename);
|
||||||
/** Appends all targets as build systems to the project file and get all
|
/** Appends all targets as build systems to the project file and get all
|
||||||
|
|
Loading…
Reference in New Issue