ENH: Convert cmDepends object interface to scan an entire target at once.

This commit is contained in:
Brad King 2007-12-22 22:41:42 -05:00
parent a7245e4792
commit 4d360f7ac5
5 changed files with 53 additions and 31 deletions

View File

@ -16,6 +16,8 @@
=========================================================================*/
#include "cmDepends.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
#include "cmFileTimeComparison.h"
@ -41,10 +43,39 @@ cmDepends::~cmDepends()
}
//----------------------------------------------------------------------------
bool cmDepends::Write(const char *src, const char *obj,
std::ostream &makeDepends, std::ostream &internalDepends)
bool cmDepends::Write(std::ostream &makeDepends,
std::ostream &internalDepends)
{
return this->WriteDependencies(src, obj, makeDepends, internalDepends);
// Lookup the set of sources to scan.
std::string srcLang = "CMAKE_DEPENDS_CHECK_";
srcLang += this->Language;
cmMakefile* mf = this->LocalGenerator->GetMakefile();
const char* srcStr = mf->GetSafeDefinition(srcLang.c_str());
std::vector<std::string> pairs;
cmSystemTools::ExpandListArgument(srcStr, pairs);
for(std::vector<std::string>::iterator si = pairs.begin();
si != pairs.end();)
{
// Get the source and object file.
std::string const& src = *si++;
if(si == pairs.end()) { break; }
std::string obj = *si++;
// Make sure the object file is relative to the top of the build tree.
obj = this->LocalGenerator->Convert(obj.c_str(),
cmLocalGenerator::HOME_OUTPUT,
cmLocalGenerator::MAKEFILE);
// Write the dependencies for this pair.
if(!this->WriteDependencies(src.c_str(), obj.c_str(),
makeDepends, internalDepends))
{
return false;
}
}
return true;
}
//----------------------------------------------------------------------------

View File

@ -45,6 +45,12 @@ public:
directory. */
void SetLocalGenerator(cmLocalGenerator* lg) { this->LocalGenerator = lg; }
/** Set the specific language to be scanned. */
void SetLanguage(const char* lang) { this->Language = lang; }
/** Set the target build directory. */
void SetTargetDirectory(const char* dir) { this->TargetDirectory = dir; }
/** should this be verbose in its output */
void SetVerbose(bool verb) { this->Verbose = verb; }
@ -52,8 +58,7 @@ public:
virtual ~cmDepends();
/** Write dependencies for the target file. */
bool Write(const char *src, const char *obj,
std::ostream &makeDepends, std::ostream &internalDepends);
bool Write(std::ostream &makeDepends, std::ostream &internalDepends);
/** Check dependencies for the target file. Returns true if
dependencies are okay and false if they must be generated. If
@ -90,6 +95,11 @@ protected:
bool Verbose;
cmFileTimeComparison* FileComparison;
std::string Language;
// The full path to the target's build directory.
std::string TargetDirectory;
size_t MaxPath;
char* Dependee;
char* Depender;

View File

@ -90,9 +90,8 @@ cmDependsFortran::cmDependsFortran():
}
//----------------------------------------------------------------------------
cmDependsFortran::cmDependsFortran(std::vector<std::string> const& includes,
std::string const& targetDirectory):
IncludePath(&includes), TargetDirectory(targetDirectory)
cmDependsFortran::cmDependsFortran(std::vector<std::string> const& includes):
IncludePath(&includes)
{
}

View File

@ -33,8 +33,7 @@ public:
path from the build directory to the target file, the source
file from which to start scanning, the include file search
path, and the target directory. */
cmDependsFortran(std::vector<std::string> const& includes,
std::string const& targetDirectory);
cmDependsFortran(std::vector<std::string> const& includes);
/** Virtual destructor to cleanup subclasses properly. */
virtual ~cmDependsFortran();
@ -62,9 +61,6 @@ protected:
// The include file search path.
std::vector<std::string> const* IncludePath;
// The full path to the target's build directory.
std::string TargetDirectory;
private:
cmDependsFortran(cmDependsFortran const&); // Purposely not implemented.
void operator=(cmDependsFortran const&); // Purposely not implemented.

View File

@ -1412,7 +1412,7 @@ cmLocalUnixMakefileGenerator3
#ifdef CMAKE_BUILD_WITH_CMAKE
else if(lang == "Fortran")
{
scanner = new cmDependsFortran(includes, dir);
scanner = new cmDependsFortran(includes);
}
else if(lang == "Java")
{
@ -1425,23 +1425,9 @@ cmLocalUnixMakefileGenerator3
scanner->SetLocalGenerator(this);
scanner->SetFileComparison
(this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
// for each file we need to scan
std::string srcLang = "CMAKE_DEPENDS_CHECK_";
srcLang += lang;
const char *srcStr = mf->GetSafeDefinition(srcLang.c_str());
std::vector<std::string> srcs;
cmSystemTools::ExpandListArgument(srcStr, srcs);
for (std::vector<std::string>::iterator si =
srcs.begin(); si != srcs.end(); ++si)
{
std::string &src = *si;
++si;
// make sure the object file is relative to home output
std::string obj = *si;
obj = this->Convert(obj.c_str(),HOME_OUTPUT,MAKEFILE);
scanner->Write(src.c_str(),obj.c_str(),
ruleFileStream, internalRuleFileStream);
}
scanner->SetLanguage(lang.c_str());
scanner->SetTargetDirectory(dir.c_str());
scanner->Write(ruleFileStream, internalRuleFileStream);
// free the scanner for this language
delete scanner;