summaryrefslogtreecommitdiffstats
path: root/Source/cmExtraSublimeTextGenerator.cxx
diff options
context:
space:
mode:
authorMorné Chamberlain <thefreeman.za@gmail.com>2012-11-24 18:19:35 (GMT)
committerMorné Chamberlain <thefreeman.za@gmail.com>2012-11-24 18:19:35 (GMT)
commit089d9ccdce530ebd08dfc4681833cefeff4a7eb9 (patch)
tree2abf72eb6037f5f23edd15ba760ac06cd96b8dd1 /Source/cmExtraSublimeTextGenerator.cxx
parent44c2eee8967860499a8b86baccd188799ad25966 (diff)
downloadCMake-089d9ccdce530ebd08dfc4681833cefeff4a7eb9.zip
CMake-089d9ccdce530ebd08dfc4681833cefeff4a7eb9.tar.gz
CMake-089d9ccdce530ebd08dfc4681833cefeff4a7eb9.tar.bz2
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.
Diffstat (limited to 'Source/cmExtraSublimeTextGenerator.cxx')
-rw-r--r--Source/cmExtraSublimeTextGenerator.cxx29
1 files changed, 28 insertions, 1 deletions
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 03e2e1d..b174125 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -161,7 +161,11 @@ void cmExtraSublimeTextGenerator
std::string projectName = mf->GetProjectName();
std::string sublimeClangOptionsFilename = outputDir+"/";
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";
// End of the settings section
fout << "}\n";
@@ -171,9 +175,31 @@ void cmExtraSublimeTextGenerator
this->WriteSublimeClangOptionsFile(sourceFileFlags,
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::
WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
const std::string& filename)
{
@@ -351,6 +377,7 @@ void cmExtraSublimeTextGenerator::
this->ComputeDefines(*iter, lg, target, gtgt);
flags.clear();
cmsys::RegularExpression flagRegex;
+ // Regular expression to extract compiler flags from a string
// https://gist.github.com/3944250
const char* regexString =
"(^|[ ])-[DIOUWfgs][^= ]+(=\\\"[^\"]+\\\"|=[^\"][^ ]+)?";