mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-10-07 04:02:23 +03: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:
1 parent
1e0a9ac45d
commit
25d261efa7
9 files changed
+64
-39
No files matched your search
@@ -26,7 +26,6 @@ cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
|
|||||||
, GlobalGenerator(static_cast<cmGlobalCommonGenerator*>(
|
, GlobalGenerator(static_cast<cmGlobalCommonGenerator*>(
|
||||||
gt->LocalGenerator->GetGlobalGenerator()))
|
gt->LocalGenerator->GetGlobalGenerator()))
|
||||||
, ConfigName(LocalGenerator->GetConfigName())
|
, ConfigName(LocalGenerator->GetConfigName())
|
||||||
, ModuleDefinitionFile(GeneratorTarget->GetModuleDefinitionFile(ConfigName))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,14 +62,9 @@ void cmCommonTargetGenerator::AddFeatureFlags(std::string& flags,
|
|||||||
void cmCommonTargetGenerator::AddModuleDefinitionFlag(
|
void cmCommonTargetGenerator::AddModuleDefinitionFlag(
|
||||||
cmLinkLineComputer* linkLineComputer, std::string& flags)
|
cmLinkLineComputer* linkLineComputer, std::string& flags)
|
||||||
{
|
{
|
||||||
// A module definition file only makes sense on certain target types.
|
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
|
||||||
if (this->GeneratorTarget->GetType() != cmStateEnums::SHARED_LIBRARY &&
|
this->GeneratorTarget->GetModuleDefinitionInfo(this->GetConfigName());
|
||||||
this->GeneratorTarget->GetType() != cmStateEnums::MODULE_LIBRARY &&
|
if (!mdi || mdi->DefFile.empty()) {
|
||||||
this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->ModuleDefinitionFile) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,8 +79,7 @@ void cmCommonTargetGenerator::AddModuleDefinitionFlag(
|
|||||||
// vs6's "cl -link" pass it to the linker.
|
// vs6's "cl -link" pass it to the linker.
|
||||||
std::string flag = defFileFlag;
|
std::string flag = defFileFlag;
|
||||||
flag += this->LocalGenerator->ConvertToOutputFormat(
|
flag += this->LocalGenerator->ConvertToOutputFormat(
|
||||||
linkLineComputer->ConvertToLinkReference(
|
linkLineComputer->ConvertToLinkReference(mdi->DefFile),
|
||||||
this->ModuleDefinitionFile->GetFullPath()),
|
|
||||||
cmOutputConverter::SHELL);
|
cmOutputConverter::SHELL);
|
||||||
this->LocalGenerator->AppendFlags(flags, flag);
|
this->LocalGenerator->AppendFlags(flags, flag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,9 +44,6 @@ protected:
|
|||||||
cmGlobalCommonGenerator* GlobalGenerator;
|
cmGlobalCommonGenerator* GlobalGenerator;
|
||||||
std::string ConfigName;
|
std::string ConfigName;
|
||||||
|
|
||||||
// The windows module definition source file (.def), if any.
|
|
||||||
cmSourceFile const* ModuleDefinitionFile;
|
|
||||||
|
|
||||||
void AppendFortranFormatFlags(std::string& flags,
|
void AppendFortranFormatFlags(std::string& flags,
|
||||||
cmSourceFile const& source);
|
cmSourceFile const& source);
|
||||||
|
|
||||||
|
|||||||
@@ -1944,16 +1944,40 @@ cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
|
|||||||
return &i->second;
|
return &i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmSourceFile const* cmGeneratorTarget::GetModuleDefinitionFile(
|
cmGeneratorTarget::ModuleDefinitionInfo const*
|
||||||
const std::string& config) const
|
cmGeneratorTarget::GetModuleDefinitionInfo(std::string const& config) const
|
||||||
{
|
{
|
||||||
std::vector<cmSourceFile const*> data;
|
// A module definition file only makes sense on certain target types.
|
||||||
this->GetModuleDefinitionSources(data, config);
|
if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
|
||||||
if (!data.empty()) {
|
this->GetType() != cmStateEnums::MODULE_LIBRARY &&
|
||||||
return data.front();
|
!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
|
bool cmGeneratorTarget::IsDLLPlatform() const
|
||||||
|
|||||||
@@ -235,7 +235,12 @@ public:
|
|||||||
cmLocalGenerator* LocalGenerator;
|
cmLocalGenerator* LocalGenerator;
|
||||||
cmGlobalGenerator const* GlobalGenerator;
|
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. */
|
/** Return whether or not the target is for a DLL platform. */
|
||||||
bool IsDLLPlatform() const;
|
bool IsDLLPlatform() const;
|
||||||
@@ -723,6 +728,12 @@ private:
|
|||||||
typedef std::map<std::string, OutputInfo> OutputInfoMapType;
|
typedef std::map<std::string, OutputInfo> OutputInfoMapType;
|
||||||
mutable OutputInfoMapType OutputInfoMap;
|
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::pair<std::string, bool> OutputNameKey;
|
||||||
typedef std::map<OutputNameKey, std::string> OutputNameMapType;
|
typedef std::map<OutputNameKey, std::string> OutputNameMapType;
|
||||||
mutable OutputNameMapType OutputNameMap;
|
mutable OutputNameMapType OutputNameMap;
|
||||||
|
|||||||
@@ -996,9 +996,11 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
|
|||||||
linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
|
linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
|
||||||
|
|
||||||
linkOptions.Parse(extraLinkOptions.c_str());
|
linkOptions.Parse(extraLinkOptions.c_str());
|
||||||
if (!this->ModuleDefinitionFile.empty()) {
|
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
|
||||||
std::string defFile = this->ConvertToOutputFormat(
|
target->GetModuleDefinitionInfo(configName);
|
||||||
this->ModuleDefinitionFile, cmOutputConverter::SHELL);
|
if (mdi && !mdi->DefFile.empty()) {
|
||||||
|
std::string defFile =
|
||||||
|
this->ConvertToOutputFormat(mdi->DefFile, cmOutputConverter::SHELL);
|
||||||
linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
|
linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1362,7 +1364,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
|
|||||||
std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
|
std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
|
||||||
|
|
||||||
// get the classes from the source lists then add them to the groups
|
// get the classes from the source lists then add them to the groups
|
||||||
this->ModuleDefinitionFile = "";
|
|
||||||
std::vector<cmSourceFile*> classes;
|
std::vector<cmSourceFile*> classes;
|
||||||
if (!target->GetConfigCommonSourceFiles(classes)) {
|
if (!target->GetConfigCommonSourceFiles(classes)) {
|
||||||
return;
|
return;
|
||||||
@@ -1374,9 +1375,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
|
|||||||
}
|
}
|
||||||
// Add the file to the list of sources.
|
// Add the file to the list of sources.
|
||||||
std::string source = (*i)->GetFullPath();
|
std::string source = (*i)->GetFullPath();
|
||||||
if (cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF") {
|
|
||||||
this->ModuleDefinitionFile = (*i)->GetFullPath();
|
|
||||||
}
|
|
||||||
cmSourceGroup* sourceGroup =
|
cmSourceGroup* sourceGroup =
|
||||||
this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
|
this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
|
||||||
sourceGroup->AssignSource(*i);
|
sourceGroup->AssignSource(*i);
|
||||||
|
|||||||
@@ -128,7 +128,6 @@ private:
|
|||||||
|
|
||||||
friend class EventWriter;
|
friend class EventWriter;
|
||||||
|
|
||||||
std::string ModuleDefinitionFile;
|
|
||||||
bool FortranProject;
|
bool FortranProject;
|
||||||
bool WindowsCEProject;
|
bool WindowsCEProject;
|
||||||
cmLocalVisualStudio7GeneratorInternals* Internal;
|
cmLocalVisualStudio7GeneratorInternals* Internal;
|
||||||
|
|||||||
@@ -1414,8 +1414,10 @@ void cmMakefileTargetGenerator::AppendLinkDepends(
|
|||||||
this->AppendTargetDepends(depends);
|
this->AppendTargetDepends(depends);
|
||||||
|
|
||||||
// Add a dependency on the link definitions file, if any.
|
// Add a dependency on the link definitions file, if any.
|
||||||
if (this->ModuleDefinitionFile) {
|
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
|
||||||
depends.push_back(this->ModuleDefinitionFile->GetFullPath());
|
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.
|
// 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());
|
std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath());
|
||||||
|
|
||||||
// Add a dependency on the link definitions file, if any.
|
// Add a dependency on the link definitions file, if any.
|
||||||
if (this->ModuleDefinitionFile) {
|
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
|
||||||
result.push_back(
|
this->GeneratorTarget->GetModuleDefinitionInfo(this->GetConfigName());
|
||||||
this->ConvertToNinjaPath(this->ModuleDefinitionFile->GetFullPath()));
|
if (mdi && !mdi->DefFile.empty()) {
|
||||||
|
result.push_back(this->ConvertToNinjaPath(mdi->DefFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a dependency on user-specified manifest files, if any.
|
// Add a dependency on user-specified manifest files, if any.
|
||||||
|
|||||||
@@ -2914,10 +2914,10 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
|
|||||||
linkOptions.Parse(flags.c_str());
|
linkOptions.Parse(flags.c_str());
|
||||||
|
|
||||||
if (this->MSTools) {
|
if (this->MSTools) {
|
||||||
if (cmSourceFile const* defsrc =
|
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
|
||||||
this->GeneratorTarget->GetModuleDefinitionFile("")) {
|
this->GeneratorTarget->GetModuleDefinitionInfo(config);
|
||||||
linkOptions.AddFlag("ModuleDefinitionFile",
|
if (mdi && !mdi->DefFile.empty()) {
|
||||||
defsrc->GetFullPath().c_str());
|
linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile.c_str());
|
||||||
}
|
}
|
||||||
linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
|
linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
|
||||||
"%(IgnoreSpecificDefaultLibraries)");
|
"%(IgnoreSpecificDefaultLibraries)");
|
||||||
|
|||||||
Reference in new issue
Block a user