cmSetSourceFilesPropertiesCommand.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "cmSetSourceFilesPropertiesCommand.h"
  14. // cmSetSourceFilesPropertiesCommand
  15. bool cmSetSourceFilesPropertiesCommand::InitialPass(std::vector<std::string> const&
  16. argsIn)
  17. {
  18. if(argsIn.size() < 2 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. std::vector<std::string> args;
  24. cmSystemTools::ExpandListArguments(argsIn, args);
  25. std::vector<std::string>::const_iterator j;
  26. // first collect up all the flags that need to be set on the file
  27. bool abstract = false;
  28. bool wrap_exclude = false;
  29. bool generated = false;
  30. std::string flags;
  31. for(j= args.begin(); j != args.end();++j)
  32. {
  33. if(*j == "ABSTRACT")
  34. {
  35. abstract = true;
  36. }
  37. else if(*j == "WRAP_EXCLUDE")
  38. {
  39. wrap_exclude = true;
  40. }
  41. else if(*j == "GENERATED")
  42. {
  43. generated = true;
  44. }
  45. else if(*j == "COMPILE_FLAGS")
  46. {
  47. ++j;
  48. if(j == args.end())
  49. {
  50. this->SetError("called with incorrect number of arguments FLAGS with no flags");
  51. return false;
  52. }
  53. flags = *j;
  54. }
  55. }
  56. // now loop over all the files
  57. for(j = args.begin(); j != args.end(); ++j)
  58. {
  59. // at the sign of the first property exit the loop
  60. if(*j == "ABSTRACT" || *j == "WRAP_EXCLUDE" || *j == "COMPILE_FLAGS")
  61. {
  62. break;
  63. }
  64. // if the file is already in the makefile just set properites on it
  65. cmSourceFile* sf = m_Makefile->GetSource(j->c_str());
  66. if(sf)
  67. {
  68. if(flags.size())
  69. {
  70. sf->SetCompileFlags(flags.c_str());
  71. }
  72. sf->SetIsAnAbstractClass(abstract);
  73. sf->SetWrapExclude(wrap_exclude);
  74. }
  75. // if file is not already in the makefile, then add it
  76. else
  77. {
  78. std::string newfile = *j;
  79. cmSourceFile file;
  80. std::string path = cmSystemTools::GetFilenamePath(newfile);
  81. // set the flags
  82. file.SetIsAnAbstractClass(abstract);
  83. file.SetWrapExclude(wrap_exclude);
  84. if(flags.size())
  85. {
  86. file.SetCompileFlags(flags.c_str());
  87. }
  88. if(generated)
  89. {
  90. std::string ext = cmSystemTools::GetFilenameExtension(newfile);
  91. std::string name_no_ext = cmSystemTools::GetFilenameName(newfile.c_str());
  92. name_no_ext = name_no_ext.substr(0, name_no_ext.length()-ext.length());
  93. if ( ext.length() && ext[0] == '.' )
  94. {
  95. ext = ext.substr(1);
  96. }
  97. if((path.size() && path[0] == '/') ||
  98. (path.size() > 1 && path[1] == ':'))
  99. {
  100. file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), false);
  101. }
  102. else
  103. {
  104. file.SetName(name_no_ext.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  105. ext.c_str(), false);
  106. }
  107. }
  108. else
  109. {
  110. // if this is a full path then
  111. if((path.size() && path[0] == '/') ||
  112. (path.size() > 1 && path[1] == ':'))
  113. {
  114. file.SetName(cmSystemTools::GetFilenameName(newfile.c_str()).c_str(),
  115. path.c_str(),
  116. m_Makefile->GetSourceExtensions(),
  117. m_Makefile->GetHeaderExtensions());
  118. }
  119. else
  120. {
  121. file.SetName(newfile.c_str(), m_Makefile->GetCurrentDirectory(),
  122. m_Makefile->GetSourceExtensions(),
  123. m_Makefile->GetHeaderExtensions());
  124. }
  125. }
  126. // add the source file to the makefile
  127. m_Makefile->AddSource(file);
  128. }
  129. }
  130. return true;
  131. }