mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-21 06:30:20 -06:00
Refactor module definition file selection
Create a `ModuleDefinitionInfo` structure for each configuration of a target to hold corresponding information about the selected module definition file (`.def` source).
This commit is contained in:
@@ -26,7 +26,6 @@ cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
|
||||
, GlobalGenerator(static_cast<cmGlobalCommonGenerator*>(
|
||||
gt->LocalGenerator->GetGlobalGenerator()))
|
||||
, ConfigName(LocalGenerator->GetConfigName())
|
||||
, ModuleDefinitionFile(GeneratorTarget->GetModuleDefinitionFile(ConfigName))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -63,14 +62,9 @@ void cmCommonTargetGenerator::AddFeatureFlags(std::string& flags,
|
||||
void cmCommonTargetGenerator::AddModuleDefinitionFlag(
|
||||
cmLinkLineComputer* linkLineComputer, std::string& flags)
|
||||
{
|
||||
// A module definition file only makes sense on certain target types.
|
||||
if (this->GeneratorTarget->GetType() != cmStateEnums::SHARED_LIBRARY &&
|
||||
this->GeneratorTarget->GetType() != cmStateEnums::MODULE_LIBRARY &&
|
||||
this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->ModuleDefinitionFile) {
|
||||
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
|
||||
this->GeneratorTarget->GetModuleDefinitionInfo(this->GetConfigName());
|
||||
if (!mdi || mdi->DefFile.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,8 +79,7 @@ void cmCommonTargetGenerator::AddModuleDefinitionFlag(
|
||||
// vs6's "cl -link" pass it to the linker.
|
||||
std::string flag = defFileFlag;
|
||||
flag += this->LocalGenerator->ConvertToOutputFormat(
|
||||
linkLineComputer->ConvertToLinkReference(
|
||||
this->ModuleDefinitionFile->GetFullPath()),
|
||||
linkLineComputer->ConvertToLinkReference(mdi->DefFile),
|
||||
cmOutputConverter::SHELL);
|
||||
this->LocalGenerator->AppendFlags(flags, flag);
|
||||
}
|
||||
|
||||
@@ -44,9 +44,6 @@ protected:
|
||||
cmGlobalCommonGenerator* GlobalGenerator;
|
||||
std::string ConfigName;
|
||||
|
||||
// The windows module definition source file (.def), if any.
|
||||
cmSourceFile const* ModuleDefinitionFile;
|
||||
|
||||
void AppendFortranFormatFlags(std::string& flags,
|
||||
cmSourceFile const& source);
|
||||
|
||||
|
||||
@@ -1944,16 +1944,40 @@ cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
|
||||
return &i->second;
|
||||
}
|
||||
|
||||
cmSourceFile const* cmGeneratorTarget::GetModuleDefinitionFile(
|
||||
const std::string& config) const
|
||||
cmGeneratorTarget::ModuleDefinitionInfo const*
|
||||
cmGeneratorTarget::GetModuleDefinitionInfo(std::string const& config) const
|
||||
{
|
||||
std::vector<cmSourceFile const*> data;
|
||||
this->GetModuleDefinitionSources(data, config);
|
||||
if (!data.empty()) {
|
||||
return data.front();
|
||||
// A module definition file only makes sense on certain target types.
|
||||
if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
|
||||
this->GetType() != cmStateEnums::MODULE_LIBRARY &&
|
||||
!this->IsExecutableWithExports()) {
|
||||
return CM_NULLPTR;
|
||||
}
|
||||
|
||||
return CM_NULLPTR;
|
||||
// Lookup/compute/cache the compile information for this configuration.
|
||||
std::string config_upper;
|
||||
if (!config.empty()) {
|
||||
config_upper = cmSystemTools::UpperCase(config);
|
||||
}
|
||||
ModuleDefinitionInfoMapType::const_iterator i =
|
||||
this->ModuleDefinitionInfoMap.find(config_upper);
|
||||
if (i == this->ModuleDefinitionInfoMap.end()) {
|
||||
ModuleDefinitionInfo info;
|
||||
this->ComputeModuleDefinitionInfo(config, info);
|
||||
ModuleDefinitionInfoMapType::value_type entry(config_upper, info);
|
||||
i = this->ModuleDefinitionInfoMap.insert(entry).first;
|
||||
}
|
||||
return &i->second;
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::ComputeModuleDefinitionInfo(
|
||||
std::string const& config, ModuleDefinitionInfo& info) const
|
||||
{
|
||||
std::vector<cmSourceFile const*> sources;
|
||||
this->GetModuleDefinitionSources(sources, config);
|
||||
if (!sources.empty()) {
|
||||
info.DefFile = sources.front()->GetFullPath();
|
||||
}
|
||||
}
|
||||
|
||||
bool cmGeneratorTarget::IsDLLPlatform() const
|
||||
|
||||
@@ -235,7 +235,12 @@ public:
|
||||
cmLocalGenerator* LocalGenerator;
|
||||
cmGlobalGenerator const* GlobalGenerator;
|
||||
|
||||
cmSourceFile const* GetModuleDefinitionFile(const std::string& config) const;
|
||||
struct ModuleDefinitionInfo
|
||||
{
|
||||
std::string DefFile;
|
||||
};
|
||||
ModuleDefinitionInfo const* GetModuleDefinitionInfo(
|
||||
std::string const& config) const;
|
||||
|
||||
/** Return whether or not the target is for a DLL platform. */
|
||||
bool IsDLLPlatform() const;
|
||||
@@ -723,6 +728,12 @@ private:
|
||||
typedef std::map<std::string, OutputInfo> OutputInfoMapType;
|
||||
mutable OutputInfoMapType OutputInfoMap;
|
||||
|
||||
typedef std::map<std::string, ModuleDefinitionInfo>
|
||||
ModuleDefinitionInfoMapType;
|
||||
mutable ModuleDefinitionInfoMapType ModuleDefinitionInfoMap;
|
||||
void ComputeModuleDefinitionInfo(std::string const& config,
|
||||
ModuleDefinitionInfo& info) const;
|
||||
|
||||
typedef std::pair<std::string, bool> OutputNameKey;
|
||||
typedef std::map<OutputNameKey, std::string> OutputNameMapType;
|
||||
mutable OutputNameMapType OutputNameMap;
|
||||
|
||||
@@ -996,9 +996,11 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
|
||||
linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
|
||||
|
||||
linkOptions.Parse(extraLinkOptions.c_str());
|
||||
if (!this->ModuleDefinitionFile.empty()) {
|
||||
std::string defFile = this->ConvertToOutputFormat(
|
||||
this->ModuleDefinitionFile, cmOutputConverter::SHELL);
|
||||
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
|
||||
target->GetModuleDefinitionInfo(configName);
|
||||
if (mdi && !mdi->DefFile.empty()) {
|
||||
std::string defFile =
|
||||
this->ConvertToOutputFormat(mdi->DefFile, cmOutputConverter::SHELL);
|
||||
linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
|
||||
}
|
||||
|
||||
@@ -1362,7 +1364,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
|
||||
std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
|
||||
|
||||
// get the classes from the source lists then add them to the groups
|
||||
this->ModuleDefinitionFile = "";
|
||||
std::vector<cmSourceFile*> classes;
|
||||
if (!target->GetConfigCommonSourceFiles(classes)) {
|
||||
return;
|
||||
@@ -1374,9 +1375,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
|
||||
}
|
||||
// Add the file to the list of sources.
|
||||
std::string source = (*i)->GetFullPath();
|
||||
if (cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF") {
|
||||
this->ModuleDefinitionFile = (*i)->GetFullPath();
|
||||
}
|
||||
cmSourceGroup* sourceGroup =
|
||||
this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
|
||||
sourceGroup->AssignSource(*i);
|
||||
|
||||
@@ -128,7 +128,6 @@ private:
|
||||
|
||||
friend class EventWriter;
|
||||
|
||||
std::string ModuleDefinitionFile;
|
||||
bool FortranProject;
|
||||
bool WindowsCEProject;
|
||||
cmLocalVisualStudio7GeneratorInternals* Internal;
|
||||
|
||||
@@ -1414,8 +1414,10 @@ void cmMakefileTargetGenerator::AppendLinkDepends(
|
||||
this->AppendTargetDepends(depends);
|
||||
|
||||
// Add a dependency on the link definitions file, if any.
|
||||
if (this->ModuleDefinitionFile) {
|
||||
depends.push_back(this->ModuleDefinitionFile->GetFullPath());
|
||||
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
|
||||
this->GeneratorTarget->GetModuleDefinitionInfo(this->GetConfigName());
|
||||
if (mdi && !mdi->DefFile.empty()) {
|
||||
depends.push_back(mdi->DefFile);
|
||||
}
|
||||
|
||||
// Add a dependency on user-specified manifest files, if any.
|
||||
|
||||
@@ -212,9 +212,10 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
|
||||
std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath());
|
||||
|
||||
// Add a dependency on the link definitions file, if any.
|
||||
if (this->ModuleDefinitionFile) {
|
||||
result.push_back(
|
||||
this->ConvertToNinjaPath(this->ModuleDefinitionFile->GetFullPath()));
|
||||
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
|
||||
this->GeneratorTarget->GetModuleDefinitionInfo(this->GetConfigName());
|
||||
if (mdi && !mdi->DefFile.empty()) {
|
||||
result.push_back(this->ConvertToNinjaPath(mdi->DefFile));
|
||||
}
|
||||
|
||||
// Add a dependency on user-specified manifest files, if any.
|
||||
|
||||
@@ -2914,10 +2914,10 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
|
||||
linkOptions.Parse(flags.c_str());
|
||||
|
||||
if (this->MSTools) {
|
||||
if (cmSourceFile const* defsrc =
|
||||
this->GeneratorTarget->GetModuleDefinitionFile("")) {
|
||||
linkOptions.AddFlag("ModuleDefinitionFile",
|
||||
defsrc->GetFullPath().c_str());
|
||||
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
|
||||
this->GeneratorTarget->GetModuleDefinitionInfo(config);
|
||||
if (mdi && !mdi->DefFile.empty()) {
|
||||
linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile.c_str());
|
||||
}
|
||||
linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
|
||||
"%(IgnoreSpecificDefaultLibraries)");
|
||||
|
||||
Reference in New Issue
Block a user