cmAuxSourceDirectoryCommand.cxx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. // Load all the files in the directory
  29. cmDirectory dir;
  30. if(dir.Load(tdir.c_str()))
  31. {
  32. int numfiles = dir.GetNumberOfFiles();
  33. for(int i =0; i < numfiles; ++i)
  34. {
  35. std::string file = dir.GetFile(i);
  36. // Split the filename into base and extension
  37. std::string::size_type dotpos = file.rfind(".");
  38. if( dotpos != std::string::npos )
  39. {
  40. std::string ext = file.substr(dotpos+1);
  41. file = file.substr(0, dotpos);
  42. // Process only source files
  43. if( file.size() != 0
  44. && std::find( m_Makefile->GetSourceExtensions().begin(),
  45. m_Makefile->GetSourceExtensions().end(), ext )
  46. != m_Makefile->GetSourceExtensions().end() )
  47. {
  48. std::string fullname = templateDirectory;
  49. fullname += "/";
  50. fullname += file;
  51. // add the file as a class file so
  52. // depends can be done
  53. cmSourceFile cmfile;
  54. cmfile.SetName(fullname.c_str(), m_Makefile->GetCurrentDirectory(),
  55. m_Makefile->GetSourceExtensions(),
  56. m_Makefile->GetHeaderExtensions());
  57. cmfile.SetIsAnAbstractClass(false);
  58. m_Makefile->AddSource(cmfile,args[1].c_str());
  59. }
  60. }
  61. }
  62. }
  63. return true;
  64. }