cmSourceFilesCommand.cxx 4.3 KB

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