diff options
Diffstat (limited to 'Source/cmExtraSublimeTextGenerator.cxx')
-rw-r--r-- | Source/cmExtraSublimeTextGenerator.cxx | 90 |
1 files changed, 52 insertions, 38 deletions
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 1fd1418..2443ece 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -68,11 +68,9 @@ void cmExtraSublimeTextGenerator::Generate() "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(); - it != this->GlobalGenerator->GetProjectMap().end(); ++it) { + for (auto const& it : this->GlobalGenerator->GetProjectMap()) { // create a project file - this->CreateProjectFile(it->second); + this->CreateProjectFile(it.second); } } @@ -144,20 +142,19 @@ void cmExtraSublimeTextGenerator::CreateNewProjectFile( 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('='); + for (std::string const& t : tokens) { + size_t const pos = t.find_first_of('='); if (pos != std::string::npos) { - std::string varName = i->substr(0, pos); - std::string varValue = i->substr(pos + 1); + std::string varName = t.substr(0, pos); + std::string varValue = t.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; + << ", corrupted string " << t; mf->IssueMessage(cmake::FATAL_ERROR, e.str()); } } @@ -174,28 +171,26 @@ void cmExtraSublimeTextGenerator::AppendAllTargets( std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); std::string compiler; if (!lgs.empty()) { - this->AppendTarget(fout, "all", lgs[0], CM_NULLPTR, make.c_str(), mf, + this->AppendTarget(fout, "all", lgs[0], nullptr, make.c_str(), mf, compiler.c_str(), sourceFileFlags, true); - this->AppendTarget(fout, "clean", lgs[0], CM_NULLPTR, make.c_str(), mf, + this->AppendTarget(fout, "clean", lgs[0], nullptr, make.c_str(), mf, compiler.c_str(), sourceFileFlags, false); } // add all executable and library targets and some of the GLOBAL // and UTILITY targets - for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin(); - lg != lgs.end(); lg++) { - cmMakefile* makefile = (*lg)->GetMakefile(); - std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin(); - ti != targets.end(); ti++) { - std::string targetName = (*ti)->GetName(); - switch ((*ti)->GetType()) { + for (cmLocalGenerator* lg : lgs) { + cmMakefile* makefile = lg->GetMakefile(); + const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { + std::string targetName = target->GetName(); + switch (target->GetType()) { case cmStateEnums::GLOBAL_TARGET: { // Only add the global targets from CMAKE_BINARY_DIR, // not from the subdirs - if (strcmp((*lg)->GetCurrentBinaryDirectory(), - (*lg)->GetBinaryDirectory()) == 0) { - this->AppendTarget(fout, targetName, *lg, CM_NULLPTR, make.c_str(), + if (strcmp(lg->GetCurrentBinaryDirectory(), + lg->GetBinaryDirectory()) == 0) { + this->AppendTarget(fout, targetName, lg, nullptr, make.c_str(), makefile, compiler.c_str(), sourceFileFlags, false); } @@ -212,7 +207,7 @@ void cmExtraSublimeTextGenerator::AppendAllTargets( break; } - this->AppendTarget(fout, targetName, *lg, CM_NULLPTR, make.c_str(), + this->AppendTarget(fout, targetName, lg, nullptr, make.c_str(), makefile, compiler.c_str(), sourceFileFlags, false); break; @@ -221,12 +216,12 @@ void cmExtraSublimeTextGenerator::AppendAllTargets( case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::MODULE_LIBRARY: case cmStateEnums::OBJECT_LIBRARY: { - this->AppendTarget(fout, targetName, *lg, *ti, make.c_str(), + this->AppendTarget(fout, targetName, lg, target, make.c_str(), makefile, compiler.c_str(), sourceFileFlags, false); std::string fastTarget = targetName; fastTarget += "/fast"; - this->AppendTarget(fout, fastTarget, *lg, *ti, make.c_str(), + this->AppendTarget(fout, fastTarget, lg, target, make.c_str(), makefile, compiler.c_str(), sourceFileFlags, false); } break; @@ -244,15 +239,11 @@ void cmExtraSublimeTextGenerator::AppendTarget( MapSourceFileFlags& sourceFileFlags, bool firstTarget) { - if (target != CM_NULLPTR) { + if (target != nullptr) { std::vector<cmSourceFile*> sourceFiles; target->GetSourceFiles(sourceFiles, makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); - std::vector<cmSourceFile*>::const_iterator sourceFilesEnd = - sourceFiles.end(); - for (std::vector<cmSourceFile*>::const_iterator iter = sourceFiles.begin(); - iter != sourceFilesEnd; ++iter) { - cmSourceFile* sourceFile = *iter; + for (cmSourceFile* sourceFile : sourceFiles) { MapSourceFileFlags::iterator sourceFileFlagsIter = sourceFileFlags.find(sourceFile->GetFullPath()); if (sourceFileFlagsIter == sourceFileFlags.end()) { @@ -263,8 +254,9 @@ void cmExtraSublimeTextGenerator::AppendTarget( .first; } std::vector<std::string>& flags = sourceFileFlagsIter->second; - std::string flagsString = this->ComputeFlagsForObject(*iter, lg, target); - std::string definesString = this->ComputeDefines(*iter, lg, target); + std::string flagsString = + this->ComputeFlagsForObject(sourceFile, lg, target); + std::string definesString = this->ComputeDefines(sourceFile, lg, target); flags.clear(); cmsys::RegularExpression flagRegex; // Regular expression to extract compiler flags from a string @@ -282,7 +274,7 @@ void cmExtraSublimeTextGenerator::AppendTarget( if (flagRegex.end() < workString.size()) { workString = workString.substr(flagRegex.end()); } else { - workString = ""; + workString.clear(); } } } @@ -370,9 +362,8 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject( // Add source file specific flags. if (const char* cflags = source->GetProperty("COMPILE_FLAGS")) { - cmGeneratorExpression ge; - const char* processed = ge.Parse(cflags)->Evaluate(lg, config); - lg->AppendFlags(flags, processed); + cmGeneratorExpressionInterpreter genexInterpreter(lg, gtgt, config); + lg->AppendFlags(flags, genexInterpreter.Evaluate(cflags)); } return flags; @@ -408,3 +399,26 @@ std::string cmExtraSublimeTextGenerator::ComputeDefines( return definesString; } + +bool cmExtraSublimeTextGenerator::Open(const std::string& bindir, + const std::string& projectName, + bool dryRun) +{ + const char* sublExecutable = + this->GlobalGenerator->GetCMakeInstance()->GetCacheDefinition( + "CMAKE_SUBLIMETEXT_EXECUTABLE"); + if (!sublExecutable) { + return false; + } + if (cmSystemTools::IsNOTFOUND(sublExecutable)) { + return false; + } + + std::string filename = bindir + "/" + projectName + ".sublime-project"; + if (dryRun) { + return cmSystemTools::FileExists(filename, true); + } + + return cmSystemTools::RunSingleCommand( + { sublExecutable, "--project", filename }); +} |