cmAuxSourceDirectoryCommand.cxx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "cmSourceFile.h"
  15. #include <cmsys/Directory.hxx>
  16. // cmAuxSourceDirectoryCommand
  17. bool cmAuxSourceDirectoryCommand::InitialPass
  18. (std::vector<std::string> const& args, cmExecutionStatus &)
  19. {
  20. if(args.size() < 2 || args.size() > 2)
  21. {
  22. this->SetError("called with incorrect number of arguments");
  23. return false;
  24. }
  25. std::string sourceListValue;
  26. std::string templateDirectory = args[0];
  27. this->Makefile->AddExtraDirectory(templateDirectory.c_str());
  28. std::string tdir;
  29. if(!cmSystemTools::FileIsFullPath(templateDirectory.c_str()))
  30. {
  31. tdir = this->Makefile->GetCurrentDirectory();
  32. tdir += "/";
  33. tdir += templateDirectory;
  34. }
  35. else
  36. {
  37. tdir = templateDirectory;
  38. }
  39. // was the list already populated
  40. const char *def = this->Makefile->GetDefinition(args[1].c_str());
  41. if (def)
  42. {
  43. sourceListValue = def;
  44. }
  45. // Load all the files in the directory
  46. cmsys::Directory dir;
  47. if(dir.Load(tdir.c_str()))
  48. {
  49. size_t numfiles = dir.GetNumberOfFiles();
  50. for(size_t i =0; i < numfiles; ++i)
  51. {
  52. std::string file = dir.GetFile(static_cast<unsigned long>(i));
  53. // Split the filename into base and extension
  54. std::string::size_type dotpos = file.rfind(".");
  55. if( dotpos != std::string::npos )
  56. {
  57. std::string ext = file.substr(dotpos+1);
  58. std::string base = file.substr(0, dotpos);
  59. // Process only source files
  60. if( base.size() != 0
  61. && std::find( this->Makefile->GetSourceExtensions().begin(),
  62. this->Makefile->GetSourceExtensions().end(), ext )
  63. != this->Makefile->GetSourceExtensions().end() )
  64. {
  65. std::string fullname = templateDirectory;
  66. fullname += "/";
  67. fullname += file;
  68. // add the file as a class file so
  69. // depends can be done
  70. cmSourceFile* sf =
  71. this->Makefile->GetOrCreateSource(fullname.c_str());
  72. sf->SetProperty("ABSTRACT","0");
  73. if(!sourceListValue.empty())
  74. {
  75. sourceListValue += ";";
  76. }
  77. sourceListValue += fullname;
  78. }
  79. }
  80. }
  81. }
  82. this->Makefile->AddDefinition(args[1].c_str(), sourceListValue.c_str());
  83. return true;
  84. }