cmAuxSourceDirectoryCommand.cxx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. // cmAuxSourceDirectoryCommand
  16. bool cmAuxSourceDirectoryCommand::InitialPass(std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 2 || args.size() > 2)
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. std::string templateDirectory = args[0];
  24. m_Makefile->AddExtraDirectory(templateDirectory.c_str());
  25. std::string tdir = m_Makefile->GetCurrentDirectory();
  26. tdir += "/";
  27. tdir += templateDirectory;
  28. // The Makefile should be dependent on the directory's last mod date,
  29. // so that if a file is added or removed from the directory, it will
  30. // be rescanned, and the makefile rebuilt.
  31. m_Makefile->AddCMakeDependFile(tdir.c_str());
  32. // Load all the files in the directory
  33. cmDirectory dir;
  34. if(dir.Load(tdir.c_str()))
  35. {
  36. int numfiles = dir.GetNumberOfFiles();
  37. for(int i =0; i < numfiles; ++i)
  38. {
  39. std::string file = dir.GetFile(i);
  40. // Split the filename into base and extension
  41. std::string::size_type dotpos = file.rfind(".");
  42. if( dotpos != std::string::npos )
  43. {
  44. std::string ext = file.substr(dotpos+1);
  45. file = file.substr(0, dotpos);
  46. // Process only source files
  47. if( file.size() != 0
  48. && std::find( m_Makefile->GetSourceExtensions().begin(),
  49. m_Makefile->GetSourceExtensions().end(), ext )
  50. != m_Makefile->GetSourceExtensions().end() )
  51. {
  52. std::string fullname = templateDirectory;
  53. fullname += "/";
  54. fullname += file;
  55. // add the file as a class file so
  56. // depends can be done
  57. cmSourceFile cmfile;
  58. cmfile.SetName(fullname.c_str(), m_Makefile->GetCurrentDirectory(),
  59. m_Makefile->GetSourceExtensions(),
  60. m_Makefile->GetHeaderExtensions());
  61. cmfile.SetIsAnAbstractClass(false);
  62. m_Makefile->AddSource(cmfile,args[1].c_str());
  63. }
  64. }
  65. }
  66. }
  67. return true;
  68. }