cmAuxSourceDirectoryCommand.cxx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmAuxSourceDirectoryCommand.h"
  14. #include "cmDirectory.h"
  15. #include "cmSourceFile.h"
  16. // cmAuxSourceDirectoryCommand
  17. bool cmAuxSourceDirectoryCommand::InitialPass(std::vector<std::string> const& args)
  18. {
  19. if(args.size() < 2 || args.size() > 2)
  20. {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. std::string sourceListValue;
  25. std::string templateDirectory = args[0];
  26. m_Makefile->AddExtraDirectory(templateDirectory.c_str());
  27. std::string tdir = m_Makefile->GetCurrentDirectory();
  28. tdir += "/";
  29. tdir += templateDirectory;
  30. // was the list already populated
  31. const char *def = m_Makefile->GetDefinition(args[1].c_str());
  32. if (def)
  33. {
  34. sourceListValue = def;
  35. }
  36. // Load all the files in the directory
  37. cmDirectory dir;
  38. if(dir.Load(tdir.c_str()))
  39. {
  40. size_t numfiles = dir.GetNumberOfFiles();
  41. for(size_t i =0; i < numfiles; ++i)
  42. {
  43. std::string file = dir.GetFile(i);
  44. // Split the filename into base and extension
  45. std::string::size_type dotpos = file.rfind(".");
  46. if( dotpos != std::string::npos )
  47. {
  48. std::string ext = file.substr(dotpos+1);
  49. file = file.substr(0, dotpos);
  50. // Process only source files
  51. if( file.size() != 0
  52. && std::find( m_Makefile->GetSourceExtensions().begin(),
  53. m_Makefile->GetSourceExtensions().end(), ext )
  54. != m_Makefile->GetSourceExtensions().end() )
  55. {
  56. std::string fullname = templateDirectory;
  57. fullname += "/";
  58. fullname += file;
  59. // add the file as a class file so
  60. // depends can be done
  61. cmSourceFile cmfile;
  62. cmfile.SetName(fullname.c_str(), m_Makefile->GetCurrentDirectory(),
  63. m_Makefile->GetSourceExtensions(),
  64. m_Makefile->GetHeaderExtensions());
  65. cmfile.SetProperty("ABSTRACT","0");
  66. m_Makefile->AddSource(cmfile);
  67. if (sourceListValue.size() > 0)
  68. {
  69. sourceListValue += ";";
  70. }
  71. sourceListValue += cmfile.GetSourceName();
  72. }
  73. }
  74. }
  75. }
  76. m_Makefile->AddDefinition(args[1].c_str(), sourceListValue.c_str());
  77. return true;
  78. }