kate: add project generator for the Kate project plugin

This patch adds an extra generator for KDE's kate text editor,
or better more specifically, the project plugin.

Alex
This commit is contained in:
Alex Neundorf 2013-11-16 15:41:32 +01:00 committed by Brad King
parent da6b86f4f0
commit 644e012863
5 changed files with 335 additions and 0 deletions

View File

@ -0,0 +1,31 @@
#=============================================================================
# Copyright 2009 Kitware, Inc.
#
# 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.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
# This file is included in CMakeSystemSpecificInformation.cmake if
# the Eclipse CDT4 extra generator has been selected.
# Try to find out how many CPUs we have and set the -j argument for make accordingly
include(ProcessorCount)
processorcount(_CMAKE_KATE_PROCESSOR_COUNT)
# Only set -j if we are under UNIX and if the make-tool used actually has "make" in the name
# (we may also get here in the future e.g. for ninja)
if("${_CMAKE_KATE_PROCESSOR_COUNT}" GREATER 1 AND CMAKE_HOST_UNIX AND "${CMAKE_MAKE_PROGRAM}" MATCHES make)
set(_CMAKE_KATE_INITIAL_MAKE_ARGS "-j${_CMAKE_KATE_PROCESSOR_COUNT}")
endif()
# This variable is used by the Eclipse generator and appended to the make invocation commands.
set(CMAKE_KATE_MAKE_ARGUMENTS "${_CMAKE_KATE_INITIAL_MAKE_ARGS}" CACHE STRING "Additional command line arguments when Kate invokes make. Enter e.g. -j<some_number> to get parallel builds")

View File

@ -188,6 +188,8 @@ set(SRCS
cmExtraCodeBlocksGenerator.h cmExtraCodeBlocksGenerator.h
cmExtraEclipseCDT4Generator.cxx cmExtraEclipseCDT4Generator.cxx
cmExtraEclipseCDT4Generator.h cmExtraEclipseCDT4Generator.h
cmExtraKateGenerator.cxx
cmExtraKateGenerator.h
cmExtraSublimeTextGenerator.cxx cmExtraSublimeTextGenerator.cxx
cmExtraSublimeTextGenerator.h cmExtraSublimeTextGenerator.h
cmFileTimeComparison.cxx cmFileTimeComparison.cxx

View File

@ -0,0 +1,244 @@
/*============================================================================
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 "cmExtraKateGenerator.h"
#include "cmGlobalUnixMakefileGenerator3.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
#include "cmake.h"
#include "cmSourceFile.h"
#include "cmGeneratedFileStream.h"
#include "cmTarget.h"
#include "cmSystemTools.h"
#include "cmXMLSafe.h"
#include <cmsys/SystemTools.hxx>
//----------------------------------------------------------------------------
void cmExtraKateGenerator
::GetDocumentation(cmDocumentationEntry& entry, const char*) const
{
entry.Name = this->GetName();
entry.Brief = "Generates Kate project files.";
}
cmExtraKateGenerator::cmExtraKateGenerator()
: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 cmExtraKateGenerator::Generate()
{
const cmMakefile* mf
= this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
this->ProjectName = this->GenerateProjectName(mf->GetProjectName(),
mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
this->GetPathBasename(mf->GetHomeOutputDirectory()));
this->CreateKateProjectFile(mf);
this->CreateDummyKateProjectFile(mf);
}
void cmExtraKateGenerator::CreateKateProjectFile(const cmMakefile* mf) const
{
std::string filename = mf->GetHomeOutputDirectory();
filename += "/.kateproject";
cmGeneratedFileStream fout(filename.c_str());
if (!fout)
{
return;
}
std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
std::string args = mf->GetRequiredDefinition("CMAKE_KATE_MAKE_ARGUMENTS");
fout <<
"{\n"
"\t\"name\": \"" << this->ProjectName << "\",\n"
"\t\"directory\": \"" << mf->GetHomeDirectory() << "\",\n"
"\t\"files\": [ { " << this->GenerateFilesString(mf) << "} ],\n"
"\t\"build\": {\n"
"\t\t\"directory\": \"" << mf->GetHomeOutputDirectory() << "\",\n"
"\t\t\"build\": \"" << make << " " << args <<" all\",\n"
"\t\t\"clean\": \"" << make << " clean\",\n"
"\t\t\"quick\": \"" << make << " help\"\n"
"\t}\n"
"}\n";
}
void
cmExtraKateGenerator::CreateDummyKateProjectFile(const cmMakefile* mf) const
{
std::string filename = mf->GetHomeOutputDirectory();
filename += "/";
filename += this->ProjectName;
filename += ".kateproject";
cmGeneratedFileStream fout(filename.c_str());
if (!fout)
{
return;
}
fout << "#Generated by cmake, do not edit.\n";
}
std::string
cmExtraKateGenerator::GenerateFilesString(const cmMakefile* mf) const
{
std::string s = mf->GetHomeDirectory();
s += "/.git";
if(cmSystemTools::FileExists(s.c_str()))
{
return std::string("\"git\": 1 ");
}
s = mf->GetHomeDirectory();
s += "/.svn";
if(cmSystemTools::FileExists(s.c_str()))
{
return std::string("\"svn\": 1 ");
}
s = mf->GetHomeDirectory();
s += "/";
std::set<std::string> files;
std::string tmp;
const std::vector<cmLocalGenerator *>& lgs =
this->GlobalGenerator->GetLocalGenerators();
for (std::vector<cmLocalGenerator*>::const_iterator it=lgs.begin();
it!=lgs.end(); it++)
{
cmMakefile* makefile=(*it)->GetMakefile();
const std::vector<std::string>& listFiles=makefile->GetListFiles();
for (std::vector<std::string>::const_iterator lt=listFiles.begin();
lt!=listFiles.end(); lt++)
{
tmp=*lt;
{
files.insert(tmp);
}
}
const std::vector<cmSourceFile*>& sources = makefile->GetSourceFiles();
for (std::vector<cmSourceFile*>::const_iterator sfIt = sources.begin();
sfIt != sources.end(); sfIt++)
{
cmSourceFile* sf = *sfIt;
if (sf->GetPropertyAsBool("GENERATED"))
{
continue;
}
tmp = sf->GetFullPath();
files.insert(tmp);
}
}
const char* sep = "";
tmp = "\"list\": [";
for(std::set<std::string>::const_iterator it = files.begin();
it != files.end(); ++it)
{
tmp += sep;
tmp += " \"";
tmp += *it;
tmp += "\"";
sep = ",";
}
tmp += "] ";
return tmp;
}
std::string cmExtraKateGenerator::GenerateProjectName(const std::string& name,
const std::string& type,
const std::string& path) const
{
return name + (type.empty() ? "" : "-") + type + "@" + path;
}
std::string cmExtraKateGenerator::GetPathBasename(const std::string& path)const
{
std::string outputBasename = path;
while (outputBasename.size() > 0 &&
(outputBasename[outputBasename.size() - 1] == '/' ||
outputBasename[outputBasename.size() - 1] == '\\'))
{
outputBasename.resize(outputBasename.size() - 1);
}
std::string::size_type loc = outputBasename.find_last_of("/\\");
if (loc != std::string::npos)
{
outputBasename = outputBasename.substr(loc + 1);
}
return outputBasename;
}
// Create the command line for building the given target using the selected
// make
std::string cmExtraKateGenerator::BuildMakeCommand(const std::string& make,
const char* makefile, const char* target) const
{
std::string command = make;
if (strcmp(this->GlobalGenerator->GetName(), "NMake Makefiles")==0)
{
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
command += " /NOLOGO /f &quot;";
command += makefileName;
command += "&quot; ";
command += " VERBOSE=1 ";
command += target;
}
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 &quot;";
command += makefileName;
command += "&quot; ";
command += " VERBOSE=1 ";
command += target;
}
else if (strcmp(this->GlobalGenerator->GetName(), "Ninja")==0)
{
command += " -v ";
command += target;
}
else
{
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
command += " -f &quot;";
command += makefileName;
command += "&quot; ";
command += " VERBOSE=1 ";
command += target;
}
return command;
}

View File

@ -0,0 +1,55 @@
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2004-2009 Kitware, Inc.
Copyright 2013 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 cmExtraKateGenerator_h
#define cmExtraKateGenerator_h
#include "cmExternalMakefileProjectGenerator.h"
class cmLocalGenerator;
class cmMakefile;
class cmTarget;
class cmGeneratedFileStream;
/** \class cmExtraKateGenerator
* \brief Write Kate project files for Makefile or ninja based projects
*/
class cmExtraKateGenerator : public cmExternalMakefileProjectGenerator
{
public:
cmExtraKateGenerator();
virtual const char* GetName() const
{ return cmExtraKateGenerator::GetActualName();}
static const char* GetActualName() { return "Kate";}
static cmExternalMakefileProjectGenerator* New()
{ return new cmExtraKateGenerator; }
/** Get the documentation entry for this generator. */
virtual void GetDocumentation(cmDocumentationEntry& entry,
const char* fullName) const;
virtual void Generate();
private:
void CreateKateProjectFile(const cmMakefile* mf) const;
void CreateDummyKateProjectFile(const cmMakefile* mf) const;
std::string GenerateFilesString(const cmMakefile* mf) const;
std::string GetPathBasename(const std::string& path) const;
std::string GenerateProjectName(const std::string& name,
const std::string& type,
const std::string& path) const;
std::string BuildMakeCommand(const std::string& make,
const char* makefile, const char* target) const;
std::string ProjectName;
};
#endif

View File

@ -73,6 +73,7 @@
# include "cmExtraCodeBlocksGenerator.h" # include "cmExtraCodeBlocksGenerator.h"
#endif #endif
#include "cmExtraSublimeTextGenerator.h" #include "cmExtraSublimeTextGenerator.h"
#include "cmExtraKateGenerator.h"
#ifdef CMAKE_USE_KDEVELOP #ifdef CMAKE_USE_KDEVELOP
# include "cmGlobalKdevelopGenerator.h" # include "cmGlobalKdevelopGenerator.h"
@ -991,6 +992,8 @@ void cmake::AddDefaultExtraGenerators()
&cmExtraCodeBlocksGenerator::New); &cmExtraCodeBlocksGenerator::New);
this->AddExtraGenerator(cmExtraSublimeTextGenerator::GetActualName(), this->AddExtraGenerator(cmExtraSublimeTextGenerator::GetActualName(),
&cmExtraSublimeTextGenerator::New); &cmExtraSublimeTextGenerator::New);
this->AddExtraGenerator(cmExtraKateGenerator::GetActualName(),
&cmExtraKateGenerator::New);
#ifdef CMAKE_USE_ECLIPSE #ifdef CMAKE_USE_ECLIPSE
this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(), this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(),