ENH: Light refactoring of implicit dependency scanning configuration implementation.
- Move lookup of config variables from cmLocalUnixMakefileGenerator3 to cmDepends hierarchy.
This commit is contained in:
parent
92198d6b37
commit
12935b1599
@ -24,11 +24,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmDepends::cmDepends():
|
cmDepends::cmDepends(cmLocalGenerator* lg, const char* targetDir):
|
||||||
CompileDirectory(),
|
CompileDirectory(),
|
||||||
LocalGenerator(0),
|
LocalGenerator(lg),
|
||||||
Verbose(false),
|
Verbose(false),
|
||||||
FileComparison(0),
|
FileComparison(0),
|
||||||
|
TargetDirectory(targetDir),
|
||||||
MaxPath(cmSystemTools::GetMaximumFilePathLength()),
|
MaxPath(cmSystemTools::GetMaximumFilePathLength()),
|
||||||
Dependee(new char[MaxPath]),
|
Dependee(new char[MaxPath]),
|
||||||
Depender(new char[MaxPath])
|
Depender(new char[MaxPath])
|
||||||
@ -231,4 +232,15 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends)
|
|||||||
return okay;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -34,7 +34,7 @@ class cmDepends
|
|||||||
public:
|
public:
|
||||||
/** Instances need to know the build directory name and the relative
|
/** Instances need to know the build directory name and the relative
|
||||||
path from the build directory to the target file. */
|
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 */
|
/** at what level will the compile be done from */
|
||||||
void SetCompileDirectory(const char *dir) {this->CompileDirectory = dir;};
|
void SetCompileDirectory(const char *dir) {this->CompileDirectory = dir;};
|
||||||
@ -108,6 +108,11 @@ protected:
|
|||||||
char* Dependee;
|
char* Dependee;
|
||||||
char* Depender;
|
char* Depender;
|
||||||
|
|
||||||
|
// The include file search path.
|
||||||
|
std::vector<std::string> IncludePath;
|
||||||
|
|
||||||
|
void SetIncludePathFromLanguage(const char* lang);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cmDepends(cmDepends const&); // Purposely not implemented.
|
cmDepends(cmDepends const&); // Purposely not implemented.
|
||||||
void operator=(cmDepends const&); // Purposely not implemented.
|
void operator=(cmDepends const&); // Purposely not implemented.
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "cmFileTimeComparison.h"
|
#include "cmFileTimeComparison.h"
|
||||||
#include "cmLocalGenerator.h"
|
#include "cmLocalGenerator.h"
|
||||||
|
#include "cmMakefile.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
|
|
||||||
#include <ctype.h> // isspace
|
#include <ctype.h> // isspace
|
||||||
@ -31,25 +32,53 @@
|
|||||||
#define INCLUDE_REGEX_COMPLAIN_MARKER "#IncludeRegexComplain: "
|
#define INCLUDE_REGEX_COMPLAIN_MARKER "#IncludeRegexComplain: "
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmDependsC::cmDependsC():
|
cmDependsC::cmDependsC()
|
||||||
IncludePath(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// yummy look at all those constructor arguments
|
cmDependsC::cmDependsC(cmLocalGenerator* lg, const char* targetDir,
|
||||||
cmDependsC::cmDependsC(std::vector<std::string> const& includes,
|
const char* lang): cmDepends(lg, targetDir)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
|
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();
|
this->ReadCacheFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,11 +109,6 @@ bool cmDependsC::WriteDependencies(const char *src, const char *obj,
|
|||||||
cmSystemTools::Error("Cannot scan dependencies without an object file.");
|
cmSystemTools::Error("Cannot scan dependencies without an object file.");
|
||||||
return false;
|
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.
|
// Walk the dependency graph starting with the source file.
|
||||||
bool first = true;
|
bool first = true;
|
||||||
@ -138,7 +162,7 @@ bool cmDependsC::WriteDependencies(const char *src, const char *obj,
|
|||||||
cacheKey += current.FileName;
|
cacheKey += current.FileName;
|
||||||
|
|
||||||
for(std::vector<std::string>::const_iterator i =
|
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;
|
cacheKey+=*i;
|
||||||
}
|
}
|
||||||
@ -149,7 +173,7 @@ bool cmDependsC::WriteDependencies(const char *src, const char *obj,
|
|||||||
fullName=headerLocationIt->second;
|
fullName=headerLocationIt->second;
|
||||||
}
|
}
|
||||||
else for(std::vector<std::string>::const_iterator i =
|
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
|
// Construct the name of the file as if it were in the current
|
||||||
// include directory. Avoid using a leading "./".
|
// include directory. Avoid using a leading "./".
|
||||||
|
@ -30,9 +30,7 @@ public:
|
|||||||
/** Checking instances need to know the build directory name and the
|
/** Checking instances need to know the build directory name and the
|
||||||
relative path from the build directory to the target file. */
|
relative path from the build directory to the target file. */
|
||||||
cmDependsC();
|
cmDependsC();
|
||||||
cmDependsC(std::vector<std::string> const& includes,
|
cmDependsC(cmLocalGenerator* lg, const char* targetDir, const char* lang);
|
||||||
const char* scanRegex, const char* complainRegex,
|
|
||||||
const cmStdString& cachFileName);
|
|
||||||
|
|
||||||
/** Virtual destructor to cleanup subclasses properly. */
|
/** Virtual destructor to cleanup subclasses properly. */
|
||||||
virtual ~cmDependsC();
|
virtual ~cmDependsC();
|
||||||
@ -50,9 +48,6 @@ protected:
|
|||||||
void Scan(std::istream& is, const char* directory,
|
void Scan(std::istream& is, const char* directory,
|
||||||
const cmStdString& fullName);
|
const cmStdString& fullName);
|
||||||
|
|
||||||
// The include file search path.
|
|
||||||
std::vector<std::string> const* IncludePath;
|
|
||||||
|
|
||||||
// Regular expression to identify C preprocessor include directives.
|
// Regular expression to identify C preprocessor include directives.
|
||||||
cmsys::RegularExpression IncludeRegexLine;
|
cmsys::RegularExpression IncludeRegexLine;
|
||||||
|
|
||||||
@ -60,9 +55,9 @@ protected:
|
|||||||
// recursively and which to complain about not finding.
|
// recursively and which to complain about not finding.
|
||||||
cmsys::RegularExpression IncludeRegexScan;
|
cmsys::RegularExpression IncludeRegexScan;
|
||||||
cmsys::RegularExpression IncludeRegexComplain;
|
cmsys::RegularExpression IncludeRegexComplain;
|
||||||
const std::string IncludeRegexLineString;
|
std::string IncludeRegexLineString;
|
||||||
const std::string IncludeRegexScanString;
|
std::string IncludeRegexScanString;
|
||||||
const std::string IncludeRegexComplainString;
|
std::string IncludeRegexComplainString;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Data structures for dependency graph walk.
|
// Data structures for dependency graph walk.
|
||||||
|
@ -131,17 +131,25 @@ public:
|
|||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmDependsFortran::cmDependsFortran():
|
cmDependsFortran::cmDependsFortran():
|
||||||
IncludePath(0), PPDefinitions(0), Internal(0)
|
PPDefinitions(0), Internal(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmDependsFortran
|
cmDependsFortran
|
||||||
::cmDependsFortran(std::vector<std::string> const& includes,
|
::cmDependsFortran(cmLocalGenerator* lg):
|
||||||
std::vector<std::string> const& definitions):
|
cmDepends(lg),
|
||||||
IncludePath(&includes),
|
|
||||||
Internal(new cmDependsFortranInternals)
|
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
|
// translate i.e. FOO=BAR to FOO and add it to the list of defined
|
||||||
// preprocessor symbols
|
// preprocessor symbols
|
||||||
for(std::vector<std::string>::const_iterator
|
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.");
|
cmSystemTools::Error("Cannot scan dependencies without an object file.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!this->IncludePath)
|
|
||||||
{
|
|
||||||
cmSystemTools::Error("Cannot scan dependencies without an include path.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the information object for this source.
|
// Get the information object for this source.
|
||||||
cmDependsFortranSourceInfo& info =
|
cmDependsFortranSourceInfo& info =
|
||||||
@ -595,7 +598,7 @@ bool cmDependsFortran::FindModule(std::string const& name,
|
|||||||
// Search the include path for the module.
|
// Search the include path for the module.
|
||||||
std::string fullName;
|
std::string fullName;
|
||||||
for(std::vector<std::string>::const_iterator i =
|
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.
|
// Try the lower-case name.
|
||||||
fullName = *i;
|
fullName = *i;
|
||||||
@ -887,7 +890,7 @@ bool cmDependsFortran::FindIncludeFile(const char* dir,
|
|||||||
|
|
||||||
// Search the include path for the file.
|
// Search the include path for the file.
|
||||||
for(std::vector<std::string>::const_iterator i =
|
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 = *i;
|
||||||
fullName += "/";
|
fullName += "/";
|
||||||
|
@ -36,8 +36,7 @@ public:
|
|||||||
path from the build directory to the target file, the source
|
path from the build directory to the target file, the source
|
||||||
file from which to start scanning, the include file search
|
file from which to start scanning, the include file search
|
||||||
path, and the target directory. */
|
path, and the target directory. */
|
||||||
cmDependsFortran(std::vector<std::string> const& includes,
|
cmDependsFortran(cmLocalGenerator* lg);
|
||||||
std::vector<std::string> const& defines);
|
|
||||||
|
|
||||||
/** Virtual destructor to cleanup subclasses properly. */
|
/** Virtual destructor to cleanup subclasses properly. */
|
||||||
virtual ~cmDependsFortran();
|
virtual ~cmDependsFortran();
|
||||||
@ -85,8 +84,6 @@ protected:
|
|||||||
// The source file from which to start scanning.
|
// The source file from which to start scanning.
|
||||||
std::string SourceFile;
|
std::string SourceFile;
|
||||||
|
|
||||||
// The include file search path.
|
|
||||||
std::vector<std::string> const* IncludePath;
|
|
||||||
std::vector<std::string> PPDefinitions;
|
std::vector<std::string> PPDefinitions;
|
||||||
|
|
||||||
// Internal implementation details.
|
// Internal implementation details.
|
||||||
|
@ -1473,68 +1473,18 @@ cmLocalUnixMakefileGenerator3
|
|||||||
{
|
{
|
||||||
// construct the checker
|
// construct the checker
|
||||||
std::string lang = li->c_str();
|
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
|
// Create the scanner for this language
|
||||||
cmDepends *scanner = 0;
|
cmDepends *scanner = 0;
|
||||||
if(lang == "C" || lang == "CXX" || lang == "RC")
|
if(lang == "C" || lang == "CXX" || lang == "RC")
|
||||||
{
|
{
|
||||||
std::string includeCacheFileName = dir;
|
|
||||||
includeCacheFileName += "/";
|
|
||||||
includeCacheFileName += lang;
|
|
||||||
includeCacheFileName += ".includecache";
|
|
||||||
|
|
||||||
// TODO: Handle RC (resource files) dependencies correctly.
|
// TODO: Handle RC (resource files) dependencies correctly.
|
||||||
scanner = new cmDependsC(includes,
|
scanner = new cmDependsC(this, targetDir, lang.c_str());
|
||||||
includeRegexScan.c_str(),
|
|
||||||
includeRegexComplain.c_str(),
|
|
||||||
includeCacheFileName);
|
|
||||||
}
|
}
|
||||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||||
else if(lang == "Fortran")
|
else if(lang == "Fortran")
|
||||||
{
|
{
|
||||||
std::vector<std::string> defines;
|
scanner = new cmDependsFortran(this);
|
||||||
if(const char* c_defines =
|
|
||||||
mf->GetDefinition("CMAKE_TARGET_DEFINITIONS"))
|
|
||||||
{
|
|
||||||
cmSystemTools::ExpandListArgument(c_defines, defines);
|
|
||||||
}
|
|
||||||
|
|
||||||
scanner = new cmDependsFortran(includes, defines);
|
|
||||||
}
|
}
|
||||||
else if(lang == "Java")
|
else if(lang == "Java")
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user