cmSourceFilesCommand.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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. 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(args.size() < 1 )
  25. {
  26. this->SetError("called with incorrect number of arguments");
  27. return false;
  28. }
  29. std::string sourceListValue;
  30. // was the list already populated
  31. std::string name = args[0];
  32. const char *def = m_Makefile->GetDefinition(name.c_str());
  33. if (def)
  34. {
  35. sourceListValue = def;
  36. }
  37. int generated = 0;
  38. for(std::vector<std::string>::const_iterator i = (args.begin() + 1);
  39. i != args.end(); ++i)
  40. {
  41. std::string copy = *i;
  42. // Keyword GENERATED in the source file list means that
  43. // from here on files will be generated
  44. if ( copy == "GENERATED" )
  45. {
  46. generated = 1;
  47. continue;
  48. }
  49. cmSourceFile* sf = m_Makefile->GetSource(copy.c_str());
  50. if(sf)
  51. {
  52. // if the source file is already in the makefile,
  53. // then add the pointer to the source list without creating cmSourceFile
  54. if (sourceListValue.size() > 0)
  55. {
  56. sourceListValue += ";";
  57. }
  58. sourceListValue += copy;
  59. continue;
  60. }
  61. cmSourceFile file;
  62. file.SetProperty("ABSTRACT","0");
  63. std::string path = cmSystemTools::GetFilenamePath(copy);
  64. if ( generated )
  65. {
  66. // This file will be generated, so we should not check
  67. // if it exist.
  68. std::string ext = cmSystemTools::GetFilenameExtension(copy);
  69. std::string name_no_ext = cmSystemTools::GetFilenameName(copy.c_str());
  70. name_no_ext = name_no_ext.substr(0, name_no_ext.length()-ext.length());
  71. if ( ext.length() && ext[0] == '.' )
  72. {
  73. ext = ext.substr(1);
  74. }
  75. if((path.size() && path[0] == '/') ||
  76. (path.size() > 1 && path[1] == ':'))
  77. {
  78. file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), false);
  79. }
  80. else
  81. {
  82. file.SetName(name_no_ext.c_str(),
  83. m_Makefile->GetCurrentOutputDirectory(),
  84. ext.c_str(), false);
  85. }
  86. }
  87. else
  88. {
  89. // if this is a full path then
  90. if((path.size() && path[0] == '/') ||
  91. (path.size() > 1 && path[1] == ':'))
  92. {
  93. file.SetName(cmSystemTools::GetFilenameName(copy.c_str()).c_str(),
  94. path.c_str(),
  95. m_Makefile->GetSourceExtensions(),
  96. m_Makefile->GetHeaderExtensions());
  97. }
  98. else
  99. {
  100. file.SetName(copy.c_str(), m_Makefile->GetCurrentDirectory(),
  101. m_Makefile->GetSourceExtensions(),
  102. m_Makefile->GetHeaderExtensions());
  103. }
  104. }
  105. m_Makefile->AddSource(file);
  106. if (sourceListValue.size() > 0)
  107. {
  108. sourceListValue += ";";
  109. }
  110. sourceListValue += copy;
  111. }
  112. m_Makefile->AddDefinition(name.c_str(), sourceListValue.c_str());
  113. return true;
  114. }