cmAuxSourceDirectoryCommand.cxx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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)
  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 = this->Makefile->GetCurrentDirectory();
  29. tdir += "/";
  30. tdir += templateDirectory;
  31. // was the list already populated
  32. const char *def = this->Makefile->GetDefinition(args[1].c_str());
  33. if (def)
  34. {
  35. sourceListValue = def;
  36. }
  37. // Load all the files in the directory
  38. cmsys::Directory dir;
  39. if(dir.Load(tdir.c_str()))
  40. {
  41. size_t numfiles = dir.GetNumberOfFiles();
  42. for(size_t i =0; i < numfiles; ++i)
  43. {
  44. std::string file = dir.GetFile(static_cast<unsigned long>(i));
  45. // Split the filename into base and extension
  46. std::string::size_type dotpos = file.rfind(".");
  47. if( dotpos != std::string::npos )
  48. {
  49. std::string ext = file.substr(dotpos+1);
  50. file = file.substr(0, dotpos);
  51. // Process only source files
  52. if( file.size() != 0
  53. && std::find( this->Makefile->GetSourceExtensions().begin(),
  54. this->Makefile->GetSourceExtensions().end(), ext )
  55. != this->Makefile->GetSourceExtensions().end() )
  56. {
  57. std::string fullname = templateDirectory;
  58. fullname += "/";
  59. fullname += file;
  60. // add the file as a class file so
  61. // depends can be done
  62. cmSourceFile cmfile;
  63. cmfile.SetName(fullname.c_str(),
  64. this->Makefile->GetCurrentDirectory(),
  65. this->Makefile->GetSourceExtensions(),
  66. this->Makefile->GetHeaderExtensions());
  67. cmfile.SetProperty("ABSTRACT","0");
  68. this->Makefile->AddSource(cmfile);
  69. if (sourceListValue.size() > 0)
  70. {
  71. sourceListValue += ";";
  72. }
  73. sourceListValue += cmfile.GetSourceName();
  74. sourceListValue += ".";
  75. sourceListValue += cmfile.GetSourceExtension();
  76. }
  77. }
  78. }
  79. }
  80. this->Makefile->AddDefinition(args[1].c_str(), sourceListValue.c_str());
  81. return true;
  82. }