cmCableSourceFilesCommand.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. cmCablePackageCommand *cablePackage = m_CableData->GetCurrentPackage();
  18. std::string fileName = "Cxx/";
  19. fileName += cablePackage->GetPackageName();
  20. fileName += "_cxx";
  21. cmClassFile *ci = m_Makefile->GetClass(cablePackage->GetPackageName(),
  22. fileName.c_str());
  23. if(ci == 0)
  24. { return; }
  25. // The package's file has not yet been generated yet. The dependency
  26. // finder will need hints. Add one for each source file.
  27. for(Entries::const_iterator f = m_Entries.begin();
  28. f != m_Entries.end(); ++f)
  29. {
  30. std::string header = *f+".h";
  31. ci->m_Depends.push_back(header);
  32. }
  33. }
  34. /**
  35. * Write the CABLE configuration code to indicate header dependencies for
  36. * a package.
  37. */
  38. void cmCableSourceFilesCommand::WriteConfiguration() const
  39. {
  40. std::ostream& os = m_CableData->GetOutputStream();
  41. cmCableData::Indentation indent = m_CableData->GetIndentation();
  42. cmRegularExpression needCdataBlock("[&<>]");
  43. os << indent << "<Headers>" << std::endl;
  44. for(Entries::const_iterator f = m_Entries.begin();
  45. f != m_Entries.end(); ++f)
  46. {
  47. // Look for the normal include file.
  48. std::string header = *f+".h";
  49. if(this->SourceFileExists(header))
  50. {
  51. os << indent << " <File name=\"" << header.c_str() << "\"/>"
  52. << std::endl;
  53. }
  54. else
  55. {
  56. cmSystemTools::Error("Unable to find source file ", header.c_str());
  57. }
  58. // Look for an instantiation file.
  59. std::string txx = *f+".txx";
  60. if(this->SourceFileExists(txx))
  61. {
  62. os << indent << " <File name=\"" << txx.c_str()
  63. << "\" purpose=\"instantiate\"/>" << std::endl;
  64. }
  65. }
  66. os << indent << "</Headers>" << std::endl;
  67. }
  68. /**
  69. * Search the include path for the specified file.
  70. */
  71. bool cmCableSourceFilesCommand::SourceFileExists(const std::string& name) const
  72. {
  73. // We must locate the file in the include path so that we can detect
  74. // its extension, and whether there is more than one to find.
  75. std::string file = name;
  76. m_Makefile->ExpandVariablesInString(file);
  77. // See if the file just exists here. The compiler's search path will
  78. // locate it.
  79. if(cmSystemTools::FileExists(file.c_str()))
  80. {
  81. return true;
  82. }
  83. // We must look for the file in the include search path.
  84. const std::vector<std::string>& includeDirectories =
  85. m_Makefile->GetIncludeDirectories();
  86. for(std::vector<std::string>::const_iterator dir = includeDirectories.begin();
  87. dir != includeDirectories.end(); ++dir)
  88. {
  89. std::string path = *dir + "/";
  90. m_Makefile->ExpandVariablesInString(path);
  91. if(cmSystemTools::FileExists((path+file).c_str()))
  92. {
  93. return true;
  94. }
  95. }
  96. // We couldn't locate the source file.
  97. return false;
  98. }