cmClassFile.cxx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifdef _MSC_VER
  2. #pragma warning ( disable : 4786 )
  3. #endif
  4. #include "cmClassFile.h"
  5. #include <sys/stat.h>
  6. #include <iostream>
  7. // Helper function to hide the use of system stat function
  8. bool cmFileExists(const char* filename)
  9. {
  10. struct stat fs;
  11. if (stat(filename, &fs) != 0)
  12. {
  13. return false;
  14. }
  15. else
  16. {
  17. return true;
  18. }
  19. }
  20. // Set the name of the class and the full path to the file.
  21. // The class must be found in dir and end in name.cxx, name.txx,
  22. // name.c or it will be considered a header file only class
  23. // and not included in the build process
  24. void cmClassFile::SetName(const char* name, const char* dir)
  25. {
  26. m_HeaderFileOnly = true;
  27. m_ClassName = name;
  28. std::string pathname = dir;
  29. if(pathname != "")
  30. {
  31. pathname += "/";
  32. }
  33. pathname += m_ClassName;
  34. std::string hname = pathname;
  35. hname += ".cxx";
  36. if(cmFileExists(hname.c_str()))
  37. {
  38. m_HeaderFileOnly = false;
  39. m_FullPath = hname;
  40. return;
  41. }
  42. hname = pathname;
  43. hname += ".c";
  44. if(cmFileExists(hname.c_str()))
  45. {
  46. m_HeaderFileOnly = false;
  47. m_FullPath = hname;
  48. return;
  49. }
  50. hname = pathname;
  51. hname += ".txx";
  52. if(cmFileExists(hname.c_str()))
  53. {
  54. m_HeaderFileOnly = false;
  55. m_FullPath = hname;
  56. return;
  57. }
  58. std::cerr << "file seems to be a header only " << hname << " " << m_ClassName.c_str() << std::endl;
  59. }
  60. void cmClassFile::Print()
  61. {
  62. if(m_AbstractClass)
  63. std::cout << "Abstract ";
  64. else
  65. std::cout << "Concrete ";
  66. if(m_HeaderFileOnly)
  67. std::cout << "Header file ";
  68. else
  69. std::cout << "CXX file ";
  70. std::cout << m_ClassName << std::endl;
  71. }