2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2009-07-29 19:29:08 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2009-07-29 19:29:08 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
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.
|
|
|
|
============================================================================*/
|
2009-07-29 19:29:08 +04:00
|
|
|
#include "cmIDEOptions.h"
|
|
|
|
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2016-01-08 22:30:06 +03:00
|
|
|
#include <cmsys/String.h>
|
|
|
|
|
2009-07-29 19:29:08 +04:00
|
|
|
cmIDEOptions::cmIDEOptions()
|
|
|
|
{
|
|
|
|
this->DoingDefine = false;
|
|
|
|
this->AllowDefine = true;
|
|
|
|
this->AllowSlash = false;
|
2014-04-01 22:56:08 +04:00
|
|
|
this->DoingFollowing = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (int i = 0; i < FlagTableCount; ++i) {
|
2009-07-29 19:29:08 +04:00
|
|
|
this->FlagTable[i] = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-29 19:29:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmIDEOptions::~cmIDEOptions()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmIDEOptions::HandleFlag(const char* flag)
|
|
|
|
{
|
|
|
|
// If the last option was -D then this option is the definition.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->DoingDefine) {
|
2009-07-29 19:29:08 +04:00
|
|
|
this->DoingDefine = false;
|
|
|
|
this->Defines.push_back(flag);
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-29 19:29:08 +04:00
|
|
|
|
2014-04-01 22:56:08 +04:00
|
|
|
// If the last option expected a following value, this is it.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->DoingFollowing) {
|
2014-04-01 22:56:08 +04:00
|
|
|
this->FlagMapUpdate(this->DoingFollowing, flag);
|
|
|
|
this->DoingFollowing = 0;
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-04-01 22:56:08 +04:00
|
|
|
|
2009-07-29 19:29:08 +04:00
|
|
|
// Look for known arguments.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (flag[0] == '-' || (this->AllowSlash && flag[0] == '/')) {
|
2009-07-29 19:29:08 +04:00
|
|
|
// Look for preprocessor definitions.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->AllowDefine && flag[1] == 'D') {
|
|
|
|
if (flag[2] == '\0') {
|
2009-07-29 19:29:08 +04:00
|
|
|
// The next argument will have the definition.
|
|
|
|
this->DoingDefine = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2009-07-29 19:29:08 +04:00
|
|
|
// Store this definition.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Defines.push_back(flag + 2);
|
2009-07-29 19:29:08 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return;
|
|
|
|
}
|
2009-07-29 19:29:08 +04:00
|
|
|
|
|
|
|
// Look through the available flag tables.
|
|
|
|
bool flag_handled = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (int i = 0; i < FlagTableCount && this->FlagTable[i]; ++i) {
|
|
|
|
if (this->CheckFlagTable(this->FlagTable[i], flag, flag_handled)) {
|
2009-07-29 19:29:08 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-29 19:29:08 +04:00
|
|
|
|
|
|
|
// If any map entry handled the flag we are done.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (flag_handled) {
|
2009-07-29 19:29:08 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-29 19:29:08 +04:00
|
|
|
|
|
|
|
// 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.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmIDEFlagTable const* entry = table; entry->IDEName; ++entry) {
|
2009-07-29 19:29:08 +04:00
|
|
|
bool entry_found = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (entry->special & cmIDEFlagTable::UserValue) {
|
2009-07-29 19:29:08 +04:00
|
|
|
// 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));
|
2016-05-16 17:34:04 +03:00
|
|
|
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);
|
2009-07-29 19:29:08 +04:00
|
|
|
entry_found = true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (strcmp(flag + 1, entry->commandFlag) == 0 ||
|
|
|
|
(entry->special & cmIDEFlagTable::CaseInsensitive &&
|
|
|
|
cmsysString_strcasecmp(flag + 1, entry->commandFlag) == 0)) {
|
|
|
|
if (entry->special & cmIDEFlagTable::UserFollowing) {
|
2014-04-01 22:56:08 +04:00
|
|
|
// This flag expects a value in the following argument.
|
|
|
|
this->DoingFollowing = entry;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-04-01 22:56:08 +04:00
|
|
|
// This flag table entry provides a fixed value.
|
|
|
|
this->FlagMap[entry->IDEName] = entry->value;
|
2009-07-29 19:29:08 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
entry_found = true;
|
|
|
|
}
|
2009-07-29 19:29:08 +04:00
|
|
|
|
|
|
|
// If the flag has been handled by an entry not requesting a
|
|
|
|
// search continuation we are done.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (entry_found && !(entry->special & cmIDEFlagTable::Continue)) {
|
2009-07-29 19:29:08 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-29 19:29:08 +04:00
|
|
|
|
|
|
|
// If the entry was found the flag has been handled.
|
|
|
|
flag_handled = flag_handled || entry_found;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-29 19:29:08 +04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-01 22:54:28 +04:00
|
|
|
void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry,
|
|
|
|
const char* new_value)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (entry->special & cmIDEFlagTable::UserIgnored) {
|
2014-04-01 22:54:28 +04:00
|
|
|
// Ignore the user-specified value.
|
|
|
|
this->FlagMap[entry->IDEName] = entry->value;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (entry->special & cmIDEFlagTable::SemicolonAppendable) {
|
2014-07-23 19:13:13 +04:00
|
|
|
this->FlagMap[entry->IDEName].push_back(new_value);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-04-01 22:54:28 +04:00
|
|
|
// Use the user-specified value.
|
|
|
|
this->FlagMap[entry->IDEName] = new_value;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-04-01 22:54:28 +04:00
|
|
|
}
|
|
|
|
|
2009-07-29 19:29:08 +04:00
|
|
|
void cmIDEOptions::AddDefine(const std::string& def)
|
|
|
|
{
|
|
|
|
this->Defines.push_back(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmIDEOptions::AddDefines(const char* defines)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (defines) {
|
2009-07-29 19:29:08 +04:00
|
|
|
// Expand the list of definitions.
|
|
|
|
cmSystemTools::ExpandListArgument(defines, this->Defines);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-29 19:29:08 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmIDEOptions::AddDefines(const std::vector<std::string>& defines)
|
2013-07-10 17:22:59 +04:00
|
|
|
{
|
|
|
|
this->Defines.insert(this->Defines.end(), defines.begin(), defines.end());
|
|
|
|
}
|
2009-07-29 19:29:08 +04:00
|
|
|
|
|
|
|
void cmIDEOptions::AddFlag(const char* flag, const char* value)
|
|
|
|
{
|
|
|
|
this->FlagMap[flag] = value;
|
|
|
|
}
|
2011-02-09 20:59:09 +03:00
|
|
|
|
2014-07-23 19:13:13 +04:00
|
|
|
void cmIDEOptions::AddFlag(const char* flag,
|
|
|
|
std::vector<std::string> const& value)
|
|
|
|
{
|
|
|
|
this->FlagMap[flag] = value;
|
|
|
|
}
|
|
|
|
|
2014-07-31 22:02:03 +04:00
|
|
|
void cmIDEOptions::AppendFlag(std::string const& flag,
|
|
|
|
std::string const& value)
|
|
|
|
{
|
|
|
|
this->FlagMap[flag].push_back(value);
|
|
|
|
}
|
|
|
|
|
2014-08-13 21:39:35 +04:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2011-02-09 20:59:09 +03:00
|
|
|
void cmIDEOptions::RemoveFlag(const char* flag)
|
|
|
|
{
|
|
|
|
this->FlagMap.erase(flag);
|
|
|
|
}
|
2012-10-26 18:16:45 +04:00
|
|
|
|
2014-08-13 22:07:07 +04:00
|
|
|
bool cmIDEOptions::HasFlag(std::string const& flag) const
|
|
|
|
{
|
|
|
|
return this->FlagMap.find(flag) != this->FlagMap.end();
|
|
|
|
}
|
|
|
|
|
2012-10-26 18:16:45 +04:00
|
|
|
const char* cmIDEOptions::GetFlag(const char* flag)
|
|
|
|
{
|
2014-07-23 19:13:13 +04:00
|
|
|
// This method works only for single-valued flags!
|
|
|
|
std::map<std::string, FlagValue>::iterator i = this->FlagMap.find(flag);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i != this->FlagMap.end() && i->second.size() == 1) {
|
2014-07-23 19:13:13 +04:00
|
|
|
return i->second[0].c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-26 18:16:45 +04:00
|
|
|
return 0;
|
|
|
|
}
|