From b8457ad18b7eac2998fdd29fbc295c1dadbbba42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Thu, 11 Oct 2012 00:01:48 +0200 Subject: 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. --- Source/CMakeLists.txt | 2 + Source/cmExtraSublimeTextGenerator.cxx | 390 +++++++++++++++++++++++++++++++++ Source/cmExtraSublimeTextGenerator.h | 61 ++++++ Source/cmake.cxx | 3 + 4 files changed, 456 insertions(+) create mode 100644 Source/cmExtraSublimeTextGenerator.cxx create mode 100644 Source/cmExtraSublimeTextGenerator.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 8bf6c40..8e842a9 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@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 + +#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 >::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& 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& 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 folderIncludePatternsSet; + // Collect all files, this includes source files and list files + std::vector allFiles; + std::stringstream fileIncludePatternsStream; + for (std::vector::const_iterator + it = lgs.begin(); + it != lgs.end(); + ++it) + { + cmMakefile* makefile=(*it)->GetMakefile(); + // Add list files + const std::vector & 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&sources=ti->second.GetSourceFiles(); + for (std::vector::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::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::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::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@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& lgs); + + void CreateNewProjectFile(const std::vector& 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 0123427..3a25605 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -94,6 +94,7 @@ #if !defined(CMAKE_BOOT_MINGW) # include "cmExtraCodeBlocksGenerator.h" #endif +#include "cmExtraSublimeTextGenerator.h" #ifdef CMAKE_USE_KDEVELOP # include "cmGlobalKdevelopGenerator.h" @@ -1847,6 +1848,8 @@ void cmake::AddDefaultExtraGenerators() this->AddExtraGenerator(cmExtraCodeBlocksGenerator::GetActualName(), &cmExtraCodeBlocksGenerator::New); + this->AddExtraGenerator(cmExtraSublimeTextGenerator::GetActualName(), + &cmExtraSublimeTextGenerator::New); #ifdef CMAKE_USE_ECLIPSE this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(), -- cgit v0.12 From 32f79024ba18df5016eb34c9f5fcc8708eaca83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Thu, 11 Oct 2012 01:01:13 +0200 Subject: 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). --- Source/cmExtraSublimeTextGenerator.cxx | 121 +++++++++++++++++++++++++++++++-- Source/cmExtraSublimeTextGenerator.h | 3 +- 2 files changed, 116 insertions(+), 8 deletions(-) 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 includeDirs; + std::set 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::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& + includeDirs, + std::set& 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 defs; + cmSystemTools::ExpandListArgument(cdefs.c_str(), defs); + for(std::vector::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 includes; + target->GetMakefile()->GetLocalGenerator()-> + GetIncludeDirectories(includes, gtgt); + for(std::vector::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 dirs; + cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs); + for(std::vector::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 dirs; + cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs); + for(std::vector::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& includeDirs, + std::set& defines, bool firstTarget); }; -- cgit v0.12 From 75b060ff209c02a1d709fa834a853f4750427cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Thu, 11 Oct 2012 22:16:44 +0200 Subject: 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. --- Source/cmExtraSublimeTextGenerator.cxx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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:}} + // 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 defs; -- cgit v0.12 From 4d585b109d5f5984d285a82c5582f9b585e9792b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Thu, 11 Oct 2012 22:53:40 +0200 Subject: Cleaned up the Sublime Text 2 Generator code a bit. --- Source/cmExtraSublimeTextGenerator.cxx | 199 +++++++++++++++++++-------------- Source/cmExtraSublimeTextGenerator.h | 17 ++- 2 files changed, 130 insertions(+), 86 deletions(-) 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 folderIncludePatternsSet; // Collect all files, this includes source files and list files std::vector allFiles; + GetFileList(lgs, allFiles); + // A set of folders to include in the project + std::set 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::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 includeDirs; + std::set 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::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:}} + // 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& lgs, + std::vector& allFiles) +{ for (std::vector::const_iterator it = lgs.begin(); it != lgs.end(); @@ -152,7 +248,15 @@ void cmExtraSublimeTextGenerator } } } +} +void cmExtraSublimeTextGenerator:: + GetFileStringAndFolderSet(const std::vector& lgs, + const cmMakefile* mf, + const std::vector& allFiles, + std::stringstream& fileIncludePatternsStream, + std::set& folderIncludePatternsSet) +{ // Convert const char* cmakeRoot = mf->GetDefinition("CMAKE_ROOT"); for (std::vector::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::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 includeDirs; - std::set defines; +void cmExtraSublimeTextGenerator:: + AppendAllTargets(const std::vector& lgs, + const cmMakefile* mf, + cmGeneratedFileStream& fout, + std::set& includeDirs, + std::set& 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::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:}} - // 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& lgs, const std::string& filename); - + void GetFileList(const std::vector& lgs, + std::vector& allFiles); + void GetFileStringAndFolderSet(const std::vector& lgs, + const cmMakefile* mf, + const std::vector& allFiles, + std::stringstream& fileIncludePatternsStream, + std::set& + 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& lgs, + const cmMakefile* mf, + cmGeneratedFileStream& fout, + std::set& includeDirs, + std::set& defines); std::string BuildMakeCommand(const std::string& make, const char* makefile, const char* target); void AppendTarget(cmGeneratedFileStream& fout, -- cgit v0.12 From ef8aa081a164817d1d78b6df8ebcf23e421d422f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Sat, 13 Oct 2012 11:20:09 +0200 Subject: Fixed support for the Ninja build system. --- Source/cmExtraSublimeTextGenerator.cxx | 41 +++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) 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& folderIncludePatternsSet) { - // Convert const char* cmakeRoot = mf->GetDefinition("CMAKE_ROOT"); for (std::vector::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\", \""; -- cgit v0.12 From cd76ec3e22f299f03e34db3deee5e835613af315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Sat, 13 Oct 2012 12:54:51 +0200 Subject: Added and cleaned up some comments. --- Source/cmExtraSublimeTextGenerator.cxx | 3 --- Source/cmExtraSublimeTextGenerator.h | 13 +++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) 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& 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& lgs, std::vector& 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& 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& lgs, std::vector& 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& lgs, const cmMakefile* mf, const std::vector& allFiles, @@ -61,8 +68,14 @@ private: cmGeneratedFileStream& fout, std::set& includeDirs, std::set& 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, -- cgit v0.12 From 6742ee747f5d55bef73bed2c70611e8542f28f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Sun, 14 Oct 2012 10:46:29 +0200 Subject: 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. --- Source/cmExtraSublimeTextGenerator.cxx | 148 ++------------------------------- Source/cmExtraSublimeTextGenerator.h | 15 ---- 2 files changed, 9 insertions(+), 154 deletions(-) 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 -#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 allFiles; - GetFileList(lgs, allFiles); - // A set of folders to include in the project - std::set 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::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& lgs, - std::vector& allFiles) -{ - for (std::vector::const_iterator - it = lgs.begin(); - it != lgs.end(); - ++it) - { - cmMakefile* makefile=(*it)->GetMakefile(); - // Add list files - const std::vector & 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&sources=ti->second.GetSourceFiles(); - for (std::vector::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& lgs, - const cmMakefile* mf, - const std::vector& allFiles, - std::stringstream& fileIncludePatternsStream, - std::set& folderIncludePatternsSet) -{ - const char* cmakeRoot = mf->GetDefinition("CMAKE_ROOT"); - for (std::vector::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& 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& 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& lgs, - std::vector& 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& lgs, - const cmMakefile* mf, - const std::vector& allFiles, - std::stringstream& fileIncludePatternsStream, - std::set& - folderIncludePatternsSet); /** Appends all targets as build systems to the project file and get all * include directories and compiler definitions used. */ -- cgit v0.12 From 9657acb55a62f2e37a0378d01e93ab2ee4d151be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Sun, 14 Oct 2012 12:11:32 +0200 Subject: The generator no longer generates absolute paths to the ninja.build/Makefiles. --- Source/cmExtraSublimeTextGenerator.cxx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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) { -- cgit v0.12 From 44f35f7824c0d97d575ab566a1f9fd1c83be8fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Sun, 14 Oct 2012 14:06:20 +0200 Subject: 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. --- Source/cmDocumentVariables.cxx | 9 +++++++++ Source/cmExtraSublimeTextGenerator.cxx | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx index 8db0e8f..6232162 100644 --- a/Source/cmDocumentVariables.cxx +++ b/Source/cmDocumentVariables.cxx @@ -896,6 +896,15 @@ void cmDocumentVariables::DefineVariables(cmake* cm) " script, it may get fatal error messages from the script.",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 cm->DefineProperty 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::const_iterator stringSetIter = includeDirs.begin(); while (stringSetIter != includeDirs.end()) -- cgit v0.12 From 9cd3e7071f1769eb6bd751a501d36c6130019a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Sun, 14 Oct 2012 17:37:51 +0200 Subject: 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. --- Source/cmExtraSublimeTextGenerator.cxx | 40 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) 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"; -- cgit v0.12 From 8670cbe1660acbb8abc638e29ed60a2e27c0716a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Thu, 18 Oct 2012 22:54:19 +0200 Subject: 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. --- Source/cmExtraSublimeTextGenerator.cxx | 57 ++++++++++++++++++++++++---------- Source/cmExtraSublimeTextGenerator.h | 6 ++-- 2 files changed, 44 insertions(+), 19 deletions(-) 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 &defines) +{ + std::vector defs; + cmSystemTools::ExpandListArgument(value, defs); + for(std::vector::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 defs; - cmSystemTools::ExpandListArgument(cdefs.c_str(), defs); - for(std::vector::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 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& includeDirs, std::set& defines, bool firstTarget); - + /** Extracts -D compile flags from a variable */ + void ExtractDefines(const char* value, bool check, + std::set &defines); }; #endif -- cgit v0.12 From 90bcb77956464b53aaf2ce8d17b2a878f74ce27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Sun, 4 Nov 2012 16:15:04 +0200 Subject: 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. --- Source/cmExtraSublimeTextGenerator.cxx | 36 +++++++++++++++++++--------------- Source/cmExtraSublimeTextGenerator.h | 9 ++++++--- 2 files changed, 26 insertions(+), 19 deletions(-) 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:}} // 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 &defines) + ExtractFlags(const char* value, const std::string& flag, + std::set &defines) { + std::string::size_type flagLength = flag.length(); std::vector defs; cmSystemTools::ExpandListArgument(value, defs); for(std::vector::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 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& includeDirs, std::set& defines, bool firstTarget); - /** Extracts -D compile flags from a variable */ - void ExtractDefines(const char* value, bool check, - std::set &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 &defines); }; #endif -- cgit v0.12 From 5b2aa3dd9af903e7aae0a252d2119847ceac4aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Wed, 7 Nov 2012 21:45:07 +0200 Subject: SublimeText2 Gen: Fixed the issue where include directory flags used -D --- Source/cmExtraSublimeTextGenerator.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 includes; target->GetMakefile()->GetLocalGenerator()-> -- cgit v0.12 From 304b885d365b5814838e3c595bc17342553d3b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Sun, 11 Nov 2012 22:07:49 +0200 Subject: 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. --- Source/cmExtraSublimeTextGenerator.cxx | 397 ++++++++++++++++++++------------- Source/cmExtraSublimeTextGenerator.h | 26 ++- 2 files changed, 263 insertions(+), 160 deletions(-) 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 includeDirs; - std::set 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::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:}} - // 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& flags = iter->second; + fout << "\t\"" << sourceFilePath << "\":\n\t[\n\t"; + std::vector::const_iterator flagsEnd = flags.end(); + for (std::vector::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& lgs, const cmMakefile* mf, cmGeneratedFileStream& fout, - std::set& includeDirs, - std::set& 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 &defines) -{ - std::string::size_type flagLength = flag.length(); - std::vector defs; - cmSystemTools::ExpandListArgument(value, defs); - for(std::vector::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& - includeDirs, - std::set& 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 includes; - target->GetMakefile()->GetLocalGenerator()-> - GetIncludeDirectories(includes, gtgt); - for(std::vector::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 dirs; - cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs); - for(std::vector::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 const& sourceFiles = target->GetSourceFiles(); + std::vector::const_iterator sourceFilesEnd = + sourceFiles.end(); + for (std::vector::const_iterator iter = + sourceFiles.begin(); iter != sourceFilesEnd; ++iter) { - std::vector dirs; - cmSystemTools::ExpandListArgument(systemIncludeDirs.c_str(), dirs); - for(std::vector::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())).first; + } + std::vector& 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 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 args; + cmSystemTools:: + ParseWindowsCommandLine(gtgt->GetProperty("COMPILE_FLAGS"), args); + for(std::vector::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 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 > MapSourceFileFlags; cmExtraSublimeTextGenerator(); virtual const char* GetName() const @@ -45,14 +48,15 @@ private: void CreateNewProjectFile(const std::vector& 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& lgs, const cmMakefile* mf, cmGeneratedFileStream& fout, - std::set& includeDirs, - std::set& 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& includeDirs, - std::set& 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 &defines); + std::string ComputeFlagsForObject(cmSourceFile *source, + cmLocalGenerator* lg, + cmTarget *target, + cmGeneratorTarget* gtgt); + + std::string ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg, + cmTarget *target, cmGeneratorTarget* gtgt); }; #endif -- cgit v0.12 From 089d9ccdce530ebd08dfc4681833cefeff4a7eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morn=C3=A9=20Chamberlain?= Date: Sat, 24 Nov 2012 20:19:35 +0200 Subject: 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. --- Source/cmExtraSublimeTextGenerator.cxx | 29 ++++++++++++++++++++++++++++- Source/cmExtraSublimeTextGenerator.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) 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& 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 -- cgit v0.12 From da0898e0a2f01cfbc5f2a1061ea94662fd3e455e Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 23 Jan 2013 17:26:35 -0500 Subject: Correct missing parameter to CMP0018Flags call. --- Source/cmExtraSublimeTextGenerator.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. { -- cgit v0.12 From 4760eade425e8e294ac9400785ffce70912d5b43 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 6 Feb 2013 13:31:44 -0500 Subject: 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. --- Source/cmDocumentVariables.cxx | 8 --- Source/cmExtraSublimeTextGenerator.cxx | 102 ++------------------------------- Source/cmExtraSublimeTextGenerator.h | 4 +- 3 files changed, 5 insertions(+), 109 deletions(-) diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx index 579f77f..08b3ef1 100644 --- a/Source/cmDocumentVariables.cxx +++ b/Source/cmDocumentVariables.cxx @@ -904,14 +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& flags = iter->second; - fout << "\t\"" << sourceFilePath << "\":\n\t[\n\t"; - std::vector::const_iterator flagsEnd = flags.end(); - for (std::vector::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& 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& 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. */ -- cgit v0.12 From f616ff2c25e9902ed1cffc15f19d9299b83cba5a Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 11 Feb 2013 17:23:02 -0500 Subject: Update generator to use new cmGeneratorTarget api. --- Source/cmExtraSublimeTextGenerator.cxx | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index ef29329..5431401 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -11,14 +11,16 @@ See the License for more information. ============================================================================*/ #include "cmExtraSublimeTextGenerator.h" +#include "cmake.h" +#include "cmGeneratedFileStream.h" +#include "cmGeneratorTarget.h" #include "cmGlobalUnixMakefileGenerator3.h" +#include "cmLocalGenerator.h" #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" -#include "cmake.h" #include "cmSourceFile.h" -#include "cmGeneratedFileStream.h" -#include "cmTarget.h" #include "cmSystemTools.h" +#include "cmTarget.h" #include "cmXMLSafe.h" #include @@ -253,10 +255,11 @@ void cmExtraSublimeTextGenerator:: cmTarget* target, const char* make, const cmMakefile* makefile, - const char* compiler, + const char*, //compiler MapSourceFileFlags& sourceFileFlags, bool firstTarget) { + if (target != 0) { cmGeneratorTarget *gtgt = this->GlobalGenerator @@ -426,7 +429,7 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source, lg->AppendFlags(flags, makefile->GetDefineFlags()); // Add target-specific flags. - if(gtgt->GetProperty("COMPILE_FLAGS")) + if(target->GetProperty("COMPILE_FLAGS")) { std::string langIncludeExpr = "CMAKE_"; langIncludeExpr += language; @@ -437,7 +440,7 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source, cmsys::RegularExpression r(regex); std::vector args; cmSystemTools:: - ParseWindowsCommandLine(gtgt->GetProperty("COMPILE_FLAGS"), args); + ParseWindowsCommandLine(target->GetProperty("COMPILE_FLAGS"), args); for(std::vector::iterator i = args.begin(); i != args.end(); ++i) { @@ -449,12 +452,12 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source, } else { - lg->AppendFlags(flags, gtgt->GetProperty("COMPILE_FLAGS")); + lg->AppendFlags(flags, target->GetProperty("COMPILE_FLAGS")); } } // Add source file specific flags. - lg->AppendFlags(flags, source->GetProperty("COMPILE_FLAGS")); + lg->AppendFlags(flags, target->GetProperty("COMPILE_FLAGS")); // TODO: Handle Apple frameworks. @@ -466,7 +469,7 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source, std::string cmExtraSublimeTextGenerator:: ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg, cmTarget *target, - cmGeneratorTarget* gtgt) + cmGeneratorTarget*) { std::set defines; @@ -485,12 +488,12 @@ ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg, cmTarget *target, } // Add preprocessor definitions for this target and configuration. - lg->AppendDefines(defines, gtgt->GetCompileDefinitions()); + lg->AppendDefines(defines, target->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, target->GetCompileDefinitions(config)); lg->AppendDefines(defines, source->GetProperty(defPropName.c_str())); } -- cgit v0.12