cmAuxSourceDirectoryCommand.cxx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmAuxSourceDirectoryCommand.h"
  11. #include "cmSourceFile.h"
  12. #include <cmsys/Directory.hxx>
  13. // cmAuxSourceDirectoryCommand
  14. bool cmAuxSourceDirectoryCommand::InitialPass
  15. (std::vector<std::string> const& args, cmExecutionStatus &)
  16. {
  17. if(args.size() < 2 || args.size() > 2)
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. std::string sourceListValue;
  23. std::string templateDirectory = args[0];
  24. std::string tdir;
  25. if(!cmSystemTools::FileIsFullPath(templateDirectory.c_str()))
  26. {
  27. tdir = this->Makefile->GetCurrentDirectory();
  28. tdir += "/";
  29. tdir += templateDirectory;
  30. }
  31. else
  32. {
  33. tdir = templateDirectory;
  34. }
  35. // was the list already populated
  36. const char *def = this->Makefile->GetDefinition(args[1]);
  37. if (def)
  38. {
  39. sourceListValue = def;
  40. }
  41. // Load all the files in the directory
  42. cmsys::Directory dir;
  43. if(dir.Load(tdir.c_str()))
  44. {
  45. size_t numfiles = dir.GetNumberOfFiles();
  46. for(size_t i =0; i < numfiles; ++i)
  47. {
  48. std::string file = dir.GetFile(static_cast<unsigned long>(i));
  49. // Split the filename into base and extension
  50. std::string::size_type dotpos = file.rfind(".");
  51. if( dotpos != std::string::npos )
  52. {
  53. std::string ext = file.substr(dotpos+1);
  54. std::string base = file.substr(0, dotpos);
  55. // Process only source files
  56. if(!base.empty()
  57. && std::find( this->Makefile->GetSourceExtensions().begin(),
  58. this->Makefile->GetSourceExtensions().end(), ext )
  59. != this->Makefile->GetSourceExtensions().end() )
  60. {
  61. std::string fullname = templateDirectory;
  62. fullname += "/";
  63. fullname += file;
  64. // add the file as a class file so
  65. // depends can be done
  66. cmSourceFile* sf =
  67. this->Makefile->GetOrCreateSource(fullname);
  68. sf->SetProperty("ABSTRACT","0");
  69. if(!sourceListValue.empty())
  70. {
  71. sourceListValue += ";";
  72. }
  73. sourceListValue += fullname;
  74. }
  75. }
  76. }
  77. }
  78. this->Makefile->AddDefinition(args[1], sourceListValue.c_str());
  79. return true;
  80. }