cmAuxSourceDirectoryCommand.cxx 2.8 KB

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