cmSourceFilesCommand.cxx 3.3 KB

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