diff options
author | MyungJoo Ham <myungjoo.ham@samsung.com> | 2017-10-11 15:16:57 +0900 |
---|---|---|
committer | MyungJoo Ham <myungjoo.ham@samsung.com> | 2017-10-11 15:16:57 +0900 |
commit | 915c76ded744c0f5f151402b9fa69f3fd8452573 (patch) | |
tree | ca6a387466543248890f346847acaa8343989b22 /Source/cmIDEOptions.cxx | |
parent | 317dbdb79761ef65e45c7358cfc7571c6afa54ad (diff) | |
download | cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.tar.gz cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.tar.bz2 cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.zip |
Imported Upstream version 3.9.4upstream/3.9.4
Diffstat (limited to 'Source/cmIDEOptions.cxx')
-rw-r--r-- | Source/cmIDEOptions.cxx | 213 |
1 files changed, 112 insertions, 101 deletions
diff --git a/Source/cmIDEOptions.cxx b/Source/cmIDEOptions.cxx index 34a9c7c78..5e872d2ff 100644 --- a/Source/cmIDEOptions.cxx +++ b/Source/cmIDEOptions.cxx @@ -1,195 +1,206 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmIDEOptions.h" +#include "cmsys/String.h" +#include <iterator> +#include <string.h> + +#include "cmIDEFlagTable.h" #include "cmSystemTools.h" -//---------------------------------------------------------------------------- cmIDEOptions::cmIDEOptions() { this->DoingDefine = false; this->AllowDefine = true; this->AllowSlash = false; - for(int i=0; i < FlagTableCount; ++i) - { + this->DoingFollowing = 0; + for (int i = 0; i < FlagTableCount; ++i) { this->FlagTable[i] = 0; - } + } } -//---------------------------------------------------------------------------- cmIDEOptions::~cmIDEOptions() { } -//---------------------------------------------------------------------------- void cmIDEOptions::HandleFlag(const char* flag) { // If the last option was -D then this option is the definition. - if(this->DoingDefine) - { + if (this->DoingDefine) { this->DoingDefine = false; this->Defines.push_back(flag); return; - } + } + + // If the last option expected a following value, this is it. + if (this->DoingFollowing) { + this->FlagMapUpdate(this->DoingFollowing, flag); + this->DoingFollowing = 0; + return; + } // Look for known arguments. - if(flag[0] == '-' || (this->AllowSlash && flag[0] == '/')) - { + if (flag[0] == '-' || (this->AllowSlash && flag[0] == '/')) { // Look for preprocessor definitions. - if(this->AllowDefine && flag[1] == 'D') - { - if(flag[2] == '\0') - { + if (this->AllowDefine && flag[1] == 'D') { + if (flag[2] == '\0') { // The next argument will have the definition. this->DoingDefine = true; - } - else - { + } else { // Store this definition. - this->Defines.push_back(flag+2); - } - return; + this->Defines.push_back(flag + 2); } + return; + } // Look through the available flag tables. bool flag_handled = false; - for(int i=0; i < FlagTableCount && this->FlagTable[i]; ++i) - { - if(this->CheckFlagTable(this->FlagTable[i], flag, flag_handled)) - { + for (int i = 0; i < FlagTableCount && this->FlagTable[i]; ++i) { + if (this->CheckFlagTable(this->FlagTable[i], flag, flag_handled)) { return; - } } + } // If any map entry handled the flag we are done. - if(flag_handled) - { + if (flag_handled) { return; - } } + } // This option is not known. Store it in the output flags. this->StoreUnknownFlag(flag); } -//---------------------------------------------------------------------------- bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table, const char* flag, bool& flag_handled) { // Look for an entry in the flag table matching this flag. - for(cmIDEFlagTable const* entry = table; entry->IDEName; ++entry) - { + for (cmIDEFlagTable const* entry = table; entry->IDEName; ++entry) { bool entry_found = false; - if(entry->special & cmIDEFlagTable::UserValue) - { + if (entry->special & cmIDEFlagTable::UserValue) { // This flag table entry accepts a user-specified value. If // the entry specifies UserRequired we must match only if a // non-empty value is given. int n = static_cast<int>(strlen(entry->commandFlag)); - if(strncmp(flag+1, entry->commandFlag, n) == 0 && - (!(entry->special & cmIDEFlagTable::UserRequired) || - static_cast<int>(strlen(flag+1)) > n)) - { - if(entry->special & cmIDEFlagTable::UserIgnored) - { - // Ignore the user-specified value. - this->FlagMap[entry->IDEName] = entry->value; - } - else if(entry->special & cmIDEFlagTable::SemicolonAppendable) - { - const char *new_value = flag+1+n; - - std::map<cmStdString,cmStdString>::iterator itr; - itr = this->FlagMap.find(entry->IDEName); - if(itr != this->FlagMap.end()) - { - // Append to old value (if present) with semicolons; - itr->second += ";"; - itr->second += new_value; - } - else - { - this->FlagMap[entry->IDEName] = new_value; - } - } - else - { - // Use the user-specified value. - this->FlagMap[entry->IDEName] = flag+1+n; - } + if ((strncmp(flag + 1, entry->commandFlag, n) == 0 || + (entry->special & cmIDEFlagTable::CaseInsensitive && + cmsysString_strncasecmp(flag + 1, entry->commandFlag, n))) && + (!(entry->special & cmIDEFlagTable::UserRequired) || + static_cast<int>(strlen(flag + 1)) > n)) { + this->FlagMapUpdate(entry, flag + n + 1); entry_found = true; - } } - else if(strcmp(flag+1, entry->commandFlag) == 0) - { - // This flag table entry provides a fixed value. - this->FlagMap[entry->IDEName] = entry->value; - entry_found = true; + } else if (strcmp(flag + 1, entry->commandFlag) == 0 || + (entry->special & cmIDEFlagTable::CaseInsensitive && + cmsysString_strcasecmp(flag + 1, entry->commandFlag) == 0)) { + if (entry->special & cmIDEFlagTable::UserFollowing) { + // This flag expects a value in the following argument. + this->DoingFollowing = entry; + } else { + // This flag table entry provides a fixed value. + this->FlagMap[entry->IDEName] = entry->value; } + entry_found = true; + } // If the flag has been handled by an entry not requesting a // search continuation we are done. - if(entry_found && !(entry->special & cmIDEFlagTable::Continue)) - { + if (entry_found && !(entry->special & cmIDEFlagTable::Continue)) { return true; - } + } // If the entry was found the flag has been handled. flag_handled = flag_handled || entry_found; - } + } return false; } -//---------------------------------------------------------------------------- +void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry, + const char* new_value) +{ + if (entry->special & cmIDEFlagTable::UserIgnored) { + // Ignore the user-specified value. + this->FlagMap[entry->IDEName] = entry->value; + } else if (entry->special & cmIDEFlagTable::SemicolonAppendable) { + this->FlagMap[entry->IDEName].push_back(new_value); + } else if (entry->special & cmIDEFlagTable::SpaceAppendable) { + this->FlagMap[entry->IDEName].append_with_space(new_value); + } else { + // Use the user-specified value. + this->FlagMap[entry->IDEName] = new_value; + } +} + void cmIDEOptions::AddDefine(const std::string& def) { this->Defines.push_back(def); } -//---------------------------------------------------------------------------- void cmIDEOptions::AddDefines(const char* defines) { - if(defines) - { + if (defines) { // Expand the list of definitions. cmSystemTools::ExpandListArgument(defines, this->Defines); - } + } } -//---------------------------------------------------------------------------- -void cmIDEOptions::AddDefines(const std::vector<std::string> &defines) +void cmIDEOptions::AddDefines(const std::vector<std::string>& defines) { this->Defines.insert(this->Defines.end(), defines.begin(), defines.end()); } -//---------------------------------------------------------------------------- +std::vector<std::string> const& cmIDEOptions::GetDefines() const +{ + return this->Defines; +} + void cmIDEOptions::AddFlag(const char* flag, const char* value) { this->FlagMap[flag] = value; } -//---------------------------------------------------------------------------- +void cmIDEOptions::AddFlag(const char* flag, + std::vector<std::string> const& value) +{ + this->FlagMap[flag] = value; +} + +void cmIDEOptions::AppendFlag(std::string const& flag, + std::string const& value) +{ + this->FlagMap[flag].push_back(value); +} + +void cmIDEOptions::AppendFlag(std::string const& flag, + std::vector<std::string> const& value) +{ + FlagValue& fv = this->FlagMap[flag]; + std::copy(value.begin(), value.end(), std::back_inserter(fv)); +} + +void cmIDEOptions::AppendFlagString(std::string const& flag, + std::string const& value) +{ + this->FlagMap[flag].append_with_space(value); +} + void cmIDEOptions::RemoveFlag(const char* flag) { this->FlagMap.erase(flag); } -//---------------------------------------------------------------------------- +bool cmIDEOptions::HasFlag(std::string const& flag) const +{ + return this->FlagMap.find(flag) != this->FlagMap.end(); +} + const char* cmIDEOptions::GetFlag(const char* flag) { - std::map<cmStdString, cmStdString>::iterator i = this->FlagMap.find(flag); - if(i != this->FlagMap.end()) - { - return i->second.c_str(); - } + // This method works only for single-valued flags! + std::map<std::string, FlagValue>::iterator i = this->FlagMap.find(flag); + if (i != this->FlagMap.end() && i->second.size() == 1) { + return i->second[0].c_str(); + } return 0; } |