diff options
Diffstat (limited to 'Source/cmLocalVisualStudio7Generator.cxx')
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 206 |
1 files changed, 101 insertions, 105 deletions
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 38dda04..f86c034 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -9,13 +9,14 @@ #include "cmSourceFile.h" #include "cmSystemTools.h" #include "cmXMLParser.h" +#include "cm_expat.h" #include "cmake.h" -#include <cm_expat.h> #include "cmComputeLinkInformation.h" #include "cmGeneratedFileStream.h" #include <ctype.h> // for isspace +#include <windows.h> static bool cmLVS7G_IsFAT(const char* dir); @@ -29,7 +30,7 @@ public: typedef cmComputeLinkInformation::ItemVector ItemVector; void OutputLibraries(std::ostream& fout, ItemVector const& libs); void OutputObjects(std::ostream& fout, cmGeneratorTarget* t, - const char* isep = 0); + std::string const& config, const char* isep = 0); private: cmLocalVisualStudio7Generator* LocalGenerator; @@ -669,6 +670,9 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( // Add the target-specific flags. this->AddCompileOptions(flags, target, linkLanguage, configName); + + // Check IPO related warning/error. + target->IsIPOEnabled(configName); } if (this->FortranProject) { @@ -745,11 +749,13 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( if (this->FortranProject) { // Intel Fortran >= 15.0 uses TargetName property. - std::string targetNameFull = target->GetFullName(configName); - std::string targetName = + std::string const targetNameFull = target->GetFullName(configName); + std::string const targetName = cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull); - std::string targetExt = - cmSystemTools::GetFilenameLastExtension(targetNameFull); + std::string const targetExt = + target->GetType() == cmStateEnums::OBJECT_LIBRARY + ? ".lib" + : cmSystemTools::GetFilenameLastExtension(targetNameFull); /* clang-format off */ fout << "\t\t\tTargetName=\"" << this->EscapeForXML(targetName) << "\"\n" @@ -787,7 +793,6 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( << this->ConvertToXMLOutputPath(modDir.c_str()) << "\\$(ConfigurationName)\"\n"; } - targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n"); fout << "\t\t\t\tAdditionalIncludeDirectories=\""; std::vector<std::string> includes; this->GetIncludeDirectories(includes, target, "C", configName); @@ -893,8 +898,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( // end of <Tool Name=VCMIDLTool // Add manifest tool settings. - if (targetBuilds && - this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8) { + if (targetBuilds) { const char* manifestTool = "VCManifestTool"; if (this->FortranProject) { manifestTool = "VFManifestTool"; @@ -997,19 +1001,14 @@ 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()); } - 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; @@ -1040,10 +1039,9 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( fout << "\t\t\t<Tool\n" << "\t\t\t\tName=\"" << tool << "\"\n"; - if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS8 || - this->FortranProject) { + if (this->FortranProject) { std::ostringstream libdeps; - this->Internal->OutputObjects(libdeps, target); + this->Internal->OutputObjects(libdeps, target, configName); if (!libdeps.str().empty()) { fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str() << "\"\n"; @@ -1090,14 +1088,12 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( if (!gg->NeedLinkLibraryDependencies(target)) { fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n"; } - linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n"); // Use the NOINHERIT macro to avoid getting VS project default // libraries which may be set by the user to something bad. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) " << this->Makefile->GetSafeDefinition(standardLibsVar.c_str()); - if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS8 || - this->FortranProject) { - this->Internal->OutputObjects(fout, target, " "); + if (this->FortranProject) { + this->Internal->OutputObjects(fout, target, configName, " "); } fout << " "; this->Internal->OutputLibraries(fout, cli.GetItems()); @@ -1134,7 +1130,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( if (stackVal) { fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n"; } - temp = target->GetDirectory(configName, true); + temp = + target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact); temp += "/"; temp += targetNameImport; fout << "\t\t\t\tImportLibrary=\"" @@ -1176,14 +1173,12 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( if (!gg->NeedLinkLibraryDependencies(target)) { fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n"; } - linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n"); // Use the NOINHERIT macro to avoid getting VS project default // libraries which may be set by the user to something bad. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) " << this->Makefile->GetSafeDefinition(standardLibsVar.c_str()); - if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS8 || - this->FortranProject) { - this->Internal->OutputObjects(fout, target, " "); + if (this->FortranProject) { + this->Internal->OutputObjects(fout, target, configName, " "); } fout << " "; this->Internal->OutputLibraries(fout, cli.GetItems()); @@ -1233,7 +1228,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( if (stackVal) { fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\""; } - temp = target->GetDirectory(configName, true); + temp = + target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact); temp += "/"; temp += targetNameImport; fout << "\t\t\t\tImportLibrary=\"" @@ -1302,20 +1298,26 @@ void cmLocalVisualStudio7GeneratorInternals::OutputLibraries( } void cmLocalVisualStudio7GeneratorInternals::OutputObjects( - std::ostream& fout, cmGeneratorTarget* gt, const char* isep) + std::ostream& fout, cmGeneratorTarget* gt, std::string const& configName, + const char* isep) { // VS < 8 does not support per-config source locations so we // list object library content on the link line instead. cmLocalVisualStudio7Generator* lg = this->LocalGenerator; std::string currentBinDir = lg->GetCurrentBinaryDirectory(); - std::vector<std::string> objs; - gt->UseObjectLibraries(objs, ""); + + std::vector<cmSourceFile const*> objs; + gt->GetExternalObjects(objs, configName); + const char* sep = isep ? isep : ""; - for (std::vector<std::string>::const_iterator oi = objs.begin(); - oi != objs.end(); ++oi) { - std::string rel = lg->ConvertToRelativePath(currentBinDir, oi->c_str()); - fout << sep << lg->ConvertToXMLOutputPath(rel.c_str()); - sep = " "; + for (std::vector<cmSourceFile const*>::const_iterator i = objs.begin(); + i != objs.end(); ++i) { + if (!(*i)->GetObjectLibrary().empty()) { + std::string const& objFile = (*i)->GetFullPath(); + std::string rel = lg->ConvertToRelativePath(currentBinDir, objFile); + fout << sep << lg->ConvertToXMLOutputPath(rel.c_str()); + sep = " "; + } } } @@ -1364,25 +1366,26 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, // We may be modifying the source groups temporarily, so make a copy. 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; - } - for (std::vector<cmSourceFile*>::const_iterator i = classes.begin(); - i != classes.end(); i++) { - if (!(*i)->GetObjectLibrary().empty()) { - continue; + std::vector<cmGeneratorTarget::AllConfigSource> const& sources = + target->GetAllConfigSources(); + std::map<cmSourceFile const*, size_t> sourcesIndex; + + for (size_t si = 0; si < sources.size(); ++si) { + cmSourceFile const* sf = sources[si].Source; + sourcesIndex[sf] = si; + if (!sf->GetObjectLibrary().empty()) { + if (this->FortranProject) { + // Intel Fortran does not support per-config source locations + // so we list object library content on the link line instead. + // See OutputObjects. + continue; + } } // Add the file to the list of sources. - std::string source = (*i)->GetFullPath(); - if (cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF") { - this->ModuleDefinitionFile = (*i)->GetFullPath(); - } + std::string const source = sf->GetFullPath(); cmSourceGroup* sourceGroup = this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); - sourceGroup->AssignSource(*i); + sourceGroup->AssignSource(sf); } // open the project @@ -1395,25 +1398,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, // Loop through every source group. for (unsigned int i = 0; i < sourceGroups.size(); ++i) { cmSourceGroup sg = sourceGroups[i]; - this->WriteGroup(&sg, target, fout, libName, configs); - } - - if (this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8 && - !this->FortranProject) { - // VS >= 8 support per-config source locations so we - // list object library content as external objects. - std::vector<std::string> objs; - target->UseObjectLibraries(objs, ""); - if (!objs.empty()) { - // TODO: Separate sub-filter for each object library used? - fout << "\t\t<Filter Name=\"Object Libraries\">\n"; - for (std::vector<std::string>::const_iterator oi = objs.begin(); - oi != objs.end(); ++oi) { - std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str()); - fout << "\t\t\t<File RelativePath=\"" << o << "\" />\n"; - } - fout << "\t\t</Filter>\n"; - } + this->WriteGroup(&sg, target, fout, libName, configs, sourcesIndex); } fout << "\t</Files>\n"; @@ -1435,25 +1420,28 @@ struct cmLVS7GFileConfig class cmLocalVisualStudio7GeneratorFCInfo { public: - cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg, - cmGeneratorTarget* target, - cmSourceFile const& sf, - std::vector<std::string> const& configs); + cmLocalVisualStudio7GeneratorFCInfo( + cmLocalVisualStudio7Generator* lg, cmGeneratorTarget* target, + cmGeneratorTarget::AllConfigSource const& acs, + std::vector<std::string> const& configs); std::map<std::string, cmLVS7GFileConfig> FileConfigMap; }; cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( cmLocalVisualStudio7Generator* lg, cmGeneratorTarget* gt, - cmSourceFile const& sf, std::vector<std::string> const& configs) + cmGeneratorTarget::AllConfigSource const& acs, + std::vector<std::string> const& configs) { + cmSourceFile const& sf = *acs.Source; std::string objectName; if (gt->HasExplicitObjectName(&sf)) { objectName = gt->GetObjectName(&sf); } // Compute per-source, per-config information. + size_t ci = 0; for (std::vector<std::string>::const_iterator i = configs.begin(); - i != configs.end(); ++i) { + i != configs.end(); ++i, ++ci) { std::string configUpper = cmSystemTools::UpperCase(*i); cmLVS7GFileConfig fc; bool needfc = false; @@ -1519,7 +1507,9 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( } // If HEADER_FILE_ONLY is set, we must suppress this generation in // the project file - fc.ExcludedFromBuild = (sf.GetPropertyAsBool("HEADER_FILE_ONLY")); + fc.ExcludedFromBuild = sf.GetPropertyAsBool("HEADER_FILE_ONLY") || + std::find(acs.Configs.begin(), acs.Configs.end(), ci) == + acs.Configs.end(); if (fc.ExcludedFromBuild) { needfc = true; } @@ -1574,7 +1564,8 @@ std::string cmLocalVisualStudio7Generator::ComputeLongestObjectDirectory( bool cmLocalVisualStudio7Generator::WriteGroup( const cmSourceGroup* sg, cmGeneratorTarget* target, std::ostream& fout, - const std::string& libName, std::vector<std::string> const& configs) + const std::string& libName, std::vector<std::string> const& configs, + std::map<cmSourceFile const*, size_t> const& sourcesIndex) { cmGlobalVisualStudio7Generator* gg = static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator); @@ -1585,7 +1576,8 @@ bool cmLocalVisualStudio7Generator::WriteGroup( bool hasChildrenWithSources = false; std::ostringstream tmpOut; for (unsigned int i = 0; i < children.size(); ++i) { - if (this->WriteGroup(&children[i], target, tmpOut, libName, configs)) { + if (this->WriteGroup(&children[i], target, tmpOut, libName, configs, + sourcesIndex)) { hasChildrenWithSources = true; } } @@ -1601,15 +1593,26 @@ bool cmLocalVisualStudio7Generator::WriteGroup( this->WriteVCProjBeginGroup(fout, name.c_str(), ""); } + std::vector<cmGeneratorTarget::AllConfigSource> const& sources = + target->GetAllConfigSources(); + // Loop through each source in the source group. for (std::vector<const cmSourceFile*>::const_iterator sf = sourceFiles.begin(); sf != sourceFiles.end(); ++sf) { std::string source = (*sf)->GetFullPath(); - FCInfo fcinfo(this, target, *(*sf), configs); if (source != libName || target->GetType() == cmStateEnums::UTILITY || target->GetType() == cmStateEnums::GLOBAL_TARGET) { + // Look up the source kind and configs. + std::map<cmSourceFile const*, size_t>::const_iterator map_it = + sourcesIndex.find(*sf); + // The map entry must exist because we populated it earlier. + assert(map_it != sourcesIndex.end()); + cmGeneratorTarget::AllConfigSource const& acs = sources[map_it->second]; + + FCInfo fcinfo(this, target, acs, configs); + fout << "\t\t\t<File\n"; std::string d = this->ConvertToXMLOutputPathSingle(source.c_str()); // Tell MS-Dev what the source is. If the compiler knows how to @@ -1649,6 +1652,9 @@ bool cmLocalVisualStudio7Generator::WriteGroup( lang == "ASM_MASM") { aCompilerTool = "MASM"; } + if (acs.Kind == cmGeneratorTarget::SourceKindExternalObject) { + aCompilerTool = "VCCustomBuildTool"; + } for (std::map<std::string, cmLVS7GFileConfig>::const_iterator fci = fcinfo.FileConfigMap.begin(); fci != fcinfo.FileConfigMap.end(); ++fci) { @@ -1675,7 +1681,6 @@ bool cmLocalVisualStudio7Generator::WriteGroup( fileOptions.Parse(fc.CompileFlags.c_str()); fileOptions.AddDefines(fc.CompileDefs.c_str()); fileOptions.AddDefines(fc.CompileDefsConfig.c_str()); - fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n"); fileOptions.OutputFlagMap(fout, "\t\t\t\t\t"); fileOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t\t", "\n", ppLang); @@ -1829,17 +1834,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<cmCustomCommand> commands = target->GetPreLinkCommands(); - cmGlobalVisualStudioGenerator* gg = - static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator); - gg->AddSymbolExportCommand(target, commands, configName); - event.Write(commands); - } + cmGeneratorTarget::ModuleDefinitionInfo const* mdi = + target->GetModuleDefinitionInfo(configName); + if (mdi && mdi->DefFileGenerated) { + addedPrelink = true; + std::vector<cmCustomCommand> commands = target->GetPreLinkCommands(); + cmGlobalVisualStudioGenerator* gg = + static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator); + gg->AddSymbolExportCommand(target, commands, configName); + event.Write(commands); } if (!addedPrelink) { event.Write(target->GetPreLinkCommands()); @@ -1956,11 +1959,7 @@ void cmLocalVisualStudio7Generator::WriteProjectStart( << "<VisualStudioProject\n" << "\tProjectType=\"Visual C++\"\n"; /* clang-format on */ - if (gg->GetVersion() == cmGlobalVisualStudioGenerator::VS71) { - fout << "\tVersion=\"7.10\"\n"; - } else { - fout << "\tVersion=\"" << (gg->GetVersion() / 10) << ".00\"\n"; - } + fout << "\tVersion=\"" << (gg->GetVersion() / 10) << ".00\"\n"; const char* projLabel = target->GetProperty("PROJECT_LABEL"); if (!projLabel) { projLabel = libName.c_str(); @@ -1970,9 +1969,7 @@ void cmLocalVisualStudio7Generator::WriteProjectStart( keyword = "Win32Proj"; } fout << "\tName=\"" << projLabel << "\"\n"; - if (gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS8) { - fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n"; - } + fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n"; this->WriteProjectSCC(fout, target); if (const char* targetFrameworkVersion = target->GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION")) { @@ -2130,7 +2127,6 @@ std::string cmLocalVisualStudio7Generator::GetTargetDirectory( return dir; } -#include <windows.h> static bool cmLVS7G_IsFAT(const char* dir) { if (dir[0] && dir[1] == ':') { |