cmMakefile: Convert private helpers to file static functions

The two-argument forms of `AddDefineFlag` and `RemoveDefineFlag`
need no access to `cmMakefile` class members.  They are used only
within the implementation file.
This commit is contained in:
Vitaly Stakhovsky
2018-04-30 10:50:23 -04:00
committed by Brad King
parent e13fa223fc
commit 0c47ed6430
2 changed files with 33 additions and 36 deletions

View File

@@ -1130,6 +1130,17 @@ cmTarget* cmMakefile::AddUtilityCommand(
return target;
}
static void s_AddDefineFlag(std::string const& flag, std::string& dflags)
{
// remove any \n\r
std::string::size_type initSize = dflags.size();
dflags += ' ';
dflags += flag;
std::string::iterator flagStart = dflags.begin() + initSize + 1;
std::replace(flagStart, dflags.end(), '\n', ' ');
std::replace(flagStart, dflags.end(), '\r', ' ');
}
void cmMakefile::AddDefineFlag(std::string const& flag)
{
if (flag.empty()) {
@@ -1137,7 +1148,7 @@ void cmMakefile::AddDefineFlag(std::string const& flag)
}
// Update the string used for the old DEFINITIONS property.
this->AddDefineFlag(flag, this->DefineFlagsOrig);
s_AddDefineFlag(flag, this->DefineFlagsOrig);
// If this is really a definition, update COMPILE_DEFINITIONS.
if (this->ParseDefineFlag(flag, false)) {
@@ -1145,42 +1156,12 @@ void cmMakefile::AddDefineFlag(std::string const& flag)
}
// Add this flag that does not look like a definition.
this->AddDefineFlag(flag, this->DefineFlags);
s_AddDefineFlag(flag, this->DefineFlags);
}
void cmMakefile::AddDefineFlag(std::string const& flag, std::string& dflags)
static void s_RemoveDefineFlag(std::string const& flag, std::string& dflags)
{
// remove any \n\r
std::string::size_type initSize = dflags.size();
dflags += std::string(" ") + flag;
std::string::iterator flagStart = dflags.begin() + initSize + 1;
std::replace(flagStart, dflags.end(), '\n', ' ');
std::replace(flagStart, dflags.end(), '\r', ' ');
}
void cmMakefile::RemoveDefineFlag(std::string const& flag)
{
// Check the length of the flag to remove.
if (flag.empty()) {
return;
}
std::string::size_type const len = flag.length();
// Update the string used for the old DEFINITIONS property.
this->RemoveDefineFlag(flag, len, this->DefineFlagsOrig);
// If this is really a definition, update COMPILE_DEFINITIONS.
if (this->ParseDefineFlag(flag, true)) {
return;
}
// Remove this flag that does not look like a definition.
this->RemoveDefineFlag(flag, len, this->DefineFlags);
}
void cmMakefile::RemoveDefineFlag(std::string const& flag,
std::string::size_type len,
std::string& dflags)
{
// Remove all instances of the flag that are surrounded by
// whitespace or the beginning/end of the string.
for (std::string::size_type lpos = dflags.find(flag, 0);
@@ -1195,6 +1176,25 @@ void cmMakefile::RemoveDefineFlag(std::string const& flag,
}
}
void cmMakefile::RemoveDefineFlag(std::string const& flag)
{
// Check the length of the flag to remove.
if (flag.empty()) {
return;
}
// Update the string used for the old DEFINITIONS property.
s_RemoveDefineFlag(flag, this->DefineFlagsOrig);
// If this is really a definition, update COMPILE_DEFINITIONS.
if (this->ParseDefineFlag(flag, true)) {
return;
}
// Remove this flag that does not look like a definition.
s_RemoveDefineFlag(flag, this->DefineFlags);
}
void cmMakefile::AddCompileDefinition(std::string const& option)
{
this->AppendProperty("COMPILE_DEFINITIONS", option.c_str());

View File

@@ -885,9 +885,6 @@ protected:
std::string DefineFlags;
// Track the value of the computed DEFINITIONS property.
void AddDefineFlag(std::string const& flag, std::string&);
void RemoveDefineFlag(std::string const& flag, std::string::size_type,
std::string&);
std::string DefineFlagsOrig;
#if defined(CMAKE_BUILD_WITH_CMAKE)