summaryrefslogtreecommitdiff
path: root/Source/cmExtraSublimeTextGenerator.cxx
diff options
context:
space:
mode:
authorBruno Pedrosa <brupelo@gmail.com>2016-10-26 20:58:11 +0200
committerBrad King <brad.king@kitware.com>2016-10-27 14:07:18 -0400
commit95805d725d49af665c2254f97effbe8b812239ea (patch)
tree80813318e704a4a0b569a3cc1ef85564f8b72443 /Source/cmExtraSublimeTextGenerator.cxx
parent9d203c0051bbec48dfbee90940e6faff87a2bdeb (diff)
downloadcmake-95805d725d49af665c2254f97effbe8b812239ea.tar.gz
Sublime: Add option to specify env vars for the .sublime-project
Create a `CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS` variable to control addition of env vars in the `.sublime-project`. Closes: #16387
Diffstat (limited to 'Source/cmExtraSublimeTextGenerator.cxx')
-rw-r--r--Source/cmExtraSublimeTextGenerator.cxx34
1 files changed, 33 insertions, 1 deletions
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index f46019eb79..ff5036f608 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -62,6 +62,8 @@ void cmExtraSublimeTextGenerator::Generate()
{
this->ExcludeBuildFolder = this->GlobalGenerator->GlobalSettingIsOn(
"CMAKE_SUBLIME_TEXT_2_EXCLUDE_BUILD_TREE");
+ this->EnvSettings = this->GlobalGenerator->GetSafeGlobalSetting(
+ "CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS");
// for each sub project in the project create a sublime text 2 project
for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
@@ -130,7 +132,37 @@ void cmExtraSublimeTextGenerator::CreateNewProjectFile(
// End of build_systems
fout << "\n\t]";
- fout << "\n\t}";
+ std::string systemName = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
+ std::vector<std::string> tokens;
+ cmSystemTools::ExpandListArgument(this->EnvSettings, tokens);
+
+ if (!this->EnvSettings.empty()) {
+ fout << ",";
+ fout << "\n\t\"env\":";
+ fout << "\n\t{";
+ fout << "\n\t\t" << systemName << ":";
+ fout << "\n\t\t{";
+ for (std::vector<std::string>::iterator i = tokens.begin();
+ i != tokens.end(); ++i) {
+ size_t const pos = i->find_first_of('=');
+
+ if (pos != std::string::npos) {
+ std::string varName = i->substr(0, pos);
+ std::string varValue = i->substr(pos + 1);
+
+ fout << "\n\t\t\t\"" << varName << "\":\"" << varValue << "\"";
+ } else {
+ std::ostringstream e;
+ e << "Could not parse Env Vars specified in "
+ "\"CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS\""
+ << ", corrupted string " << *i;
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ }
+ }
+ fout << "\n\t\t}";
+ fout << "\n\t}";
+ }
+ fout << "\n}";
}
void cmExtraSublimeTextGenerator::AppendAllTargets(