diff --git a/Source/cmCableSourceFilesCommand.cxx b/Source/cmCableSourceFilesCommand.cxx index d41dcc8d5..466560242 100644 --- a/Source/cmCableSourceFilesCommand.cxx +++ b/Source/cmCableSourceFilesCommand.cxx @@ -48,17 +48,13 @@ void cmCableSourceFilesCommand::WriteConfiguration() const cmRegularExpression needCdataBlock("[&<>]"); - // Look for the files on a path relative to the current CMakeLists.txt. - std::string curPath = m_Makefile->GetCurrentDirectory(); - curPath += "/"; - os << indent << "" << std::endl; for(Entries::const_iterator f = m_Entries.begin(); f != m_Entries.end(); ++f) { // Look for the normal include file. std::string header = *f+".h"; - if(cmSystemTools::FileExists((curPath+header).c_str())) + if(this->SourceFileExists(header)) { os << indent << " " << std::endl; @@ -70,7 +66,7 @@ void cmCableSourceFilesCommand::WriteConfiguration() const // Look for an instantiation file. std::string txx = *f+".txx"; - if(cmSystemTools::FileExists((curPath+txx).c_str())) + if(this->SourceFileExists(txx)) { os << indent << " " << std::endl; @@ -78,3 +74,40 @@ void cmCableSourceFilesCommand::WriteConfiguration() const } os << indent << "" << std::endl; } + + +/** + * Search the include path for the specified file. + */ +bool cmCableSourceFilesCommand::SourceFileExists(const std::string& name) const +{ + // We must locate the file in the include path so that we can detect + // its extension, and whether there is more than one to find. + std::string file = name; + m_Makefile->ExpandVariablesInString(file); + + // See if the file just exists here. The compiler's search path will + // locate it. + if(cmSystemTools::FileExists(file.c_str())) + { + return true; + } + + // We must look for the file in the include search path. + const std::vector& includeDirectories = + m_Makefile->GetIncludeDirectories(); + + for(std::vector::const_iterator dir = includeDirectories.begin(); + dir != includeDirectories.end(); ++dir) + { + std::string path = *dir + "/"; + m_Makefile->ExpandVariablesInString(path); + if(cmSystemTools::FileExists((path+file).c_str())) + { + return true; + } + } + + // We couldn't locate the source file. + return false; +} diff --git a/Source/cmCableSourceFilesCommand.h b/Source/cmCableSourceFilesCommand.h index 866eb50a9..4aefeb032 100644 --- a/Source/cmCableSourceFilesCommand.h +++ b/Source/cmCableSourceFilesCommand.h @@ -68,7 +68,8 @@ public: } virtual void WriteConfiguration() const; - + bool SourceFileExists(const std::string&) const; + cmTypeMacro(cmCableSourceFilesCommand, cmCableCommand); protected: typedef cmCablePackageEntryCommand::Entries Entries;