cmSourceFilesCommand.cxx 4.4 KB

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