cmSourceFilesCommand.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "cmSourceFilesCommand.h"
  14. // cmSourceFilesCommand
  15. bool cmSourceFilesCommand::InitialPass(std::vector<std::string> const& argsIn)
  16. {
  17. if(argsIn.size() < 1 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. std::vector<std::string> args;
  23. cmSystemTools::ExpandListArguments(argsIn, args);
  24. std::string name = args[0];
  25. int generated = 0;
  26. for(std::vector<std::string>::const_iterator i = (args.begin() + 1);
  27. i != args.end(); ++i)
  28. {
  29. std::string copy = *i;
  30. // Keyword GENERATED in the source file list means that
  31. // from here on files will be generated
  32. if ( copy == "GENERATED" )
  33. {
  34. generated = 1;
  35. continue;
  36. }
  37. cmSourceFile* sf = m_Makefile->GetSource(copy.c_str());
  38. if(sf)
  39. {
  40. // if the source file is already in the makefile,
  41. // then add the pointer to the source list without creating a cmSourceFile
  42. m_Makefile->GetSources()[name].push_back(sf);
  43. continue;
  44. }
  45. cmSourceFile file;
  46. file.SetIsAnAbstractClass(false);
  47. std::string path = cmSystemTools::GetFilenamePath(copy);
  48. if ( generated )
  49. {
  50. // This file will be generated, so we should not check
  51. // if it exist.
  52. std::string ext = cmSystemTools::GetFilenameExtension(copy);
  53. std::string name_no_ext = cmSystemTools::GetFilenameName(copy.c_str());
  54. name_no_ext = name_no_ext.substr(0, name_no_ext.length()-ext.length());
  55. if ( ext.length() && ext[0] == '.' )
  56. {
  57. ext = ext.substr(1);
  58. }
  59. if((path.size() && path[0] == '/') ||
  60. (path.size() > 1 && path[1] == ':'))
  61. {
  62. file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), false);
  63. }
  64. else
  65. {
  66. file.SetName(name_no_ext.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  67. ext.c_str(), false);
  68. }
  69. }
  70. else
  71. // if this is a full path then
  72. if((path.size() && path[0] == '/') ||
  73. (path.size() > 1 && path[1] == ':'))
  74. {
  75. file.SetName(cmSystemTools::GetFilenameName(copy.c_str()).c_str(),
  76. path.c_str(),
  77. m_Makefile->GetSourceExtensions(),
  78. m_Makefile->GetHeaderExtensions());
  79. }
  80. else
  81. {
  82. file.SetName(copy.c_str(), m_Makefile->GetCurrentDirectory(),
  83. m_Makefile->GetSourceExtensions(),
  84. m_Makefile->GetHeaderExtensions());
  85. }
  86. m_Makefile->AddSource(file, name.c_str());
  87. }
  88. return true;
  89. }