some cleanup to the make depend process

This commit is contained in:
Ken Martin 2001-06-12 09:00:21 -04:00
parent d0614d75ea
commit ff529aa861
4 changed files with 104 additions and 38 deletions

View File

@ -64,7 +64,7 @@ cmMakeDepend::~cmMakeDepend()
// The pointer is kept so the cmSourceFile array can // The pointer is kept so the cmSourceFile array can
// be updated with the depend information in the cmMakefile. // be updated with the depend information in the cmMakefile.
void cmMakeDepend::SetMakefile(cmMakefile* makefile) void cmMakeDepend::SetMakefile(const cmMakefile* makefile)
{ {
m_Makefile = makefile; m_Makefile = makefile;
@ -73,20 +73,20 @@ void cmMakeDepend::SetMakefile(cmMakefile* makefile)
m_Makefile->m_IncludeFileRegularExpression.c_str()); m_Makefile->m_IncludeFileRegularExpression.c_str());
// Now extract any include paths from the makefile flags // Now extract any include paths from the makefile flags
std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories(); const std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
std::vector<std::string>::iterator j; std::vector<std::string>::const_iterator j;
for(j = includes.begin(); j != includes.end(); ++j) for(j = includes.begin(); j != includes.end(); ++j)
{ {
this->AddSearchPath(j->c_str()); this->AddSearchPath(j->c_str());
} }
// Now create cmDependInformation objects for files in the directory // Now create cmDependInformation objects for files in the directory
cmTargets &tgts = m_Makefile->GetTargets(); const cmTargets &tgts = m_Makefile->GetTargets();
for(cmTargets::iterator l = tgts.begin(); for(cmTargets::const_iterator l = tgts.begin();
l != tgts.end(); l++) l != tgts.end(); l++)
{ {
std::vector<cmSourceFile> &classes = l->second.GetSourceFiles(); const std::vector<cmSourceFile> &classes = l->second.GetSourceFiles();
for(std::vector<cmSourceFile>::iterator i = classes.begin(); for(std::vector<cmSourceFile>::const_iterator i = classes.begin();
i != classes.end(); ++i) i != classes.end(); ++i)
{ {
if(!i->GetIsAHeaderFileOnly()) if(!i->GetIsAHeaderFileOnly())
@ -104,7 +104,7 @@ void cmMakeDepend::SetMakefile(cmMakefile* makefile)
// Compute the depends. // Compute the depends.
void cmMakeDepend::DoDepends() void cmMakeDepend::GenerateDependInformation()
{ {
// The size of the m_DependInformation will change as // The size of the m_DependInformation will change as
// Depend is called so do not use an iterater but rather // Depend is called so do not use an iterater but rather
@ -119,25 +119,43 @@ void cmMakeDepend::DoDepends()
this->Depend(info); this->Depend(info);
++j; ++j;
} }
}
const cmDependInformation *
cmMakeDepend::GetDependInformationForSourceFile(const cmSourceFile &sf) const
{
// Now update the depend information for each cmSourceFile // Now update the depend information for each cmSourceFile
// in the cmMakefile m_Makefile // in the cmMakefile m_Makefile
for(DependArray::iterator i = m_DependInformation.begin(); for(DependArray::const_iterator i = m_DependInformation.begin();
i != m_DependInformation.end(); ++i) i != m_DependInformation.end(); ++i)
{ {
cmDependInformation* info = *i; cmDependInformation* info = *i;
// find the class // find the class
if(info->m_ClassFileIndex != 0) if(info->m_ClassFileIndex == &sf)
{ {
cmSourceFile& cfile = *(info->m_ClassFileIndex); return info;
for( cmDependInformation::IndexSet::const_iterator indx = info->m_IndexSet.begin();
indx != info->m_IndexSet.end(); ++indx)
{
cfile.GetDepends().push_back(m_DependInformation[*indx]->m_FullPath);
}
} }
} }
return 0;
} }
const cmDependInformation *
cmMakeDepend::GetDependInformationForSourceFile(const char *fname) const
{
// Now update the depend information for each cmSourceFile
// in the cmMakefile m_Makefile
for(DependArray::const_iterator i = m_DependInformation.begin();
i != m_DependInformation.end(); ++i)
{
cmDependInformation* info = *i;
// find the class
if(info->m_FullPath == fname)
{
return info;
}
}
return 0;
}
void cmMakeDepend::Depend(cmDependInformation* info) void cmMakeDepend::Depend(cmDependInformation* info)
{ {
@ -155,9 +173,9 @@ void cmMakeDepend::Depend(cmDependInformation* info)
// exist since we can find the dependencies for real. // exist since we can find the dependencies for real.
if(info->m_ClassFileIndex != 0) if(info->m_ClassFileIndex != 0)
{ {
cmSourceFile& cFile = *(info->m_ClassFileIndex); const cmSourceFile& cFile = *(info->m_ClassFileIndex);
cFile.GetDepends().erase(cFile.GetDepends().begin(), //cFile.GetDepends().erase(cFile.GetDepends().begin(),
cFile.GetDepends().end()); // cFile.GetDepends().end());
} }
// Use the real file to find its dependencies. // Use the real file to find its dependencies.
@ -171,14 +189,14 @@ void cmMakeDepend::Depend(cmDependInformation* info)
if(info->m_ClassFileIndex != 0) if(info->m_ClassFileIndex != 0)
{ {
// Get the cmSourceFile corresponding to this. // Get the cmSourceFile corresponding to this.
cmSourceFile& cFile = *(info->m_ClassFileIndex); const cmSourceFile& cFile = *(info->m_ClassFileIndex);
// See if there are any hints for finding dependencies for the missing // See if there are any hints for finding dependencies for the missing
// file. // file.
if(!cFile.GetDepends().empty()) if(!cFile.GetDepends().empty())
{ {
// Initial dependencies have been given. Use them to begin the // Initial dependencies have been given. Use them to begin the
// recursion. // recursion.
for(std::vector<std::string>::iterator file = for(std::vector<std::string>::const_iterator file =
cFile.GetDepends().begin(); file != cFile.GetDepends().end(); cFile.GetDepends().begin(); file != cFile.GetDepends().end();
++file) ++file)
{ {
@ -187,8 +205,8 @@ void cmMakeDepend::Depend(cmDependInformation* info)
// Erase the dependency hints from the cmSourceFile. They will be // Erase the dependency hints from the cmSourceFile. They will be
// put in again as real dependencies later. // put in again as real dependencies later.
cFile.GetDepends().erase(cFile.GetDepends().begin(), //cFile.GetDepends().erase(cFile.GetDepends().begin(),
cFile.GetDepends().end()); // cFile.GetDepends().end());
// Found dependency information. We are done. // Found dependency information. We are done.
return; return;
@ -320,7 +338,11 @@ void cmDependInformation::MergeInfo(cmDependInformation* info)
{ {
if(this != info) if(this != info)
{ {
m_IndexSet.insert(info->m_IndexSet.begin(), info->m_IndexSet.end()); for (std::set<int>::const_iterator p = info->m_IndexSet.begin();
p != info->m_IndexSet.end(); ++p)
{
m_IndexSet.insert(*p);
}
} }
} }

View File

@ -51,8 +51,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This structure stores the depend information for a single source file. * This structure stores the depend information for a single source file.
*/ */
struct cmDependInformation class cmDependInformation
{ {
public:
/** /**
* Construct with dependency generation marked not done; instance * Construct with dependency generation marked not done; instance
* not placed in cmMakefile's list. * not placed in cmMakefile's list.
@ -85,7 +86,7 @@ struct cmDependInformation
* The index into the cmMakefile::m_Classes list. * The index into the cmMakefile::m_Classes list.
* The index value of 0 indicates that it is not in the list. * The index value of 0 indicates that it is not in the list.
*/ */
cmSourceFile *m_ClassFileIndex; const cmSourceFile *m_ClassFileIndex;
/** /**
* This flag indicates whether dependency checking has been * This flag indicates whether dependency checking has been
@ -113,24 +114,37 @@ public:
/** /**
* Destructor. * Destructor.
*/ */
~cmMakeDepend(); virtual ~cmMakeDepend();
/** /**
* Set the makefile that is used as a source of classes. * Set the makefile that is used as a source of classes.
*/ */
void SetMakefile(cmMakefile* makefile); virtual void SetMakefile(const cmMakefile* makefile);
/** /**
* Generate the depend information * Generate the depend information
*/ */
void DoDepends(); virtual void GenerateDependInformation();
/**
* Get the depend info struct for a source file
*/
const cmDependInformation *GetDependInformationForSourceFile(const cmSourceFile &sf) const;
const cmDependInformation *GetDependInformationForSourceFile(const char *) const;
/**
* Get the depend info struct
*/
typedef std::vector<cmDependInformation*> DependArray;
const DependArray &GetDependInformation() const {
return m_DependInformation; }
/** /**
* Add a directory to the search path for include files. * Add a directory to the search path for include files.
*/ */
void AddSearchPath(const char*); virtual void AddSearchPath(const char*);
private: protected:
/** /**
* Add a source file to the search path. * Add a source file to the search path.
*/ */
@ -140,22 +154,22 @@ private:
* Find the index into the m_DependInformation array * Find the index into the m_DependInformation array
* that matches the given m_IncludeName. * that matches the given m_IncludeName.
*/ */
int FindInformation(const char* includeName); virtual int FindInformation(const char* includeName);
/** /**
* Compute the depend information for this class. * Compute the depend information for this class.
*/ */
void Depend(cmDependInformation* info); virtual void Depend(cmDependInformation* info);
/** /**
* Compute the depend information for this class. * Compute the depend information for this class.
*/ */
void DependWalk(cmDependInformation* info, const char* file); virtual void DependWalk(cmDependInformation* info, const char* file);
/** /**
* Add a dependency. Possibly walk it for more dependencies. * Add a dependency. Possibly walk it for more dependencies.
*/ */
void AddDependency(cmDependInformation* info, const char* file); virtual void AddDependency(cmDependInformation* info, const char* file);
/** /**
* Find the full path name for the given file name. * Find the full path name for the given file name.
@ -163,10 +177,9 @@ private:
*/ */
std::string FullPath(const char*); std::string FullPath(const char*);
cmMakefile* m_Makefile; const cmMakefile* m_Makefile;
bool m_Verbose; bool m_Verbose;
cmRegularExpression m_IncludeFileRegularExpression; cmRegularExpression m_IncludeFileRegularExpression;
typedef std::vector<cmDependInformation*> DependArray;
DependArray m_DependInformation; DependArray m_DependInformation;
std::vector<std::string> m_IncludeDirectories; std::vector<std::string> m_IncludeDirectories;
}; };

View File

@ -71,12 +71,42 @@ void cmUnixMakefileGenerator::GenerateMakefile()
// Generate depends // Generate depends
cmMakeDepend md; cmMakeDepend md;
md.SetMakefile(m_Makefile); md.SetMakefile(m_Makefile);
md.DoDepends(); md.GenerateDependInformation();
this->ProcessDepends(md);
// output the makefile fragment // output the makefile fragment
this->OutputMakefile("Makefile"); this->OutputMakefile("Makefile");
} }
} }
void cmUnixMakefileGenerator::ProcessDepends(const cmMakeDepend &md)
{
// Now create cmDependInformation objects for files in the directory
cmTargets &tgts = m_Makefile->GetTargets();
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
{
std::vector<cmSourceFile> &classes = l->second.GetSourceFiles();
for(std::vector<cmSourceFile>::iterator i = classes.begin();
i != classes.end(); ++i)
{
if(!i->GetIsAHeaderFileOnly())
{
// get the depends
const cmDependInformation *info =
md.GetDependInformationForSourceFile(*i);
if (info)
{
for( cmDependInformation::IndexSet::const_iterator indx =
info->m_IndexSet.begin();
indx != info->m_IndexSet.end(); ++indx)
{
i->GetDepends().push_back(md.GetDependInformation()[*indx]->m_FullPath);
}
}
}
}
}
}
// This is where CMakeTargets.make is generated // This is where CMakeTargets.make is generated
void cmUnixMakefileGenerator::OutputMakefile(const char* file) void cmUnixMakefileGenerator::OutputMakefile(const char* file)

View File

@ -92,6 +92,7 @@ public:
private: private:
void RecursiveGenerateCacheOnly(); void RecursiveGenerateCacheOnly();
void ProcessDepends(const cmMakeDepend &md);
void GenerateCacheOnly(); void GenerateCacheOnly();
void OutputMakefile(const char* file); void OutputMakefile(const char* file);
void OutputMakeFlags(std::ostream&); void OutputMakeFlags(std::ostream&);