ENH: Light refactoring of implicit dependency scanning configuration implementation.

- Move lookup of config variables from cmLocalUnixMakefileGenerator3 to cmDepends hierarchy.
This commit is contained in:
Brad King 2008-05-08 10:09:14 -04:00
parent 92198d6b37
commit 12935b1599
7 changed files with 88 additions and 102 deletions

View File

@ -24,11 +24,12 @@
#include <string.h>
//----------------------------------------------------------------------------
cmDepends::cmDepends():
cmDepends::cmDepends(cmLocalGenerator* lg, const char* targetDir):
CompileDirectory(),
LocalGenerator(0),
LocalGenerator(lg),
Verbose(false),
FileComparison(0),
TargetDirectory(targetDir),
MaxPath(cmSystemTools::GetMaximumFilePathLength()),
Dependee(new char[MaxPath]),
Depender(new char[MaxPath])
@ -231,4 +232,15 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends)
return okay;
}
//----------------------------------------------------------------------------
void cmDepends::SetIncludePathFromLanguage(const char* lang)
{
std::string includePathVar = "CMAKE_";
includePathVar += lang;
includePathVar += "_INCLUDE_PATH";
cmMakefile* mf = this->LocalGenerator->GetMakefile();
if(const char* includePath = mf->GetDefinition(includePathVar.c_str()))
{
cmSystemTools::ExpandListArgument(includePath, this->IncludePath);
}
}

View File

@ -34,7 +34,7 @@ class cmDepends
public:
/** Instances need to know the build directory name and the relative
path from the build directory to the target file. */
cmDepends();
cmDepends(cmLocalGenerator* lg=0, const char* targetDir="");
/** at what level will the compile be done from */
void SetCompileDirectory(const char *dir) {this->CompileDirectory = dir;};
@ -108,6 +108,11 @@ protected:
char* Dependee;
char* Depender;
// The include file search path.
std::vector<std::string> IncludePath;
void SetIncludePathFromLanguage(const char* lang);
private:
cmDepends(cmDepends const&); // Purposely not implemented.
void operator=(cmDepends const&); // Purposely not implemented.

View File

@ -18,6 +18,7 @@
#include "cmFileTimeComparison.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
#include <ctype.h> // isspace
@ -31,25 +32,53 @@
#define INCLUDE_REGEX_COMPLAIN_MARKER "#IncludeRegexComplain: "
//----------------------------------------------------------------------------
cmDependsC::cmDependsC():
IncludePath(0)
cmDependsC::cmDependsC()
{
}
//----------------------------------------------------------------------------
// yummy look at all those constructor arguments
cmDependsC::cmDependsC(std::vector<std::string> const& includes,
const char* scanRegex, const char* complainRegex,
const cmStdString& cacheFileName):
IncludePath(&includes),
IncludeRegexLine(INCLUDE_REGEX_LINE),
IncludeRegexScan(scanRegex),
IncludeRegexComplain(complainRegex),
IncludeRegexLineString(INCLUDE_REGEX_LINE_MARKER INCLUDE_REGEX_LINE),
IncludeRegexScanString(std::string(INCLUDE_REGEX_SCAN_MARKER)+scanRegex),
IncludeRegexComplainString(
std::string(INCLUDE_REGEX_COMPLAIN_MARKER)+complainRegex),
CacheFileName(cacheFileName)
cmDependsC::cmDependsC(cmLocalGenerator* lg, const char* targetDir,
const char* lang): cmDepends(lg, targetDir)
{
cmMakefile* mf = lg->GetMakefile();
// Configure the include file search path.
this->SetIncludePathFromLanguage(lang);
// Configure regular expressions.
std::string scanRegex = "^.*$";
std::string complainRegex = "^$";
{
std::string scanRegexVar = "CMAKE_";
scanRegexVar += lang;
scanRegexVar += "_INCLUDE_REGEX_SCAN";
if(const char* sr = mf->GetDefinition(scanRegexVar.c_str()))
{
scanRegex = sr;
}
std::string complainRegexVar = "CMAKE_";
complainRegexVar += lang;
complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
if(const char* cr = mf->GetDefinition(complainRegexVar.c_str()))
{
complainRegex = cr;
}
}
this->IncludeRegexLine.compile(INCLUDE_REGEX_LINE);
this->IncludeRegexScan.compile(scanRegex.c_str());
this->IncludeRegexComplain.compile(complainRegex.c_str());
this->IncludeRegexLineString = INCLUDE_REGEX_LINE_MARKER INCLUDE_REGEX_LINE;
this->IncludeRegexScanString = INCLUDE_REGEX_SCAN_MARKER;
this->IncludeRegexScanString += scanRegex;
this->IncludeRegexComplainString = INCLUDE_REGEX_COMPLAIN_MARKER;
this->IncludeRegexComplainString += complainRegex;
this->CacheFileName = this->TargetDirectory;
this->CacheFileName += "/";
this->CacheFileName += lang;
this->CacheFileName += ".includecache";
this->ReadCacheFile();
}
@ -80,11 +109,6 @@ bool cmDependsC::WriteDependencies(const char *src, const char *obj,
cmSystemTools::Error("Cannot scan dependencies without an object file.");
return false;
}
if(!this->IncludePath)
{
cmSystemTools::Error("Cannot scan dependencies without an include path.");
return false;
}
// Walk the dependency graph starting with the source file.
bool first = true;
@ -138,7 +162,7 @@ bool cmDependsC::WriteDependencies(const char *src, const char *obj,
cacheKey += current.FileName;
for(std::vector<std::string>::const_iterator i =
this->IncludePath->begin(); i != this->IncludePath->end(); ++i)
this->IncludePath.begin(); i != this->IncludePath.end(); ++i)
{
cacheKey+=*i;
}
@ -149,7 +173,7 @@ bool cmDependsC::WriteDependencies(const char *src, const char *obj,
fullName=headerLocationIt->second;
}
else for(std::vector<std::string>::const_iterator i =
this->IncludePath->begin(); i != this->IncludePath->end(); ++i)
this->IncludePath.begin(); i != this->IncludePath.end(); ++i)
{
// Construct the name of the file as if it were in the current
// include directory. Avoid using a leading "./".

View File

@ -30,9 +30,7 @@ public:
/** Checking instances need to know the build directory name and the
relative path from the build directory to the target file. */
cmDependsC();
cmDependsC(std::vector<std::string> const& includes,
const char* scanRegex, const char* complainRegex,
const cmStdString& cachFileName);
cmDependsC(cmLocalGenerator* lg, const char* targetDir, const char* lang);
/** Virtual destructor to cleanup subclasses properly. */
virtual ~cmDependsC();
@ -50,9 +48,6 @@ protected:
void Scan(std::istream& is, const char* directory,
const cmStdString& fullName);
// The include file search path.
std::vector<std::string> const* IncludePath;
// Regular expression to identify C preprocessor include directives.
cmsys::RegularExpression IncludeRegexLine;
@ -60,9 +55,9 @@ protected:
// recursively and which to complain about not finding.
cmsys::RegularExpression IncludeRegexScan;
cmsys::RegularExpression IncludeRegexComplain;
const std::string IncludeRegexLineString;
const std::string IncludeRegexScanString;
const std::string IncludeRegexComplainString;
std::string IncludeRegexLineString;
std::string IncludeRegexScanString;
std::string IncludeRegexComplainString;
public:
// Data structures for dependency graph walk.

View File

@ -131,17 +131,25 @@ public:
//----------------------------------------------------------------------------
cmDependsFortran::cmDependsFortran():
IncludePath(0), PPDefinitions(0), Internal(0)
PPDefinitions(0), Internal(0)
{
}
//----------------------------------------------------------------------------
cmDependsFortran
::cmDependsFortran(std::vector<std::string> const& includes,
std::vector<std::string> const& definitions):
IncludePath(&includes),
::cmDependsFortran(cmLocalGenerator* lg):
cmDepends(lg),
Internal(new cmDependsFortranInternals)
{
// Get the list of definitions.
std::vector<std::string> definitions;
cmMakefile* mf = this->LocalGenerator->GetMakefile();
if(const char* c_defines =
mf->GetDefinition("CMAKE_TARGET_DEFINITIONS"))
{
cmSystemTools::ExpandListArgument(c_defines, definitions);
}
// translate i.e. FOO=BAR to FOO and add it to the list of defined
// preprocessor symbols
for(std::vector<std::string>::const_iterator
@ -178,11 +186,6 @@ bool cmDependsFortran::WriteDependencies(const char *src, const char *obj,
cmSystemTools::Error("Cannot scan dependencies without an object file.");
return false;
}
if(!this->IncludePath)
{
cmSystemTools::Error("Cannot scan dependencies without an include path.");
return false;
}
// Get the information object for this source.
cmDependsFortranSourceInfo& info =
@ -595,7 +598,7 @@ bool cmDependsFortran::FindModule(std::string const& name,
// Search the include path for the module.
std::string fullName;
for(std::vector<std::string>::const_iterator i =
this->IncludePath->begin(); i != this->IncludePath->end(); ++i)
this->IncludePath.begin(); i != this->IncludePath.end(); ++i)
{
// Try the lower-case name.
fullName = *i;
@ -887,7 +890,7 @@ bool cmDependsFortran::FindIncludeFile(const char* dir,
// Search the include path for the file.
for(std::vector<std::string>::const_iterator i =
this->IncludePath->begin(); i != this->IncludePath->end(); ++i)
this->IncludePath.begin(); i != this->IncludePath.end(); ++i)
{
fullName = *i;
fullName += "/";

View File

@ -36,8 +36,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::vector<std::string> const& defines);
cmDependsFortran(cmLocalGenerator* lg);
/** Virtual destructor to cleanup subclasses properly. */
virtual ~cmDependsFortran();
@ -85,8 +84,6 @@ protected:
// The source file from which to start scanning.
std::string SourceFile;
// The include file search path.
std::vector<std::string> const* IncludePath;
std::vector<std::string> PPDefinitions;
// Internal implementation details.

View File

@ -1473,68 +1473,18 @@ cmLocalUnixMakefileGenerator3
{
// construct the checker
std::string lang = li->c_str();
// Get the set of include directories.
std::vector<std::string> includes;
if(haveDirectoryInfo)
{
std::string includePathVar = "CMAKE_";
includePathVar += lang;
includePathVar += "_INCLUDE_PATH";
if(const char* includePath = mf->GetDefinition(includePathVar.c_str()))
{
cmSystemTools::ExpandListArgument(includePath, includes);
}
}
// Get the include file regular expression.
std::string includeRegexScan = "^.*$";
std::string includeRegexComplain = "^$";
if(haveDirectoryInfo)
{
std::string scanRegexVar = "CMAKE_";
scanRegexVar += lang;
scanRegexVar += "_INCLUDE_REGEX_SCAN";
if(const char* scanRegex = mf->GetDefinition(scanRegexVar.c_str()))
{
includeRegexScan = scanRegex;
}
std::string complainRegexVar = "CMAKE_";
complainRegexVar += lang;
complainRegexVar += "_INCLUDE_REGEX_COMPLAIN";
if(const char* complainRegex =
mf->GetDefinition(complainRegexVar.c_str()))
{
includeRegexComplain = complainRegex;
}
}
// Create the scanner for this language
cmDepends *scanner = 0;
if(lang == "C" || lang == "CXX" || lang == "RC")
{
std::string includeCacheFileName = dir;
includeCacheFileName += "/";
includeCacheFileName += lang;
includeCacheFileName += ".includecache";
// TODO: Handle RC (resource files) dependencies correctly.
scanner = new cmDependsC(includes,
includeRegexScan.c_str(),
includeRegexComplain.c_str(),
includeCacheFileName);
scanner = new cmDependsC(this, targetDir, lang.c_str());
}
#ifdef CMAKE_BUILD_WITH_CMAKE
else if(lang == "Fortran")
{
std::vector<std::string> defines;
if(const char* c_defines =
mf->GetDefinition("CMAKE_TARGET_DEFINITIONS"))
{
cmSystemTools::ExpandListArgument(c_defines, defines);
}
scanner = new cmDependsFortran(includes, defines);
scanner = new cmDependsFortran(this);
}
else if(lang == "Java")
{