2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2009-07-29 15:29:08 +00:00
|
|
|
#include "cmIDEOptions.h"
|
|
|
|
|
2017-04-11 20:00:21 +00:00
|
|
|
#include "cmsys/String.h"
|
2016-11-25 21:54:58 +00:00
|
|
|
#include <iterator>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-05-23 12:49:54 +00:00
|
|
|
#include "cmAlgorithms.h"
|
2016-11-25 21:54:58 +00:00
|
|
|
#include "cmIDEFlagTable.h"
|
|
|
|
#include "cmSystemTools.h"
|
2016-01-08 19:30:06 +00:00
|
|
|
|
2009-07-29 15:29:08 +00:00
|
|
|
cmIDEOptions::cmIDEOptions()
|
|
|
|
{
|
|
|
|
this->DoingDefine = false;
|
|
|
|
this->AllowDefine = true;
|
2017-12-19 15:03:41 +00:00
|
|
|
this->DoingInclude = false;
|
2009-07-29 15:29:08 +00:00
|
|
|
this->AllowSlash = false;
|
2014-04-01 18:56:08 +00:00
|
|
|
this->DoingFollowing = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (int i = 0; i < FlagTableCount; ++i) {
|
2009-07-29 15:29:08 +00:00
|
|
|
this->FlagTable[i] = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-07-29 15:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmIDEOptions::~cmIDEOptions()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-26 16:24:45 +00:00
|
|
|
void cmIDEOptions::HandleFlag(std::string const& flag)
|
2009-07-29 15:29:08 +00:00
|
|
|
{
|
|
|
|
// If the last option was -D then this option is the definition.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->DoingDefine) {
|
2009-07-29 15:29:08 +00:00
|
|
|
this->DoingDefine = false;
|
|
|
|
this->Defines.push_back(flag);
|
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-07-29 15:29:08 +00:00
|
|
|
|
2017-12-19 15:03:41 +00:00
|
|
|
// If the last option was -I then this option is the include directory.
|
|
|
|
if (this->DoingInclude) {
|
|
|
|
this->DoingInclude = false;
|
|
|
|
this->Includes.push_back(flag);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-01 18:56:08 +00:00
|
|
|
// If the last option expected a following value, this is it.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->DoingFollowing) {
|
2014-04-01 18:56:08 +00:00
|
|
|
this->FlagMapUpdate(this->DoingFollowing, flag);
|
|
|
|
this->DoingFollowing = 0;
|
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-04-01 18:56:08 +00:00
|
|
|
|
2009-07-29 15:29:08 +00:00
|
|
|
// Look for known arguments.
|
2018-02-26 16:24:45 +00:00
|
|
|
size_t len = flag.length();
|
|
|
|
if (len > 0 && (flag[0] == '-' || (this->AllowSlash && flag[0] == '/'))) {
|
2009-07-29 15:29:08 +00:00
|
|
|
// Look for preprocessor definitions.
|
2018-02-26 16:24:45 +00:00
|
|
|
if (this->AllowDefine && len > 1 && flag[1] == 'D') {
|
|
|
|
if (len <= 2) {
|
2009-07-29 15:29:08 +00:00
|
|
|
// The next argument will have the definition.
|
|
|
|
this->DoingDefine = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2009-07-29 15:29:08 +00:00
|
|
|
// Store this definition.
|
2018-02-26 16:24:45 +00:00
|
|
|
this->Defines.push_back(flag.substr(2));
|
2009-07-29 15:29:08 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-12-19 15:03:41 +00:00
|
|
|
// Look for include directory.
|
2018-02-26 16:24:45 +00:00
|
|
|
if (this->AllowInclude && len > 1 && flag[1] == 'I') {
|
|
|
|
if (len <= 2) {
|
2017-12-19 15:03:41 +00:00
|
|
|
// The next argument will have the include directory.
|
|
|
|
this->DoingInclude = true;
|
|
|
|
} else {
|
|
|
|
// Store this include directory.
|
2018-02-26 16:24:45 +00:00
|
|
|
this->Includes.push_back(flag.substr(2));
|
2017-12-19 15:03:41 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-07-29 15:29:08 +00:00
|
|
|
|
|
|
|
// Look through the available flag tables.
|
|
|
|
bool flag_handled = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (int i = 0; i < FlagTableCount && this->FlagTable[i]; ++i) {
|
|
|
|
if (this->CheckFlagTable(this->FlagTable[i], flag, flag_handled)) {
|
2009-07-29 15:29:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-07-29 15:29:08 +00:00
|
|
|
|
|
|
|
// If any map entry handled the flag we are done.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (flag_handled) {
|
2009-07-29 15:29:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-07-29 15:29:08 +00:00
|
|
|
|
|
|
|
// This option is not known. Store it in the output flags.
|
|
|
|
this->StoreUnknownFlag(flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
|
2018-02-26 16:24:45 +00:00
|
|
|
std::string const& flag, bool& flag_handled)
|
2009-07-29 15:29:08 +00:00
|
|
|
{
|
2018-02-26 16:24:45 +00:00
|
|
|
const char* pf = flag.c_str() + 1;
|
2009-07-29 15:29:08 +00:00
|
|
|
// Look for an entry in the flag table matching this flag.
|
2018-11-20 18:09:57 +00:00
|
|
|
for (cmIDEFlagTable const* entry = table; !entry->IDEName.empty(); ++entry) {
|
2009-07-29 15:29:08 +00:00
|
|
|
bool entry_found = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (entry->special & cmIDEFlagTable::UserValue) {
|
2009-07-29 15:29:08 +00: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.
|
2018-11-20 18:09:57 +00:00
|
|
|
int n = static_cast<int>(entry->commandFlag.length());
|
|
|
|
if ((strncmp(pf, entry->commandFlag.c_str(), n) == 0 ||
|
2016-05-16 14:34:04 +00:00
|
|
|
(entry->special & cmIDEFlagTable::CaseInsensitive &&
|
2018-11-20 18:09:57 +00:00
|
|
|
cmsysString_strncasecmp(pf, entry->commandFlag.c_str(), n))) &&
|
2016-05-16 14:34:04 +00:00
|
|
|
(!(entry->special & cmIDEFlagTable::UserRequired) ||
|
2018-02-26 16:24:45 +00:00
|
|
|
static_cast<int>(strlen(pf)) > n)) {
|
|
|
|
this->FlagMapUpdate(entry, std::string(pf + n));
|
2009-07-29 15:29:08 +00:00
|
|
|
entry_found = true;
|
|
|
|
}
|
2018-11-20 18:09:57 +00:00
|
|
|
} else if (strcmp(pf, entry->commandFlag.c_str()) == 0 ||
|
2016-05-16 14:34:04 +00:00
|
|
|
(entry->special & cmIDEFlagTable::CaseInsensitive &&
|
2018-11-20 18:09:57 +00:00
|
|
|
cmsysString_strcasecmp(pf, entry->commandFlag.c_str()) == 0)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (entry->special & cmIDEFlagTable::UserFollowing) {
|
2014-04-01 18:56:08 +00:00
|
|
|
// This flag expects a value in the following argument.
|
|
|
|
this->DoingFollowing = entry;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2014-04-01 18:56:08 +00:00
|
|
|
// This flag table entry provides a fixed value.
|
|
|
|
this->FlagMap[entry->IDEName] = entry->value;
|
2009-07-29 15:29:08 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
entry_found = true;
|
|
|
|
}
|
2009-07-29 15:29:08 +00:00
|
|
|
|
|
|
|
// If the flag has been handled by an entry not requesting a
|
|
|
|
// search continuation we are done.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (entry_found && !(entry->special & cmIDEFlagTable::Continue)) {
|
2009-07-29 15:29:08 +00:00
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-07-29 15:29:08 +00:00
|
|
|
|
|
|
|
// If the entry was found the flag has been handled.
|
|
|
|
flag_handled = flag_handled || entry_found;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-07-29 15:29:08 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-01 18:54:28 +00:00
|
|
|
void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry,
|
2018-02-26 16:24:45 +00:00
|
|
|
std::string const& new_value)
|
2014-04-01 18:54:28 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (entry->special & cmIDEFlagTable::UserIgnored) {
|
2014-04-01 18:54:28 +00:00
|
|
|
// Ignore the user-specified value.
|
|
|
|
this->FlagMap[entry->IDEName] = entry->value;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (entry->special & cmIDEFlagTable::SemicolonAppendable) {
|
2014-07-23 15:13:13 +00:00
|
|
|
this->FlagMap[entry->IDEName].push_back(new_value);
|
2017-02-15 14:35:36 +00:00
|
|
|
} else if (entry->special & cmIDEFlagTable::SpaceAppendable) {
|
|
|
|
this->FlagMap[entry->IDEName].append_with_space(new_value);
|
2019-02-05 23:12:38 +00:00
|
|
|
} else if (entry->special & cmIDEFlagTable::CommaAppendable) {
|
|
|
|
this->FlagMap[entry->IDEName].append_with_comma(new_value);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2014-04-01 18:54:28 +00:00
|
|
|
// Use the user-specified value.
|
|
|
|
this->FlagMap[entry->IDEName] = new_value;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-04-01 18:54:28 +00:00
|
|
|
}
|
|
|
|
|
2009-07-29 15:29:08 +00:00
|
|
|
void cmIDEOptions::AddDefine(const std::string& def)
|
|
|
|
{
|
|
|
|
this->Defines.push_back(def);
|
|
|
|
}
|
|
|
|
|
2018-02-26 16:24:45 +00:00
|
|
|
void cmIDEOptions::AddDefines(std::string const& defines)
|
2009-07-29 15:29:08 +00:00
|
|
|
{
|
2018-02-26 16:24:45 +00:00
|
|
|
if (!defines.empty()) {
|
2009-07-29 15:29:08 +00:00
|
|
|
// Expand the list of definitions.
|
|
|
|
cmSystemTools::ExpandListArgument(defines, this->Defines);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-07-29 15:29:08 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
void cmIDEOptions::AddDefines(const std::vector<std::string>& defines)
|
2013-07-10 13:22:59 +00:00
|
|
|
{
|
2019-05-23 12:49:54 +00:00
|
|
|
cmAppend(this->Defines, defines);
|
2013-07-10 13:22:59 +00:00
|
|
|
}
|
2009-07-29 15:29:08 +00:00
|
|
|
|
2017-03-28 16:55:14 +00:00
|
|
|
std::vector<std::string> const& cmIDEOptions::GetDefines() const
|
|
|
|
{
|
|
|
|
return this->Defines;
|
|
|
|
}
|
|
|
|
|
2017-12-19 15:03:41 +00:00
|
|
|
void cmIDEOptions::AddInclude(const std::string& include)
|
|
|
|
{
|
|
|
|
this->Includes.push_back(include);
|
|
|
|
}
|
|
|
|
|
2018-02-26 16:24:45 +00:00
|
|
|
void cmIDEOptions::AddIncludes(std::string const& includes)
|
2017-12-19 15:03:41 +00:00
|
|
|
{
|
2018-02-26 16:24:45 +00:00
|
|
|
if (!includes.empty()) {
|
2017-12-19 15:03:41 +00:00
|
|
|
// Expand the list of includes.
|
|
|
|
cmSystemTools::ExpandListArgument(includes, this->Includes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void cmIDEOptions::AddIncludes(const std::vector<std::string>& includes)
|
|
|
|
{
|
2019-05-23 12:49:54 +00:00
|
|
|
cmAppend(this->Includes, includes);
|
2017-12-19 15:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> const& cmIDEOptions::GetIncludes() const
|
|
|
|
{
|
|
|
|
return this->Includes;
|
|
|
|
}
|
|
|
|
|
2017-12-09 03:30:16 +00:00
|
|
|
void cmIDEOptions::AddFlag(std::string const& flag, std::string const& value)
|
2009-07-29 15:29:08 +00:00
|
|
|
{
|
|
|
|
this->FlagMap[flag] = value;
|
|
|
|
}
|
2011-02-09 17:59:09 +00:00
|
|
|
|
2017-12-09 03:30:16 +00:00
|
|
|
void cmIDEOptions::AddFlag(std::string const& flag,
|
2014-07-23 15:13:13 +00:00
|
|
|
std::vector<std::string> const& value)
|
|
|
|
{
|
|
|
|
this->FlagMap[flag] = value;
|
|
|
|
}
|
|
|
|
|
2014-07-31 18:02:03 +00:00
|
|
|
void cmIDEOptions::AppendFlag(std::string const& flag,
|
|
|
|
std::string const& value)
|
|
|
|
{
|
|
|
|
this->FlagMap[flag].push_back(value);
|
|
|
|
}
|
|
|
|
|
2014-08-13 17:39:35 +00: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));
|
|
|
|
}
|
|
|
|
|
2017-02-15 14:35:36 +00:00
|
|
|
void cmIDEOptions::AppendFlagString(std::string const& flag,
|
|
|
|
std::string const& value)
|
|
|
|
{
|
|
|
|
this->FlagMap[flag].append_with_space(value);
|
|
|
|
}
|
|
|
|
|
2017-12-09 03:30:16 +00:00
|
|
|
void cmIDEOptions::RemoveFlag(std::string const& flag)
|
2011-02-09 17:59:09 +00:00
|
|
|
{
|
|
|
|
this->FlagMap.erase(flag);
|
|
|
|
}
|
2012-10-26 14:16:45 +00:00
|
|
|
|
2014-08-13 18:07:07 +00:00
|
|
|
bool cmIDEOptions::HasFlag(std::string const& flag) const
|
|
|
|
{
|
|
|
|
return this->FlagMap.find(flag) != this->FlagMap.end();
|
|
|
|
}
|
|
|
|
|
2017-12-09 03:30:16 +00:00
|
|
|
const char* cmIDEOptions::GetFlag(std::string const& flag) const
|
2012-10-26 14:16:45 +00:00
|
|
|
{
|
2014-07-23 15:13:13 +00:00
|
|
|
// This method works only for single-valued flags!
|
2017-12-09 03:30:16 +00:00
|
|
|
std::map<std::string, FlagValue>::const_iterator i =
|
|
|
|
this->FlagMap.find(flag);
|
|
|
|
if (i != this->FlagMap.cend() && i->second.size() == 1) {
|
2014-07-23 15:13:13 +00:00
|
|
|
return i->second[0].c_str();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2017-12-09 03:30:16 +00:00
|
|
|
return nullptr;
|
2012-10-26 14:16:45 +00:00
|
|
|
}
|