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) else if(entry->special & cmIDEFlagTable::SemicolonAppendable)
{ {
std::map<std::string,std::string>::iterator itr; this->FlagMap[entry->IDEName].push_back(new_value);
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 else
{ {
@ -199,6 +188,13 @@ void cmIDEOptions::AddFlag(const char* flag, const char* value)
this->FlagMap[flag] = 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) void cmIDEOptions::RemoveFlag(const char* flag)
{ {
@ -208,10 +204,11 @@ void cmIDEOptions::RemoveFlag(const char* flag)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* cmIDEOptions::GetFlag(const char* flag) const char* cmIDEOptions::GetFlag(const char* flag)
{ {
std::map<std::string, std::string>::iterator i = this->FlagMap.find(flag); // This method works only for single-valued flags!
if(i != this->FlagMap.end()) 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; return 0;
} }

View File

@ -29,6 +29,7 @@ public:
void AddDefines(const char* defines); void AddDefines(const char* defines);
void AddDefines(const std::vector<std::string> &defines); void AddDefines(const std::vector<std::string> &defines);
void AddFlag(const char* flag, const char* value); void AddFlag(const char* flag, const char* value);
void AddFlag(const char* flag, std::vector<std::string> const& value);
void RemoveFlag(const char* flag); void RemoveFlag(const char* flag);
const char* GetFlag(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 // Then parse the command line flags specified in CMAKE_CXX_FLAGS
// and CMAKE_C_FLAGS // and CMAKE_C_FLAGS
// and overwrite or add new values to this map // 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. // Preprocessor definitions.
std::vector<std::string> Defines; std::vector<std::string> Defines;

View File

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

View File

@ -90,7 +90,8 @@ private:
void WriteGroups(); void WriteGroups();
void WriteProjectReferences(); void WriteProjectReferences();
bool OutputSourceSpecificFlags(cmSourceFile const* source); 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 WriteLibOptions(std::string const& config);
void WriteEvents(std::string const& configName); void WriteEvents(std::string const& configName);
void WriteEvent(const char* name, void WriteEvent(const char* name,

View File

@ -301,7 +301,7 @@ cmVisualStudioGeneratorOptions
{ {
if(this->Version >= cmLocalVisualStudioGenerator::VS10) 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) m != this->FlagMap.end(); ++m)
{ {
fout << indent; fout << indent;
@ -317,20 +317,34 @@ cmVisualStudioGeneratorOptions
{ {
fout << "<" << m->first << ">"; 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") if (m->first == "AdditionalIncludeDirectories")
{ {
fout << ";%(AdditionalIncludeDirectories)"; fout << sep << "%(AdditionalIncludeDirectories)";
} }
fout << "</" << m->first << ">\n"; fout << "</" << m->first << ">\n";
} }
} }
else 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) 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";
} }
} }
} }