ENH: added new generator

This commit is contained in:
Ken Martin 2005-05-12 10:49:56 -04:00
parent e1c9730a01
commit caf17c123b
11 changed files with 91 additions and 38 deletions

View File

@ -52,12 +52,15 @@ SET(SRCS
cmGlobalGenerator.h cmGlobalGenerator.h
cmGlobalUnixMakefileGenerator.cxx cmGlobalUnixMakefileGenerator.cxx
cmGlobalUnixMakefileGenerator.h cmGlobalUnixMakefileGenerator.h
cmGlobalUnixMakefileGenerator3.cxx
cmGlobalUnixMakefileGenerator3.h
cmListFileCache.cxx cmListFileCache.cxx
cmListFileCache.h cmListFileCache.h
cmListFileLexer.c cmListFileLexer.c
cmLocalGenerator.cxx cmLocalGenerator.cxx
cmLocalGenerator.h cmLocalGenerator.h
cmLocalUnixMakefileGenerator2.cxx cmLocalUnixMakefileGenerator2.cxx
cmLocalUnixMakefileGenerator3.cxx
cmMakeDepend.cxx cmMakeDepend.cxx
cmMakeDepend.h cmMakeDepend.h
cmMakefile.cxx cmMakefile.cxx

View File

@ -15,7 +15,7 @@
=========================================================================*/ =========================================================================*/
#include "cmGlobalBorlandMakefileGenerator.h" #include "cmGlobalBorlandMakefileGenerator.h"
#include "cmLocalUnixMakefileGenerator2.h" #include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmake.h" #include "cmake.h"
@ -33,14 +33,13 @@ void cmGlobalBorlandMakefileGenerator::EnableLanguage(std::vector<std::string>co
mf->AddDefinition("BORLAND", "1"); mf->AddDefinition("BORLAND", "1");
mf->AddDefinition("CMAKE_GENERATOR_CC", "bcc32"); mf->AddDefinition("CMAKE_GENERATOR_CC", "bcc32");
mf->AddDefinition("CMAKE_GENERATOR_CXX", "bcc32"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "bcc32");
this->cmGlobalUnixMakefileGenerator::EnableLanguage(l, mf); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf);
} }
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *cmGlobalBorlandMakefileGenerator::CreateLocalGenerator() cmLocalGenerator *cmGlobalBorlandMakefileGenerator::CreateLocalGenerator()
{ {
cmLocalUnixMakefileGenerator2* lg = new cmLocalUnixMakefileGenerator2; cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
lg->SetEmptyCommand("@REM Borland Make needs a command here.");
lg->SetEchoNeedsQuote(false); lg->SetEchoNeedsQuote(false);
lg->SetIncludeDirective("!include"); lg->SetIncludeDirective("!include");
lg->SetWindowsShell(true); lg->SetWindowsShell(true);

View File

@ -15,7 +15,7 @@
=========================================================================*/ =========================================================================*/
#include "cmGlobalNMakeMakefileGenerator.h" #include "cmGlobalNMakeMakefileGenerator.h"
#include "cmLocalUnixMakefileGenerator2.h" #include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h" #include "cmMakefile.h"
cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator() cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator()
@ -30,13 +30,13 @@ void cmGlobalNMakeMakefileGenerator::EnableLanguage(std::vector<std::string>cons
// pick a default // pick a default
mf->AddDefinition("CMAKE_GENERATOR_CC", "cl"); mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
this->cmGlobalUnixMakefileGenerator::EnableLanguage(l, mf); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf);
} }
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *cmGlobalNMakeMakefileGenerator::CreateLocalGenerator() cmLocalGenerator *cmGlobalNMakeMakefileGenerator::CreateLocalGenerator()
{ {
cmLocalUnixMakefileGenerator2* lg = new cmLocalUnixMakefileGenerator2; cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
lg->SetEchoNeedsQuote(false); lg->SetEchoNeedsQuote(false);
lg->SetWindowsShell(true); lg->SetWindowsShell(true);
lg->SetMakeSilentFlag("/nologo"); lg->SetMakeSilentFlag("/nologo");

View File

@ -17,14 +17,14 @@
#ifndef cmGlobalNMakeMakefileGenerator_h #ifndef cmGlobalNMakeMakefileGenerator_h
#define cmGlobalNMakeMakefileGenerator_h #define cmGlobalNMakeMakefileGenerator_h
#include "cmGlobalUNIXMakefileGenerator.h" #include "cmGlobalUNIXMakefileGenerator3.h"
/** \class cmGlobalNMakeMakefileGenerator /** \class cmGlobalNMakeMakefileGenerator
* \brief Write a NMake makefiles. * \brief Write a NMake makefiles.
* *
* cmGlobalNMakeMakefileGenerator manages nmake build process for a tree * cmGlobalNMakeMakefileGenerator manages nmake build process for a tree
*/ */
class cmGlobalNMakeMakefileGenerator : public cmGlobalUnixMakefileGenerator class cmGlobalNMakeMakefileGenerator : public cmGlobalUnixMakefileGenerator3
{ {
public: public:
cmGlobalNMakeMakefileGenerator(); cmGlobalNMakeMakefileGenerator();

View File

@ -187,6 +187,11 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
// Write the do not edit header. // Write the do not edit header.
lg->WriteDisclaimer(cmakefileStream); lg->WriteDisclaimer(cmakefileStream);
// Save the generator name
cmakefileStream
<< "# The generator used is:\n"
<< "SET(CMAKE_DEPENDS_GENERATOR \"" << this->GetName() << "\")\n\n";
// for each cmMakefile get its list of dependencies // for each cmMakefile get its list of dependencies
unsigned int i; unsigned int i;
std::vector<std::string> lfiles; std::vector<std::string> lfiles;

View File

@ -134,6 +134,12 @@ public:
///! for existing files convert to output path and short path if spaces ///! for existing files convert to output path and short path if spaces
std::string ConvertToOutputForExisting(const char* p); std::string ConvertToOutputForExisting(const char* p);
/** Called from command-line hook to check dependencies. */
virtual void CheckDependencies(cmMakefile* /* mf */, bool /* verbose */) {};
/** Called from command-line hook to scan dependencies. */
virtual bool ScanDependencies(std::vector<std::string> const& /* args */) {return true;};
protected: protected:
/** Construct a script from the given list of command lines. */ /** Construct a script from the given list of command lines. */
std::string ConstructScript(const cmCustomCommandLines& commandLines, std::string ConstructScript(const cmCustomCommandLines& commandLines,

View File

@ -535,7 +535,9 @@ cmLocalUnixMakefileGenerator2
cmOStringStream depCmd; cmOStringStream depCmd;
// TODO: Account for source file properties and directory-level // TODO: Account for source file properties and directory-level
// definitions when scanning for dependencies. // definitions when scanning for dependencies.
depCmd << "$(CMAKE_COMMAND) -E cmake_depends " << lang << " " depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
<< m_GlobalGenerator->GetName() << "\" "
<< lang << " "
<< this->ConvertToRelativeOutputPath(obj.c_str()) << " " << this->ConvertToRelativeOutputPath(obj.c_str()) << " "
<< this->ConvertToRelativeOutputPath(source.GetFullPath().c_str()); << this->ConvertToRelativeOutputPath(source.GetFullPath().c_str());
commands.push_back(depCmd.str()); commands.push_back(depCmd.str());
@ -3131,17 +3133,17 @@ cmLocalUnixMakefileGenerator2
::ScanDependencies(std::vector<std::string> const& args) ::ScanDependencies(std::vector<std::string> const& args)
{ {
// Format of arguments is: // Format of arguments is:
// $(CMAKE_COMMAND), cmake_depends, <lang>, <obj>, <src> // $(CMAKE_COMMAND), cmake_depends, GeneratorName, <lang>, <obj>, <src>
// The caller has ensured that all required arguments exist. // The caller has ensured that all required arguments exist.
// The language for which we are scanning dependencies. // The language for which we are scanning dependencies.
std::string const& lang = args[2]; std::string const& lang = args[3];
// The file to which to write dependencies. // The file to which to write dependencies.
const char* objFile = args[3].c_str(); const char* objFile = args[4].c_str();
// The source file at which to start the scan. // The source file at which to start the scan.
const char* srcFile = args[4].c_str(); const char* srcFile = args[5].c_str();
// Read the directory information file. // Read the directory information file.
cmake cm; cmake cm;

View File

@ -94,10 +94,10 @@ public:
virtual void Generate(); virtual void Generate();
/** Called from command-line hook to scan dependencies. */ /** Called from command-line hook to scan dependencies. */
static bool ScanDependencies(std::vector<std::string> const& args); virtual bool ScanDependencies(std::vector<std::string> const& args);
/** Called from command-line hook to check dependencies. */ /** Called from command-line hook to check dependencies. */
static void CheckDependencies(cmMakefile* mf, bool verbose); virtual void CheckDependencies(cmMakefile* mf, bool verbose);
protected: protected:

View File

@ -489,7 +489,9 @@ cmLocalUnixMakefileGenerator3
cmOStringStream depCmd; cmOStringStream depCmd;
// TODO: Account for source file properties and directory-level // TODO: Account for source file properties and directory-level
// definitions when scanning for dependencies. // definitions when scanning for dependencies.
depCmd << "$(CMAKE_COMMAND) -E cmake_depends " << lang << " " depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
<< m_GlobalGenerator->GetName() << "\" "
<< lang << " "
<< relativeObj.c_str() << " " << relativeObj.c_str() << " "
<< m_GlobalGenerator->ConvertToHomeRelativeOutputPath << m_GlobalGenerator->ConvertToHomeRelativeOutputPath
(source.GetFullPath().c_str()); (source.GetFullPath().c_str());
@ -576,8 +578,12 @@ cmLocalUnixMakefileGenerator3
this->AppendFlags(flags, this->GetIncludeFlags(lang)); this->AppendFlags(flags, this->GetIncludeFlags(lang));
// Get the output paths for source and object files. // Get the output paths for source and object files.
std::string sourceFile = std::string sourceFile = source.GetFullPath();
this->ConvertToOptionallyRelativeOutputPath(source.GetFullPath().c_str()); if(m_UseRelativePaths)
{
sourceFile = m_GlobalGenerator->ConvertToHomeRelativePath(sourceFile.c_str());
}
sourceFile = cmSystemTools::ConvertToOutputPath(sourceFile.c_str());
std::string objectFile = std::string objectFile =
this->ConvertToRelativeOutputPath(obj.c_str()); this->ConvertToRelativeOutputPath(obj.c_str());
@ -2844,21 +2850,27 @@ cmLocalUnixMakefileGenerator3::GetDependsChecker(const std::string& lang,
const char* objFile, const char* objFile,
bool verbose) bool verbose)
{ {
cmDepends *ret = 0;
if(lang == "C" || lang == "CXX" || lang == "RC") if(lang == "C" || lang == "CXX" || lang == "RC")
{ {
return new cmDependsC(dir, objFile, verbose); ret = new cmDependsC();
} }
#ifdef CMAKE_BUILD_WITH_CMAKE #ifdef CMAKE_BUILD_WITH_CMAKE
else if(lang == "Fortran") else if(lang == "Fortran")
{ {
return new cmDependsFortran(dir, objFile, verbose); ret = new cmDependsFortran();
} }
else if(lang == "Java") else if(lang == "Java")
{ {
return new cmDependsJava(dir, objFile, verbose); ret = new cmDependsJava();
} }
#endif #endif
return 0; if (ret)
{
ret->SetTargetFile(dir, objFile, ".depend",".build.depend.make");
ret->SetVerbose(verbose);
}
return ret;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -2867,17 +2879,17 @@ cmLocalUnixMakefileGenerator3
::ScanDependencies(std::vector<std::string> const& args) ::ScanDependencies(std::vector<std::string> const& args)
{ {
// Format of arguments is: // Format of arguments is:
// $(CMAKE_COMMAND), cmake_depends, <lang>, <obj>, <src> // $(CMAKE_COMMAND), cmake_depends, GeneratorName, <lang>, <obj>, <src>
// The caller has ensured that all required arguments exist. // The caller has ensured that all required arguments exist.
// The language for which we are scanning dependencies. // The language for which we are scanning dependencies.
std::string const& lang = args[2]; std::string const& lang = args[3];
// The file to which to write dependencies. // The file to which to write dependencies.
const char* objFile = args[3].c_str(); const char* objFile = args[4].c_str();
// The source file at which to start the scan. // The source file at which to start the scan.
const char* srcFile = args[4].c_str(); const char* srcFile = args[5].c_str();
// Read the directory information file. // Read the directory information file.
cmake cm; cmake cm;
@ -2943,19 +2955,22 @@ cmLocalUnixMakefileGenerator3
if(lang == "C" || lang == "CXX" || lang == "RC") if(lang == "C" || lang == "CXX" || lang == "RC")
{ {
// TODO: Handle RC (resource files) dependencies correctly. // TODO: Handle RC (resource files) dependencies correctly.
cmDependsC scanner(".", objFile, srcFile, includes, cmDependsC scanner(srcFile, includes,
includeRegexScan.c_str(), includeRegexComplain.c_str()); includeRegexScan.c_str(), includeRegexComplain.c_str());
scanner.SetTargetFile(".",objFile,".depend",".build.depend.make");
return scanner.Write(); return scanner.Write();
} }
#ifdef CMAKE_BUILD_WITH_CMAKE #ifdef CMAKE_BUILD_WITH_CMAKE
else if(lang == "Fortran") else if(lang == "Fortran")
{ {
cmDependsFortran scanner(".", objFile, srcFile, includes); cmDependsFortran scanner(srcFile, includes);
scanner.SetTargetFile(".",objFile,".depend",".build.depend.make");
return scanner.Write(); return scanner.Write();
} }
else if(lang == "Java") else if(lang == "Java")
{ {
cmDependsJava scanner(".", objFile, srcFile); cmDependsJava scanner(srcFile);
scanner.SetTargetFile(".",objFile,".depend",".build.depend.make");
return scanner.Write(); return scanner.Write();
} }
#endif #endif

View File

@ -119,10 +119,10 @@ public:
/** Called from command-line hook to scan dependencies. */ /** Called from command-line hook to scan dependencies. */
static bool ScanDependencies(std::vector<std::string> const& args); virtual bool ScanDependencies(std::vector<std::string> const& args);
/** Called from command-line hook to check dependencies. */ /** Called from command-line hook to check dependencies. */
static void CheckDependencies(cmMakefile* mf, bool verbose); virtual void CheckDependencies(cmMakefile* mf, bool verbose);
/** write some extra rules suahc as make test etc */ /** write some extra rules suahc as make test etc */
void WriteSpecialTargetsTop(std::ostream& makefileStream); void WriteSpecialTargetsTop(std::ostream& makefileStream);

View File

@ -28,8 +28,6 @@
# include "cmVersion.h" # include "cmVersion.h"
#endif #endif
#include "cmLocalUnixMakefileGenerator2.h" // For -E cmake_depends callback.
// only build kdevelop generator on non-windows platforms // only build kdevelop generator on non-windows platforms
// when not bootstrapping cmake // when not bootstrapping cmake
#if !defined(_WIN32) #if !defined(_WIN32)
@ -52,6 +50,7 @@
#else #else
#endif #endif
#include "cmGlobalUnixMakefileGenerator.h" #include "cmGlobalUnixMakefileGenerator.h"
#include "cmGlobalUnixMakefileGenerator3.h"
#ifdef CMAKE_USE_KDEVELOP #ifdef CMAKE_USE_KDEVELOP
# include "cmGlobalKdevelopGenerator.h" # include "cmGlobalKdevelopGenerator.h"
@ -827,9 +826,18 @@ int cmake::CMakeCommand(std::vector<std::string>& args)
} }
// Internal CMake dependency scanning support. // Internal CMake dependency scanning support.
else if (args[1] == "cmake_depends" && args.size() >= 5) else if (args[1] == "cmake_depends" && args.size() >= 6)
{ {
return cmLocalUnixMakefileGenerator2::ScanDependencies(args)? 0 : 1; cmake cm;
cmGlobalGenerator *ggd = cm.CreateGlobalGenerator(args[2].c_str());
ggd->SetCMakeInstance(&cm);
if (ggd)
{
std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
lgd->SetGlobalGenerator(ggd);
return lgd->ScanDependencies(args)? 0 : 1;
}
return 1;
} }
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
@ -1103,7 +1111,7 @@ int cmake::Configure()
} }
this->SetGlobalGenerator(gen); this->SetGlobalGenerator(gen);
#else #else
this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator); this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator2);
#endif #endif
} }
if(!m_GlobalGenerator) if(!m_GlobalGenerator)
@ -1419,6 +1427,8 @@ void cmake::AddDefaultGenerators()
#endif #endif
m_Generators[cmGlobalUnixMakefileGenerator::GetActualName()] = m_Generators[cmGlobalUnixMakefileGenerator::GetActualName()] =
&cmGlobalUnixMakefileGenerator::New; &cmGlobalUnixMakefileGenerator::New;
m_Generators[cmGlobalUnixMakefileGenerator3::GetActualName()] =
&cmGlobalUnixMakefileGenerator3::New;
#ifdef CMAKE_USE_XCODE #ifdef CMAKE_USE_XCODE
m_Generators[cmGlobalXCodeGenerator::GetActualName()] = m_Generators[cmGlobalXCodeGenerator::GetActualName()] =
&cmGlobalXCodeGenerator::New; &cmGlobalXCodeGenerator::New;
@ -1618,7 +1628,20 @@ int cmake::CheckBuildSystem()
// the make system's VERBOSE environment variable to enable verbose // the make system's VERBOSE environment variable to enable verbose
// output. // output.
bool verbose = cmSystemTools::GetEnv("VERBOSE") != 0; bool verbose = cmSystemTools::GetEnv("VERBOSE") != 0;
cmLocalUnixMakefileGenerator2::CheckDependencies(mf, verbose);
// compute depends based on the generator specified
const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
if (!genName || genName[0] == '\0')
{
genName = "Unix Makefiles";
}
cmGlobalGenerator *ggd = this->CreateGlobalGenerator(genName);
if (ggd)
{
std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
lgd->SetGlobalGenerator(ggd);
lgd->CheckDependencies(mf, verbose);
}
// No need to rerun. // No need to rerun.
return 0; return 0;