cmCableSourceFilesCommand.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmCableSourceFilesCommand.h"
  12. #include "cmCacheManager.h"
  13. void cmCableSourceFilesCommand::FinalPass()
  14. {
  15. // Get the index of the current package's cmClassFile.
  16. // If it doesn't exist, ignore this command.
  17. int index = m_CableData->GetPackageClassIndex();
  18. if(index < 0)
  19. { return; }
  20. // The package's file has not yet been generated yet. The dependency
  21. // finder will need hints. Add one for each source file.
  22. cmClassFile& cFile = m_Makefile->GetClasses()[index];
  23. for(Entries::const_iterator f = m_Entries.begin();
  24. f != m_Entries.end(); ++f)
  25. {
  26. std::string header = *f+".h";
  27. cFile.m_Depends.push_back(header);
  28. }
  29. }
  30. /**
  31. * Write the CABLE configuration code to indicate header dependencies for
  32. * a package.
  33. */
  34. void cmCableSourceFilesCommand::WriteConfiguration() const
  35. {
  36. std::ostream& os = m_CableData->GetOutputStream();
  37. cmCableData::Indentation indent = m_CableData->GetIndentation();
  38. cmRegularExpression needCdataBlock("[&<>]");
  39. os << indent << "<Headers>" << std::endl;
  40. for(Entries::const_iterator f = m_Entries.begin();
  41. f != m_Entries.end(); ++f)
  42. {
  43. // Look for the normal include file.
  44. std::string header = *f+".h";
  45. if(this->SourceFileExists(header))
  46. {
  47. os << indent << " <File name=\"" << header.c_str() << "\"/>"
  48. << std::endl;
  49. }
  50. else
  51. {
  52. cmSystemTools::Error("Unable to find source file ", header.c_str());
  53. }
  54. // Look for an instantiation file.
  55. std::string txx = *f+".txx";
  56. if(this->SourceFileExists(txx))
  57. {
  58. os << indent << " <File name=\"" << txx.c_str()
  59. << "\" purpose=\"instantiate\"/>" << std::endl;
  60. }
  61. }
  62. os << indent << "</Headers>" << std::endl;
  63. }
  64. /**
  65. * Search the include path for the specified file.
  66. */
  67. bool cmCableSourceFilesCommand::SourceFileExists(const std::string& name) const
  68. {
  69. // We must locate the file in the include path so that we can detect
  70. // its extension, and whether there is more than one to find.
  71. std::string file = name;
  72. m_Makefile->ExpandVariablesInString(file);
  73. // See if the file just exists here. The compiler's search path will
  74. // locate it.
  75. if(cmSystemTools::FileExists(file.c_str()))
  76. {
  77. return true;
  78. }
  79. // We must look for the file in the include search path.
  80. const std::vector<std::string>& includeDirectories =
  81. m_Makefile->GetIncludeDirectories();
  82. for(std::vector<std::string>::const_iterator dir = includeDirectories.begin();
  83. dir != includeDirectories.end(); ++dir)
  84. {
  85. std::string path = *dir + "/";
  86. m_Makefile->ExpandVariablesInString(path);
  87. if(cmSystemTools::FileExists((path+file).c_str()))
  88. {
  89. return true;
  90. }
  91. }
  92. // We couldn't locate the source file.
  93. return false;
  94. }