summaryrefslogtreecommitdiffstats
path: root/Source/cmDepends.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2005-01-18 22:09:05 (GMT)
committerBrad King <brad.king@kitware.com>2005-01-18 22:09:05 (GMT)
commit195cdf172e2eecdb1b7fb3c2154cfe34c14afd9f (patch)
tree41c1bbb581fed83207b8d0f6515c8ea018061a46 /Source/cmDepends.cxx
parented9e0626fdf7d0d97733997d3b40a886cc082ebf (diff)
downloadCMake-195cdf172e2eecdb1b7fb3c2154cfe34c14afd9f.zip
CMake-195cdf172e2eecdb1b7fb3c2154cfe34c14afd9f.tar.gz
CMake-195cdf172e2eecdb1b7fb3c2154cfe34c14afd9f.tar.bz2
ENH: Split dependency scanning and checking into separate cmDepends superclass with language-specific subclasses such as cmDependsC.
Diffstat (limited to 'Source/cmDepends.cxx')
-rw-r--r--Source/cmDepends.cxx96
1 files changed, 96 insertions, 0 deletions
diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx
new file mode 100644
index 0000000..4933f5f
--- /dev/null
+++ b/Source/cmDepends.cxx
@@ -0,0 +1,96 @@
+/*=========================================================================
+
+ Program: CMake - Cross-Platform Makefile Generator
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+ Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
+ See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*/
+#include "cmDepends.h"
+
+#include "cmGeneratedFileStream.h"
+#include "cmSystemTools.h"
+
+//----------------------------------------------------------------------------
+cmDepends::cmDepends(const char* dir, const char* targetFile):
+ m_Directory(dir),
+ m_TargetFile(targetFile),
+ m_DependsMakeFile(dir),
+ m_DependsMarkFile(dir)
+{
+ // Construct the path to the make and mark files. Append
+ // appropriate extensions to their names.
+ m_DependsMakeFile += "/";
+ m_DependsMarkFile += "/";
+ m_DependsMakeFile += m_TargetFile;
+ m_DependsMarkFile += m_TargetFile;
+ m_DependsMakeFile += ".depends.make";
+ m_DependsMarkFile += ".depends";
+}
+
+//----------------------------------------------------------------------------
+cmDepends::~cmDepends()
+{
+}
+
+//----------------------------------------------------------------------------
+void cmDepends::Write()
+{
+ // Try to generate dependencies for the target file.
+ cmGeneratedFileStream fout(m_DependsMakeFile.c_str());
+ fout << "# Dependencies for " << m_TargetFile.c_str() << std::endl;
+ if(this->WriteDependencies(fout) && fout)
+ {
+ // Dependencies were generated. Touch the mark file.
+ std::ofstream fmark(m_DependsMarkFile.c_str());
+ fmark << "Dependencies updated for " << m_TargetFile.c_str() << std::endl;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDepends::Check()
+{
+ // Check whether dependencies must be regenerated.
+ std::ifstream fin(m_DependsMakeFile.c_str());
+ if(!(fin && this->CheckDependencies(fin)))
+ {
+ // Clear all dependencies so they will be regenerated.
+ this->Clear();
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmDepends::Clear()
+{
+ // Remove the dependency mark file to be sure dependencies will be
+ // regenerated.
+ cmSystemTools::RemoveFile(m_DependsMarkFile.c_str());
+
+ // Write an empty dependency file.
+ cmGeneratedFileStream depFileStream(m_DependsMakeFile.c_str());
+ depFileStream
+ << "# Empty dependencies file for " << m_TargetFile.c_str() << ".\n"
+ << "# This may be replaced when dependencies are built." << std::endl;
+}
+
+//----------------------------------------------------------------------------
+const char* cmDepends::GetMakeFileName()
+{
+ // Skip over the directory part of the name.
+ return m_DependsMakeFile.c_str() + m_Directory.length() + 1;
+}
+
+//----------------------------------------------------------------------------
+const char* cmDepends::GetMarkFileName()
+{
+ // Skip over the directory part of the name.
+ return m_DependsMarkFile.c_str() + m_Directory.length() + 1;
+}