summaryrefslogtreecommitdiffstats
path: root/Source/cmExtraSublimeTextGenerator.cxx
diff options
context:
space:
mode:
authorKitware Robot <kwrobot@kitware.com>2016-05-16 14:34:04 (GMT)
committerBrad King <brad.king@kitware.com>2016-05-16 20:05:19 (GMT)
commitd9fd2f5402eeaa345691313658e02b51038f570b (patch)
treedca71b9a7e267f4c6300da3eb770415381726785 /Source/cmExtraSublimeTextGenerator.cxx
parent82df6deaafb36cbbfd450202bb20b320f637751a (diff)
downloadCMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip
CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz
CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update all our C++ code to a new style defined by `.clang-format`. Use `clang-format` version 3.8. * If you reached this commit for a line in `git blame`, re-run the blame operation starting at the parent of this commit to see older history for the content. * See the parent commit for instructions to rebase a change across this style transition commit.
Diffstat (limited to 'Source/cmExtraSublimeTextGenerator.cxx')
-rw-r--r--Source/cmExtraSublimeTextGenerator.cxx372
1 files changed, 158 insertions, 214 deletions
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 0f64eda..9b3ea0b 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -38,15 +38,15 @@ http://www.sublimetext.com/docs/2/projects.html
http://sublimetext.info/docs/en/reference/build_systems.html
*/
-void cmExtraSublimeTextGenerator
-::GetDocumentation(cmDocumentationEntry& entry, const std::string&) const
+void cmExtraSublimeTextGenerator::GetDocumentation(cmDocumentationEntry& entry,
+ const std::string&) const
{
entry.Name = this->GetName();
entry.Brief = "Generates Sublime Text 2 project files.";
}
cmExtraSublimeTextGenerator::cmExtraSublimeTextGenerator()
-:cmExternalMakefileProjectGenerator()
+ : cmExternalMakefileProjectGenerator()
{
#if defined(_WIN32)
this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
@@ -58,68 +58,57 @@ cmExtraSublimeTextGenerator::cmExtraSublimeTextGenerator()
this->SupportedGlobalGenerators.push_back("Unix Makefiles");
}
-
void cmExtraSublimeTextGenerator::Generate()
{
// 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)
- {
+ it = this->GlobalGenerator->GetProjectMap().begin();
+ it != this->GlobalGenerator->GetProjectMap().end(); ++it) {
// create a project file
this->CreateProjectFile(it->second);
- }
+ }
}
-
void cmExtraSublimeTextGenerator::CreateProjectFile(
- const std::vector<cmLocalGenerator*>& lgs)
+ const std::vector<cmLocalGenerator*>& lgs)
{
- std::string outputDir=lgs[0]->GetCurrentBinaryDirectory();
- std::string projectName=lgs[0]->GetProjectName();
+ std::string outputDir = lgs[0]->GetCurrentBinaryDirectory();
+ std::string projectName = lgs[0]->GetProjectName();
const std::string filename =
- outputDir + "/" + projectName + ".sublime-project";
+ outputDir + "/" + projectName + ".sublime-project";
this->CreateNewProjectFile(lgs, filename);
}
-void cmExtraSublimeTextGenerator
- ::CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
- const std::string& filename)
+void cmExtraSublimeTextGenerator::CreateNewProjectFile(
+ const std::vector<cmLocalGenerator*>& lgs, const std::string& filename)
{
- const cmMakefile* mf=lgs[0]->GetMakefile();
+ const cmMakefile* mf = lgs[0]->GetMakefile();
cmGeneratedFileStream fout(filename.c_str());
- if(!fout)
- {
+ if (!fout) {
return;
- }
+ }
- const std::string &sourceRootRelativeToOutput = cmSystemTools::RelativePath(
- lgs[0]->GetBinaryDirectory(),
- lgs[0]->GetSourceDirectory());
+ const std::string& sourceRootRelativeToOutput = cmSystemTools::RelativePath(
+ lgs[0]->GetBinaryDirectory(), lgs[0]->GetSourceDirectory());
// Write the folder entries to the project file
fout << "{\n";
fout << "\t\"folders\":\n\t[\n\t";
- if (!sourceRootRelativeToOutput.empty())
- {
- fout << "\t{\n\t\t\t\"path\": \"" << sourceRootRelativeToOutput << "\"";
- const std::string &outputRelativeToSourceRoot =
- cmSystemTools::RelativePath(lgs[0]->GetSourceDirectory(),
- lgs[0]->GetBinaryDirectory());
- if ((!outputRelativeToSourceRoot.empty()) &&
+ if (!sourceRootRelativeToOutput.empty()) {
+ fout << "\t{\n\t\t\t\"path\": \"" << sourceRootRelativeToOutput << "\"";
+ const std::string& outputRelativeToSourceRoot =
+ cmSystemTools::RelativePath(lgs[0]->GetSourceDirectory(),
+ lgs[0]->GetBinaryDirectory());
+ if ((!outputRelativeToSourceRoot.empty()) &&
((outputRelativeToSourceRoot.length() < 3) ||
- (outputRelativeToSourceRoot.substr(0, 3) != "../")))
- {
- fout << ",\n\t\t\t\"folder_exclude_patterns\": [\"" <<
- outputRelativeToSourceRoot << "\"]";
- }
- }
- else
- {
- fout << "\t{\n\t\t\t\"path\": \"./\"";
+ (outputRelativeToSourceRoot.substr(0, 3) != "../"))) {
+ fout << ",\n\t\t\t\"folder_exclude_patterns\": [\""
+ << outputRelativeToSourceRoot << "\"]";
}
+ } else {
+ fout << "\t{\n\t\t\t\"path\": \"./\"";
+ }
fout << "\n\t\t}";
// End of the folders section
fout << "\n\t]";
@@ -138,173 +127,143 @@ void cmExtraSublimeTextGenerator
fout << "\n\t}";
}
-
-void cmExtraSublimeTextGenerator::
- AppendAllTargets(const std::vector<cmLocalGenerator*>& lgs,
- const cmMakefile* mf,
- cmGeneratedFileStream& fout,
- MapSourceFileFlags& sourceFileFlags)
+void cmExtraSublimeTextGenerator::AppendAllTargets(
+ const std::vector<cmLocalGenerator*>& lgs, const cmMakefile* mf,
+ cmGeneratedFileStream& fout, MapSourceFileFlags& sourceFileFlags)
{
std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
std::string compiler = "";
- if (!lgs.empty())
- {
- this->AppendTarget(fout, "all", lgs[0], 0, make.c_str(), mf,
- compiler.c_str(), sourceFileFlags, true);
- this->AppendTarget(fout, "clean", lgs[0], 0, make.c_str(), mf,
- compiler.c_str(), sourceFileFlags, false);
- }
+ if (!lgs.empty()) {
+ this->AppendTarget(fout, "all", lgs[0], 0, make.c_str(), mf,
+ compiler.c_str(), sourceFileFlags, true);
+ this->AppendTarget(fout, "clean", lgs[0], 0, 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<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++)
- {
+ ti != targets.end(); ti++) {
std::string targetName = (*ti)->GetName();
- switch((*ti)->GetType())
- {
- case cmState::GLOBAL_TARGET:
- {
+ switch ((*ti)->GetType()) {
+ case cmState::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, 0,
- make.c_str(), makefile, compiler.c_str(),
- sourceFileFlags, false);
- }
+ (*lg)->GetBinaryDirectory()) == 0) {
+ this->AppendTarget(fout, targetName, *lg, 0, make.c_str(),
+ makefile, compiler.c_str(), sourceFileFlags,
+ false);
}
- break;
+ } break;
case cmState::UTILITY:
// Add all utility targets, except the Nightly/Continuous/
// Experimental-"sub"targets as e.g. NightlyStart
- if (((targetName.find("Nightly")==0) &&(targetName!="Nightly"))
- || ((targetName.find("Continuous")==0)
- &&(targetName!="Continuous"))
- || ((targetName.find("Experimental")==0)
- && (targetName!="Experimental")))
- {
+ if (((targetName.find("Nightly") == 0) &&
+ (targetName != "Nightly")) ||
+ ((targetName.find("Continuous") == 0) &&
+ (targetName != "Continuous")) ||
+ ((targetName.find("Experimental") == 0) &&
+ (targetName != "Experimental"))) {
break;
- }
+ }
- this->AppendTarget(fout, targetName, *lg, 0,
- make.c_str(), makefile, compiler.c_str(),
- sourceFileFlags, false);
+ this->AppendTarget(fout, targetName, *lg, 0, make.c_str(), 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:
- {
- this->AppendTarget(fout, targetName, *lg, *ti,
- make.c_str(), makefile, compiler.c_str(),
- sourceFileFlags, false);
+ case cmState::OBJECT_LIBRARY: {
+ this->AppendTarget(fout, targetName, *lg, *ti, make.c_str(),
+ makefile, compiler.c_str(), sourceFileFlags,
+ false);
std::string fastTarget = targetName;
fastTarget += "/fast";
- this->AppendTarget(fout, fastTarget, *lg, *ti,
- make.c_str(), makefile, compiler.c_str(),
- sourceFileFlags, false);
- }
- break;
+ this->AppendTarget(fout, fastTarget, *lg, *ti, make.c_str(),
+ makefile, compiler.c_str(), sourceFileFlags,
+ false);
+ } break;
default:
break;
- }
}
}
+ }
}
-void cmExtraSublimeTextGenerator::
- AppendTarget(cmGeneratedFileStream& fout,
- const std::string& targetName,
- cmLocalGenerator* lg,
- cmGeneratorTarget* target,
- const char* make,
- const cmMakefile* makefile,
- const char*, //compiler
- MapSourceFileFlags& sourceFileFlags,
- bool firstTarget)
+void cmExtraSublimeTextGenerator::AppendTarget(
+ cmGeneratedFileStream& fout, const std::string& targetName,
+ cmLocalGenerator* lg, cmGeneratorTarget* target, const char* make,
+ const cmMakefile* makefile,
+ const char*, // compiler
+ MapSourceFileFlags& sourceFileFlags, bool firstTarget)
{
- if (target != 0)
- {
- 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;
- MapSourceFileFlags::iterator sourceFileFlagsIter =
- sourceFileFlags.find(sourceFile->GetFullPath());
- if (sourceFileFlagsIter == sourceFileFlags.end())
- {
- sourceFileFlagsIter =
- sourceFileFlags.insert(MapSourceFileFlags::value_type(
- sourceFile->GetFullPath(), std::vector<std::string>())).first;
- }
- std::vector<std::string>& flags = sourceFileFlagsIter->second;
- std::string flagsString =
- this->ComputeFlagsForObject(*iter, lg, target);
- std::string definesString =
- this->ComputeDefines(*iter, lg, target);
- flags.clear();
- cmsys::RegularExpression flagRegex;
- // Regular expression to extract compiler flags from a string
- // https://gist.github.com/3944250
- const char* regexString =
- "(^|[ ])-[DIOUWfgs][^= ]+(=\\\"[^\"]+\\\"|=[^\"][^ ]+)?";
- flagRegex.compile(regexString);
- std::string workString = flagsString + " " + definesString;
- while (flagRegex.find(workString))
- {
- std::string::size_type start = flagRegex.start();
- if (workString[start] == ' ')
- {
- start++;
- }
- flags.push_back(workString.substr(start,
- flagRegex.end() - start));
- if (flagRegex.end() < workString.size())
- {
- workString = workString.substr(flagRegex.end());
- }
- else
- {
- workString = "";
- }
- }
+ if (target != 0) {
+ 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;
+ MapSourceFileFlags::iterator sourceFileFlagsIter =
+ sourceFileFlags.find(sourceFile->GetFullPath());
+ if (sourceFileFlagsIter == sourceFileFlags.end()) {
+ sourceFileFlagsIter =
+ sourceFileFlags
+ .insert(MapSourceFileFlags::value_type(sourceFile->GetFullPath(),
+ std::vector<std::string>()))
+ .first;
+ }
+ std::vector<std::string>& flags = sourceFileFlagsIter->second;
+ std::string flagsString = this->ComputeFlagsForObject(*iter, lg, target);
+ std::string definesString = this->ComputeDefines(*iter, lg, target);
+ flags.clear();
+ cmsys::RegularExpression flagRegex;
+ // Regular expression to extract compiler flags from a string
+ // https://gist.github.com/3944250
+ const char* regexString =
+ "(^|[ ])-[DIOUWfgs][^= ]+(=\\\"[^\"]+\\\"|=[^\"][^ ]+)?";
+ flagRegex.compile(regexString);
+ std::string workString = flagsString + " " + definesString;
+ while (flagRegex.find(workString)) {
+ std::string::size_type start = flagRegex.start();
+ if (workString[start] == ' ') {
+ start++;
}
+ flags.push_back(workString.substr(start, flagRegex.end() - start));
+ if (flagRegex.end() < workString.size()) {
+ workString = workString.substr(flagRegex.end());
+ } else {
+ workString = "";
+ }
+ }
}
+ }
// Ninja uses ninja.build files (look for a way to get the output file name
// from cmMakefile or something)
std::string makefileName;
- if (this->GlobalGenerator->GetName() == "Ninja")
- {
- makefileName = "build.ninja";
- }
- else
- {
- makefileName = "Makefile";
- }
- if (!firstTarget)
- {
+ if (this->GlobalGenerator->GetName() == "Ninja") {
+ makefileName = "build.ninja";
+ } else {
+ makefileName = "Makefile";
+ }
+ if (!firstTarget) {
fout << ",\n\t";
- }
- fout << "\t{\n\t\t\t\"name\": \"" << lg->GetProjectName() << " - " <<
- targetName << "\",\n";
- fout << "\t\t\t\"cmd\": [" <<
- this->BuildMakeCommand(make, makefileName.c_str(), targetName) <<
- "],\n";
+ }
+ fout << "\t{\n\t\t\t\"name\": \"" << lg->GetProjectName() << " - "
+ << targetName << "\",\n";
+ fout << "\t\t\t\"cmd\": ["
+ << 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}";
@@ -313,66 +272,54 @@ void cmExtraSublimeTextGenerator::
// Create the command line for building the given target using the selected
// make
std::string cmExtraSublimeTextGenerator::BuildMakeCommand(
- const std::string& make, const char* makefile,
- const std::string& target)
+ const std::string& make, const char* makefile, const std::string& target)
{
std::string command = "\"";
command += make + "\"";
std::string generator = this->GlobalGenerator->GetName();
- if (generator == "NMake Makefiles")
- {
+ if (generator == "NMake Makefiles") {
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
command += ", \"/NOLOGO\", \"/f\", \"";
command += makefileName + "\"";
command += ", \"VERBOSE=1\", \"";
command += target;
command += "\"";
- }
- else if (generator == "Ninja")
- {
+ } else if (generator == "Ninja") {
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
command += ", \"-f\", \"";
command += makefileName + "\"";
command += ", \"-v\", \"";
command += target;
command += "\"";
- }
- else
- {
+ } else {
std::string makefileName;
- if (generator == "MinGW Makefiles")
- {
- // no escaping of spaces in this case, see
- // http://public.kitware.com/Bug/view.php?id=10014
- makefileName = makefile;
- }
- else
- {
- makefileName = cmSystemTools::ConvertToOutputPath(makefile);
- }
+ if (generator == "MinGW Makefiles") {
+ // no escaping of spaces in this case, see
+ // http://public.kitware.com/Bug/view.php?id=10014
+ makefileName = makefile;
+ } else {
+ makefileName = cmSystemTools::ConvertToOutputPath(makefile);
+ }
command += ", \"-f\", \"";
command += makefileName + "\"";
command += ", \"VERBOSE=1\", \"";
command += target;
command += "\"";
- }
+ }
return command;
}
// TODO: Most of the code is picked up from the Ninja generator, refactor it.
-std::string
-cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
- cmLocalGenerator* lg,
- cmGeneratorTarget* gtgt)
+std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject(
+ cmSourceFile* source, cmLocalGenerator* lg, cmGeneratorTarget* gtgt)
{
std::string flags;
- cmMakefile *makefile = lg->GetMakefile();
+ cmMakefile* makefile = lg->GetMakefile();
std::string language = source->GetLanguage();
- if (language.empty())
- {
- language = "C";
- }
+ if (language.empty()) {
+ language = "C";
+ }
const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
// Add language-specific flags.
lg->AddLanguageFlags(flags, language, config);
@@ -391,11 +338,11 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
// Add include directory flags.
{
- std::vector<std::string> includes;
- lg->GetIncludeDirectories(includes, gtgt, language, config);
- std::string includeFlags =
- lg->GetIncludeFlags(includes, gtgt, language, true); // full include paths
- lg->AppendFlags(flags, includeFlags);
+ std::vector<std::string> includes;
+ lg->GetIncludeDirectories(includes, gtgt, language, config);
+ std::string includeFlags = lg->GetIncludeFlags(includes, gtgt, language,
+ true); // full include paths
+ lg->AppendFlags(flags, includeFlags);
}
// Append old-style preprocessor definition flags.
@@ -414,30 +361,27 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
// TODO: Refactor with
// void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
-std::string
-cmExtraSublimeTextGenerator::
-ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg,
- cmGeneratorTarget* target)
+std::string cmExtraSublimeTextGenerator::ComputeDefines(
+ cmSourceFile* source, cmLocalGenerator* lg, cmGeneratorTarget* target)
{
std::set<std::string> defines;
- cmMakefile *makefile = lg->GetMakefile();
+ cmMakefile* makefile = lg->GetMakefile();
const std::string& language = source->GetLanguage();
const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
// Add the export symbol definition for shared library objects.
- if(const char* exportMacro = target->GetExportMacro())
- {
+ if (const char* exportMacro = target->GetExportMacro()) {
lg->AppendDefines(defines, exportMacro);
- }
+ }
// Add preprocessor definitions for this target and configuration.
lg->AddCompileDefinitions(defines, target, config, language);
lg->AppendDefines(defines, source->GetProperty("COMPILE_DEFINITIONS"));
{
- std::string defPropName = "COMPILE_DEFINITIONS_";
- defPropName += cmSystemTools::UpperCase(config);
- lg->AppendDefines(defines, source->GetProperty(defPropName));
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += cmSystemTools::UpperCase(config);
+ lg->AppendDefines(defines, source->GetProperty(defPropName));
}
std::string definesString;