From 1e0a9ac45d51e0076222026b9c44604b287a6eae Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 8 Mar 2017 15:54:40 -0500 Subject: Refactor module definition source enumeration Add a `cmGeneratorTarget::GetModuleDefinitionSources` method. --- Source/cmGeneratorTarget.cxx | 15 ++++++++++----- Source/cmGeneratorTarget.h | 2 ++ Source/cmVisualStudio10TargetGenerator.cxx | 7 +++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 47d685d..39336b2 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -112,7 +112,7 @@ struct IDLSourcesTag struct ResxTag { }; -struct ModuleDefinitionFileTag +struct ModuleDefinitionSourcesTag { }; struct AppManifestTag @@ -236,8 +236,8 @@ struct TagVisitor } else if (!sf->GetLanguage().empty()) { DoAccept::Result>::Do(this->Data, sf); } else if (ext == "def") { - DoAccept::Result>::Do(this->Data, - sf); + DoAccept::Result>::Do( + this->Data, sf); if (this->IsObjLib) { this->BadObjLibFiles.push_back(sf); } @@ -681,6 +681,12 @@ bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const return it != this->ExplicitObjectName.end(); } +void cmGeneratorTarget::GetModuleDefinitionSources( + std::vector& data, const std::string& config) const +{ + IMPLEMENT_VISIT(ModuleDefinitionSources); +} + void cmGeneratorTarget::GetIDLSources(std::vector& data, const std::string& config) const { @@ -1942,8 +1948,7 @@ cmSourceFile const* cmGeneratorTarget::GetModuleDefinitionFile( const std::string& config) const { std::vector data; - IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, - COMMA std::vector) + this->GetModuleDefinitionSources(data, config); if (!data.empty()) { return data.front(); } diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index e72e0a6..ea36e16 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -77,6 +77,8 @@ public: bool HasExplicitObjectName(cmSourceFile const* file) const; void AddExplicitObjectName(cmSourceFile const* sf); + void GetModuleDefinitionSources(std::vector&, + const std::string& config) const; void GetResxSources(std::vector&, const std::string& config) const; void GetIDLSources(std::vector&, diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index fbf7447..a5b1edf 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1841,10 +1841,9 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() (*this->BuildFileStream) << cmVS10EscapeXML(obj) << "\" />\n"; } - if (cmSourceFile const* defsrc = - this->GeneratorTarget->GetModuleDefinitionFile("")) { - this->WriteSource("None", defsrc); - } + std::vector defSources; + this->GeneratorTarget->GetModuleDefinitionSources(defSources, ""); + this->WriteSources("None", defSources); if (this->IsMissingFiles) { this->WriteMissingFiles(); -- cgit v0.12 From 25d261efa7c80ce7d9cbcb8b94d5d4a77cb12aaf Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 9 Mar 2017 15:28:14 -0500 Subject: 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). --- Source/cmCommonTargetGenerator.cxx | 15 ++++-------- Source/cmCommonTargetGenerator.h | 3 --- Source/cmGeneratorTarget.cxx | 38 ++++++++++++++++++++++++------ Source/cmGeneratorTarget.h | 13 +++++++++- Source/cmLocalVisualStudio7Generator.cxx | 12 ++++------ Source/cmLocalVisualStudio7Generator.h | 1 - Source/cmMakefileTargetGenerator.cxx | 6 +++-- Source/cmNinjaTargetGenerator.cxx | 7 +++--- Source/cmVisualStudio10TargetGenerator.cxx | 8 +++---- 9 files changed, 64 insertions(+), 39 deletions(-) diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index 239582f..fd1ad36 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -26,7 +26,6 @@ cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt) , GlobalGenerator(static_cast( 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); } diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h index d67fefb..8d68123 100644 --- a/Source/cmCommonTargetGenerator.h +++ b/Source/cmCommonTargetGenerator.h @@ -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); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 39336b2..acaa383 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -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 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 sources; + this->GetModuleDefinitionSources(sources, config); + if (!sources.empty()) { + info.DefFile = sources.front()->GetFullPath(); + } } bool cmGeneratorTarget::IsDLLPlatform() const diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index ea36e16..2f75e20 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -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 OutputInfoMapType; mutable OutputInfoMapType OutputInfoMap; + typedef std::map + ModuleDefinitionInfoMapType; + mutable ModuleDefinitionInfoMapType ModuleDefinitionInfoMap; + void ComputeModuleDefinitionInfo(std::string const& config, + ModuleDefinitionInfo& info) const; + typedef std::pair OutputNameKey; typedef std::map OutputNameMapType; mutable OutputNameMapType OutputNameMap; diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 6e976e1..e14e20c 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -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 sourceGroups = this->Makefile->GetSourceGroups(); // get the classes from the source lists then add them to the groups - this->ModuleDefinitionFile = ""; std::vector 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); diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index d69cce1..ae6e2ed 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -128,7 +128,6 @@ private: friend class EventWriter; - std::string ModuleDefinitionFile; bool FortranProject; bool WindowsCEProject; cmLocalVisualStudio7GeneratorInternals* Internal; diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 54b3f36..d9361f3 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -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. diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index b1f26e4..0e10ab4 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -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. diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index a5b1edf..698271d 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -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)"); -- cgit v0.12 From f36eaf6a6eb8a7ef1127ad43e419896be89f0e39 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 9 Mar 2017 15:56:30 -0500 Subject: Refactor WINDOWS_EXPORT_ALL_SYMBOLS implementation Use `cmGeneratorTarget::ModuleDefinitionInfo` to combine the implementation of `WINDOWS_EXPORT_ALL_SYMBOLS` with that of using a `.def` file as a source. Only one of these could be used within a single target before anyway. --- Source/cmGeneratorTarget.cxx | 7 ++- Source/cmGeneratorTarget.h | 1 + Source/cmGlobalVisualStudioGenerator.cxx | 12 +++-- Source/cmLocalVisualStudio7Generator.cxx | 27 ++++------ Source/cmMakefileExecutableTargetGenerator.cxx | 5 +- Source/cmMakefileLibraryTargetGenerator.cxx | 5 +- Source/cmMakefileTargetGenerator.cxx | 74 +++++++++++--------------- Source/cmMakefileTargetGenerator.h | 3 +- Source/cmNinjaNormalTargetGenerator.cxx | 61 ++++++++------------- Source/cmNinjaTargetGenerator.cxx | 2 +- Source/cmVisualStudio10TargetGenerator.cxx | 30 ++++------- 11 files changed, 90 insertions(+), 137 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index acaa383..29698cf 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1975,7 +1975,12 @@ void cmGeneratorTarget::ComputeModuleDefinitionInfo( { std::vector sources; this->GetModuleDefinitionSources(sources, config); - if (!sources.empty()) { + info.WindowsExportAllSymbols = + this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") && + this->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"); + if (info.WindowsExportAllSymbols) { + info.DefFile = this->ObjectDirectory /* has slash */ + "exports.def"; + } else if (!sources.empty()) { info.DefFile = sources.front()->GetFullPath(); } } diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 2f75e20..92285f3 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -238,6 +238,7 @@ public: struct ModuleDefinitionInfo { std::string DefFile; + bool WindowsExportAllSymbols; }; ModuleDefinitionInfo const* GetModuleDefinitionInfo( std::string const& config) const; diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index ced0c26..a073426 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -814,10 +814,14 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand( cmGeneratorTarget* gt, std::vector& commands, std::string const& configName) { + cmGeneratorTarget::ModuleDefinitionInfo const* mdi = + gt->GetModuleDefinitionInfo(configName); + if (!mdi || !mdi->WindowsExportAllSymbols) { + return; + } + std::vector outputs; - std::string deffile = gt->ObjectDirectory; - deffile += "/exportall.def"; - outputs.push_back(deffile); + outputs.push_back(mdi->DefFile); std::vector empty; std::vector objectSources; gt->GetObjectSources(objectSources, configName); @@ -835,7 +839,7 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand( cmdl.push_back(cmakeCommand); cmdl.push_back("-E"); cmdl.push_back("__create_def"); - cmdl.push_back(deffile); + cmdl.push_back(mdi->DefFile); std::string obj_dir_expanded = obj_dir; cmSystemTools::ReplaceString(obj_dir_expanded, this->GetCMakeCFGIntDir(), configName.c_str()); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index e14e20c..8026de9 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1004,13 +1004,6 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str()); } - if ((target->GetType() == cmStateEnums::SHARED_LIBRARY || - target->IsExecutableWithExports()) && - this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) { - if (target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) { - linkOptions.AddFlag("ModuleDefinitionFile", "$(IntDir)/exportall.def"); - } - } switch (target->GetType()) { case cmStateEnums::UNKNOWN_LIBRARY: break; @@ -1823,17 +1816,15 @@ void cmLocalVisualStudio7Generator::OutputTargetRules( tool = this->FortranProject ? "VFPreLinkEventTool" : "VCPreLinkEventTool"; event.Start(tool); bool addedPrelink = false; - if ((target->GetType() == cmStateEnums::SHARED_LIBRARY || - target->IsExecutableWithExports()) && - this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) { - if (target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) { - addedPrelink = true; - std::vector commands = target->GetPreLinkCommands(); - cmGlobalVisualStudioGenerator* gg = - static_cast(this->GlobalGenerator); - gg->AddSymbolExportCommand(target, commands, configName); - event.Write(commands); - } + cmGeneratorTarget::ModuleDefinitionInfo const* mdi = + target->GetModuleDefinitionInfo(configName); + if (mdi && mdi->WindowsExportAllSymbols) { + addedPrelink = true; + std::vector commands = target->GetPreLinkCommands(); + cmGlobalVisualStudioGenerator* gg = + static_cast(this->GlobalGenerator); + gg->AddSymbolExportCommand(target, commands, configName); + event.Write(commands); } if (!addedPrelink) { event.Write(target->GetPreLinkCommands()); diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 8ed5051..493f474 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -556,10 +556,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) } // maybe create .def file from list of objects - if (this->GeneratorTarget->IsExecutableWithExports() && - this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) { - this->GenDefFile(real_link_commands, linkFlags); - } + this->GenDefFile(real_link_commands); std::string manifests = this->GetManifests(); diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index bc456cf..e5fae13 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -750,10 +750,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( } // maybe create .def file from list of objects - if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY && - this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) { - this->GenDefFile(real_link_commands, linkFlags); - } + this->GenDefFile(real_link_commands); std::string manifests = this->GetManifests(); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index d9361f3..1fa8702 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -1416,7 +1416,7 @@ void cmMakefileTargetGenerator::AppendLinkDepends( // Add a dependency on the link definitions file, if any. cmGeneratorTarget::ModuleDefinitionInfo const* mdi = this->GeneratorTarget->GetModuleDefinitionInfo(this->GetConfigName()); - if (mdi && !mdi->DefFile.empty()) { + if (mdi && !mdi->WindowsExportAllSymbols && !mdi->DefFile.empty()) { depends.push_back(mdi->DefFile); } @@ -1720,49 +1720,39 @@ void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags, } void cmMakefileTargetGenerator::GenDefFile( - std::vector& real_link_commands, std::string& linkFlags) + std::vector& real_link_commands) { - if (this->GeneratorTarget->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) { - std::string name_of_def_file = - this->GeneratorTarget->GetSupportDirectory(); - name_of_def_file += std::string("/") + this->GeneratorTarget->GetName(); - name_of_def_file += ".def"; - std::string cmd = cmSystemTools::GetCMakeCommand(); - cmd = this->LocalGenerator->ConvertToOutputFormat( - cmd, cmOutputConverter::SHELL); - cmd += " -E __create_def "; - cmd += this->LocalGenerator->ConvertToOutputFormat( - this->LocalGenerator->MaybeConvertToRelativePath( - this->LocalGenerator->GetCurrentBinaryDirectory(), name_of_def_file), - cmOutputConverter::SHELL); - cmd += " "; - std::string objlist_file = name_of_def_file; - objlist_file += ".objs"; - cmd += this->LocalGenerator->ConvertToOutputFormat( - this->LocalGenerator->MaybeConvertToRelativePath( - this->LocalGenerator->GetCurrentBinaryDirectory(), objlist_file), - cmOutputConverter::SHELL); - real_link_commands.insert(real_link_commands.begin(), cmd); - // create a list of obj files for the -E __create_def to read - cmGeneratedFileStream fout(objlist_file.c_str()); - for (std::vector::const_iterator i = this->Objects.begin(); - i != this->Objects.end(); ++i) { - if (cmHasLiteralSuffix(*i, ".obj")) { - fout << *i << "\n"; - } - } - for (std::vector::const_iterator i = - this->ExternalObjects.begin(); - i != this->ExternalObjects.end(); ++i) { + cmGeneratorTarget::ModuleDefinitionInfo const* mdi = + this->GeneratorTarget->GetModuleDefinitionInfo(this->GetConfigName()); + if (!mdi || !mdi->WindowsExportAllSymbols) { + return; + } + std::string cmd = cmSystemTools::GetCMakeCommand(); + cmd = + this->LocalGenerator->ConvertToOutputFormat(cmd, cmOutputConverter::SHELL); + cmd += " -E __create_def "; + cmd += this->LocalGenerator->ConvertToOutputFormat( + this->LocalGenerator->MaybeConvertToRelativePath( + this->LocalGenerator->GetCurrentBinaryDirectory(), mdi->DefFile), + cmOutputConverter::SHELL); + cmd += " "; + std::string objlist_file = mdi->DefFile + ".objs"; + cmd += this->LocalGenerator->ConvertToOutputFormat( + this->LocalGenerator->MaybeConvertToRelativePath( + this->LocalGenerator->GetCurrentBinaryDirectory(), objlist_file), + cmOutputConverter::SHELL); + real_link_commands.insert(real_link_commands.begin(), cmd); + // create a list of obj files for the -E __create_def to read + cmGeneratedFileStream fout(objlist_file.c_str()); + for (std::vector::const_iterator i = this->Objects.begin(); + i != this->Objects.end(); ++i) { + if (cmHasLiteralSuffix(*i, ".obj")) { fout << *i << "\n"; } - // now add the def file link flag - linkFlags += " "; - linkFlags += this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG"); - linkFlags += this->LocalGenerator->ConvertToOutputFormat( - this->LocalGenerator->MaybeConvertToRelativePath( - this->LocalGenerator->GetCurrentBinaryDirectory(), name_of_def_file), - cmOutputConverter::SHELL); - linkFlags += " "; + } + for (std::vector::const_iterator i = + this->ExternalObjects.begin(); + i != this->ExternalObjects.end(); ++i) { + fout << *i << "\n"; } } diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index 347f9f2..07b8005 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -166,8 +166,7 @@ protected: bool useWatcomQuote); /** Add commands for generate def files */ - void GenDefFile(std::vector& real_link_commands, - std::string& linkFlags); + void GenDefFile(std::vector& real_link_commands); void AddIncludeFlags(std::string& flags, const std::string& lang) CM_OVERRIDE; diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 9bf0ccd..300618f 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -860,19 +860,6 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() linkLineComputer.get(), this->GetConfigName(), vars["LINK_LIBRARIES"], vars["FLAGS"], vars["LINK_FLAGS"], frameworkPath, linkPath, &genTarget); - if (this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") && - (gt.GetType() == cmStateEnums::SHARED_LIBRARY || - gt.IsExecutableWithExports())) { - if (gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) { - std::string name_of_def_file = gt.GetSupportDirectory(); - name_of_def_file += "/" + gt.GetName(); - name_of_def_file += ".def "; - vars["LINK_FLAGS"] += " /DEF:"; - vars["LINK_FLAGS"] += this->GetLocalGenerator()->ConvertToOutputFormat( - name_of_def_file, cmOutputConverter::SHELL); - } - } - // Add OS X version flags, if any. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY || this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) { @@ -989,33 +976,27 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() } // maybe create .def file from list of objects - if ((gt.GetType() == cmStateEnums::SHARED_LIBRARY || - gt.IsExecutableWithExports()) && - this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) { - if (gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) { - std::string cmakeCommand = - this->GetLocalGenerator()->ConvertToOutputFormat( - cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL); - std::string name_of_def_file = gt.GetSupportDirectory(); - name_of_def_file += "/" + gt.GetName(); - name_of_def_file += ".def"; - std::string cmd = cmakeCommand; - cmd += " -E __create_def "; - cmd += this->GetLocalGenerator()->ConvertToOutputFormat( - name_of_def_file, cmOutputConverter::SHELL); - cmd += " "; - cmNinjaDeps objs = this->GetObjects(); - std::string obj_list_file = name_of_def_file; - obj_list_file += ".objs"; - cmd += this->GetLocalGenerator()->ConvertToOutputFormat( - obj_list_file, cmOutputConverter::SHELL); - preLinkCmdLines.push_back(cmd); - // create a list of obj files for the -E __create_def to read - cmGeneratedFileStream fout(obj_list_file.c_str()); - for (cmNinjaDeps::iterator i = objs.begin(); i != objs.end(); ++i) { - if (cmHasLiteralSuffix(*i, ".obj")) { - fout << *i << "\n"; - } + cmGeneratorTarget::ModuleDefinitionInfo const* mdi = + gt.GetModuleDefinitionInfo(this->GetConfigName()); + if (mdi && mdi->WindowsExportAllSymbols) { + std::string cmakeCommand = + this->GetLocalGenerator()->ConvertToOutputFormat( + cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL); + std::string cmd = cmakeCommand; + cmd += " -E __create_def "; + cmd += this->GetLocalGenerator()->ConvertToOutputFormat( + mdi->DefFile, cmOutputConverter::SHELL); + cmd += " "; + cmNinjaDeps objs = this->GetObjects(); + std::string obj_list_file = mdi->DefFile + ".objs"; + cmd += this->GetLocalGenerator()->ConvertToOutputFormat( + obj_list_file, cmOutputConverter::SHELL); + preLinkCmdLines.push_back(cmd); + // create a list of obj files for the -E __create_def to read + cmGeneratedFileStream fout(obj_list_file.c_str()); + for (cmNinjaDeps::iterator i = objs.begin(); i != objs.end(); ++i) { + if (cmHasLiteralSuffix(*i, ".obj")) { + fout << *i << "\n"; } } } diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 0e10ab4..917383d 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -214,7 +214,7 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const // Add a dependency on the link definitions file, if any. cmGeneratorTarget::ModuleDefinitionInfo const* mdi = this->GeneratorTarget->GetModuleDefinitionInfo(this->GetConfigName()); - if (mdi && !mdi->DefFile.empty()) { + if (mdi && !mdi->WindowsExportAllSymbols && !mdi->DefFile.empty()) { result.push_back(this->ConvertToNinjaPath(mdi->DefFile)); } diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 698271d..4aea6f8 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2923,15 +2923,6 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( "%(IgnoreSpecificDefaultLibraries)"); } - if ((this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY || - this->GeneratorTarget->IsExecutableWithExports()) && - this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) { - if (this->GeneratorTarget->GetPropertyAsBool( - "WINDOWS_EXPORT_ALL_SYMBOLS")) { - linkOptions.AddFlag("ModuleDefinitionFile", "$(IntDir)exportall.def"); - } - } - // Hack to fix flag version selection in a common use case. // FIXME: Select flag table based on toolset instead of VS version. if (this->LocalGenerator->GetVersion() >= @@ -3169,18 +3160,15 @@ void cmVisualStudio10TargetGenerator::WriteEvents( std::string const& configName) { bool addedPrelink = false; - if ((this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY || - this->GeneratorTarget->IsExecutableWithExports()) && - this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) { - if (this->GeneratorTarget->GetPropertyAsBool( - "WINDOWS_EXPORT_ALL_SYMBOLS")) { - addedPrelink = true; - std::vector commands = - this->GeneratorTarget->GetPreLinkCommands(); - this->GlobalGenerator->AddSymbolExportCommand(this->GeneratorTarget, - commands, configName); - this->WriteEvent("PreLinkEvent", commands, configName); - } + cmGeneratorTarget::ModuleDefinitionInfo const* mdi = + this->GeneratorTarget->GetModuleDefinitionInfo(configName); + if (mdi && mdi->WindowsExportAllSymbols) { + addedPrelink = true; + std::vector commands = + this->GeneratorTarget->GetPreLinkCommands(); + this->GlobalGenerator->AddSymbolExportCommand(this->GeneratorTarget, + commands, configName); + this->WriteEvent("PreLinkEvent", commands, configName); } if (!addedPrelink) { this->WriteEvent("PreLinkEvent", -- cgit v0.12