cmSourceFilesCommand.cxx 2.7 KB

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