VS: Refactor flag table lookup

In cmVisualStudio10TargetGenerator, convert the static functions
currently used to lookup the flag table for each tool into class
methods.  This avoids passing the this->LocalGenerator member and
gives the methods access to other information that may be useful
in the future.
This commit is contained in:
Brad King 2014-06-03 13:34:21 -04:00
parent 9e8fa1043c
commit ee329d543c
2 changed files with 24 additions and 16 deletions

View File

@ -32,34 +32,37 @@
#include <cmsys/auto_ptr.hxx> #include <cmsys/auto_ptr.hxx>
static cmVS7FlagTable const* cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetClFlagTable() const
cmVSGetCLFlagTable(cmLocalVisualStudioGenerator* lg)
{ {
if(lg->GetVersion() >= cmLocalVisualStudioGenerator::VS12) cmLocalVisualStudioGenerator::VSVersion
v = this->LocalGenerator->GetVersion();
if(v >= cmLocalVisualStudioGenerator::VS12)
{ return cmVS12CLFlagTable; } { return cmVS12CLFlagTable; }
else if(lg->GetVersion() == cmLocalVisualStudioGenerator::VS11) else if(v == cmLocalVisualStudioGenerator::VS11)
{ return cmVS11CLFlagTable; } { return cmVS11CLFlagTable; }
else else
{ return cmVS10CLFlagTable; } { return cmVS10CLFlagTable; }
} }
static cmVS7FlagTable const* cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLibFlagTable() const
cmVSGetLibFlagTable(cmLocalVisualStudioGenerator* lg)
{ {
if(lg->GetVersion() >= cmLocalVisualStudioGenerator::VS12) cmLocalVisualStudioGenerator::VSVersion
v = this->LocalGenerator->GetVersion();
if(v >= cmLocalVisualStudioGenerator::VS12)
{ return cmVS12LibFlagTable; } { return cmVS12LibFlagTable; }
else if(lg->GetVersion() == cmLocalVisualStudioGenerator::VS11) else if(v == cmLocalVisualStudioGenerator::VS11)
{ return cmVS11LibFlagTable; } { return cmVS11LibFlagTable; }
else else
{ return cmVS10LibFlagTable; } { return cmVS10LibFlagTable; }
} }
static cmVS7FlagTable const* cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLinkFlagTable() const
cmVSGetLinkFlagTable(cmLocalVisualStudioGenerator* lg)
{ {
if(lg->GetVersion() >= cmLocalVisualStudioGenerator::VS12) cmLocalVisualStudioGenerator::VSVersion
v = this->LocalGenerator->GetVersion();
if(v >= cmLocalVisualStudioGenerator::VS12)
{ return cmVS12LinkFlagTable; } { return cmVS12LinkFlagTable; }
else if(lg->GetVersion() == cmLocalVisualStudioGenerator::VS11) else if(v == cmLocalVisualStudioGenerator::VS11)
{ return cmVS11LinkFlagTable; } { return cmVS11LinkFlagTable; }
else else
{ return cmVS10LinkFlagTable; } { return cmVS10LinkFlagTable; }
@ -1198,7 +1201,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
cmVisualStudioGeneratorOptions cmVisualStudioGeneratorOptions
clOptions(this->LocalGenerator, clOptions(this->LocalGenerator,
cmVisualStudioGeneratorOptions::Compiler, cmVisualStudioGeneratorOptions::Compiler,
cmVSGetCLFlagTable(this->LocalGenerator), 0, this); this->GetClFlagTable(), 0, this);
clOptions.Parse(flags.c_str()); clOptions.Parse(flags.c_str());
clOptions.AddDefines(configDefines.c_str()); clOptions.AddDefines(configDefines.c_str());
clOptions.SetConfiguration((*config).c_str()); clOptions.SetConfiguration((*config).c_str());
@ -1355,7 +1358,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
cmsys::auto_ptr<Options> pOptions( cmsys::auto_ptr<Options> pOptions(
new Options(this->LocalGenerator, Options::Compiler, new Options(this->LocalGenerator, Options::Compiler,
cmVSGetCLFlagTable(this->LocalGenerator))); this->GetClFlagTable()));
Options& clOptions = *pOptions; Options& clOptions = *pOptions;
std::string flags; std::string flags;
@ -1508,7 +1511,7 @@ cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
cmVisualStudioGeneratorOptions cmVisualStudioGeneratorOptions
libOptions(this->LocalGenerator, libOptions(this->LocalGenerator,
cmVisualStudioGeneratorOptions::Linker, cmVisualStudioGeneratorOptions::Linker,
cmVSGetLibFlagTable(this->LocalGenerator), 0, this); this->GetLibFlagTable(), 0, this);
libOptions.Parse(libflags.c_str()); libOptions.Parse(libflags.c_str());
libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
libOptions.OutputFlagMap(*this->BuildFileStream, " "); libOptions.OutputFlagMap(*this->BuildFileStream, " ");
@ -1543,7 +1546,7 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
{ {
cmsys::auto_ptr<Options> pOptions( cmsys::auto_ptr<Options> pOptions(
new Options(this->LocalGenerator, Options::Linker, new Options(this->LocalGenerator, Options::Linker,
cmVSGetLinkFlagTable(this->LocalGenerator), 0, this)); this->GetLinkFlagTable(), 0, this));
Options& linkOptions = *pOptions; Options& linkOptions = *pOptions;
const std::string& linkLanguage = const std::string& linkLanguage =

View File

@ -23,6 +23,7 @@ class cmCustomCommand;
class cmLocalVisualStudio7Generator; class cmLocalVisualStudio7Generator;
class cmComputeLinkInformation; class cmComputeLinkInformation;
class cmVisualStudioGeneratorOptions; class cmVisualStudioGeneratorOptions;
struct cmIDEFlagTable;
#include "cmSourceGroup.h" #include "cmSourceGroup.h"
class cmVisualStudio10TargetGenerator class cmVisualStudio10TargetGenerator
@ -98,6 +99,10 @@ private:
const std::vector<cmSourceGroup>& allGroups); const std::vector<cmSourceGroup>& allGroups);
bool IsResxHeader(const std::string& headerFile); bool IsResxHeader(const std::string& headerFile);
cmIDEFlagTable const* GetClFlagTable() const;
cmIDEFlagTable const* GetLibFlagTable() const;
cmIDEFlagTable const* GetLinkFlagTable() const;
private: private:
typedef cmVisualStudioGeneratorOptions Options; typedef cmVisualStudioGeneratorOptions Options;
typedef std::map<std::string, Options*> OptionsMap; typedef std::map<std::string, Options*> OptionsMap;