cmAuxSourceDirectoryCommand.cxx 2.8 KB

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