cmSourceFilesCommand.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #include <stdlib.h> // required for atof
  15. bool cmSourceFilesCommand::IsDeprecated(int major, int minor)
  16. {
  17. if ( major >= 1 && minor >= 4 )
  18. {
  19. this->SetError("The SOURCE_FILES command was deprecated in CMake version 1.4 and will be removed in later versions of CMake. You should modify your CMakeLists.txt files to use the SET command instead, or set the cache value of CMAKE_BACKWARDS_COMPATIBILITY to 1.2 or less.\n");
  20. return true;
  21. }
  22. return false;
  23. }
  24. // cmSourceFilesCommand
  25. bool cmSourceFilesCommand::InitialPass(std::vector<std::string> const& args)
  26. {
  27. const char* versionValue
  28. = m_Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  29. if (atof(versionValue) > 1.2)
  30. {
  31. cmSystemTools::Message("The SOURCE_FILES command was deprecated in CMake version 1.4 and will be removed in later versions. You should modify your CMakeLists.txt files to use the SET command instead, or set the cache value of CMAKE_BACKWARDS_COMPATIBILITY to 1.2 or less.\n","Warning");
  32. }
  33. if(args.size() < 1 )
  34. {
  35. this->SetError("called with incorrect number of arguments");
  36. return false;
  37. }
  38. std::string sourceListValue;
  39. // was the list already populated
  40. std::string name = args[0];
  41. const char *def = m_Makefile->GetDefinition(name.c_str());
  42. if (def)
  43. {
  44. sourceListValue = def;
  45. }
  46. int generated = 0;
  47. for(std::vector<std::string>::const_iterator i = (args.begin() + 1);
  48. i != args.end(); ++i)
  49. {
  50. std::string copy = *i;
  51. // Keyword GENERATED in the source file list means that
  52. // from here on files will be generated
  53. if ( copy == "GENERATED" )
  54. {
  55. generated = 1;
  56. continue;
  57. }
  58. cmSourceFile* sf = m_Makefile->GetSource(copy.c_str());
  59. if(sf)
  60. {
  61. // if the source file is already in the makefile,
  62. // then add the pointer to the source list without creating cmSourceFile
  63. if (sourceListValue.size() > 0)
  64. {
  65. sourceListValue += ";";
  66. }
  67. sourceListValue += copy;
  68. continue;
  69. }
  70. cmSourceFile file;
  71. file.SetProperty("ABSTRACT","0");
  72. std::string path = cmSystemTools::GetFilenamePath(copy);
  73. if ( generated )
  74. {
  75. // This file will be generated, so we should not check
  76. // if it exist.
  77. std::string ext = cmSystemTools::GetFilenameExtension(copy);
  78. std::string name_no_ext = cmSystemTools::GetFilenameName(copy.c_str());
  79. name_no_ext = name_no_ext.substr(0, name_no_ext.length()-ext.length());
  80. if ( ext.length() && ext[0] == '.' )
  81. {
  82. ext = ext.substr(1);
  83. }
  84. if((path.size() && path[0] == '/') ||
  85. (path.size() > 1 && path[1] == ':'))
  86. {
  87. file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), false);
  88. }
  89. else
  90. {
  91. file.SetName(name_no_ext.c_str(),
  92. m_Makefile->GetCurrentOutputDirectory(),
  93. ext.c_str(), false);
  94. }
  95. }
  96. else
  97. {
  98. // if this is a full path then
  99. if((path.size() && path[0] == '/') ||
  100. (path.size() > 1 && path[1] == ':'))
  101. {
  102. file.SetName(cmSystemTools::GetFilenameName(copy.c_str()).c_str(),
  103. path.c_str(),
  104. m_Makefile->GetSourceExtensions(),
  105. m_Makefile->GetHeaderExtensions());
  106. }
  107. else
  108. {
  109. file.SetName(copy.c_str(), m_Makefile->GetCurrentDirectory(),
  110. m_Makefile->GetSourceExtensions(),
  111. m_Makefile->GetHeaderExtensions());
  112. }
  113. }
  114. m_Makefile->AddSource(file);
  115. if (sourceListValue.size() > 0)
  116. {
  117. sourceListValue += ";";
  118. }
  119. sourceListValue += copy;
  120. }
  121. m_Makefile->AddDefinition(name.c_str(), sourceListValue.c_str());
  122. return true;
  123. }