cmCommonTargetGenerator: Adopt ModuleDefinitionFile member

De-duplicate the ModuleDefinitionFile and AddModuleDefinitionFlag
members from the Makefile and Ninja target generators.
This commit is contained in:
Brad King 2015-07-08 15:24:17 -04:00
parent beee793732
commit cdb5b65752
7 changed files with 39 additions and 70 deletions

View File

@ -14,6 +14,7 @@
#include "cmGeneratorTarget.h"
#include "cmGlobalCommonGenerator.h"
#include "cmLocalCommonGenerator.h"
#include "cmMakefile.h"
#include "cmTarget.h"
cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
@ -24,6 +25,7 @@ cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
, GlobalGenerator(static_cast<cmGlobalCommonGenerator*>(
gt->LocalGenerator->GetGlobalGenerator()))
, ConfigName(LocalGenerator->GetConfigName())
, ModuleDefinitionFile(GeneratorTarget->GetModuleDefinitionFile(ConfigName))
{
}
@ -61,3 +63,27 @@ void cmCommonTargetGenerator::AddFeatureFlags(
this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO");
}
}
//----------------------------------------------------------------------------
void cmCommonTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
{
if(this->ModuleDefinitionFile.empty())
{
return;
}
// TODO: Create a per-language flag variable.
const char* defFileFlag =
this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
if(!defFileFlag)
{
return;
}
// Append the flag and value. Use ConvertToLinkReference to help
// vs6's "cl -link" pass it to the linker.
std::string flag = defFileFlag;
flag += (this->LocalGenerator->ConvertToLinkReference(
this->ModuleDefinitionFile));
this->LocalGenerator->AppendFlags(flags, flag);
}

View File

@ -40,12 +40,18 @@ protected:
const char* GetFeature(const std::string& feature);
bool GetFeatureAsBool(const std::string& feature);
// Helper to add flag for windows .def file.
void AddModuleDefinitionFlag(std::string& flags);
cmGeneratorTarget* GeneratorTarget;
cmTarget* Target;
cmMakefile* Makefile;
cmLocalCommonGenerator* LocalGenerator;
cmGlobalCommonGenerator* GlobalGenerator;
std::string ConfigName;
// The windows module definition source file (.def), if any.
std::string ModuleDefinitionFile;
};
#endif

View File

@ -14,6 +14,8 @@
#include "cmLocalGenerator.h"
class cmCommonTargetGenerator;
/** \class cmLocalCommonGenerator
* \brief Common infrastructure for Makefile and Ninja local generators.
*/
@ -30,6 +32,8 @@ public:
protected:
void SetConfigName();
std::string ConfigName;
friend class cmCommonTargetGenerator;
};
#endif

View File

@ -1668,11 +1668,9 @@ void cmMakefileTargetGenerator
this->AppendTargetDepends(depends);
// Add a dependency on the link definitions file, if any.
std::string def = this->GeneratorTarget->GetModuleDefinitionFile(
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
if(!def.empty())
if(!this->ModuleDefinitionFile.empty())
{
depends.push_back(def);
depends.push_back(this->ModuleDefinitionFile);
}
// Add user-specified dependencies.
@ -2074,28 +2072,3 @@ void cmMakefileTargetGenerator::AddFortranFlags(std::string& flags)
}
}
}
//----------------------------------------------------------------------------
void cmMakefileTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
{
std::string def = this->GeneratorTarget->GetModuleDefinitionFile(
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
if(def.empty())
{
return;
}
// TODO: Create a per-language flag variable.
const char* defFileFlag =
this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
if(!defFileFlag)
{
return;
}
// Append the flag and value. Use ConvertToLinkReference to help
// vs6's "cl -link" pass it to the linker.
std::string flag = defFileFlag;
flag += (this->LocalGenerator->ConvertToLinkReference(def));
this->LocalGenerator->AppendFlags(flags, flag);
}

View File

@ -255,9 +255,6 @@ protected:
// Compute target-specific Fortran language flags.
void AddFortranFlags(std::string& flags);
// Helper to add flag for windows .def file.
void AddModuleDefinitionFlag(std::string& flags);
//==================================================================
// Convenience routines that do nothing more than forward to
// implementaitons

View File

@ -244,7 +244,7 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
// Add a dependency on the link definitions file, if any.
if(!this->ModuleDefinitionFile.empty())
{
result.push_back(this->ModuleDefinitionFile);
result.push_back(this->ConvertToNinjaPath(this->ModuleDefinitionFile));
}
return result;
@ -574,11 +574,6 @@ cmNinjaTargetGenerator
{
this->WriteObjectBuildStatement(*si, !orderOnlyDeps.empty());
}
std::string def = this->GeneratorTarget->GetModuleDefinitionFile(config);
if(!def.empty())
{
this->ModuleDefinitionFile = this->ConvertToNinjaPath(def);
}
this->GetBuildFileStream() << "\n";
}
@ -728,32 +723,6 @@ cmNinjaTargetGenerator
}
}
//----------------------------------------------------------------------------
void
cmNinjaTargetGenerator
::AddModuleDefinitionFlag(std::string& flags)
{
if(this->ModuleDefinitionFile.empty())
{
return;
}
// TODO: Create a per-language flag variable.
const char* defFileFlag =
this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
if(!defFileFlag)
{
return;
}
// Append the flag and value. Use ConvertToLinkReference to help
// vs6's "cl -link" pass it to the linker.
std::string flag = defFileFlag;
flag += (this->LocalGenerator->ConvertToLinkReference(
this->ModuleDefinitionFile));
this->LocalGenerator->AppendFlags(flags, flag);
}
void
cmNinjaTargetGenerator
::EnsureDirectoryExists(const std::string& path) const

View File

@ -115,9 +115,6 @@ protected:
cmNinjaDeps GetObjects() const
{ return this->Objects; }
// Helper to add flag for windows .def file.
void AddModuleDefinitionFlag(std::string& flags);
void EnsureDirectoryExists(const std::string& dir) const;
void EnsureParentDirectoryExists(const std::string& path) const;
@ -153,9 +150,6 @@ private:
typedef std::map<std::string, std::string> LanguageFlagMap;
LanguageFlagMap LanguageFlags;
// The windows module definition source file (.def), if any.
std::string ModuleDefinitionFile;
};
#endif // ! cmNinjaTargetGenerator_h