diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index 93beee659..327f508a0 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -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 pairs; + cmSystemTools::ExpandListArgument(srcStr, pairs); + + for(std::vector::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; } //---------------------------------------------------------------------------- diff --git a/Source/cmDepends.h b/Source/cmDepends.h index 40dc59ab9..4f7a02b35 100644 --- a/Source/cmDepends.h +++ b/Source/cmDepends.h @@ -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; diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index 34aa39d94..b0c666fa6 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -90,9 +90,8 @@ cmDependsFortran::cmDependsFortran(): } //---------------------------------------------------------------------------- -cmDependsFortran::cmDependsFortran(std::vector const& includes, - std::string const& targetDirectory): - IncludePath(&includes), TargetDirectory(targetDirectory) +cmDependsFortran::cmDependsFortran(std::vector const& includes): + IncludePath(&includes) { } diff --git a/Source/cmDependsFortran.h b/Source/cmDependsFortran.h index 3b35315a4..9ed087f3f 100644 --- a/Source/cmDependsFortran.h +++ b/Source/cmDependsFortran.h @@ -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 const& includes, - std::string const& targetDirectory); + cmDependsFortran(std::vector const& includes); /** Virtual destructor to cleanup subclasses properly. */ virtual ~cmDependsFortran(); @@ -62,9 +61,6 @@ protected: // The include file search path. std::vector 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. diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 550165bae..49a068cee 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -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 srcs; - cmSystemTools::ExpandListArgument(srcStr, srcs); - for (std::vector::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;