diff options
author | Morné Chamberlain <thefreeman.za@gmail.com> | 2012-11-24 18:19:35 (GMT) |
---|---|---|
committer | Morné Chamberlain <thefreeman.za@gmail.com> | 2012-11-24 18:19:35 (GMT) |
commit | 089d9ccdce530ebd08dfc4681833cefeff4a7eb9 (patch) | |
tree | 2abf72eb6037f5f23edd15ba760ac06cd96b8dd1 /Source | |
parent | 44c2eee8967860499a8b86baccd188799ad25966 (diff) | |
download | CMake-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')
-rw-r--r-- | Source/cmExtraSublimeTextGenerator.cxx | 29 | ||||
-rw-r--r-- | Source/cmExtraSublimeTextGenerator.h | 1 |
2 files changed, 29 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][^= ]+(=\\\"[^\"]+\\\"|=[^\"][^ ]+)?"; diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h index 26e09a6..8c0c1f3 100644 --- a/Source/cmExtraSublimeTextGenerator.h +++ b/Source/cmExtraSublimeTextGenerator.h @@ -48,6 +48,7 @@ private: void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs, const std::string& filename); + void WriteSublimeClangOptionsScript(const std::string& filename); void WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags, const std::string& filename); /** Appends all targets as build systems to the project file and get all |