[Cmake-commits] CMake branch, next, updated. v2.8.10.2-2081-g3bb7607

Robert Maynard robert.maynard at kitware.com
Mon Feb 11 16:55:44 EST 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  3bb7607b315bc1ffc060a2f7bc4d8e2cc601cabd (commit)
       via  1b750886e21ca8fe8ffa8152fd4db4c3da67dd10 (commit)
       via  d3e94622eca1f0351d4fdd80bfecded20f48e342 (commit)
       via  970483e92eaae78e60663419d79772b89f599e70 (commit)
       via  7a6808294f5c39367596617e960ea0cd5d1fd695 (commit)
       via  a95e536398c618d7fbeb4bad7dc6e4ab1f5b54be (commit)
       via  24ed58623adb8efd4d717c52422365230732bafd (commit)
       via  28e81db68a4b93e7b149768c49bd684374468cce (commit)
       via  fec0149bb8d42cfc40896baf291dfc2100cf5cca (commit)
       via  b45d7a431491a4eb852c0b94942af8896d7ae300 (commit)
       via  a95df0d8f4a8f867fd702266ad67c7911807f342 (commit)
       via  c87a4e3ea9ae29b9e380e8ff3378183eadd96b95 (commit)
       via  4ec2a35e39731e8668456b630532e1176f419a36 (commit)
       via  46e986735b42ae4d637ce314f25a0dc046beb430 (commit)
       via  62dfd3905d7c8920e0fb04b629a27bb8cb93b2e5 (commit)
       via  6108ebba0222d9276c278175cf1ffdf8e8a74117 (commit)
       via  fbeaa4282b0099d16a03b77483c311bd13e54a4b (commit)
       via  8f4d36439bafa6fd96f6ed35fd1898473f56e74d (commit)
      from  dc189378aec16972a0ab63cb145e4d092fd5a12a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3bb7607b315bc1ffc060a2f7bc4d8e2cc601cabd
commit 3bb7607b315bc1ffc060a2f7bc4d8e2cc601cabd
Merge: dc18937 1b75088
Author:     Robert Maynard <robert.maynard at kitware.com>
AuthorDate: Mon Feb 11 16:55:40 2013 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Mon Feb 11 16:55:40 2013 -0500

    Merge topic 'sublimeText2Generator' into next
    
    1b75088 Remove ability to generate sublime clang files.
    d3e9462 Correct missing parameter to CMP0018Flags call.
    970483e SublimeText 2 Gen: Set the sublimeclang_options_script property.
    7a68082 Sublime Text 2 Gen: Per-source Compile flags are now saved in a separate file.
    a95e536 SublimeText2 Gen: Fixed the issue where include directory flags used -D
    24ed586 SublimeText2 Gen: Improved use of define, include flags from CMAKE_C(XX)_FLAGS
    28e81db Define flags in CMAKE_C(XX)_FLAGS are now included in SublimeClang settings.
    fec0149 Fixed Sublime Text project generation for in-source builds
    b45d7a4 Added a CMAKE_SUBLIMECLANG_DISABLED variable that disables SublimeClang.
    a95df0d The generator no longer generates absolute paths to the ninja.build/Makefiles.
    c87a4e3 The generator no longer generates an explicit list of source files.
    4ec2a35 Added and cleaned up some comments.
    46e9867 Fixed support for the Ninja build system.
    62dfd39 Cleaned up the Sublime Text 2 Generator code a bit.
    6108ebb Changed SublimeClang include path generation to expand to absolute paths.
    fbeaa42 Added some support for sublimeclang_options in the generated project file.
    ...


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1b750886e21ca8fe8ffa8152fd4db4c3da67dd10
commit 1b750886e21ca8fe8ffa8152fd4db4c3da67dd10
Author:     Robert Maynard <robert.maynard at kitware.com>
AuthorDate: Wed Feb 6 13:31:44 2013 -0500
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Feb 11 16:44:22 2013 -0500

    Remove ability to generate sublime clang files.
    
    SublimeClang is a optional plugin to SublimeText and I felt it
    shouldn't be part of the generator for the following reasons:
    
    1. Reduces the amount of sublime and sublimeClang specific
       code we have to maintain inside CMake.
    2. In testing the SublimeClang commands generated did not work
       for the VTK project.
    
    For people that do want this feature I recommend that they
    looking into https://gist.github.com/robertmaynard/4724705 for a
    way to use CMAKE_EXPORT_COMPILE_COMMANDS to generate JSON files
    that can be used by SublimeClang.

diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx
index 382d0e8..08b3ef1 100644
--- a/Source/cmDocumentVariables.cxx
+++ b/Source/cmDocumentVariables.cxx
@@ -904,15 +904,6 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
      "only be used when evaluating the INCLUDE_DIRECTORIES target property.  "
      "In that case, it outputs a backtrace for each include directory in "
      "the build.  Default is unset.",false,"Variables That Change Behavior");
-cm->DefineProperty
-    ("CMAKE_SUBLIMECLANG_DISABLED", cmProperty::VARIABLE,
-     "Used by the Sublime Text 2 generator to disable SublimeClang in "
-     "generated project files.",
-     "For very large projects SublimeClang might run slowly. Set this variable"
-     " to TRUE to instruct the Sublime Text 2 generator to disable "
-     " SublimeClang in the generated project files.", false,
-     "Variables That Change Behavior");
-
 
   // Variables defined by CMake that describe the system
 
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index d10179e..ef29329 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -87,8 +87,8 @@ void cmExtraSublimeTextGenerator::CreateProjectFile(
   std::string outputDir=mf->GetStartOutputDirectory();
   std::string projectName=mf->GetProjectName();
 
-  std::string filename=outputDir+"/";
-  filename+=projectName+".sublime-project";
+  const std::string filename =
+                     outputDir + "/" + projectName + ".sublime-project";
 
   this->CreateNewProjectFile(lgs, filename);
 }
@@ -140,108 +140,14 @@ void cmExtraSublimeTextGenerator
   // wide
   MapSourceFileFlags sourceFileFlags;
   AppendAllTargets(lgs, mf, fout, sourceFileFlags);
+
   // End of build_systems
   fout << "\n\t]";
-
-  // Write the settings section with sublimeclang options
-  fout << ",\n\t\"settings\":\n\t{\n\t";
-  // Check if the CMAKE_SUBLIMECLANG_DISABLED flag has been set. If it has
-  // disable sublimeclang for this project.
-  const char* sublimeclangDisabledValue =
-    mf->GetSafeDefinition("CMAKE_SUBLIMECLANG_DISABLED");
-  bool sublimeclangEnabled = cmSystemTools::IsOff(sublimeclangDisabledValue);
-  // Per project sublimeclang settings override default and user settings,
-  // so we only write the sublimeclang_enabled setting to the project file
-  // if it is set to be disabled.
-  if (!sublimeclangEnabled)
-    {
-      fout << "\t\"sublimeclang_enabled\": false,\n\t";
-    }
-  std::string outputDir = mf->GetStartOutputDirectory();
-  std::string projectName = mf->GetProjectName();
-  std::string sublimeClangOptionsFilename = outputDir+"/";
-  sublimeClangOptionsFilename += projectName + ".sublimeclang-options";
-  std::string sublimeClangOptionsScriptFilename = outputDir + "/"
-    + projectName + "_sublimeclang_options_script.py";
-  fout << "\t\"sublimeclang_options_script\": \"python "
-       << sublimeClangOptionsScriptFilename << " "
-       << sublimeClangOptionsFilename
-       << "\"\n\t";
-  // End of the settings section
-  fout << "}\n";
-
-  // End of file
-  fout << "}";
-
-  this->WriteSublimeClangOptionsFile(sourceFileFlags,
-    sublimeClangOptionsFilename);
-  this->WriteSublimeClangOptionsScript(sublimeClangOptionsScriptFilename);
-}
-
-void cmExtraSublimeTextGenerator::
-  WriteSublimeClangOptionsScript(const std::string& filename)
-{
-  cmGeneratedFileStream fout(filename.c_str());
-  if(!fout)
-    {
-    return;
-    }
-  fout << "import json\n";
-  fout << "import sys\n\n\n";
-  fout << "if len(sys.argv) < 2:\n";
-  fout << "    sys.exit(1)\n";
-  fout << "data = None\n";
-  fout << "with open(sys.argv[1]) as f:\n";
-  fout << "    data = json.load(f)\n";
-  fout << "if data is not None:\n";
-  fout << "    for arg in data.get(sys.argv[2], []):\n";
-  fout << "        print arg\n";
+  fout << "\n\t}";
 }
 
 
 void cmExtraSublimeTextGenerator::
-  WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
-                               const std::string& filename)
-{
-  cmGeneratedFileStream fout(filename.c_str());
-  if(!fout)
-    {
-    return;
-    }
-  fout << "{\n";
-  MapSourceFileFlags::const_iterator sourceFileFlagsEnd =
-    sourceFileFlags.end();
-  int totalFiles = sourceFileFlags.size();
-  int fileIndex = 0;
-  for (MapSourceFileFlags::const_iterator iter = sourceFileFlags.begin();
-    iter != sourceFileFlagsEnd; ++iter)
-    {
-    const std::string& sourceFilePath = iter->first;
-    const std::vector<std::string>& flags = iter->second;
-    fout << "\t\"" << sourceFilePath << "\":\n\t[\n\t";
-    std::vector<std::string>::const_iterator flagsEnd = flags.end();
-    for (std::vector<std::string>::const_iterator flagsIter = flags.begin();
-      flagsIter != flagsEnd; ++flagsIter)
-      {
-      fout << "\t\"" << *flagsIter << "\"";
-      if (flagsIter + 1 != flagsEnd)
-        {
-        fout << ",";
-        }
-      fout << "\n\t";
-      }
-      fout << "]";
-      if (fileIndex < totalFiles - 1)
-        {
-        fout << ",";
-        }
-      fout << "\n";
-      fileIndex++;
-    }
-  fout << "}\n";
-}
-
-void cmExtraSublimeTextGenerator::
   AppendAllTargets(const std::vector<cmLocalGenerator*>& lgs,
                    const cmMakefile* mf,
                    cmGeneratedFileStream& fout,
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index 8c0c1f3..7902593 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -48,9 +48,7 @@ private:
 
   void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
                                 const std::string& filename);
-  void WriteSublimeClangOptionsScript(const std::string& filename);
-  void WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
-                                    const std::string& filename);
+
   /** Appends all targets as build systems to the project file and get all
    * include directories and compiler definitions used.
    */

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d3e94622eca1f0351d4fdd80bfecded20f48e342
commit d3e94622eca1f0351d4fdd80bfecded20f48e342
Author:     Robert Maynard <robert.maynard at kitware.com>
AuthorDate: Wed Jan 23 17:26:35 2013 -0500
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Wed Feb 6 11:39:34 2013 -0500

    Correct missing parameter to CMP0018Flags call.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index b174125..d10179e 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -505,7 +505,7 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
   //   }
 
   // Add shared-library flags if needed.
-  lg->AddCMP0018Flags(flags, target, language);
+  lg->AddCMP0018Flags(flags, target, language, config);
 
   // Add include directory flags.
   {

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=970483e92eaae78e60663419d79772b89f599e70
commit 970483e92eaae78e60663419d79772b89f599e70
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Sat Nov 24 20:19:35 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:08:12 2013 -0500

    SublimeText 2 Gen: Set the sublimeclang_options_script property.
    
    The sublimeclang_options_script property is now set in the project
    file. It is set to execute a python script that reads the JSON options
    file to get options per source file. Python must be installed and in the
    path for this feature to work from Sublime Text.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 03e2e1d..b174125 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -161,7 +161,11 @@ void cmExtraSublimeTextGenerator
   std::string projectName = mf->GetProjectName();
   std::string sublimeClangOptionsFilename = outputDir+"/";
   sublimeClangOptionsFilename += projectName + ".sublimeclang-options";
-  fout << "\t\"sublimeclang_options_file\": \"" << sublimeClangOptionsFilename
+  std::string sublimeClangOptionsScriptFilename = outputDir + "/"
+    + projectName + "_sublimeclang_options_script.py";
+  fout << "\t\"sublimeclang_options_script\": \"python "
+       << sublimeClangOptionsScriptFilename << " "
+       << sublimeClangOptionsFilename
        << "\"\n\t";
   // End of the settings section
   fout << "}\n";
@@ -171,9 +175,31 @@ void cmExtraSublimeTextGenerator
 
   this->WriteSublimeClangOptionsFile(sourceFileFlags,
     sublimeClangOptionsFilename);
+  this->WriteSublimeClangOptionsScript(sublimeClangOptionsScriptFilename);
 }
 
 void cmExtraSublimeTextGenerator::
+  WriteSublimeClangOptionsScript(const std::string& filename)
+{
+  cmGeneratedFileStream fout(filename.c_str());
+  if(!fout)
+    {
+    return;
+    }
+  fout << "import json\n";
+  fout << "import sys\n\n\n";
+  fout << "if len(sys.argv) < 2:\n";
+  fout << "    sys.exit(1)\n";
+  fout << "data = None\n";
+  fout << "with open(sys.argv[1]) as f:\n";
+  fout << "    data = json.load(f)\n";
+  fout << "if data is not None:\n";
+  fout << "    for arg in data.get(sys.argv[2], []):\n";
+  fout << "        print arg\n";
+}
+
+
+void cmExtraSublimeTextGenerator::
   WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
                                const std::string& filename)
 {
@@ -351,6 +377,7 @@ void cmExtraSublimeTextGenerator::
             this->ComputeDefines(*iter, lg, target, gtgt);
           flags.clear();
           cmsys::RegularExpression flagRegex;
+          // Regular expression to extract compiler flags from a string
           // https://gist.github.com/3944250
           const char* regexString =
             "(^|[ ])-[DIOUWfgs][^= ]+(=\\\"[^\"]+\\\"|=[^\"][^ ]+)?";
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index 26e09a6..8c0c1f3 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -48,6 +48,7 @@ private:
 
   void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
                                 const std::string& filename);
+  void WriteSublimeClangOptionsScript(const std::string& filename);
   void WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
                                     const std::string& filename);
   /** Appends all targets as build systems to the project file and get all

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7a6808294f5c39367596617e960ea0cd5d1fd695
commit 7a6808294f5c39367596617e960ea0cd5d1fd695
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Sun Nov 11 22:07:49 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:08:12 2013 -0500

    Sublime Text 2 Gen: Per-source Compile flags are now saved in a separate file.
    
    We no longer write sublimeclang_options to the project file, but instead
    write a separate .sublimeclang-options JSON file that contains a map
    of source file paths to compile flags for that file.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 279d9f4..03e2e1d 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -105,8 +105,8 @@ void cmExtraSublimeTextGenerator
     }
 
   const std::string &sourceRootRelativeToOutput = cmSystemTools::RelativePath(
-                     lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
-                     lgs[0]->GetMakefile()->GetHomeDirectory());
+                     mf->GetHomeOutputDirectory(),
+                     mf->GetHomeDirectory());
   // Write the folder entries to the project file
   fout << "{\n";
   fout << "\t\"folders\":\n\t[\n\t";
@@ -114,9 +114,8 @@ void cmExtraSublimeTextGenerator
     {
       fout << "\t{\n\t\t\t\"path\": \"" << sourceRootRelativeToOutput << "\"";
       const std::string &outputRelativeToSourceRoot =
-        cmSystemTools::RelativePath(lgs[0]->GetMakefile()->GetHomeDirectory(),
-                                    lgs[0]->GetMakefile()->
-                                      GetHomeOutputDirectory());
+        cmSystemTools::RelativePath(mf->GetHomeDirectory(),
+                                    mf->GetHomeOutputDirectory());
       if ((!outputRelativeToSourceRoot.empty()) &&
         ((outputRelativeToSourceRoot.length() < 3) ||
           (outputRelativeToSourceRoot.substr(0, 3) != "../")))
@@ -130,18 +129,6 @@ void cmExtraSublimeTextGenerator
       fout << "\t{\n\t\t\t\"path\": \"./\"";
     }
   fout << "\n\t\t}";
-  // In order for SublimeClang's path resolution to work, the directory that
-  // contains the sublime-project file must be included here. We just ensure
-  // that no files or subfolders are included.
-  // In the case of an in-source build, however, this must not be used, since
-  // it'll end up excluding the source directory.
-  if (!sourceRootRelativeToOutput.empty())
-  {
-    fout << ",\n\t\t{\n\t\t\t\"path\": \"./\",\n";
-    fout << "\t\t\t\"folder_exclude_patterns\": [\"*\"],\n";
-    fout << "\t\t\t\"file_exclude_patterns\": [\"*\"]\n";
-    fout << "\t\t}";
-  }
   // End of the folders section
   fout << "\n\t]";
 
@@ -151,9 +138,8 @@ void cmExtraSublimeTextGenerator
   // Set of include directories over all targets (sublime text/sublimeclang
   // doesn't currently support these settings per build system, only project
   // wide
-  std::set<std::string> includeDirs;
-  std::set<std::string> defines;
-  AppendAllTargets(lgs, mf, fout, includeDirs, defines);
+  MapSourceFileFlags sourceFileFlags;
+  AppendAllTargets(lgs, mf, fout, sourceFileFlags);
   // End of build_systems
   fout << "\n\t]";
 
@@ -162,7 +148,7 @@ void cmExtraSublimeTextGenerator
   // Check if the CMAKE_SUBLIMECLANG_DISABLED flag has been set. If it has
   // disable sublimeclang for this project.
   const char* sublimeclangDisabledValue =
-    lgs[0]->GetMakefile()->GetSafeDefinition("CMAKE_SUBLIMECLANG_DISABLED");
+    mf->GetSafeDefinition("CMAKE_SUBLIMECLANG_DISABLED");
   bool sublimeclangEnabled = cmSystemTools::IsOff(sublimeclangDisabledValue);
   // Per project sublimeclang settings override default and user settings,
   // so we only write the sublimeclang_enabled setting to the project file
@@ -171,60 +157,79 @@ void cmExtraSublimeTextGenerator
     {
       fout << "\t\"sublimeclang_enabled\": false,\n\t";
     }
-  fout << "\t\"sublimeclang_options\":\n\t\t[\n\t\t";
-  std::set<std::string>::const_iterator stringSetIter = includeDirs.begin();
-  while (stringSetIter != includeDirs.end())
-    {
-    const std::string &includeDir = *stringSetIter;
-    const std::string &relative = cmSystemTools::RelativePath(
-                       lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
-                       includeDir.c_str());
-    // It appears that a relative path to the sublime-project file doesn't
-    // always work. So we use ${folder:${project_path:<project_filename>}}
-    // that SublimeClang will expand to the correct path
-    // fout << "\t\"-I${folder:${project_path:" << mf->GetProjectName() <<
-    //         ".sublime-project}}/" << relative << "\"";
-    fout << "\t\"-I" << includeDir << "\"";
-    stringSetIter++;
-    if ((stringSetIter != includeDirs.end()) || (!defines.empty()))
-      {
-      fout << ",";
-      }
-    fout << "\n\t\t";
-  }
-  stringSetIter = defines.begin();
-  while (stringSetIter != defines.end())
-    {
-    fout << "\t\"-D" << *stringSetIter << "\"";
-    stringSetIter++;
-    if (stringSetIter != defines.end())
-      {
-      fout << ",";
-      }
-    fout << "\n\t\t";
-  }
-  // End of the sublimeclang_options section
-  fout << "]\n\t";
+  std::string outputDir = mf->GetStartOutputDirectory();
+  std::string projectName = mf->GetProjectName();
+  std::string sublimeClangOptionsFilename = outputDir+"/";
+  sublimeClangOptionsFilename += projectName + ".sublimeclang-options";
+  fout << "\t\"sublimeclang_options_file\": \"" << sublimeClangOptionsFilename
+       << "\"\n\t";
   // End of the settings section
   fout << "}\n";
 
   // End of file
   fout << "}";
+
+  this->WriteSublimeClangOptionsFile(sourceFileFlags,
+    sublimeClangOptionsFilename);
+}
+
+void cmExtraSublimeTextGenerator::
+  WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
+                               const std::string& filename)
+{
+  cmGeneratedFileStream fout(filename.c_str());
+  if(!fout)
+    {
+    return;
+    }
+  fout << "{\n";
+  MapSourceFileFlags::const_iterator sourceFileFlagsEnd =
+    sourceFileFlags.end();
+  int totalFiles = sourceFileFlags.size();
+  int fileIndex = 0;
+  for (MapSourceFileFlags::const_iterator iter = sourceFileFlags.begin();
+    iter != sourceFileFlagsEnd; ++iter)
+    {
+    const std::string& sourceFilePath = iter->first;
+    const std::vector<std::string>& flags = iter->second;
+    fout << "\t\"" << sourceFilePath << "\":\n\t[\n\t";
+    std::vector<std::string>::const_iterator flagsEnd = flags.end();
+    for (std::vector<std::string>::const_iterator flagsIter = flags.begin();
+      flagsIter != flagsEnd; ++flagsIter)
+      {
+      fout << "\t\"" << *flagsIter << "\"";
+      if (flagsIter + 1 != flagsEnd)
+        {
+        fout << ",";
+        }
+      fout << "\n\t";
+      }
+      fout << "]";
+      if (fileIndex < totalFiles - 1)
+        {
+        fout << ",";
+        }
+      fout << "\n";
+      fileIndex++;
+    }
+  fout << "}\n";
 }
 
 void cmExtraSublimeTextGenerator::
   AppendAllTargets(const std::vector<cmLocalGenerator*>& lgs,
                    const cmMakefile* mf,
                    cmGeneratedFileStream& fout,
-                   std::set<std::string>& includeDirs,
-                   std::set<std::string>& defines)
+                   MapSourceFileFlags& sourceFileFlags)
 {
   std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
   std::string compiler = "";
-  this->AppendTarget(fout, "all", 0, make.c_str(), mf, compiler.c_str(),
-                     includeDirs, defines, true);
-  this->AppendTarget(fout, "clean", 0, make.c_str(), mf, compiler.c_str(),
-                     includeDirs, defines, 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
@@ -265,9 +270,9 @@ void cmExtraSublimeTextGenerator::
             }
           if (insertTarget)
             {
-            this->AppendTarget(fout, ti->first.c_str(), 0,
+            this->AppendTarget(fout, ti->first.c_str(), *lg, 0,
                                make.c_str(), makefile, compiler.c_str(),
-                               includeDirs, defines, false);
+                               sourceFileFlags, false);
             }
           }
           break;
@@ -282,9 +287,9 @@ void cmExtraSublimeTextGenerator::
             break;
             }
 
-          this->AppendTarget(fout, ti->first.c_str(), 0,
+          this->AppendTarget(fout, ti->first.c_str(), *lg, 0,
                              make.c_str(), makefile, compiler.c_str(),
-                             includeDirs, defines, false);
+                             sourceFileFlags, false);
           break;
         case cmTarget::EXECUTABLE:
         case cmTarget::STATIC_LIBRARY:
@@ -292,14 +297,14 @@ void cmExtraSublimeTextGenerator::
         case cmTarget::MODULE_LIBRARY:
         case cmTarget::OBJECT_LIBRARY:
           {
-          this->AppendTarget(fout, ti->first.c_str(), &ti->second,
+          this->AppendTarget(fout, ti->first.c_str(), *lg, &ti->second,
                              make.c_str(), makefile, compiler.c_str(),
-                             includeDirs, defines, false);
+                             sourceFileFlags, false);
           std::string fastTarget = ti->first;
           fastTarget += "/fast";
-          this->AppendTarget(fout, fastTarget.c_str(), &ti->second,
+          this->AppendTarget(fout, fastTarget.c_str(), *lg, &ti->second,
                              make.c_str(), makefile, compiler.c_str(),
-                             includeDirs, defines, false);
+                             sourceFileFlags, false);
           }
           break;
         default:
@@ -310,95 +315,65 @@ void cmExtraSublimeTextGenerator::
 }
 
 void cmExtraSublimeTextGenerator::
-  ExtractFlags(const char* value, const std::string& flag,
-               std::set<std::string> &defines)
-{
-  std::string::size_type flagLength = flag.length();
-  std::vector<std::string> defs;
-  cmSystemTools::ExpandListArgument(value, defs);
-  for(std::vector<std::string>::const_iterator di = defs.begin();
-      di != defs.end(); ++di)
-    {
-    cmXMLSafe safedef(di->c_str());
-    std::string safedefString = safedef.str();
-    if ((flagLength == 0) || ((safedefString.length() >= flagLength) &&
-      (safedefString.substr(0, flagLength) == flag)))
-      {
-        if (flagLength > 0)
-          {
-          defines.insert(safedefString.substr(flagLength));
-          }
-        else
-          {
-          defines.insert(safedefString);
-          }
-      }
-    }
-}
-
-void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
-                                              const char* targetName,
-                                              cmTarget* target,
-                                              const char* make,
-                                              const cmMakefile* makefile,
-                                              const char* compiler,
-                                              std::set<std::string>&
-                                                              includeDirs,
-                                              std::set<std::string>& defines,
-                                              bool firstTarget)
+  AppendTarget(cmGeneratedFileStream& fout,
+               const char* targetName,
+               cmLocalGenerator* lg,
+               cmTarget* target,
+               const char* make,
+               const cmMakefile* makefile,
+               const char* compiler,
+               MapSourceFileFlags& sourceFileFlags,
+               bool firstTarget)
 {
   if (target != 0)
     {
-      // the compilerdefines for this target
       cmGeneratorTarget *gtgt = this->GlobalGenerator
                                     ->GetGeneratorTarget(target);
-      std::string cdefs = gtgt->GetCompileDefinitions();
-      ExtractFlags(cdefs.c_str(), "", defines);
-      // Get compiler definitions from CMAKE_CXX_FLAGS and CMAKE_C_FLAGS as
-      // well, in case the user set those flags directly
-      std::string cflags = makefile->GetSafeDefinition("CMAKE_CXX_FLAGS");
-      ExtractFlags(cflags.c_str(), "-D", defines);
-      ExtractFlags(cflags.c_str(), "-I", includeDirs);
-      cflags = makefile->GetSafeDefinition("CMAKE_C_FLAGS");
-      ExtractFlags(cflags.c_str(), "-D", defines);
-      ExtractFlags(cflags.c_str(), "-I", includeDirs);
-      // the include directories for this target
-      std::vector<std::string> includes;
-      target->GetMakefile()->GetLocalGenerator()->
-        GetIncludeDirectories(includes, gtgt);
-      for(std::vector<std::string>::const_iterator dirIt=includes.begin();
-          dirIt != includes.end();
-          ++dirIt)
-        {
-        includeDirs.insert(*dirIt);
-        }
-
-      std::string systemIncludeDirs = makefile->GetSafeDefinition(
-                                "CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
-      if (!systemIncludeDirs.empty())
-        {
-        std::vector<std::string> dirs;
-        cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs);
-        for(std::vector<std::string>::const_iterator dirIt=dirs.begin();
-            dirIt != dirs.end();
-            ++dirIt)
-          {
-          includeDirs.insert(*dirIt);
-          }
-        }
-
-      systemIncludeDirs = makefile->GetSafeDefinition(
-                            "CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
-      if (!systemIncludeDirs.empty())
+      std::vector<cmSourceFile*> const& sourceFiles = target->GetSourceFiles();
+      std::vector<cmSourceFile*>::const_iterator sourceFilesEnd =
+        sourceFiles.end();
+      for (std::vector<cmSourceFile*>::const_iterator iter =
+        sourceFiles.begin(); iter != sourceFilesEnd; ++iter)
         {
-        std::vector<std::string> dirs;
-        cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs);
-        for(std::vector<std::string>::const_iterator dirIt=dirs.begin();
-            dirIt != dirs.end();
-            ++dirIt)
-          {
-          includeDirs.insert(*dirIt);
-          }
+          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, gtgt);
+          std::string definesString =
+            this->ComputeDefines(*iter, lg, target, gtgt);
+          flags.clear();
+          cmsys::RegularExpression flagRegex;
+          // 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 = "";
+                }
+            }
         }
     }
 
@@ -473,3 +448,121 @@ std::string cmExtraSublimeTextGenerator::BuildMakeCommand(
     }
   return command;
 }
+
+// TODO: Most of the code is picked up from the Ninja generator, refactor it.
+std::string
+cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
+                                                   cmLocalGenerator* lg,
+                                                   cmTarget *target,
+                                                   cmGeneratorTarget* gtgt)
+{
+  std::string flags;
+
+  cmMakefile *makefile = lg->GetMakefile();
+  const char* language = source->GetLanguage();
+  if (language == NULL)
+   {
+   language = "C";
+   }
+  const char* config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+  // Add language-specific flags.
+  lg->AddLanguageFlags(flags, language, config);
+
+  lg->AddArchitectureFlags(flags, gtgt, language, config);
+
+  // TODO: Fortran support.
+  // // Fortran-specific flags computed for this target.
+  // if(*l == "Fortran")
+  //   {
+  //   this->AddFortranFlags(flags);
+  //   }
+
+  // Add shared-library flags if needed.
+  lg->AddCMP0018Flags(flags, target, language);
+
+  // Add include directory flags.
+  {
+  std::vector<std::string> includes;
+  lg->GetIncludeDirectories(includes, gtgt, language, config);
+  std::string includeFlags =
+    lg->GetIncludeFlags(includes, language, true); // full include paths
+  lg->AppendFlags(flags, includeFlags.c_str());
+  }
+
+  // Append old-style preprocessor definition flags.
+  lg->AppendFlags(flags, makefile->GetDefineFlags());
+
+  // Add target-specific flags.
+  if(gtgt->GetProperty("COMPILE_FLAGS"))
+    {
+    std::string langIncludeExpr = "CMAKE_";
+    langIncludeExpr += language;
+    langIncludeExpr += "_FLAG_REGEX";
+    const char* regex = makefile->GetDefinition(langIncludeExpr.c_str());
+    if(regex)
+      {
+      cmsys::RegularExpression r(regex);
+      std::vector<std::string> args;
+      cmSystemTools::
+        ParseWindowsCommandLine(gtgt->GetProperty("COMPILE_FLAGS"), args);
+      for(std::vector<std::string>::iterator i = args.begin();
+          i != args.end(); ++i)
+        {
+        if(r.find(i->c_str()))
+          {
+          lg->AppendFlags(flags, i->c_str());
+          }
+        }
+      }
+    else
+      {
+      lg->AppendFlags(flags, gtgt->GetProperty("COMPILE_FLAGS"));
+      }
+    }
+
+  // Add source file specific flags.
+  lg->AppendFlags(flags, source->GetProperty("COMPILE_FLAGS"));
+
+  // TODO: Handle Apple frameworks.
+
+  return flags;
+}
+
+// TODO: Refactor with
+// void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
+std::string
+cmExtraSublimeTextGenerator::
+ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg, cmTarget *target,
+               cmGeneratorTarget* gtgt)
+
+{
+  std::set<std::string> defines;
+  cmMakefile *makefile = lg->GetMakefile();
+  const char* language = source->GetLanguage();
+  if (language == NULL)
+   {
+   language = "";
+   }
+  const char* config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+
+  // Add the export symbol definition for shared library objects.
+  if(const char* exportMacro = target->GetExportMacro())
+    {
+    lg->AppendDefines(defines, exportMacro);
+    }
+
+  // Add preprocessor definitions for this target and configuration.
+  lg->AppendDefines(defines, gtgt->GetCompileDefinitions());
+  lg->AppendDefines(defines, source->GetProperty("COMPILE_DEFINITIONS"));
+  {
+  std::string defPropName = "COMPILE_DEFINITIONS_";
+  defPropName += cmSystemTools::UpperCase(config);
+  lg->AppendDefines(defines, gtgt->GetCompileDefinitions(config));
+  lg->AppendDefines(defines, source->GetProperty(defPropName.c_str()));
+  }
+
+  std::string definesString;
+  lg->JoinDefines(defines, definesString, language);
+
+  return definesString;
+}
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index fe8832f..26e09a6 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -14,11 +14,13 @@
 #define cmExtraSublimeTextGenerator_h
 
 #include "cmExternalMakefileProjectGenerator.h"
+#include "cmSourceFile.h"
 
 class cmLocalGenerator;
 class cmMakefile;
 class cmTarget;
 class cmGeneratedFileStream;
+class cmGeneratorTarget;
 
 /** \class cmExtraSublimeTextGenerator
  * \brief Write Sublime Text 2 project files for Makefile based projects
@@ -26,6 +28,7 @@ class cmGeneratedFileStream;
 class cmExtraSublimeTextGenerator : public cmExternalMakefileProjectGenerator
 {
 public:
+  typedef std::map<std::string, std::vector<std::string> > MapSourceFileFlags;
   cmExtraSublimeTextGenerator();
 
   virtual const char* GetName() const
@@ -45,14 +48,15 @@ private:
 
   void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
                                 const std::string& filename);
+  void WriteSublimeClangOptionsFile(const MapSourceFileFlags& sourceFileFlags,
+                                    const std::string& filename);
   /** Appends all targets as build systems to the project file and get all
    * include directories and compiler definitions used.
    */
   void AppendAllTargets(const std::vector<cmLocalGenerator*>& lgs,
                         const cmMakefile* mf,
                         cmGeneratedFileStream& fout,
-                        std::set<std::string>& includeDirs,
-                        std::set<std::string>& defines);
+                        MapSourceFileFlags& sourceFileFlags);
   /** Returns the build command that needs to be executed to build the
    *  specified target.
    */
@@ -63,18 +67,24 @@ private:
    */
   void AppendTarget(cmGeneratedFileStream& fout,
                     const char* targetName,
+                    cmLocalGenerator* lg,
                     cmTarget* target,
                     const char* make,
                     const cmMakefile* makefile,
                     const char* compiler,
-                    std::set<std::string>& includeDirs,
-                    std::set<std::string>& defines, bool firstTarget);
+                    MapSourceFileFlags& sourceFileFlags, bool firstTarget);
   /**
-   * Extracts compile flags from a variable.
-   * flag would typically be "-D" or "-I"
+   * Compute the flags for compilation of object files for a given @a language.
+   * @note Generally it is the value of the variable whose name is computed
+   *       by LanguageFlagsVarName().
    */
-  void ExtractFlags(const char* value, const std::string& flag,
-                    std::set<std::string> &defines);
+  std::string ComputeFlagsForObject(cmSourceFile *source,
+                                    cmLocalGenerator* lg,
+                                    cmTarget *target,
+                                    cmGeneratorTarget* gtgt);
+
+  std::string ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg,
+                             cmTarget *target, cmGeneratorTarget* gtgt);
 };
 
 #endif

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a95e536398c618d7fbeb4bad7dc6e4ab1f5b54be
commit a95e536398c618d7fbeb4bad7dc6e4ab1f5b54be
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Wed Nov 7 21:45:07 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:08:12 2013 -0500

    SublimeText2 Gen: Fixed the issue where include directory flags used -D

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 64796c8..279d9f4 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -361,7 +361,7 @@ void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
       ExtractFlags(cflags.c_str(), "-I", includeDirs);
       cflags = makefile->GetSafeDefinition("CMAKE_C_FLAGS");
       ExtractFlags(cflags.c_str(), "-D", defines);
-      ExtractFlags(cflags.c_str(), "-D", includeDirs);
+      ExtractFlags(cflags.c_str(), "-I", includeDirs);
       // the include directories for this target
       std::vector<std::string> includes;
       target->GetMakefile()->GetLocalGenerator()->

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=24ed58623adb8efd4d717c52422365230732bafd
commit 24ed58623adb8efd4d717c52422365230732bafd
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Sun Nov 4 16:15:04 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:08:12 2013 -0500

    SublimeText2 Gen: Improved use of define, include flags from CMAKE_C(XX)_FLAGS
    
    Both define and include flags from CMAKE_C(XX)_FLAGS are now included in
    SublimeClang options.
    
    Include directories are now used with absolute paths instead of relative
    paths since CMake generated build trees cannot be moved anyway.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index d1ea484..64796c8 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -182,8 +182,9 @@ void cmExtraSublimeTextGenerator
     // It appears that a relative path to the sublime-project file doesn't
     // always work. So we use ${folder:${project_path:<project_filename>}}
     // that SublimeClang will expand to the correct path
-    fout << "\t\"-I${folder:${project_path:" << mf->GetProjectName() <<
-            ".sublime-project}}/" << relative << "\"";
+    // fout << "\t\"-I${folder:${project_path:" << mf->GetProjectName() <<
+    //         ".sublime-project}}/" << relative << "\"";
+    fout << "\t\"-I" << includeDir << "\"";
     stringSetIter++;
     if ((stringSetIter != includeDirs.end()) || (!defines.empty()))
       {
@@ -309,27 +310,28 @@ void cmExtraSublimeTextGenerator::
 }
 
 void cmExtraSublimeTextGenerator::
-  ExtractDefines(const char* value, bool check,
-                 std::set<std::string> &defines)
+  ExtractFlags(const char* value, const std::string& flag,
+               std::set<std::string> &defines)
 {
+  std::string::size_type flagLength = flag.length();
   std::vector<std::string> defs;
   cmSystemTools::ExpandListArgument(value, defs);
   for(std::vector<std::string>::const_iterator di = defs.begin();
       di != defs.end(); ++di)
     {
     cmXMLSafe safedef(di->c_str());
-    if (check)
+    std::string safedefString = safedef.str();
+    if ((flagLength == 0) || ((safedefString.length() >= flagLength) &&
+      (safedefString.substr(0, flagLength) == flag)))
       {
-        std::string safedefString = safedef.str();
-        if ((safedefString.length() >= 2) &&
-          (safedefString.substr(0, 2) == "-D"))
+        if (flagLength > 0)
           {
-          defines.insert(safedefString.substr(2));
+          defines.insert(safedefString.substr(flagLength));
+          }
+        else
+          {
+          defines.insert(safedefString);
           }
-      }
-    else
-      {
-      defines.insert(safedef.str());
       }
     }
 }
@@ -351,13 +353,15 @@ void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
       cmGeneratorTarget *gtgt = this->GlobalGenerator
                                     ->GetGeneratorTarget(target);
       std::string cdefs = gtgt->GetCompileDefinitions();
-      ExtractDefines(cdefs.c_str(), false, defines);
+      ExtractFlags(cdefs.c_str(), "", defines);
       // Get compiler definitions from CMAKE_CXX_FLAGS and CMAKE_C_FLAGS as
       // well, in case the user set those flags directly
       std::string cflags = makefile->GetSafeDefinition("CMAKE_CXX_FLAGS");
-      ExtractDefines(cflags.c_str(), true, defines);
+      ExtractFlags(cflags.c_str(), "-D", defines);
+      ExtractFlags(cflags.c_str(), "-I", includeDirs);
       cflags = makefile->GetSafeDefinition("CMAKE_C_FLAGS");
-      ExtractDefines(cflags.c_str(), true, defines);
+      ExtractFlags(cflags.c_str(), "-D", defines);
+      ExtractFlags(cflags.c_str(), "-D", includeDirs);
       // the include directories for this target
       std::vector<std::string> includes;
       target->GetMakefile()->GetLocalGenerator()->
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index 1735b75..fe8832f 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -69,9 +69,12 @@ private:
                     const char* compiler,
                     std::set<std::string>& includeDirs,
                     std::set<std::string>& defines, bool firstTarget);
-  /** Extracts -D compile flags from a variable */
-  void ExtractDefines(const char* value, bool check,
-                      std::set<std::string> &defines);
+  /**
+   * Extracts compile flags from a variable.
+   * flag would typically be "-D" or "-I"
+   */
+  void ExtractFlags(const char* value, const std::string& flag,
+                    std::set<std::string> &defines);
 };
 
 #endif

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=28e81db68a4b93e7b149768c49bd684374468cce
commit 28e81db68a4b93e7b149768c49bd684374468cce
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Thu Oct 18 22:54:19 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:08:12 2013 -0500

    Define flags in CMAKE_C(XX)_FLAGS are now included in SublimeClang settings.
    
    Changed the the SublimeText2 generator name to Sublime Text 2.
    
    Fixed a minor issue where if the build directory was outside of the source
    directory an unnecessary folder_exclude_pattern was generated in the
    Sublime Text 2 project file.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index ea15be5..d1ea484 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -117,8 +117,13 @@ void cmExtraSublimeTextGenerator
         cmSystemTools::RelativePath(lgs[0]->GetMakefile()->GetHomeDirectory(),
                                     lgs[0]->GetMakefile()->
                                       GetHomeOutputDirectory());
-      fout << ",\n\t\t\t\"folder_exclude_patterns\": [\"" <<
-              outputRelativeToSourceRoot << "\"]";
+      if ((!outputRelativeToSourceRoot.empty()) &&
+        ((outputRelativeToSourceRoot.length() < 3) ||
+          (outputRelativeToSourceRoot.substr(0, 3) != "../")))
+        {
+        fout << ",\n\t\t\t\"folder_exclude_patterns\": [\"" <<
+                outputRelativeToSourceRoot << "\"]";
+        }
     }
   else
     {
@@ -303,7 +308,32 @@ void cmExtraSublimeTextGenerator::
     }
 }
 
-// Generate the build_system entry for one target
+void cmExtraSublimeTextGenerator::
+  ExtractDefines(const char* value, bool check,
+                 std::set<std::string> &defines)
+{
+  std::vector<std::string> defs;
+  cmSystemTools::ExpandListArgument(value, defs);
+  for(std::vector<std::string>::const_iterator di = defs.begin();
+      di != defs.end(); ++di)
+    {
+    cmXMLSafe safedef(di->c_str());
+    if (check)
+      {
+        std::string safedefString = safedef.str();
+        if ((safedefString.length() >= 2) &&
+          (safedefString.substr(0, 2) == "-D"))
+          {
+          defines.insert(safedefString.substr(2));
+          }
+      }
+    else
+      {
+      defines.insert(safedef.str());
+      }
+    }
+}
+
 void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
                                               const char* targetName,
                                               cmTarget* target,
@@ -321,20 +351,13 @@ void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
       cmGeneratorTarget *gtgt = this->GlobalGenerator
                                     ->GetGeneratorTarget(target);
       std::string cdefs = gtgt->GetCompileDefinitions();
-
-      if(!cdefs.empty())
-        {
-        // Expand the list.
-        std::vector<std::string> defs;
-        cmSystemTools::ExpandListArgument(cdefs.c_str(), defs);
-        for(std::vector<std::string>::const_iterator di = defs.begin();
-            di != defs.end(); ++di)
-          {
-          cmXMLSafe safedef(di->c_str());
-          defines.insert(safedef.str());
-          }
-        }
-
+      ExtractDefines(cdefs.c_str(), false, defines);
+      // Get compiler definitions from CMAKE_CXX_FLAGS and CMAKE_C_FLAGS as
+      // well, in case the user set those flags directly
+      std::string cflags = makefile->GetSafeDefinition("CMAKE_CXX_FLAGS");
+      ExtractDefines(cflags.c_str(), true, defines);
+      cflags = makefile->GetSafeDefinition("CMAKE_C_FLAGS");
+      ExtractDefines(cflags.c_str(), true, defines);
       // the include directories for this target
       std::vector<std::string> includes;
       target->GetMakefile()->GetLocalGenerator()->
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index 05ab421..1735b75 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -31,7 +31,7 @@ public:
   virtual const char* GetName() const
                         { return cmExtraSublimeTextGenerator::GetActualName();}
   static const char* GetActualName()
-                        { return "SublimeText2";}
+                        { return "Sublime Text 2";}
   static cmExternalMakefileProjectGenerator* New()
                                     { return new cmExtraSublimeTextGenerator; }
   /** Get the documentation entry for this generator.  */
@@ -69,7 +69,9 @@ private:
                     const char* compiler,
                     std::set<std::string>& includeDirs,
                     std::set<std::string>& defines, bool firstTarget);
-
+  /** Extracts -D compile flags from a variable */
+  void ExtractDefines(const char* value, bool check,
+                      std::set<std::string> &defines);
 };
 
 #endif

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fec0149bb8d42cfc40896baf291dfc2100cf5cca
commit fec0149bb8d42cfc40896baf291dfc2100cf5cca
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Sun Oct 14 17:37:51 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:08:12 2013 -0500

    Fixed Sublime Text project generation for in-source builds
    
    Fixed the issue where for in-source builds the source directory
    (which is also the build directory) was excluded from the project file.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 5c20ef9..ea15be5 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -107,26 +107,38 @@ void cmExtraSublimeTextGenerator
   const std::string &sourceRootRelativeToOutput = cmSystemTools::RelativePath(
                      lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
                      lgs[0]->GetMakefile()->GetHomeDirectory());
-  const std::string &outputRelativeToSourceRoot = cmSystemTools::RelativePath(
-                     lgs[0]->GetMakefile()->GetHomeDirectory(),
-                     lgs[0]->GetMakefile()->GetHomeOutputDirectory());
   // Write the folder entries to the project file
   fout << "{\n";
   fout << "\t\"folders\":\n\t[\n\t";
-  fout << "\t{\n\t\t\t\"path\": \"" << sourceRootRelativeToOutput << "\",\n";
-  fout << "\t\t\t\"folder_exclude_patterns\": [\"" <<
-          outputRelativeToSourceRoot << "\"],\n";
-  fout << "\t\t\t\"file_exclude_patterns\": []\n";
-  fout << "\t\t},\n\t";
+  if (!sourceRootRelativeToOutput.empty())
+    {
+      fout << "\t{\n\t\t\t\"path\": \"" << sourceRootRelativeToOutput << "\"";
+      const std::string &outputRelativeToSourceRoot =
+        cmSystemTools::RelativePath(lgs[0]->GetMakefile()->GetHomeDirectory(),
+                                    lgs[0]->GetMakefile()->
+                                      GetHomeOutputDirectory());
+      fout << ",\n\t\t\t\"folder_exclude_patterns\": [\"" <<
+              outputRelativeToSourceRoot << "\"]";
+    }
+  else
+    {
+      fout << "\t{\n\t\t\t\"path\": \"./\"";
+    }
+  fout << "\n\t\t}";
   // In order for SublimeClang's path resolution to work, the directory that
   // contains the sublime-project file must be included here. We just ensure
-  // that no files or subfolders are included
-  fout << "\t{\n\t\t\t\"path\": \"./\",\n";
-  fout << "\t\t\t\"folder_exclude_patterns\": [\"*\"],\n";
-  fout << "\t\t\t\"file_exclude_patterns\": [\"*\"]\n";
-  fout << "\t\t}\n\t";
+  // that no files or subfolders are included.
+  // In the case of an in-source build, however, this must not be used, since
+  // it'll end up excluding the source directory.
+  if (!sourceRootRelativeToOutput.empty())
+  {
+    fout << ",\n\t\t{\n\t\t\t\"path\": \"./\",\n";
+    fout << "\t\t\t\"folder_exclude_patterns\": [\"*\"],\n";
+    fout << "\t\t\t\"file_exclude_patterns\": [\"*\"]\n";
+    fout << "\t\t}";
+  }
   // End of the folders section
-  fout << "]";
+  fout << "\n\t]";
 
   // Write the beginning of the build systems section to the project file
   fout << ",\n\t\"build_systems\":\n\t[\n\t";

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b45d7a431491a4eb852c0b94942af8896d7ae300
commit b45d7a431491a4eb852c0b94942af8896d7ae300
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Sun Oct 14 14:06:20 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:08:12 2013 -0500

    Added a CMAKE_SUBLIMECLANG_DISABLED variable that disables SublimeClang.
    
    If the CMAKE_SUBLIMECLANG_DISABLED variable is on then SublimeClang
    is disabled in the generated project file. This is useful in large
    projects where SublimeClang might run slowly or perform poorly.

diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx
index 08b3ef1..382d0e8 100644
--- a/Source/cmDocumentVariables.cxx
+++ b/Source/cmDocumentVariables.cxx
@@ -904,6 +904,15 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
      "only be used when evaluating the INCLUDE_DIRECTORIES target property.  "
      "In that case, it outputs a backtrace for each include directory in "
      "the build.  Default is unset.",false,"Variables That Change Behavior");
+cm->DefineProperty
+    ("CMAKE_SUBLIMECLANG_DISABLED", cmProperty::VARIABLE,
+     "Used by the Sublime Text 2 generator to disable SublimeClang in "
+     "generated project files.",
+     "For very large projects SublimeClang might run slowly. Set this variable"
+     " to TRUE to instruct the Sublime Text 2 generator to disable "
+     " SublimeClang in the generated project files.", false,
+     "Variables That Change Behavior");
+
 
   // Variables defined by CMake that describe the system
 
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index af26965..5c20ef9 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -47,7 +47,7 @@ void cmExtraSublimeTextGenerator
     "Project files for Sublime Text 2 will be created in the top directory "
     "and in every subdirectory which features a CMakeLists.txt file "
     "containing a PROJECT() call. "
-    "Additionally a hierarchy of makefiles is generated into the "
+    "Additionally Makefiles (or build.ninja files) are generated into the "
     "build tree.  The appropriate make program can build the project through "
     "the default make target.  A \"make install\" target is also provided.";
 }
@@ -142,6 +142,18 @@ void cmExtraSublimeTextGenerator
 
   // Write the settings section with sublimeclang options
   fout << ",\n\t\"settings\":\n\t{\n\t";
+  // Check if the CMAKE_SUBLIMECLANG_DISABLED flag has been set. If it has
+  // disable sublimeclang for this project.
+  const char* sublimeclangDisabledValue =
+    lgs[0]->GetMakefile()->GetSafeDefinition("CMAKE_SUBLIMECLANG_DISABLED");
+  bool sublimeclangEnabled = cmSystemTools::IsOff(sublimeclangDisabledValue);
+  // Per project sublimeclang settings override default and user settings,
+  // so we only write the sublimeclang_enabled setting to the project file
+  // if it is set to be disabled.
+  if (!sublimeclangEnabled)
+    {
+      fout << "\t\"sublimeclang_enabled\": false,\n\t";
+    }
   fout << "\t\"sublimeclang_options\":\n\t\t[\n\t\t";
   std::set<std::string>::const_iterator stringSetIter = includeDirs.begin();
   while (stringSetIter != includeDirs.end())

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a95df0d8f4a8f867fd702266ad67c7911807f342
commit a95df0d8f4a8f867fd702266ad67c7911807f342
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Sun Oct 14 12:11:32 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:02:58 2013 -0500

    The generator no longer generates absolute paths to the ninja.build/Makefiles.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index ab8af7e..af26965 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -351,17 +351,16 @@ void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
         }
     }
 
-  // Write out the build_system data for this target
-  std::string makefileName = makefile->GetHomeOutputDirectory();
   // Ninja uses ninja.build files (look for a way to get the output file name
-  // from cmMakefile)
+  // from cmMakefile or something)
+  std::string makefileName;
   if (strcmp(this->GlobalGenerator->GetName(), "Ninja")==0)
     {
-      makefileName += "/build.ninja";
+      makefileName = "build.ninja";
     }
     else
     {
-      makefileName += "/Makefile";
+      makefileName = "Makefile";
     }
   if (!firstTarget)
     {

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c87a4e3ea9ae29b9e380e8ff3378183eadd96b95
commit c87a4e3ea9ae29b9e380e8ff3378183eadd96b95
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Sun Oct 14 10:46:29 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:02:58 2013 -0500

    The generator no longer generates an explicit list of source files.
    
    Now the source directory is simply added to the project file,
    with the output/build directory excluded.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index f116088..ab8af7e 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -23,12 +23,6 @@
 
 #include <cmsys/SystemTools.hxx>
 
-#if defined(_WIN32)
-#  define PATH_SEP "\\"
-#else
-#  define PATH_SEP "/"
-#endif
-
 /*
 Sublime Text 2 Generator
 Author: Morné Chamberlain
@@ -110,36 +104,19 @@ void cmExtraSublimeTextGenerator
     return;
     }
 
-  // Collect all files, this includes source files and list files
-  std::vector<std::string> allFiles;
-  GetFileList(lgs, allFiles);
-  // A set of folders to include in the project
-  std::set<std::string> folderIncludePatternsSet;
-  std::stringstream fileIncludePatternsStream;
-  GetFileStringAndFolderSet(lgs, mf, allFiles, fileIncludePatternsStream,
-                            folderIncludePatternsSet);
-  // Write the folder entries to the project file
-  const std::string &homeRelative = cmSystemTools::RelativePath(
+  const std::string &sourceRootRelativeToOutput = cmSystemTools::RelativePath(
                      lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
                      lgs[0]->GetMakefile()->GetHomeDirectory());
+  const std::string &outputRelativeToSourceRoot = cmSystemTools::RelativePath(
+                     lgs[0]->GetMakefile()->GetHomeDirectory(),
+                     lgs[0]->GetMakefile()->GetHomeOutputDirectory());
+  // Write the folder entries to the project file
   fout << "{\n";
   fout << "\t\"folders\":\n\t[\n\t";
-  fout << "\t{\n\t\t\t\"path\": \"" << homeRelative << "\",\n";
-  fout << "\t\t\t\"folder_include_patterns\": [";
-  std::set<std::string>::const_iterator folderIter =
-          folderIncludePatternsSet.begin();
-  while (folderIter != folderIncludePatternsSet.end())
-    {
-    fout << "\"" << *folderIter << "\"";
-    folderIter++;
-    if (folderIter != folderIncludePatternsSet.end())
-      {
-        fout << ", ";
-      }
-    }
-  fout << "],\n";
-  fout << "\t\t\t\"file_include_patterns\": [" <<
-          fileIncludePatternsStream.str() << "]\n";
+  fout << "\t{\n\t\t\t\"path\": \"" << sourceRootRelativeToOutput << "\",\n";
+  fout << "\t\t\t\"folder_exclude_patterns\": [\"" <<
+          outputRelativeToSourceRoot << "\"],\n";
+  fout << "\t\t\t\"file_exclude_patterns\": []\n";
   fout << "\t\t},\n\t";
   // In order for SublimeClang's path resolution to work, the directory that
   // contains the sublime-project file must be included here. We just ensure
@@ -205,113 +182,6 @@ void cmExtraSublimeTextGenerator
   fout << "}";
 }
 
-void cmExtraSublimeTextGenerator
-  ::GetFileList(const std::vector<cmLocalGenerator*>& lgs,
-                std::vector<std::string>& allFiles)
-{
-  for (std::vector<cmLocalGenerator *>::const_iterator
-       it = lgs.begin();
-       it != lgs.end();
-       ++it)
-    {
-    cmMakefile* makefile=(*it)->GetMakefile();
-    // Add list files
-    const std::vector<std::string> & listFiles =
-                                            makefile->GetListFiles();
-    allFiles.insert(allFiles.end(), listFiles.begin(), listFiles.end());
-    // Add source files
-    cmTargets& targets=makefile->GetTargets();
-    for (cmTargets::iterator ti = targets.begin();
-         ti != targets.end(); ti++)
-      {
-      switch(ti->second.GetType())
-        {
-        case cmTarget::EXECUTABLE:
-        case cmTarget::STATIC_LIBRARY:
-        case cmTarget::SHARED_LIBRARY:
-        case cmTarget::MODULE_LIBRARY:
-        case cmTarget::OBJECT_LIBRARY:
-        case cmTarget::UTILITY: // can have sources since 2.6.3
-          {
-          const std::vector<cmSourceFile*>&sources=ti->second.GetSourceFiles();
-          for (std::vector<cmSourceFile*>::const_iterator si=sources.begin();
-               si!=sources.end(); si++)
-            {
-            // don't add source files which have the GENERATED property set:
-            if ((*si)->GetPropertyAsBool("GENERATED"))
-              {
-              continue;
-              }
-              allFiles.push_back((*si)->GetFullPath());
-            }
-          }
-        default:  // intended fallthrough
-           break;
-        }
-      }
-    }
-}
-
-void cmExtraSublimeTextGenerator::
-  GetFileStringAndFolderSet(const std::vector<cmLocalGenerator*>& lgs,
-                            const cmMakefile* mf,
-                            const std::vector<std::string>& allFiles,
-                            std::stringstream& fileIncludePatternsStream,
-                            std::set<std::string>& folderIncludePatternsSet)
-{
-  const char* cmakeRoot = mf->GetDefinition("CMAKE_ROOT");
-  for (std::vector<std::string>::const_iterator jt = allFiles.begin();
-       jt != allFiles.end();
-       ++jt)
-    {
-    // don't put cmake's own files into the project (#12110):
-    if (jt->find(cmakeRoot) == 0)
-      {
-      continue;
-      }
-
-    const std::string &relative = cmSystemTools::RelativePath(
-                       lgs[0]->GetMakefile()->GetHomeDirectory(),
-                       jt->c_str());
-    // Split filename from path
-    std::string fileName = cmSystemTools::GetFilenameName(relative);
-    std::string path = "";
-    if (fileName.length() < relative.length())
-      {
-      path = relative.substr(0, relative.length() - fileName.length() - 1);
-      }
-
-    // We don't want paths with CMakeFiles in them
-    if (relative.find("CMakeFiles") == std::string::npos)
-      {
-      if (fileIncludePatternsStream.tellp() > 0)
-        {
-          fileIncludePatternsStream << ", ";
-        }
-      fileIncludePatternsStream << "\"" << relative << "\"";
-      if ((!path.empty()) && (folderIncludePatternsSet.find(path) ==
-                              folderIncludePatternsSet.end()))
-        {
-        folderIncludePatternsSet.insert(path);
-        std::string::size_type splitIndex = path.rfind(PATH_SEP);
-        std::string splitPath = path;
-        while (splitIndex != std::string::npos)
-          {
-          splitPath = splitPath.substr(0, splitIndex);
-          if ((splitPath.empty()) ||
-                  (folderIncludePatternsSet.insert(splitPath).second == false))
-            {
-            // If the path is already in the set then all of its
-            // parents are as well
-            break;
-            }
-          splitIndex = splitPath.rfind(PATH_SEP);
-          }
-        }
-      }
-    }
-}
-
 void cmExtraSublimeTextGenerator::
   AppendAllTargets(const std::vector<cmLocalGenerator*>& lgs,
                    const cmMakefile* mf,
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index 05d3526..05ab421 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -45,21 +45,6 @@ private:
 
   void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
                                 const std::string& filename);
-  /** Populates allFiles with the full paths to all of the source files
-   *  from the local generators in lgs.
-   */
-  void GetFileList(const std::vector<cmLocalGenerator*>& lgs,
-                   std::vector<std::string>& allFiles);
-  /** Sends comma seperated source files paths to fileIncludePatternsStream
-   *  and builds a set of all directories and subdirectories containing
-   *  source files.
-   */
-  void GetFileStringAndFolderSet(const std::vector<cmLocalGenerator*>& lgs,
-                                 const cmMakefile* mf,
-                                 const std::vector<std::string>& allFiles,
-                                 std::stringstream& fileIncludePatternsStream,
-                                 std::set<std::string>&
-                                   folderIncludePatternsSet);
   /** Appends all targets as build systems to the project file and get all
    * include directories and compiler definitions used.
    */

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4ec2a35e39731e8668456b630532e1176f419a36
commit 4ec2a35e39731e8668456b630532e1176f419a36
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Sat Oct 13 12:54:51 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:02:58 2013 -0500

    Added and cleaned up some comments.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 1338241..f116088 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -86,7 +86,6 @@ void cmExtraSublimeTextGenerator::Generate()
 }
 
 
-/* create the project file */
 void cmExtraSublimeTextGenerator::CreateProjectFile(
                                      const std::vector<cmLocalGenerator*>& lgs)
 {
@@ -206,8 +205,6 @@ void cmExtraSublimeTextGenerator
   fout << "}";
 }
 
-// Get a list of all files and a set of all directories and subdirectories
-// with source files
 void cmExtraSublimeTextGenerator
   ::GetFileList(const std::vector<cmLocalGenerator*>& lgs,
                 std::vector<std::string>& allFiles)
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index e23e472..05d3526 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -45,8 +45,15 @@ private:
 
   void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
                                 const std::string& filename);
+  /** Populates allFiles with the full paths to all of the source files
+   *  from the local generators in lgs.
+   */
   void GetFileList(const std::vector<cmLocalGenerator*>& lgs,
                    std::vector<std::string>& allFiles);
+  /** Sends comma seperated source files paths to fileIncludePatternsStream
+   *  and builds a set of all directories and subdirectories containing
+   *  source files.
+   */
   void GetFileStringAndFolderSet(const std::vector<cmLocalGenerator*>& lgs,
                                  const cmMakefile* mf,
                                  const std::vector<std::string>& allFiles,
@@ -61,8 +68,14 @@ private:
                         cmGeneratedFileStream& fout,
                         std::set<std::string>& includeDirs,
                         std::set<std::string>& defines);
+  /** Returns the build command that needs to be executed to build the
+   *  specified target.
+   */
   std::string BuildMakeCommand(const std::string& make, const char* makefile,
                                const char* target);
+  /** Appends the specified target to the generated project file as a Sublime
+   *  Text build system.
+   */
   void AppendTarget(cmGeneratedFileStream& fout,
                     const char* targetName,
                     cmTarget* target,

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=46e986735b42ae4d637ce314f25a0dc046beb430
commit 46e986735b42ae4d637ce314f25a0dc046beb430
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Sat Oct 13 11:20:09 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:02:57 2013 -0500

    Fixed support for the Ninja build system.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 6a95aa3..1338241 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -29,7 +29,12 @@
 #  define PATH_SEP "/"
 #endif
 
-/* Some useful URLs:
+/*
+Sublime Text 2 Generator
+Author: Morné Chamberlain
+This generator was initially based off of the CodeBlocks generator.
+
+Some useful URLs:
 Homepage:
 http://www.sublimetext.com/
 
@@ -257,7 +262,6 @@ void cmExtraSublimeTextGenerator::
                             std::stringstream& fileIncludePatternsStream,
                             std::set<std::string>& folderIncludePatternsSet)
 {
-  // Convert
   const char* cmakeRoot = mf->GetDefinition("CMAKE_ROOT");
   for (std::vector<std::string>::const_iterator jt = allFiles.begin();
        jt != allFiles.end();
@@ -481,8 +485,17 @@ void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
     }
 
   // Write out the build_system data for this target
-  std::string makefileName = makefile->GetStartOutputDirectory();
-  makefileName += "/Makefile";
+  std::string makefileName = makefile->GetHomeOutputDirectory();
+  // Ninja uses ninja.build files (look for a way to get the output file name
+  // from cmMakefile)
+  if (strcmp(this->GlobalGenerator->GetName(), "Ninja")==0)
+    {
+      makefileName += "/build.ninja";
+    }
+    else
+    {
+      makefileName += "/Makefile";
+    }
   if (!firstTarget)
     {
     fout << ",\n\t";
@@ -513,20 +526,28 @@ std::string cmExtraSublimeTextGenerator::BuildMakeCommand(
     command += target;
     command += "\"";
     }
-  else if (strcmp(this->GlobalGenerator->GetName(), "MinGW Makefiles")==0)
+  else if (strcmp(this->GlobalGenerator->GetName(), "Ninja")==0)
     {
-    // no escaping of spaces in this case, see
-    // http://public.kitware.com/Bug/view.php?id=10014
-    std::string makefileName = makefile;
+    std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
     command += ", \"-f\", \"";
     command += makefileName + "\"";
-    command += ", \"VERBOSE=1\", \"";
+    command += ", \"-v\", \"";
     command += target;
     command += "\"";
     }
   else
     {
-    std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
+    std::string makefileName;
+    if (strcmp(this->GlobalGenerator->GetName(), "MinGW Makefiles")==0)
+      {
+        // 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\", \"";

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=62dfd3905d7c8920e0fb04b629a27bb8cb93b2e5
commit 62dfd3905d7c8920e0fb04b629a27bb8cb93b2e5
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Thu Oct 11 22:53:40 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:02:57 2013 -0500

    Cleaned up the Sublime Text 2 Generator code a bit.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 486658d..6a95aa3 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -106,11 +106,107 @@ void cmExtraSublimeTextGenerator
     return;
     }
 
-  // A set of folders to include in the project
-  std::set<std::string> folderIncludePatternsSet;
   // Collect all files, this includes source files and list files
   std::vector<std::string> allFiles;
+  GetFileList(lgs, allFiles);
+  // A set of folders to include in the project
+  std::set<std::string> folderIncludePatternsSet;
   std::stringstream fileIncludePatternsStream;
+  GetFileStringAndFolderSet(lgs, mf, allFiles, fileIncludePatternsStream,
+                            folderIncludePatternsSet);
+  // Write the folder entries to the project file
+  const std::string &homeRelative = cmSystemTools::RelativePath(
+                     lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
+                     lgs[0]->GetMakefile()->GetHomeDirectory());
+  fout << "{\n";
+  fout << "\t\"folders\":\n\t[\n\t";
+  fout << "\t{\n\t\t\t\"path\": \"" << homeRelative << "\",\n";
+  fout << "\t\t\t\"folder_include_patterns\": [";
+  std::set<std::string>::const_iterator folderIter =
+          folderIncludePatternsSet.begin();
+  while (folderIter != folderIncludePatternsSet.end())
+    {
+    fout << "\"" << *folderIter << "\"";
+    folderIter++;
+    if (folderIter != folderIncludePatternsSet.end())
+      {
+        fout << ", ";
+      }
+    }
+  fout << "],\n";
+  fout << "\t\t\t\"file_include_patterns\": [" <<
+          fileIncludePatternsStream.str() << "]\n";
+  fout << "\t\t},\n\t";
+  // In order for SublimeClang's path resolution to work, the directory that
+  // contains the sublime-project file must be included here. We just ensure
+  // that no files or subfolders are included
+  fout << "\t{\n\t\t\t\"path\": \"./\",\n";
+  fout << "\t\t\t\"folder_exclude_patterns\": [\"*\"],\n";
+  fout << "\t\t\t\"file_exclude_patterns\": [\"*\"]\n";
+  fout << "\t\t}\n\t";
+  // End of the folders section
+  fout << "]";
+
+  // Write the beginning of the build systems section to the project file
+  fout << ",\n\t\"build_systems\":\n\t[\n\t";
+
+  // Set of include directories over all targets (sublime text/sublimeclang
+  // doesn't currently support these settings per build system, only project
+  // wide
+  std::set<std::string> includeDirs;
+  std::set<std::string> defines;
+  AppendAllTargets(lgs, mf, fout, includeDirs, defines);
+  // End of build_systems
+  fout << "\n\t]";
+
+  // Write the settings section with sublimeclang options
+  fout << ",\n\t\"settings\":\n\t{\n\t";
+  fout << "\t\"sublimeclang_options\":\n\t\t[\n\t\t";
+  std::set<std::string>::const_iterator stringSetIter = includeDirs.begin();
+  while (stringSetIter != includeDirs.end())
+    {
+    const std::string &includeDir = *stringSetIter;
+    const std::string &relative = cmSystemTools::RelativePath(
+                       lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
+                       includeDir.c_str());
+    // It appears that a relative path to the sublime-project file doesn't
+    // always work. So we use ${folder:${project_path:<project_filename>}}
+    // that SublimeClang will expand to the correct path
+    fout << "\t\"-I${folder:${project_path:" << mf->GetProjectName() <<
+            ".sublime-project}}/" << relative << "\"";
+    stringSetIter++;
+    if ((stringSetIter != includeDirs.end()) || (!defines.empty()))
+      {
+      fout << ",";
+      }
+    fout << "\n\t\t";
+  }
+  stringSetIter = defines.begin();
+  while (stringSetIter != defines.end())
+    {
+    fout << "\t\"-D" << *stringSetIter << "\"";
+    stringSetIter++;
+    if (stringSetIter != defines.end())
+      {
+      fout << ",";
+      }
+    fout << "\n\t\t";
+  }
+  // End of the sublimeclang_options section
+  fout << "]\n\t";
+  // End of the settings section
+  fout << "}\n";
+
+  // End of file
+  fout << "}";
+}
+
+// Get a list of all files and a set of all directories and subdirectories
+// with source files
+void cmExtraSublimeTextGenerator
+  ::GetFileList(const std::vector<cmLocalGenerator*>& lgs,
+                std::vector<std::string>& allFiles)
+{
   for (std::vector<cmLocalGenerator *>::const_iterator
        it = lgs.begin();
        it != lgs.end();
@@ -152,7 +248,15 @@ void cmExtraSublimeTextGenerator
         }
       }
     }
+}
 
+void cmExtraSublimeTextGenerator::
+  GetFileStringAndFolderSet(const std::vector<cmLocalGenerator*>& lgs,
+                            const cmMakefile* mf,
+                            const std::vector<std::string>& allFiles,
+                            std::stringstream& fileIncludePatternsStream,
+                            std::set<std::string>& folderIncludePatternsSet)
+{
   // Convert
   const char* cmakeRoot = mf->GetDefinition("CMAKE_ROOT");
   for (std::vector<std::string>::const_iterator jt = allFiles.begin();
@@ -205,47 +309,15 @@ void cmExtraSublimeTextGenerator
         }
       }
     }
-  // Write the folder entries to the project file
-  const std::string &homeRelative = cmSystemTools::RelativePath(
-                     lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
-                     lgs[0]->GetMakefile()->GetHomeDirectory());
-  fout << "{\n";
-  fout << "\t\"folders\":\n\t[\n\t";
-  fout << "\t{\n\t\t\t\"path\": \"" << homeRelative << "\",\n";
-  fout << "\t\t\t\"folder_include_patterns\": [";
-  std::set<std::string>::const_iterator folderIter =
-          folderIncludePatternsSet.begin();
-  while (folderIter != folderIncludePatternsSet.end())
-    {
-    fout << "\"" << *folderIter << "\"";
-    folderIter++;
-    if (folderIter != folderIncludePatternsSet.end())
-      {
-        fout << ", ";
-      }
-    }
-  fout << "],\n";
-  fout << "\t\t\t\"file_include_patterns\": [" <<
-          fileIncludePatternsStream.str() << "]\n";
-  fout << "\t\t},\n\t";
-  // In order for SublimeClang's path resolution to work, the directory that
-  // contains the sublime-project file must be included here. We just ensure
-  // that no files or subfolders are included
-  fout << "\t{\n\t\t\t\"path\": \"./\",\n";
-  fout << "\t\t\t\"folder_exclude_patterns\": [\"*\"],\n";
-  fout << "\t\t\t\"file_exclude_patterns\": [\"*\"]\n";
-  fout << "\t\t}\n\t";
-  // End of the folders section
-  fout << "]";
-
-  // Write the beginning of the build systems section to the project file
-  fout << ",\n\t\"build_systems\":\n\t[\n\t";
+}
 
-  // Set of include directories over all targets (sublime text/sublimeclang
-  // doesn't currently support these settings per build system, only project
-  // wide
-  std::set<std::string> includeDirs;
-  std::set<std::string> defines;
+void cmExtraSublimeTextGenerator::
+  AppendAllTargets(const std::vector<cmLocalGenerator*>& lgs,
+                   const cmMakefile* mf,
+                   cmGeneratedFileStream& fout,
+                   std::set<std::string>& includeDirs,
+                   std::set<std::string>& defines)
+{
   std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
   std::string compiler = "";
   this->AppendTarget(fout, "all", 0, make.c_str(), mf, compiler.c_str(),
@@ -334,49 +406,6 @@ void cmExtraSublimeTextGenerator
         }
       }
     }
-  // End of build_systems
-  fout << "\n\t]";
-
-  // Write the settings section with sublimeclang options
-  fout << ",\n\t\"settings\":\n\t{\n\t";
-  fout << "\t\"sublimeclang_options\":\n\t\t[\n\t\t";
-  std::set<std::string>::const_iterator stringSetIter = includeDirs.begin();
-  while (stringSetIter != includeDirs.end())
-    {
-    const std::string &includeDir = *stringSetIter;
-    const std::string &relative = cmSystemTools::RelativePath(
-                       lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
-                       includeDir.c_str());
-    // It appears that a relative path to the sublime-project file doesn't
-    // always work. So we use ${folder:${project_path:<project_filename>}}
-    // that SublimeClang will expand to the correct path
-    fout << "\t\"-I${folder:${project_path:" << mf->GetProjectName() <<
-            ".sublime-project}}/" << relative << "\"";
-    stringSetIter++;
-    if ((stringSetIter != includeDirs.end()) || (!defines.empty()))
-      {
-      fout << ",";
-      }
-    fout << "\n\t\t";
-  }
-  stringSetIter = defines.begin();
-  while (stringSetIter != defines.end())
-    {
-    fout << "\t\"-D" << *stringSetIter << "\"";
-    stringSetIter++;
-    if (stringSetIter != defines.end())
-      {
-      fout << ",";
-      }
-    fout << "\n\t\t";
-  }
-  // End of the sublimeclang_options section
-  fout << "]\n\t";
-  // End of the settings section
-  fout << "}\n";
-
-  // End of file
-  fout << "}";
 }
 
 // Generate the build_system entry for one target
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index b2d47d9..e23e472 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -45,7 +45,22 @@ private:
 
   void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
                                 const std::string& filename);
-
+  void GetFileList(const std::vector<cmLocalGenerator*>& lgs,
+                   std::vector<std::string>& allFiles);
+  void GetFileStringAndFolderSet(const std::vector<cmLocalGenerator*>& lgs,
+                                 const cmMakefile* mf,
+                                 const std::vector<std::string>& allFiles,
+                                 std::stringstream& fileIncludePatternsStream,
+                                 std::set<std::string>&
+                                   folderIncludePatternsSet);
+  /** Appends all targets as build systems to the project file and get all
+   * include directories and compiler definitions used.
+   */
+  void AppendAllTargets(const std::vector<cmLocalGenerator*>& lgs,
+                        const cmMakefile* mf,
+                        cmGeneratedFileStream& fout,
+                        std::set<std::string>& includeDirs,
+                        std::set<std::string>& defines);
   std::string BuildMakeCommand(const std::string& make, const char* makefile,
                                const char* target);
   void AppendTarget(cmGeneratedFileStream& fout,

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6108ebba0222d9276c278175cf1ffdf8e8a74117
commit 6108ebba0222d9276c278175cf1ffdf8e8a74117
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Thu Oct 11 22:16:44 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:02:57 2013 -0500

    Changed SublimeClang include path generation to expand to absolute paths.
    
    Fixed an issue where compiler definitions for SublimeClang were not
    written to the project file.

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index d9000ca..486658d 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -227,6 +227,13 @@ void cmExtraSublimeTextGenerator
   fout << "],\n";
   fout << "\t\t\t\"file_include_patterns\": [" <<
           fileIncludePatternsStream.str() << "]\n";
+  fout << "\t\t},\n\t";
+  // In order for SublimeClang's path resolution to work, the directory that
+  // contains the sublime-project file must be included here. We just ensure
+  // that no files or subfolders are included
+  fout << "\t{\n\t\t\t\"path\": \"./\",\n";
+  fout << "\t\t\t\"folder_exclude_patterns\": [\"*\"],\n";
+  fout << "\t\t\t\"file_exclude_patterns\": [\"*\"]\n";
   fout << "\t\t}\n\t";
   // End of the folders section
   fout << "]";
@@ -340,9 +347,13 @@ void cmExtraSublimeTextGenerator
     const std::string &relative = cmSystemTools::RelativePath(
                        lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
                        includeDir.c_str());
-    fout << "\t\"-I" << relative << "\"";
+    // It appears that a relative path to the sublime-project file doesn't
+    // always work. So we use ${folder:${project_path:<project_filename>}}
+    // that SublimeClang will expand to the correct path
+    fout << "\t\"-I${folder:${project_path:" << mf->GetProjectName() <<
+            ".sublime-project}}/" << relative << "\"";
     stringSetIter++;
-    if (stringSetIter != includeDirs.end())
+    if ((stringSetIter != includeDirs.end()) || (!defines.empty()))
       {
       fout << ",";
       }
@@ -387,7 +398,7 @@ void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
                                     ->GetGeneratorTarget(target);
       std::string cdefs = gtgt->GetCompileDefinitions();
 
-      if(cdefs.empty())
+      if(!cdefs.empty())
         {
         // Expand the list.
         std::vector<std::string> defs;

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fbeaa4282b0099d16a03b77483c311bd13e54a4b
commit fbeaa4282b0099d16a03b77483c311bd13e54a4b
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Thu Oct 11 01:01:13 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:02:57 2013 -0500

    Added some support for sublimeclang_options in the generated project file.
    
    This adds -I include path flags and -D define flags for sublimeclang.
    The current problem with this is that these flags cannot be set per
    target (build_system in sublime text), it can only be set project
    wide. Currently all of the include paths and compiler definitions from
    ALL of the targets are used (with duplicates removed). This could be
    problematic in some cases (conflicting compiler definitions among targets).

diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 5cd7179..d9000ca 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -234,11 +234,17 @@ void cmExtraSublimeTextGenerator
   // Write the beginning of the build systems section to the project file
   fout << ",\n\t\"build_systems\":\n\t[\n\t";
 
+  // Set of include directories over all targets (sublime text/sublimeclang
+  // doesn't currently support these settings per build system, only project
+  // wide
+  std::set<std::string> includeDirs;
+  std::set<std::string> defines;
   std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
   std::string compiler = "";
-  this->AppendTarget(fout, "all", 0, make.c_str(), mf, compiler.c_str(), true);
+  this->AppendTarget(fout, "all", 0, make.c_str(), mf, compiler.c_str(),
+                     includeDirs, defines, true);
   this->AppendTarget(fout, "clean", 0, make.c_str(), mf, compiler.c_str(),
-                     false);
+                     includeDirs, defines, false);
 
   // add all executable and library targets and some of the GLOBAL
   // and UTILITY targets
@@ -281,7 +287,7 @@ void cmExtraSublimeTextGenerator
             {
             this->AppendTarget(fout, ti->first.c_str(), 0,
                                make.c_str(), makefile, compiler.c_str(),
-                               false);
+                               includeDirs, defines, false);
             }
           }
           break;
@@ -297,7 +303,8 @@ void cmExtraSublimeTextGenerator
             }
 
           this->AppendTarget(fout, ti->first.c_str(), 0,
-                             make.c_str(), makefile, compiler.c_str(), false);
+                             make.c_str(), makefile, compiler.c_str(),
+                             includeDirs, defines, false);
           break;
         case cmTarget::EXECUTABLE:
         case cmTarget::STATIC_LIBRARY:
@@ -306,11 +313,13 @@ void cmExtraSublimeTextGenerator
         case cmTarget::OBJECT_LIBRARY:
           {
           this->AppendTarget(fout, ti->first.c_str(), &ti->second,
-                             make.c_str(), makefile, compiler.c_str(), false);
+                             make.c_str(), makefile, compiler.c_str(),
+                             includeDirs, defines, false);
           std::string fastTarget = ti->first;
           fastTarget += "/fast";
           this->AppendTarget(fout, fastTarget.c_str(), &ti->second,
-                             make.c_str(), makefile, compiler.c_str(), false);
+                             make.c_str(), makefile, compiler.c_str(),
+                             includeDirs, defines, false);
           }
           break;
         default:
@@ -319,7 +328,41 @@ void cmExtraSublimeTextGenerator
       }
     }
   // End of build_systems
-  fout << "\n\t]\n";
+  fout << "\n\t]";
+
+  // Write the settings section with sublimeclang options
+  fout << ",\n\t\"settings\":\n\t{\n\t";
+  fout << "\t\"sublimeclang_options\":\n\t\t[\n\t\t";
+  std::set<std::string>::const_iterator stringSetIter = includeDirs.begin();
+  while (stringSetIter != includeDirs.end())
+    {
+    const std::string &includeDir = *stringSetIter;
+    const std::string &relative = cmSystemTools::RelativePath(
+                       lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
+                       includeDir.c_str());
+    fout << "\t\"-I" << relative << "\"";
+    stringSetIter++;
+    if (stringSetIter != includeDirs.end())
+      {
+      fout << ",";
+      }
+    fout << "\n\t\t";
+  }
+  stringSetIter = defines.begin();
+  while (stringSetIter != defines.end())
+    {
+    fout << "\t\"-D" << *stringSetIter << "\"";
+    stringSetIter++;
+    if (stringSetIter != defines.end())
+      {
+      fout << ",";
+      }
+    fout << "\n\t\t";
+  }
+  // End of the sublimeclang_options section
+  fout << "]\n\t";
+  // End of the settings section
+  fout << "}\n";
 
   // End of file
   fout << "}";
@@ -332,8 +375,72 @@ void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
                                               const char* make,
                                               const cmMakefile* makefile,
                                               const char* compiler,
+                                              std::set<std::string>&
+                                                              includeDirs,
+                                              std::set<std::string>& defines,
                                               bool firstTarget)
 {
+  if (target != 0)
+    {
+      // the compilerdefines for this target
+      cmGeneratorTarget *gtgt = this->GlobalGenerator
+                                    ->GetGeneratorTarget(target);
+      std::string cdefs = gtgt->GetCompileDefinitions();
+
+      if(cdefs.empty())
+        {
+        // Expand the list.
+        std::vector<std::string> defs;
+        cmSystemTools::ExpandListArgument(cdefs.c_str(), defs);
+        for(std::vector<std::string>::const_iterator di = defs.begin();
+            di != defs.end(); ++di)
+          {
+          cmXMLSafe safedef(di->c_str());
+          defines.insert(safedef.str());
+          }
+        }
+
+      // the include directories for this target
+      std::vector<std::string> includes;
+      target->GetMakefile()->GetLocalGenerator()->
+        GetIncludeDirectories(includes, gtgt);
+      for(std::vector<std::string>::const_iterator dirIt=includes.begin();
+          dirIt != includes.end();
+          ++dirIt)
+        {
+        includeDirs.insert(*dirIt);
+        }
+
+      std::string systemIncludeDirs = makefile->GetSafeDefinition(
+                                "CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
+      if (!systemIncludeDirs.empty())
+        {
+        std::vector<std::string> dirs;
+        cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs);
+        for(std::vector<std::string>::const_iterator dirIt=dirs.begin();
+            dirIt != dirs.end();
+            ++dirIt)
+          {
+          includeDirs.insert(*dirIt);
+          }
+        }
+
+      systemIncludeDirs = makefile->GetSafeDefinition(
+                            "CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
+      if (!systemIncludeDirs.empty())
+        {
+        std::vector<std::string> dirs;
+        cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs);
+        for(std::vector<std::string>::const_iterator dirIt=dirs.begin();
+            dirIt != dirs.end();
+            ++dirIt)
+          {
+          includeDirs.insert(*dirIt);
+          }
+        }
+    }
+
+  // Write out the build_system data for this target
   std::string makefileName = makefile->GetStartOutputDirectory();
   makefileName += "/Makefile";
   if (!firstTarget)
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index 231cc90..b2d47d9 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -54,7 +54,8 @@ private:
                     const char* make,
                     const cmMakefile* makefile,
                     const char* compiler,
-                    bool firstTarget = true);
+                    std::set<std::string>& includeDirs,
+                    std::set<std::string>& defines, bool firstTarget);
 
 };
 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8f4d36439bafa6fd96f6ed35fd1898473f56e74d
commit 8f4d36439bafa6fd96f6ed35fd1898473f56e74d
Author:     Morné Chamberlain <thefreeman.za at gmail.com>
AuthorDate: Thu Oct 11 00:01:48 2012 +0200
Commit:     Robert Maynard <robert.maynard at kitware.com>
CommitDate: Mon Jan 21 09:02:57 2013 -0500

    Added a generator for Sublime Text 2 project files.
    
    The generator adds all list and source files for each defined
    project. The generated project files also include build_system
    entries that run the platform-specific make on the generated
    Makefiles. A build_system entry is created for each target
    that was defined in the CMakeLists.txt files.
    
    At the moment this has only been tested with C/C++ projects.

diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index 675f576..7808f23 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -184,6 +184,8 @@ set(SRCS
   cmExtraCodeBlocksGenerator.h
   cmExtraEclipseCDT4Generator.cxx
   cmExtraEclipseCDT4Generator.h
+  cmExtraSublimeTextGenerator.cxx
+  cmExtraSublimeTextGenerator.h
   cmFileTimeComparison.cxx
   cmFileTimeComparison.h
   cmGeneratedFileStream.cxx
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
new file mode 100644
index 0000000..5cd7179
--- /dev/null
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -0,0 +1,390 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2004-2009 Kitware, Inc.
+  Copyright 2004 Alexander Neundorf (neundorf at kde.org)
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+#include "cmExtraSublimeTextGenerator.h"
+#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLocalUnixMakefileGenerator3.h"
+#include "cmMakefile.h"
+#include "cmake.h"
+#include "cmSourceFile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmTarget.h"
+#include "cmSystemTools.h"
+#include "cmXMLSafe.h"
+
+#include <cmsys/SystemTools.hxx>
+
+#if defined(_WIN32)
+#  define PATH_SEP "\\"
+#else
+#  define PATH_SEP "/"
+#endif
+
+/* Some useful URLs:
+Homepage:
+http://www.sublimetext.com/
+
+File format docs:
+http://www.sublimetext.com/docs/2/projects.html
+http://sublimetext.info/docs/en/reference/build_systems.html
+*/
+
+//----------------------------------------------------------------------------
+void cmExtraSublimeTextGenerator
+::GetDocumentation(cmDocumentationEntry& entry, const char*) const
+{
+  entry.Name = this->GetName();
+  entry.Brief = "Generates Sublime Text 2 project files.";
+  entry.Full =
+    "Project files for Sublime Text 2 will be created in the top directory "
+    "and in every subdirectory which features a CMakeLists.txt file "
+    "containing a PROJECT() call. "
+    "Additionally a hierarchy of makefiles is generated into the "
+    "build tree.  The appropriate make program can build the project through "
+    "the default make target.  A \"make install\" target is also provided.";
+}
+
+cmExtraSublimeTextGenerator::cmExtraSublimeTextGenerator()
+:cmExternalMakefileProjectGenerator()
+{
+#if defined(_WIN32)
+  this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
+  this->SupportedGlobalGenerators.push_back("NMake Makefiles");
+// disable until somebody actually tests it:
+//  this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
+#endif
+  this->SupportedGlobalGenerators.push_back("Ninja");
+  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<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
+       it = this->GlobalGenerator->GetProjectMap().begin();
+      it!= this->GlobalGenerator->GetProjectMap().end();
+      ++it)
+    {
+    // create a project file
+    this->CreateProjectFile(it->second);
+    }
+}
+
+
+/* create the project file */
+void cmExtraSublimeTextGenerator::CreateProjectFile(
+                                     const std::vector<cmLocalGenerator*>& lgs)
+{
+  const cmMakefile* mf=lgs[0]->GetMakefile();
+  std::string outputDir=mf->GetStartOutputDirectory();
+  std::string projectName=mf->GetProjectName();
+
+  std::string filename=outputDir+"/";
+  filename+=projectName+".sublime-project";
+
+  this->CreateNewProjectFile(lgs, filename);
+}
+
+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;
+    }
+
+  // A set of folders to include in the project
+  std::set<std::string> folderIncludePatternsSet;
+  // Collect all files, this includes source files and list files
+  std::vector<std::string> allFiles;
+  std::stringstream fileIncludePatternsStream;
+  for (std::vector<cmLocalGenerator *>::const_iterator
+       it = lgs.begin();
+       it != lgs.end();
+       ++it)
+    {
+    cmMakefile* makefile=(*it)->GetMakefile();
+    // Add list files
+    const std::vector<std::string> & listFiles =
+                                            makefile->GetListFiles();
+    allFiles.insert(allFiles.end(), listFiles.begin(), listFiles.end());
+    // Add source files
+    cmTargets& targets=makefile->GetTargets();
+    for (cmTargets::iterator ti = targets.begin();
+         ti != targets.end(); ti++)
+      {
+      switch(ti->second.GetType())
+        {
+        case cmTarget::EXECUTABLE:
+        case cmTarget::STATIC_LIBRARY:
+        case cmTarget::SHARED_LIBRARY:
+        case cmTarget::MODULE_LIBRARY:
+        case cmTarget::OBJECT_LIBRARY:
+        case cmTarget::UTILITY: // can have sources since 2.6.3
+          {
+          const std::vector<cmSourceFile*>&sources=ti->second.GetSourceFiles();
+          for (std::vector<cmSourceFile*>::const_iterator si=sources.begin();
+               si!=sources.end(); si++)
+            {
+            // don't add source files which have the GENERATED property set:
+            if ((*si)->GetPropertyAsBool("GENERATED"))
+              {
+              continue;
+              }
+              allFiles.push_back((*si)->GetFullPath());
+            }
+          }
+        default:  // intended fallthrough
+           break;
+        }
+      }
+    }
+
+  // Convert
+  const char* cmakeRoot = mf->GetDefinition("CMAKE_ROOT");
+  for (std::vector<std::string>::const_iterator jt = allFiles.begin();
+       jt != allFiles.end();
+       ++jt)
+    {
+    // don't put cmake's own files into the project (#12110):
+    if (jt->find(cmakeRoot) == 0)
+      {
+      continue;
+      }
+
+    const std::string &relative = cmSystemTools::RelativePath(
+                       lgs[0]->GetMakefile()->GetHomeDirectory(),
+                       jt->c_str());
+    // Split filename from path
+    std::string fileName = cmSystemTools::GetFilenameName(relative);
+    std::string path = "";
+    if (fileName.length() < relative.length())
+      {
+      path = relative.substr(0, relative.length() - fileName.length() - 1);
+      }
+
+    // We don't want paths with CMakeFiles in them
+    if (relative.find("CMakeFiles") == std::string::npos)
+      {
+      if (fileIncludePatternsStream.tellp() > 0)
+        {
+          fileIncludePatternsStream << ", ";
+        }
+      fileIncludePatternsStream << "\"" << relative << "\"";
+      if ((!path.empty()) && (folderIncludePatternsSet.find(path) ==
+                              folderIncludePatternsSet.end()))
+        {
+        folderIncludePatternsSet.insert(path);
+        std::string::size_type splitIndex = path.rfind(PATH_SEP);
+        std::string splitPath = path;
+        while (splitIndex != std::string::npos)
+          {
+          splitPath = splitPath.substr(0, splitIndex);
+          if ((splitPath.empty()) ||
+                  (folderIncludePatternsSet.insert(splitPath).second == false))
+            {
+            // If the path is already in the set then all of its
+            // parents are as well
+            break;
+            }
+          splitIndex = splitPath.rfind(PATH_SEP);
+          }
+        }
+      }
+    }
+  // Write the folder entries to the project file
+  const std::string &homeRelative = cmSystemTools::RelativePath(
+                     lgs[0]->GetMakefile()->GetHomeOutputDirectory(),
+                     lgs[0]->GetMakefile()->GetHomeDirectory());
+  fout << "{\n";
+  fout << "\t\"folders\":\n\t[\n\t";
+  fout << "\t{\n\t\t\t\"path\": \"" << homeRelative << "\",\n";
+  fout << "\t\t\t\"folder_include_patterns\": [";
+  std::set<std::string>::const_iterator folderIter =
+          folderIncludePatternsSet.begin();
+  while (folderIter != folderIncludePatternsSet.end())
+    {
+    fout << "\"" << *folderIter << "\"";
+    folderIter++;
+    if (folderIter != folderIncludePatternsSet.end())
+      {
+        fout << ", ";
+      }
+    }
+  fout << "],\n";
+  fout << "\t\t\t\"file_include_patterns\": [" <<
+          fileIncludePatternsStream.str() << "]\n";
+  fout << "\t\t}\n\t";
+  // End of the folders section
+  fout << "]";
+
+  // Write the beginning of the build systems section to the project file
+  fout << ",\n\t\"build_systems\":\n\t[\n\t";
+
+  std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+  std::string compiler = "";
+  this->AppendTarget(fout, "all", 0, make.c_str(), mf, compiler.c_str(), true);
+  this->AppendTarget(fout, "clean", 0, make.c_str(), mf, compiler.c_str(),
+                     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();
+    cmTargets& targets=makefile->GetTargets();
+    for (cmTargets::iterator ti = targets.begin();
+         ti != targets.end(); ti++)
+      {
+      switch(ti->second.GetType())
+        {
+        case cmTarget::GLOBAL_TARGET:
+          {
+          bool insertTarget = false;
+          // Only add the global targets from CMAKE_BINARY_DIR,
+          // not from the subdirs
+          if (strcmp(makefile->GetStartOutputDirectory(),
+                     makefile->GetHomeOutputDirectory())==0)
+            {
+            insertTarget = true;
+            // only add the "edit_cache" target if it's not ccmake, because
+            // this will not work within the IDE
+            if (ti->first == "edit_cache")
+              {
+              const char* editCommand = makefile->GetDefinition
+                                                        ("CMAKE_EDIT_COMMAND");
+              if (editCommand == 0)
+                {
+                insertTarget = false;
+                }
+              else if (strstr(editCommand, "ccmake")!=NULL)
+                {
+                insertTarget = false;
+                }
+              }
+            }
+          if (insertTarget)
+            {
+            this->AppendTarget(fout, ti->first.c_str(), 0,
+                               make.c_str(), makefile, compiler.c_str(),
+                               false);
+            }
+          }
+          break;
+        case cmTarget::UTILITY:
+          // Add all utility targets, except the Nightly/Continuous/
+          // Experimental-"sub"targets as e.g. NightlyStart
+          if (((ti->first.find("Nightly")==0)   &&(ti->first!="Nightly"))
+             || ((ti->first.find("Continuous")==0)&&(ti->first!="Continuous"))
+             || ((ti->first.find("Experimental")==0)
+                                               && (ti->first!="Experimental")))
+            {
+            break;
+            }
+
+          this->AppendTarget(fout, ti->first.c_str(), 0,
+                             make.c_str(), makefile, compiler.c_str(), false);
+          break;
+        case cmTarget::EXECUTABLE:
+        case cmTarget::STATIC_LIBRARY:
+        case cmTarget::SHARED_LIBRARY:
+        case cmTarget::MODULE_LIBRARY:
+        case cmTarget::OBJECT_LIBRARY:
+          {
+          this->AppendTarget(fout, ti->first.c_str(), &ti->second,
+                             make.c_str(), makefile, compiler.c_str(), false);
+          std::string fastTarget = ti->first;
+          fastTarget += "/fast";
+          this->AppendTarget(fout, fastTarget.c_str(), &ti->second,
+                             make.c_str(), makefile, compiler.c_str(), false);
+          }
+          break;
+        default:
+          break;
+        }
+      }
+    }
+  // End of build_systems
+  fout << "\n\t]\n";
+
+  // End of file
+  fout << "}";
+}
+
+// Generate the build_system entry for one target
+void cmExtraSublimeTextGenerator::AppendTarget(cmGeneratedFileStream& fout,
+                                              const char* targetName,
+                                              cmTarget* target,
+                                              const char* make,
+                                              const cmMakefile* makefile,
+                                              const char* compiler,
+                                              bool firstTarget)
+{
+  std::string makefileName = makefile->GetStartOutputDirectory();
+  makefileName += "/Makefile";
+  if (!firstTarget)
+    {
+    fout << ",\n\t";
+    }
+  fout << "\t{\n\t\t\t\"name\": \"" << makefile->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}";
+}
+
+// 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 char* target)
+{
+  std::string command = "\"";
+  command += make + "\"";
+  if (strcmp(this->GlobalGenerator->GetName(), "NMake Makefiles")==0)
+    {
+    std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
+    command += ", \"/NOLOGO\", \"/f\", \"";
+    command += makefileName + "\"";
+    command += ", \"VERBOSE=1\", \"";
+    command += target;
+    command += "\"";
+    }
+  else if (strcmp(this->GlobalGenerator->GetName(), "MinGW Makefiles")==0)
+    {
+    // no escaping of spaces in this case, see
+    // http://public.kitware.com/Bug/view.php?id=10014
+    std::string makefileName = makefile;
+    command += ", \"-f\", \"";
+    command += makefileName + "\"";
+    command += ", \"VERBOSE=1\", \"";
+    command += target;
+    command += "\"";
+    }
+  else
+    {
+    std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
+    command += ", \"-f\", \"";
+    command += makefileName + "\"";
+    command += ", \"VERBOSE=1\", \"";
+    command += target;
+    command += "\"";
+    }
+  return command;
+}
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
new file mode 100644
index 0000000..231cc90
--- /dev/null
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -0,0 +1,61 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2004-2009 Kitware, Inc.
+  Copyright 2004 Alexander Neundorf (neundorf at kde.org)
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+#ifndef cmExtraSublimeTextGenerator_h
+#define cmExtraSublimeTextGenerator_h
+
+#include "cmExternalMakefileProjectGenerator.h"
+
+class cmLocalGenerator;
+class cmMakefile;
+class cmTarget;
+class cmGeneratedFileStream;
+
+/** \class cmExtraSublimeTextGenerator
+ * \brief Write Sublime Text 2 project files for Makefile based projects
+ */
+class cmExtraSublimeTextGenerator : public cmExternalMakefileProjectGenerator
+{
+public:
+  cmExtraSublimeTextGenerator();
+
+  virtual const char* GetName() const
+                        { return cmExtraSublimeTextGenerator::GetActualName();}
+  static const char* GetActualName()
+                        { return "SublimeText2";}
+  static cmExternalMakefileProjectGenerator* New()
+                                    { return new cmExtraSublimeTextGenerator; }
+  /** Get the documentation entry for this generator.  */
+  virtual void GetDocumentation(cmDocumentationEntry& entry,
+                                const char* fullName) const;
+
+  virtual void Generate();
+private:
+
+  void CreateProjectFile(const std::vector<cmLocalGenerator*>& lgs);
+
+  void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
+                                const std::string& filename);
+
+  std::string BuildMakeCommand(const std::string& make, const char* makefile,
+                               const char* target);
+  void AppendTarget(cmGeneratedFileStream& fout,
+                    const char* targetName,
+                    cmTarget* target,
+                    const char* make,
+                    const cmMakefile* makefile,
+                    const char* compiler,
+                    bool firstTarget = true);
+
+};
+
+#endif
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 2eecfba..df2852d 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -88,6 +88,7 @@
 #if !defined(CMAKE_BOOT_MINGW)
 # include "cmExtraCodeBlocksGenerator.h"
 #endif
+#include "cmExtraSublimeTextGenerator.h"
 
 #ifdef CMAKE_USE_KDEVELOP
 # include "cmGlobalKdevelopGenerator.h"
@@ -1856,6 +1857,8 @@ void cmake::AddDefaultExtraGenerators()
 
   this->AddExtraGenerator(cmExtraCodeBlocksGenerator::GetActualName(),
                           &cmExtraCodeBlocksGenerator::New);
+  this->AddExtraGenerator(cmExtraSublimeTextGenerator::GetActualName(),
+                          &cmExtraSublimeTextGenerator::New);
 
 #ifdef CMAKE_USE_ECLIPSE
   this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(),

-----------------------------------------------------------------------

Summary of changes:
 Source/CMakeLists.txt                  |    2 +
 Source/cmExtraSublimeTextGenerator.cxx |  501 ++++++++++++++++++++++++++++++++
 Source/cmExtraSublimeTextGenerator.h   |   89 ++++++
 Source/cmake.cxx                       |    3 +
 4 files changed, 595 insertions(+), 0 deletions(-)
 create mode 100644 Source/cmExtraSublimeTextGenerator.cxx
 create mode 100644 Source/cmExtraSublimeTextGenerator.h


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list