Skip to content
Snippets Groups Projects
Commit 95805d72 authored by Bruno Pedrosa's avatar Bruno Pedrosa Committed by Brad King
Browse files

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
parent 9d203c00
No related branches found
No related tags found
No related merge requests found
......@@ -160,6 +160,7 @@ Variables that Change Behavior
/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE
/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY
/variable/CMAKE_STAGING_PREFIX
/variable/CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS
/variable/CMAKE_SUBLIME_TEXT_2_EXCLUDE_BUILD_TREE
/variable/CMAKE_SYSTEM_APPBUNDLE_PATH
/variable/CMAKE_SYSTEM_FRAMEWORK_PATH
......
st2-env-settings
----------------
* The :generator:`Sublime Text 2` extra generator learned to place
environment variables in the generated ``.sublime-project``.
See the :variable:`CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS` variable.
CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS
---------------------------------
This variable contains a list of env vars as a list of tokens with the
syntax ``var=value``.
Example:
.. code-block:: cmake
set(CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS
"FOO=FOO1\;FOO2\;FOON"
"BAR=BAR1\;BAR2\;BARN"
"BAZ=BAZ1\;BAZ2\;BAZN"
"FOOBAR=FOOBAR1\;FOOBAR2\;FOOBARN"
"VALID="
)
In case of malformed variables CMake will fail:
.. code-block:: cmake
set(CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS
"THIS_IS_NOT_VALID"
)
......@@ -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(
......
......@@ -66,6 +66,7 @@ private:
cmGeneratorTarget* gtgt);
bool ExcludeBuildFolder;
std::string EnvSettings;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment