cmSourceFilesCommand.cxx 2.6 KB

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