cmSourceFilesCommand.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 sourceListValue;
  32. // was the list already populated
  33. std::string name = args[0];
  34. const char *def = m_Makefile->GetDefinition(name.c_str());
  35. if (def)
  36. {
  37. sourceListValue = def;
  38. }
  39. int generated = 0;
  40. for(std::vector<std::string>::const_iterator i = (args.begin() + 1);
  41. i != args.end(); ++i)
  42. {
  43. std::string copy = *i;
  44. // Keyword GENERATED in the source file list means that
  45. // from here on files will be generated
  46. if ( copy == "GENERATED" )
  47. {
  48. generated = 1;
  49. continue;
  50. }
  51. cmSourceFile* sf = m_Makefile->GetSource(copy.c_str());
  52. if(sf)
  53. {
  54. // if the source file is already in the makefile,
  55. // then add the pointer to the source list without creating cmSourceFile
  56. if (sourceListValue.size() > 0)
  57. {
  58. sourceListValue += ";";
  59. }
  60. sourceListValue += copy;
  61. continue;
  62. }
  63. cmSourceFile file;
  64. file.SetIsAnAbstractClass(false);
  65. std::string path = cmSystemTools::GetFilenamePath(copy);
  66. if ( generated )
  67. {
  68. // This file will be generated, so we should not check
  69. // if it exist.
  70. std::string ext = cmSystemTools::GetFilenameExtension(copy);
  71. std::string name_no_ext = cmSystemTools::GetFilenameName(copy.c_str());
  72. name_no_ext = name_no_ext.substr(0, name_no_ext.length()-ext.length());
  73. if ( ext.length() && ext[0] == '.' )
  74. {
  75. ext = ext.substr(1);
  76. }
  77. if((path.size() && path[0] == '/') ||
  78. (path.size() > 1 && path[1] == ':'))
  79. {
  80. file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), false);
  81. }
  82. else
  83. {
  84. file.SetName(name_no_ext.c_str(),
  85. m_Makefile->GetCurrentOutputDirectory(),
  86. ext.c_str(), false);
  87. }
  88. }
  89. else
  90. {
  91. // if this is a full path then
  92. if((path.size() && path[0] == '/') ||
  93. (path.size() > 1 && path[1] == ':'))
  94. {
  95. file.SetName(cmSystemTools::GetFilenameName(copy.c_str()).c_str(),
  96. path.c_str(),
  97. m_Makefile->GetSourceExtensions(),
  98. m_Makefile->GetHeaderExtensions());
  99. }
  100. else
  101. {
  102. file.SetName(copy.c_str(), m_Makefile->GetCurrentDirectory(),
  103. m_Makefile->GetSourceExtensions(),
  104. m_Makefile->GetHeaderExtensions());
  105. }
  106. }
  107. m_Makefile->AddSource(file);
  108. if (sourceListValue.size() > 0)
  109. {
  110. sourceListValue += ";";
  111. }
  112. sourceListValue += copy;
  113. }
  114. m_Makefile->AddDefinition(name.c_str(), sourceListValue.c_str());
  115. return true;
  116. }