summaryrefslogtreecommitdiffstats
path: root/Source/cmExtraSublimeTextGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmExtraSublimeTextGenerator.cxx')
-rw-r--r--Source/cmExtraSublimeTextGenerator.cxx85
1 files changed, 66 insertions, 19 deletions
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 5ae969b..5712ab2 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -2,20 +2,22 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExtraSublimeTextGenerator.h"
+#include <cmsys/RegularExpression.hxx>
+#include <set>
+#include <sstream>
+#include <string.h>
+#include <utility>
+
#include "cmGeneratedFileStream.h"
+#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmSourceFile.h"
-#include "cmState.h"
+#include "cmStateTypes.h"
#include "cmSystemTools.h"
-
-#include <cmsys/RegularExpression.hxx>
-#include <ostream>
-#include <set>
-#include <string.h>
-#include <utility>
+#include "cmake.h"
/*
Sublime Text 2 Generator
@@ -55,10 +57,16 @@ cmExtraSublimeTextGenerator::GetFactory()
cmExtraSublimeTextGenerator::cmExtraSublimeTextGenerator()
: cmExternalMakefileProjectGenerator()
{
+ this->ExcludeBuildFolder = false;
}
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
it = this->GlobalGenerator->GetProjectMap().begin();
@@ -84,6 +92,7 @@ void cmExtraSublimeTextGenerator::CreateNewProjectFile(
const std::vector<cmLocalGenerator*>& lgs, const std::string& filename)
{
const cmMakefile* mf = lgs[0]->GetMakefile();
+
cmGeneratedFileStream fout(filename.c_str());
if (!fout) {
return;
@@ -102,8 +111,10 @@ void cmExtraSublimeTextGenerator::CreateNewProjectFile(
if ((!outputRelativeToSourceRoot.empty()) &&
((outputRelativeToSourceRoot.length() < 3) ||
(outputRelativeToSourceRoot.substr(0, 3) != "../"))) {
- fout << ",\n\t\t\t\"folder_exclude_patterns\": [\""
- << outputRelativeToSourceRoot << "\"]";
+ if (this->ExcludeBuildFolder) {
+ fout << ",\n\t\t\t\"folder_exclude_patterns\": [\""
+ << outputRelativeToSourceRoot << "\"]";
+ }
}
} else {
fout << "\t{\n\t\t\t\"path\": \"./\"";
@@ -123,7 +134,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(
@@ -149,7 +190,7 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
ti != targets.end(); ti++) {
std::string targetName = (*ti)->GetName();
switch ((*ti)->GetType()) {
- case cmState::GLOBAL_TARGET: {
+ case cmStateEnums::GLOBAL_TARGET: {
// Only add the global targets from CMAKE_BINARY_DIR,
// not from the subdirs
if (strcmp((*lg)->GetCurrentBinaryDirectory(),
@@ -159,7 +200,7 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
false);
}
} break;
- case cmState::UTILITY:
+ case cmStateEnums::UTILITY:
// Add all utility targets, except the Nightly/Continuous/
// Experimental-"sub"targets as e.g. NightlyStart
if (((targetName.find("Nightly") == 0) &&
@@ -175,11 +216,11 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
makefile, compiler.c_str(), sourceFileFlags,
false);
break;
- case cmState::EXECUTABLE:
- case cmState::STATIC_LIBRARY:
- case cmState::SHARED_LIBRARY:
- case cmState::MODULE_LIBRARY:
- case cmState::OBJECT_LIBRARY: {
+ case cmStateEnums::EXECUTABLE:
+ case cmStateEnums::STATIC_LIBRARY:
+ case cmStateEnums::SHARED_LIBRARY:
+ case cmStateEnums::MODULE_LIBRARY:
+ case cmStateEnums::OBJECT_LIBRARY: {
this->AppendTarget(fout, targetName, *lg, *ti, make.c_str(),
makefile, compiler.c_str(), sourceFileFlags,
false);
@@ -264,7 +305,9 @@ void cmExtraSublimeTextGenerator::AppendTarget(
<< this->BuildMakeCommand(make, makefileName.c_str(), targetName)
<< "],\n";
fout << "\t\t\t\"working_dir\": \"${project_path}\",\n";
- fout << "\t\t\t\"file_regex\": \"^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$\"\n";
+ fout << "\t\t\t\"file_regex\": \""
+ "^(..[^:]*)(?::|\\\\()([0-9]+)(?::|\\\\))(?:([0-9]+):)?\\\\s*(.*)"
+ "\"\n";
fout << "\t\t}";
}
@@ -332,7 +375,11 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject(
}
// Add source file specific flags.
- lg->AppendFlags(flags, source->GetProperty("COMPILE_FLAGS"));
+ if (const char* cflags = source->GetProperty("COMPILE_FLAGS")) {
+ cmGeneratorExpression ge;
+ const char* processed = ge.Parse(cflags)->Evaluate(lg, config);
+ lg->AppendFlags(flags, processed);
+ }
return flags;
}