cmCableSourceFilesCommand.cxx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2001 Insight Consortium
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. * The name of the Insight Consortium, nor the names of any consortium members,
  17. nor of any contributors, may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. * Modified source versions must be plainly marked as such, and must not be
  20. misrepresented as being the original software.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  25. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. =========================================================================*/
  32. #include "cmCableSourceFilesCommand.h"
  33. #include "cmCacheManager.h"
  34. void cmCableSourceFilesCommand::FinalPass()
  35. {
  36. // Get the index of the current package's cmClassFile.
  37. // If it doesn't exist, ignore this command.
  38. cmCablePackageCommand *cablePackage = m_CableData->GetCurrentPackage();
  39. std::string fileName = "Cxx/";
  40. fileName += cablePackage->GetPackageName();
  41. fileName += "_cxx";
  42. cmSourceFile *ci = m_Makefile->GetSource(cablePackage->GetPackageName(),
  43. fileName.c_str());
  44. if(ci == 0)
  45. { return; }
  46. // The package's file has not yet been generated yet. The dependency
  47. // finder will need hints. Add one for each source file.
  48. for(Entries::const_iterator f = m_Entries.begin();
  49. f != m_Entries.end(); ++f)
  50. {
  51. std::string header = *f+".h";
  52. ci->GetDepends().push_back(header);
  53. }
  54. }
  55. /**
  56. * Write the CABLE configuration code to indicate header dependencies for
  57. * a package.
  58. */
  59. bool cmCableSourceFilesCommand::WriteConfiguration()
  60. {
  61. std::ostream& os = m_CableData->GetOutputStream();
  62. cmCableData::Indentation indent = m_CableData->GetIndentation();
  63. cmRegularExpression needCdataBlock("[&<>]");
  64. os << indent << "<Headers>" << std::endl;
  65. for(Entries::const_iterator f = m_Entries.begin();
  66. f != m_Entries.end(); ++f)
  67. {
  68. // Look for the normal include file.
  69. std::string header = *f+".h";
  70. if(this->SourceFileExists(header))
  71. {
  72. os << indent << " <File name=\"" << header.c_str() << "\"/>"
  73. << std::endl;
  74. }
  75. else
  76. {
  77. cmSystemTools::Error("Unable to find source file ", header.c_str());
  78. }
  79. // Look for an instantiation file.
  80. std::string txx = *f+".txx";
  81. if(this->SourceFileExists(txx))
  82. {
  83. os << indent << " <File name=\"" << txx.c_str()
  84. << "\" purpose=\"instantiate\"/>" << std::endl;
  85. }
  86. }
  87. os << indent << "</Headers>" << std::endl;
  88. return true;
  89. }
  90. /**
  91. * Search the include path for the specified file.
  92. */
  93. bool cmCableSourceFilesCommand::SourceFileExists(const std::string& name) const
  94. {
  95. // We must locate the file in the include path so that we can detect
  96. // its extension, and whether there is more than one to find.
  97. std::string file = name;
  98. m_Makefile->ExpandVariablesInString(file);
  99. // See if the file just exists here. The compiler's search path will
  100. // locate it.
  101. if(cmSystemTools::FileExists(file.c_str()))
  102. {
  103. return true;
  104. }
  105. // We must look for the file in the include search path.
  106. const std::vector<std::string>& includeDirectories =
  107. m_Makefile->GetIncludeDirectories();
  108. for(std::vector<std::string>::const_iterator dir = includeDirectories.begin();
  109. dir != includeDirectories.end(); ++dir)
  110. {
  111. std::string path = *dir + "/";
  112. m_Makefile->ExpandVariablesInString(path);
  113. if(cmSystemTools::FileExists((path+file).c_str()))
  114. {
  115. return true;
  116. }
  117. }
  118. // We couldn't locate the source file.
  119. return false;
  120. }