cmIDEOptions.cxx 5.2 KB

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