diff options
Diffstat (limited to 'Source/cmLocalVisualStudio7Generator.cxx')
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 158 |
1 files changed, 88 insertions, 70 deletions
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 212b06b..52524aa 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -18,6 +18,7 @@ #include "cmSourceFile.h" #include "cmCacheManager.h" #include "cmGeneratorTarget.h" +#include "cmCustomCommandGenerator.h" #include "cmake.h" #include "cmComputeLinkInformation.h" @@ -59,7 +60,7 @@ cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator() void cmLocalVisualStudio7Generator::AddHelperCommands() { - std::set<cmStdString> lang; + std::set<std::string> lang; lang.insert("C"); lang.insert("CXX"); lang.insert("RC"); @@ -83,7 +84,7 @@ void cmLocalVisualStudio7Generator::AddHelperCommands() if(path) { this->ReadAndStoreExternalGUID( - l->second.GetName(), path); + l->second.GetName().c_str(), path); } else { @@ -141,7 +142,7 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() force_command.push_back("."); cmCustomCommandLines force_commands; force_commands.push_back(force_command); - const char* no_main_dependency = 0; + std::string no_main_dependency = ""; std::string force = this->Makefile->GetStartOutputDirectory(); force += cmake::GetCMakeFilesDirectory(); force += "/"; @@ -228,7 +229,7 @@ void cmLocalVisualStudio7Generator::WriteStampFiles() //---------------------------------------------------------------------------- void cmLocalVisualStudio7Generator -::CreateSingleVCProj(const char *lname, cmTarget &target) +::CreateSingleVCProj(const std::string& lname, cmTarget &target) { this->FortranProject = static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator) @@ -245,8 +246,7 @@ void cmLocalVisualStudio7Generator } // add to the list of projects - std::string pname = lname; - target.SetProperty("GENERATOR_FILE_NAME",lname); + target.SetProperty("GENERATOR_FILE_NAME",lname.c_str()); // create the dsp.cmake file std::string fname; fname = this->Makefile->GetStartOutputDirectory(); @@ -334,8 +334,8 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() } void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout, - const char *libName, - cmTarget &target) + const std::string& libName, + cmTarget &target) { std::vector<std::string> *configs = static_cast<cmGlobalVisualStudio7Generator *> @@ -589,7 +589,7 @@ class cmLocalVisualStudio7Generator::EventWriter { public: EventWriter(cmLocalVisualStudio7Generator* lg, - const char* config, std::ostream& os): + const std::string& config, std::ostream& os): LG(lg), Config(config), Stream(os), First(true) {} void Start(const char* tool) { @@ -610,9 +610,10 @@ public: } void Write(cmCustomCommand const& cc) { + cmCustomCommandGenerator ccg(cc, this->Config, this->LG->GetMakefile()); if(this->First) { - const char* comment = cc.GetComment(); + const char* comment = ccg.GetComment(); if(comment && *comment) { this->Stream << "\nDescription=\"" @@ -625,21 +626,21 @@ public: { this->Stream << this->LG->EscapeForXML("\n"); } - std::string script = this->LG->ConstructScript(cc, this->Config); + std::string script = this->LG->ConstructScript(ccg); this->Stream << this->LG->EscapeForXML(script.c_str()); } private: cmLocalVisualStudio7Generator* LG; - const char* Config; + std::string Config; std::ostream& Stream; bool First; }; //---------------------------------------------------------------------------- void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, - const char* configName, - const char *libName, - cmTarget &target) + const std::string& configName, + const std::string& libName, + cmTarget &target) { const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG"); if(!mfcFlag) @@ -660,7 +661,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, switch(target.GetType()) { case cmTarget::OBJECT_LIBRARY: - targetBuilds = false; // TODO: PDB for object library? + targetBuilds = false; // no manifest tool for object library case cmTarget::STATIC_LIBRARY: projectType = "typeStaticLibrary"; configType = "4"; @@ -687,17 +688,18 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, std::string flags; if(strcmp(configType, "10") != 0) { - const char* linkLanguage = (this->FortranProject? "Fortran": + const std::string& linkLanguage = (this->FortranProject? + std::string("Fortran"): target.GetLinkerLanguage(configName)); - if(!linkLanguage) + if(linkLanguage.empty()) { cmSystemTools::Error ("CMake can not determine linker language for target: ", - target.GetName()); + target.GetName().c_str()); return; } - if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0 - || strcmp(linkLanguage, "Fortran") == 0) + if(linkLanguage == "C" || linkLanguage == "CXX" + || linkLanguage == "Fortran") { std::string baseFlagVar = "CMAKE_"; baseFlagVar += linkLanguage; @@ -709,11 +711,11 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, flags += this->Makefile->GetRequiredDefinition(flagVar.c_str()); } // set the correct language - if(strcmp(linkLanguage, "C") == 0) + if(linkLanguage == "C") { flags += " /TC "; } - if(strcmp(linkLanguage, "CXX") == 0) + if(linkLanguage == "CXX") { flags += " /TP "; } @@ -745,7 +747,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, table, this->ExtraFlagTable); targetOptions.FixExceptionHandlingDefault(); - std::string asmLocation = std::string(configName) + "/"; + std::string asmLocation = configName + "/"; targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str()); targetOptions.Parse(flags.c_str()); targetOptions.Parse(defineFlags.c_str()); @@ -846,6 +848,17 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, targetOptions.OutputFlagMap(fout, "\t\t\t\t"); targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX"); fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"; + if(target.GetType() <= cmTarget::OBJECT_LIBRARY) + { + // Specify the compiler program database file if configured. + std::string pdb = target.GetCompilePDBPath(configName); + if(!pdb.empty()) + { + fout << "\t\t\t\tProgramDataBaseFileName=\"" + << this->ConvertToXMLOutputPathSingle(pdb.c_str()) + << "\"\n"; + } + } fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool tool = "VCCustomBuildTool"; if(this->FortranProject) @@ -933,7 +946,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, //---------------------------------------------------------------------------- std::string cmLocalVisualStudio7Generator -::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName) +::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, + const std::string& configName) { std::string configTypeUpper = cmSystemTools::UpperCase(configName); std::string extraLinkOptionsBuildTypeDef = @@ -947,7 +961,8 @@ cmLocalVisualStudio7Generator } void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, - const char* configName, cmTarget &target, const Options& targetOptions) + const std::string& configName, cmTarget &target, + const Options& targetOptions) { cmGlobalVisualStudio7Generator* gg = static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator); @@ -1033,7 +1048,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, fout << "\t\t\t<Tool\n" << "\t\t\t\tName=\"" << tool << "\"\n"; - if(this->GetVersion() < VS8) + if(this->GetVersion() < VS8 || this->FortranProject) { cmOStringStream libdeps; this->Internal->OutputObjects(libdeps, &target); @@ -1070,7 +1085,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, return; } cmComputeLinkInformation& cli = *pcli; - const char* linkLanguage = cli.GetLinkLanguage(); + std::string linkLanguage = cli.GetLinkLanguage(); // Compute the variable name to lookup standard libraries for this // language. @@ -1093,7 +1108,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, // 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() < VS8) + if(this->GetVersion() < VS8 || this->FortranProject) { this->Internal->OutputObjects(fout, &target, " "); } @@ -1166,7 +1181,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, return; } cmComputeLinkInformation& cli = *pcli; - const char* linkLanguage = cli.GetLinkLanguage(); + std::string linkLanguage = cli.GetLinkLanguage(); bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE"); @@ -1191,7 +1206,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, // 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() < VS8) + if(this->GetVersion() < VS8 || this->FortranProject) { this->Internal->OutputObjects(fout, &target, " "); } @@ -1368,7 +1383,7 @@ cmLocalVisualStudio7Generator } void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, - const char *libName, + const std::string& libName, cmTarget &target) { // get the configurations @@ -1412,7 +1427,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, this->WriteGroup(&sg, target, fout, libName, configs); } - if(this->GetVersion() >= VS8) + if(this->GetVersion() >= VS8 && !this->FortranProject) { // VS >= 8 support per-config source locations so we // list object library content as external objects. @@ -1457,7 +1472,7 @@ public: cmTarget& target, cmSourceFile const& sf, std::vector<std::string>* configs); - std::map<cmStdString, cmLVS7GFileConfig> FileConfigMap; + std::map<std::string, cmLVS7GFileConfig> FileConfigMap; }; cmLocalVisualStudio7GeneratorFCInfo @@ -1535,14 +1550,14 @@ cmLocalVisualStudio7GeneratorFCInfo } } - const char* lang = + std::string lang = lg->GlobalGenerator->GetLanguageFromExtension (sf.GetExtension().c_str()); - const char* sourceLang = lg->GetSourceFileLanguage(sf); - const char* linkLanguage = target.GetLinkerLanguage(i->c_str()); + const std::string& sourceLang = lg->GetSourceFileLanguage(sf); + const std::string& linkLanguage = target.GetLinkerLanguage(i->c_str()); bool needForceLang = false; // source file does not match its extension language - if(lang && sourceLang && strcmp(lang, sourceLang) != 0) + if(lang != sourceLang) { needForceLang = true; lang = sourceLang; @@ -1558,16 +1573,15 @@ cmLocalVisualStudio7GeneratorFCInfo // if the source file does not match the linker language // then force c or c++ - if(needForceLang || (linkLanguage && lang - && strcmp(lang, linkLanguage) != 0)) + if(needForceLang || (linkLanguage != lang)) { - if(strcmp(lang, "CXX") == 0) + if(lang == "CXX") { // force a C++ file type fc.CompileFlags += " /TP "; needfc = true; } - else if(strcmp(lang, "C") == 0) + else if(lang == "C") { // force to c fc.CompileFlags += " /TC "; @@ -1616,7 +1630,7 @@ cmLocalVisualStudio7Generator bool cmLocalVisualStudio7Generator ::WriteGroup(const cmSourceGroup *sg, cmTarget& target, - std::ostream &fout, const char *libName, + std::ostream &fout, const std::string& libName, std::vector<std::string> *configs) { const std::vector<const cmSourceFile *> &sourceFiles = @@ -1702,7 +1716,7 @@ bool cmLocalVisualStudio7Generator aCompilerTool = "VFCustomBuildTool"; } } - for(std::map<cmStdString, cmLVS7GFileConfig>::const_iterator + for(std::map<std::string, cmLVS7GFileConfig>::const_iterator fci = fcinfo.FileConfigMap.begin(); fci != fcinfo.FileConfigMap.end(); ++fci) { @@ -1779,8 +1793,6 @@ WriteCustomRule(std::ostream& fout, const cmCustomCommand& command, FCInfo& fcinfo) { - std::string comment = this->ConstructComment(command); - // Write the rule for each configuration. std::vector<std::string>::iterator i; std::vector<std::string> *configs = @@ -1798,6 +1810,7 @@ WriteCustomRule(std::ostream& fout, } for(i = configs->begin(); i != configs->end(); ++i) { + cmCustomCommandGenerator ccg(command, *i, this->Makefile); cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i]; fout << "\t\t\t\t<FileConfiguration\n"; fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n"; @@ -1809,7 +1822,8 @@ WriteCustomRule(std::ostream& fout, << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n"; } - std::string script = this->ConstructScript(command, i->c_str()); + std::string comment = this->ConstructComment(ccg); + std::string script = this->ConstructScript(ccg); if(this->FortranProject) { cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str()); @@ -1821,7 +1835,7 @@ WriteCustomRule(std::ostream& fout, << "\t\t\t\t\tCommandLine=\"" << this->EscapeForXML(script.c_str()) << "\"\n" << "\t\t\t\t\tAdditionalDependencies=\""; - if(command.GetDepends().empty()) + if(ccg.GetDepends().empty()) { // There are no real dependencies. Produce an artificial one to // make sure the rule runs reliably. @@ -1836,8 +1850,8 @@ WriteCustomRule(std::ostream& fout, { // Write out the dependencies for the rule. for(std::vector<std::string>::const_iterator d = - command.GetDepends().begin(); - d != command.GetDepends().end(); + ccg.GetDepends().begin(); + d != ccg.GetDepends().end(); ++d) { // Get the real name of the dependency in case it is a CMake target. @@ -1851,7 +1865,7 @@ WriteCustomRule(std::ostream& fout, } fout << "\"\n"; fout << "\t\t\t\t\tOutputs=\""; - if(command.GetOutputs().empty()) + if(ccg.GetOutputs().empty()) { fout << source << "_force"; } @@ -1860,8 +1874,8 @@ WriteCustomRule(std::ostream& fout, // Write a rule for the output generated by this command. const char* sep = ""; for(std::vector<std::string>::const_iterator o = - command.GetOutputs().begin(); - o != command.GetOutputs().end(); + ccg.GetOutputs().begin(); + o != ccg.GetOutputs().end(); ++o) { fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str()); @@ -1893,9 +1907,9 @@ void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout) // look for custom rules on a target and collect them together void cmLocalVisualStudio7Generator ::OutputTargetRules(std::ostream& fout, - const char* configName, + const std::string& configName, cmTarget &target, - const char * /*libName*/) + const std::string& /*libName*/) { if (target.GetType() > cmTarget::GLOBAL_TARGET) { @@ -1955,13 +1969,14 @@ void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout, void cmLocalVisualStudio7Generator ::WriteProjectStartFortran(std::ostream& fout, - const char *libName, + const std::string& libName, cmTarget & target) { cmGlobalVisualStudio7Generator* gg = static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator); - fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n" + fout << "<?xml version=\"1.0\" encoding = \"" + << gg->Encoding() << "\"?>\n" << "<VisualStudioProject\n" << "\tProjectCreator=\"Intel Fortran\"\n" << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n"; @@ -2006,7 +2021,7 @@ cmLocalVisualStudio7Generator } this->WriteProjectSCC(fout, target); fout<< "\tKeyword=\"" << keyword << "\">\n" - << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\">\n" + << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n" << "\t<Platforms>\n" << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n" << "\t</Platforms>\n"; @@ -2015,7 +2030,7 @@ cmLocalVisualStudio7Generator void cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout, - const char *libName, + const std::string& libName, cmTarget & target, std::vector<cmSourceGroup> &) { @@ -2024,7 +2039,12 @@ cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout, this->WriteProjectStartFortran(fout, libName, target); return; } - fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n" + + cmGlobalVisualStudio7Generator* gg = + static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator); + + fout << "<?xml version=\"1.0\" encoding = \"" + << gg->Encoding() << "\"?>\n" << "<VisualStudioProject\n" << "\tProjectType=\"Visual C++\"\n"; if(this->Version == VS71) @@ -2038,19 +2058,17 @@ cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout, const char* projLabel = target.GetProperty("PROJECT_LABEL"); if(!projLabel) { - projLabel = libName; + projLabel = libName.c_str(); } const char* keyword = target.GetProperty("VS_KEYWORD"); if(!keyword) { keyword = "Win32Proj"; } - cmGlobalVisualStudio7Generator* gg = - static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator); fout << "\tName=\"" << projLabel << "\"\n"; if(this->Version >= VS8) { - fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n"; + fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n"; } this->WriteProjectSCC(fout, target); if(const char* targetFrameworkVersion = @@ -2090,7 +2108,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout, << "</VisualStudioProject>\n"; } -std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s) +std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s) { std::string ret = s; cmSystemTools::ReplaceString(ret, "&", "&"); @@ -2101,7 +2119,7 @@ std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s) return ret; } -std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s) +std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s) { return cmLocalVisualStudio7GeneratorEscapeForXML(s); } @@ -2134,10 +2152,10 @@ std::string cmLocalVisualStudio7Generator class cmVS7XMLParser : public cmXMLParser { public: - virtual void EndElement(const char* /* name */) + virtual void EndElement(const std::string& /* name */) { } - virtual void StartElement(const char* name, const char** atts) + virtual void StartElement(const std::string& name, const char** atts) { // once the GUID is found do nothing if(this->GUID.size()) @@ -2145,7 +2163,7 @@ public: return; } int i =0; - if(strcmp("VisualStudioProject", name) == 0) + if("VisualStudioProject" == name) { while(atts[i]) { @@ -2182,7 +2200,7 @@ public: }; void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID( - const char* name, + const std::string& name, const char* path) { cmVS7XMLParser parser; |