cmIDEOption: Store mapped flag values as a vector<string>

Some FlagMap entries are ;-lists.  Store values as vector<string> so
that individual values may contain ';' characters.  Delay the
construction of the final ;-list until writing to the VS project file.
With this approach the generated file may contain ;-separated values
that contain encoded ';' characters.
This commit is contained in:
Brad King 2014-07-23 11:13:13 -04:00
parent 91c933546d
commit 1c209ac165
5 changed files with 64 additions and 41 deletions

View File

@ -152,18 +152,7 @@ void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry,
}
else if(entry->special & cmIDEFlagTable::SemicolonAppendable)
{
std::map<std::string,std::string>::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;
}
this->FlagMap[entry->IDEName].push_back(new_value);
}
else
{
@ -199,6 +188,13 @@ 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::RemoveFlag(const char* flag)
{
@ -208,10 +204,11 @@ void cmIDEOptions::RemoveFlag(const char* flag)
//----------------------------------------------------------------------------
const char* cmIDEOptions::GetFlag(const char* flag)
{
std::map<std::string, std::string>::iterator i = this->FlagMap.find(flag);
if(i != this->FlagMap.end())
// 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.c_str();
return i->second[0].c_str();
}
return 0;
}

View File

@ -29,6 +29,7 @@ public:
void AddDefines(const char* defines);
void AddDefines(const std::vector<std::string> &defines);
void AddFlag(const char* flag, const char* value);
void AddFlag(const char* flag, std::vector<std::string> const& value);
void RemoveFlag(const char* flag);
const char* GetFlag(const char* flag);
@ -40,7 +41,23 @@ protected:
// Then parse the command line flags specified in CMAKE_CXX_FLAGS
// and CMAKE_C_FLAGS
// and overwrite or add new values to this map
std::map<std::string, std::string> FlagMap;
class FlagValue: public std::vector<std::string>
{
typedef std::vector<std::string> derived;
public:
FlagValue& operator=(std::string const& r)
{
this->resize(1);
this->operator[](0) = r;
return *this;
}
FlagValue& operator=(std::vector<std::string> const& r)
{
this->derived::operator=(r);
return *this;
}
};
std::map<std::string, FlagValue > FlagMap;
// Preprocessor definitions.
std::vector<std::string> Defines;

View File

@ -1735,6 +1735,9 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
}
// Replace spaces in libs with ;
cmSystemTools::ReplaceString(libs, " ", ";");
std::vector<std::string> libVec;
cmSystemTools::ExpandListArgument(libs, libVec);
cmComputeLinkInformation* pcli =
this->Target->GetLinkInformation(config.c_str());
if(!pcli)
@ -1746,27 +1749,21 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
}
// add the libraries for the target to libs string
cmComputeLinkInformation& cli = *pcli;
this->AddLibraries(cli, libs);
linkOptions.AddFlag("AdditionalDependencies", libs.c_str());
this->AddLibraries(cli, libVec);
linkOptions.AddFlag("AdditionalDependencies", libVec);
std::vector<std::string> const& ldirs = cli.GetDirectories();
const char* sep = "";
std::string linkDirs;
std::vector<std::string> linkDirs;
for(std::vector<std::string>::const_iterator d = ldirs.begin();
d != ldirs.end(); ++d)
{
// first just full path
linkDirs += sep;
linkDirs += *d;
sep = ";";
linkDirs += sep;
linkDirs.push_back(*d);
// next path with configuration type Debug, Release, etc
linkDirs += *d;
linkDirs += "/$(Configuration)";
linkDirs += sep;
linkDirs.push_back(*d + "/$(Configuration)");
}
linkDirs += "%(AdditionalLibraryDirectories)";
linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs.c_str());
linkDirs.push_back("%(AdditionalLibraryDirectories)");
linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
std::string targetName;
std::string targetNameSO;
@ -1866,11 +1863,10 @@ cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
void cmVisualStudio10TargetGenerator::AddLibraries(
cmComputeLinkInformation& cli,
std::string& libstring)
std::vector<std::string>& libVec)
{
typedef cmComputeLinkInformation::ItemVector ItemVector;
ItemVector libs = cli.GetItems();
const char* sep = ";";
for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
{
if(l->IsPath)
@ -1880,14 +1876,12 @@ void cmVisualStudio10TargetGenerator::AddLibraries(
cmLocalGenerator::START_OUTPUT,
cmLocalGenerator::UNCHANGED);
this->ConvertToWindowsSlash(path);
libstring += sep;
libstring += path;
libVec.push_back(path);
}
else if (!l->Target
|| l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
{
libstring += sep;
libstring += l->Value;
libVec.push_back(l->Value);
}
}
}

View File

@ -90,7 +90,8 @@ private:
void WriteGroups();
void WriteProjectReferences();
bool OutputSourceSpecificFlags(cmSourceFile const* source);
void AddLibraries(cmComputeLinkInformation& cli, std::string& libstring);
void AddLibraries(cmComputeLinkInformation& cli,
std::vector<std::string>& libVec);
void WriteLibOptions(std::string const& config);
void WriteEvents(std::string const& configName);
void WriteEvent(const char* name,

View File

@ -301,7 +301,7 @@ cmVisualStudioGeneratorOptions
{
if(this->Version >= cmLocalVisualStudioGenerator::VS10)
{
for(std::map<std::string, std::string>::iterator m = this->FlagMap.begin();
for(std::map<std::string, FlagValue>::iterator m = this->FlagMap.begin();
m != this->FlagMap.end(); ++m)
{
fout << indent;
@ -317,20 +317,34 @@ cmVisualStudioGeneratorOptions
{
fout << "<" << m->first << ">";
}
fout << m->second;
const char* sep = "";
for(std::vector<std::string>::iterator i = m->second.begin();
i != m->second.end(); ++i)
{
fout << sep << *i;
sep = ";";
}
if (m->first == "AdditionalIncludeDirectories")
{
fout << ";%(AdditionalIncludeDirectories)";
fout << sep << "%(AdditionalIncludeDirectories)";
}
fout << "</" << m->first << ">\n";
}
}
else
{
for(std::map<std::string, std::string>::iterator m = this->FlagMap.begin();
for(std::map<std::string, FlagValue>::iterator m = this->FlagMap.begin();
m != this->FlagMap.end(); ++m)
{
fout << indent << m->first << "=\"" << m->second << "\"\n";
fout << indent << m->first << "=\"";
const char* sep = "";
for(std::vector<std::string>::iterator i = m->second.begin();
i != m->second.end(); ++i)
{
fout << sep << *i;
sep = ";";
}
fout << "\"\n";
}
}
}