cmIDEOptions.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 "cmIDEOptions.h"
  14. #include "cmSystemTools.h"
  15. //----------------------------------------------------------------------------
  16. cmIDEOptions::cmIDEOptions()
  17. {
  18. this->DoingDefine = false;
  19. this->AllowDefine = true;
  20. this->AllowSlash = false;
  21. for(int i=0; i < FlagTableCount; ++i)
  22. {
  23. this->FlagTable[i] = 0;
  24. }
  25. }
  26. //----------------------------------------------------------------------------
  27. cmIDEOptions::~cmIDEOptions()
  28. {
  29. }
  30. //----------------------------------------------------------------------------
  31. void cmIDEOptions::HandleFlag(const char* flag)
  32. {
  33. // If the last option was -D then this option is the definition.
  34. if(this->DoingDefine)
  35. {
  36. this->DoingDefine = false;
  37. this->Defines.push_back(flag);
  38. return;
  39. }
  40. // Look for known arguments.
  41. if(flag[0] == '-' || (this->AllowSlash && flag[0] == '/'))
  42. {
  43. // Look for preprocessor definitions.
  44. if(this->AllowDefine && flag[1] == 'D')
  45. {
  46. if(flag[2] == '\0')
  47. {
  48. // The next argument will have the definition.
  49. this->DoingDefine = true;
  50. }
  51. else
  52. {
  53. // Store this definition.
  54. this->Defines.push_back(flag+2);
  55. }
  56. return;
  57. }
  58. // Look through the available flag tables.
  59. bool flag_handled = false;
  60. for(int i=0; i < FlagTableCount && this->FlagTable[i]; ++i)
  61. {
  62. if(this->CheckFlagTable(this->FlagTable[i], flag, flag_handled))
  63. {
  64. return;
  65. }
  66. }
  67. // If any map entry handled the flag we are done.
  68. if(flag_handled)
  69. {
  70. return;
  71. }
  72. }
  73. // This option is not known. Store it in the output flags.
  74. this->StoreUnknownFlag(flag);
  75. }
  76. //----------------------------------------------------------------------------
  77. bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
  78. const char* flag, bool& flag_handled)
  79. {
  80. // Look for an entry in the flag table matching this flag.
  81. for(cmIDEFlagTable const* entry = table; entry->IDEName; ++entry)
  82. {
  83. bool entry_found = false;
  84. if(entry->special & cmIDEFlagTable::UserValue)
  85. {
  86. // This flag table entry accepts a user-specified value. If
  87. // the entry specifies UserRequired we must match only if a
  88. // non-empty value is given.
  89. int n = static_cast<int>(strlen(entry->commandFlag));
  90. if(strncmp(flag+1, entry->commandFlag, n) == 0 &&
  91. (!(entry->special & cmIDEFlagTable::UserRequired) ||
  92. static_cast<int>(strlen(flag+1)) > n))
  93. {
  94. if(entry->special & cmIDEFlagTable::UserIgnored)
  95. {
  96. // Ignore the user-specified value.
  97. this->FlagMap[entry->IDEName] = entry->value;
  98. }
  99. else if(entry->special & cmIDEFlagTable::SemicolonAppendable)
  100. {
  101. const char *new_value = flag+1+n;
  102. std::map<cmStdString,cmStdString>::iterator itr;
  103. itr = this->FlagMap.find(entry->IDEName);
  104. if(itr != this->FlagMap.end())
  105. {
  106. // Append to old value (if present) with semicolons;
  107. itr->second += ";";
  108. itr->second += new_value;
  109. }
  110. else
  111. {
  112. this->FlagMap[entry->IDEName] = new_value;
  113. }
  114. }
  115. else
  116. {
  117. // Use the user-specified value.
  118. this->FlagMap[entry->IDEName] = flag+1+n;
  119. }
  120. entry_found = true;
  121. }
  122. }
  123. else if(strcmp(flag+1, entry->commandFlag) == 0)
  124. {
  125. // This flag table entry provides a fixed value.
  126. this->FlagMap[entry->IDEName] = entry->value;
  127. entry_found = true;
  128. }
  129. // If the flag has been handled by an entry not requesting a
  130. // search continuation we are done.
  131. if(entry_found && !(entry->special & cmIDEFlagTable::Continue))
  132. {
  133. return true;
  134. }
  135. // If the entry was found the flag has been handled.
  136. flag_handled = flag_handled || entry_found;
  137. }
  138. return false;
  139. }
  140. //----------------------------------------------------------------------------
  141. void cmIDEOptions::AddDefine(const std::string& def)
  142. {
  143. this->Defines.push_back(def);
  144. }
  145. //----------------------------------------------------------------------------
  146. void cmIDEOptions::AddDefines(const char* defines)
  147. {
  148. if(defines)
  149. {
  150. // Expand the list of definitions.
  151. cmSystemTools::ExpandListArgument(defines, this->Defines);
  152. }
  153. }
  154. //----------------------------------------------------------------------------
  155. void cmIDEOptions::AddFlag(const char* flag, const char* value)
  156. {
  157. this->FlagMap[flag] = value;
  158. }