Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmLocalVisualStudio7Generator.cxx
blobc7dba2813f642b12f0f12026e7fa3e14ba6471ad
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalVisualStudio7Generator.cxx,v $
5 Language: C++
6 Date: $Date: 2008-03-31 14:59:02 $
7 Version: $Revision: 1.221 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmGlobalVisualStudio7Generator.h"
18 #include "cmLocalVisualStudio7Generator.h"
19 #include "cmXMLParser.h"
20 #include <cm_expat.h>
21 #include "cmMakefile.h"
22 #include "cmSystemTools.h"
23 #include "cmSourceFile.h"
24 #include "cmCacheManager.h"
25 #include "cmake.h"
27 #include "cmComputeLinkInformation.h"
28 #include "cmGeneratedFileStream.h"
30 #include <cmsys/System.h>
32 #include <ctype.h> // for isspace
34 static bool cmLVS6G_IsFAT(const char* dir);
36 class cmLocalVisualStudio7GeneratorInternals
38 public:
39 cmLocalVisualStudio7GeneratorInternals(cmLocalVisualStudio7Generator* e):
40 LocalGenerator(e) {}
41 typedef cmComputeLinkInformation::ItemVector ItemVector;
42 void OutputLibraries(std::ostream& fout, ItemVector const& libs);
43 private:
44 cmLocalVisualStudio7Generator* LocalGenerator;
47 extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
49 //----------------------------------------------------------------------------
50 cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator()
52 this->Version = 7;
53 this->PlatformName = "Win32";
54 this->ExtraFlagTable = 0;
55 this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
58 cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
60 delete this->Internal;
63 void cmLocalVisualStudio7Generator::AddHelperCommands()
65 std::set<cmStdString> lang;
66 lang.insert("C");
67 lang.insert("CXX");
68 lang.insert("RC");
69 lang.insert("IDL");
70 lang.insert("DEF");
71 this->CreateCustomTargetsAndCommands(lang);
72 this->FixGlobalTargets();
75 void cmLocalVisualStudio7Generator::Generate()
77 this->WriteProjectFiles();
78 this->WriteStampFiles();
81 void cmLocalVisualStudio7Generator::FixGlobalTargets()
83 // Visual Studio .NET 2003 Service Pack 1 will not run post-build
84 // commands for targets in which no sources are built. Add dummy
85 // rules to force these targets to build.
86 cmTargets &tgts = this->Makefile->GetTargets();
87 for(cmTargets::iterator l = tgts.begin();
88 l != tgts.end(); l++)
90 cmTarget& tgt = l->second;
91 if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
93 std::vector<std::string> no_depends;
94 cmCustomCommandLine force_command;
95 force_command.push_back("cd");
96 force_command.push_back(".");
97 cmCustomCommandLines force_commands;
98 force_commands.push_back(force_command);
99 const char* no_main_dependency = 0;
100 std::string force = this->Makefile->GetStartOutputDirectory();
101 force += cmake::GetCMakeFilesDirectory();
102 force += "/";
103 force += tgt.GetName();
104 force += "_force";
105 this->Makefile->AddCustomCommandToOutput(force.c_str(), no_depends,
106 no_main_dependency,
107 force_commands, " ", 0, true);
108 if(cmSourceFile* file =
109 this->Makefile->GetSourceFileWithOutput(force.c_str()))
111 tgt.AddSourceFile(file);
117 // TODO
118 // for CommandLine= need to repleace quotes with &quot
119 // write out configurations
120 void cmLocalVisualStudio7Generator::WriteProjectFiles()
122 // If not an in source build, then create the output directory
123 if(strcmp(this->Makefile->GetStartOutputDirectory(),
124 this->Makefile->GetHomeDirectory()) != 0)
126 if(!cmSystemTools::MakeDirectory
127 (this->Makefile->GetStartOutputDirectory()))
129 cmSystemTools::Error("Error creating directory ",
130 this->Makefile->GetStartOutputDirectory());
134 // Get the set of targets in this directory.
135 cmTargets &tgts = this->Makefile->GetTargets();
137 // Create the regeneration custom rule.
138 if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
140 // Create a rule to regenerate the build system when the target
141 // specification source changes.
142 if(cmSourceFile* sf = this->CreateVCProjBuildRule())
144 // Add the rule to targets that need it.
145 for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
147 if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
149 l->second.AddSourceFile(sf);
155 // Create the project file for each target.
156 for(cmTargets::iterator l = tgts.begin();
157 l != tgts.end(); l++)
159 // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
160 // so don't build a projectfile for it
161 if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)
163 this->CreateSingleVCProj(l->first.c_str(),l->second);
168 //----------------------------------------------------------------------------
169 void cmLocalVisualStudio7Generator::WriteStampFiles()
171 // Touch a timestamp file used to determine when the project file is
172 // out of date.
173 std::string stampName = this->Makefile->GetStartOutputDirectory();
174 stampName += cmake::GetCMakeFilesDirectory();
175 cmSystemTools::MakeDirectory(stampName.c_str());
176 stampName += "/";
177 stampName += "generate.stamp";
178 std::ofstream stamp(stampName.c_str());
179 stamp << "# CMake generation timestamp file this directory.\n";
181 // Create a helper file so CMake can determine when it is run
182 // through the rule created by CreateVCProjBuildRule whether it
183 // really needs to regenerate the project. This file lists its own
184 // dependencies. If any file listed in it is newer than itself then
185 // CMake must rerun. Otherwise the project files are up to date and
186 // the stamp file can just be touched.
187 std::string depName = stampName;
188 depName += ".depend";
189 std::ofstream depFile(depName.c_str());
190 depFile << "# CMake generation dependency list for this directory.\n";
191 std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
192 for(std::vector<std::string>::const_iterator lf = listFiles.begin();
193 lf != listFiles.end(); ++lf)
195 depFile << *lf << std::endl;
199 //----------------------------------------------------------------------------
200 void cmLocalVisualStudio7Generator
201 ::CreateSingleVCProj(const char *lname, cmTarget &target)
203 // add to the list of projects
204 std::string pname = lname;
205 target.SetProperty("GENERATOR_FILE_NAME",lname);
206 // create the dsp.cmake file
207 std::string fname;
208 fname = this->Makefile->GetStartOutputDirectory();
209 fname += "/";
210 fname += lname;
211 fname += ".vcproj";
213 // Generate the project file and replace it atomically with
214 // copy-if-different. We use a separate timestamp so that the IDE
215 // does not reload project files unnecessarily.
216 cmGeneratedFileStream fout(fname.c_str());
217 fout.SetCopyIfDifferent(true);
218 this->WriteVCProjFile(fout,lname,target);
219 if (fout.Close())
221 this->GlobalGenerator->FileReplacedDuringGenerate(fname);
225 //----------------------------------------------------------------------------
226 cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
228 std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
229 stampName += "generate.stamp";
230 const char* dsprule =
231 this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
232 cmCustomCommandLine commandLine;
233 commandLine.push_back(dsprule);
234 std::string makefileIn = this->Makefile->GetStartDirectory();
235 makefileIn += "/";
236 makefileIn += "CMakeLists.txt";
237 makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
238 std::string comment = "Building Custom Rule ";
239 comment += makefileIn;
240 std::string args;
241 args = "-H";
242 args += this->Convert(this->Makefile->GetHomeDirectory(),
243 START_OUTPUT, UNCHANGED, true);
244 commandLine.push_back(args);
245 args = "-B";
246 args +=
247 this->Convert(this->Makefile->GetHomeOutputDirectory(),
248 START_OUTPUT, UNCHANGED, true);
249 commandLine.push_back(args);
250 commandLine.push_back("--check-stamp-file");
251 commandLine.push_back(stampName.c_str());
253 std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
255 cmCustomCommandLines commandLines;
256 commandLines.push_back(commandLine);
257 const char* no_working_directory = 0;
258 this->Makefile->AddCustomCommandToOutput(stampName.c_str(), listFiles,
259 makefileIn.c_str(), commandLines,
260 comment.c_str(),
261 no_working_directory, true);
262 if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
264 return file;
266 else
268 cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
269 return 0;
273 void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
274 const char *libName,
275 cmTarget &target)
277 std::vector<std::string> *configs =
278 static_cast<cmGlobalVisualStudio7Generator *>
279 (this->GlobalGenerator)->GetConfigurations();
281 fout << "\t<Configurations>\n";
282 for( std::vector<std::string>::iterator i = configs->begin();
283 i != configs->end(); ++i)
285 this->WriteConfiguration(fout, i->c_str(), libName, target);
287 fout << "\t</Configurations>\n";
290 // fill the table here currently the comment field is not used for
291 // anything other than documentation NOTE: Make sure the longer
292 // commandFlag comes FIRST!
293 cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
295 // option flags (some flags map to the same option)
296 {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
297 {"BasicRuntimeChecks", "RTCsu",
298 "Both stack and uninitialized checks", "3", 0},
299 {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
300 {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
301 {"BasicRuntimeChecks", "RTC1",
302 "Both stack and uninitialized checks", "3", 0},
303 {"DebugInformationFormat", "Z7", "debug format", "1", 0},
304 {"DebugInformationFormat", "Zd", "debug format", "2", 0},
305 {"DebugInformationFormat", "Zi", "debug format", "3", 0},
306 {"DebugInformationFormat", "ZI", "debug format", "4", 0},
307 {"EnableEnhancedInstructionSet", "arch:SSE2",
308 "Use sse2 instructions", "2", 0},
309 {"EnableEnhancedInstructionSet", "arch:SSE",
310 "Use sse instructions", "1", 0},
311 {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
312 {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
313 {"CompileAs", "TC", "Compile as c code", "1", 0},
314 {"CompileAs", "TP", "Compile as c++ code", "2", 0},
315 {"Optimization", "Od", "Non Debug", "0", 0},
316 {"Optimization", "O1", "Min Size", "1", 0},
317 {"Optimization", "O2", "Max Speed", "2", 0},
318 {"Optimization", "Ox", "Max Optimization", "3", 0},
319 {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
320 {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
321 {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
322 {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
323 {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
324 {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
325 {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
326 {"RuntimeLibrary", "MTd", "Multithreded debug", "1", 0},
327 {"RuntimeLibrary", "MT", "Multithreded", "0", 0},
328 {"RuntimeLibrary", "MDd", "Multithreded dll debug", "3", 0},
329 {"RuntimeLibrary", "MD", "Multithreded dll", "2", 0},
330 {"RuntimeLibrary", "MLd", "Sinble Thread debug", "5", 0},
331 {"RuntimeLibrary", "ML", "Sinble Thread", "4", 0},
332 {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
333 {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
334 {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
335 {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
336 {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
337 {"WarningLevel", "W1", "Warning level", "1", 0},
338 {"WarningLevel", "W2", "Warning level", "2", 0},
339 {"WarningLevel", "W3", "Warning level", "3", 0},
340 {"WarningLevel", "W4", "Warning level", "4", 0},
342 // Precompiled header and related options. Note that the
343 // UsePrecompiledHeader entries are marked as "Continue" so that the
344 // corresponding PrecompiledHeaderThrough entry can be found.
345 {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
346 cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
347 {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
348 cmVS7FlagTable::UserValueRequired},
349 {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
350 cmVS7FlagTable::UserValue},
351 // The YX and Yu options are in a per-global-generator table because
352 // their values differ based on the VS IDE version.
353 {"ForcedIncludeFiles", "FI", "Forced include files", "",
354 cmVS7FlagTable::UserValueRequired},
356 // boolean flags
357 {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE", 0},
358 {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "FALSE", 0},
359 {"Detect64BitPortabilityProblems", "Wp64",
360 "Detect 64-bit Portability Problems", "TRUE", 0},
361 {"EnableFiberSafeOptimization", "GT", "Enable Fiber-safe Optimizations",
362 "TRUE", 0},
363 {"EnableFunctionLevelLinking", "Gy",
364 "EnableFunctionLevelLinking", "TRUE", 0},
365 {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE", 0},
366 {"GlobalOptimizations", "Og", "Global Optimize", "TRUE", 0},
367 {"ImproveFloatingPointConsistency", "Op",
368 "ImproveFloatingPointConsistency", "TRUE", 0},
369 {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE", 0},
370 {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE", 0},
371 {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE", 0},
372 {"RuntimeTypeInfo", "GR",
373 "Turn on Run time type information for c++", "TRUE", 0},
374 {"RuntimeTypeInfo", "GR-",
375 "Turn off Run time type information for c++", "FALSE", 0},
376 {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE", 0},
377 {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "TRUE", 0},
378 {"WarnAsError", "WX", "Treat warnings as errors", "TRUE", 0},
379 {0,0,0,0,0}
382 cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
384 // option flags (some flags map to the same option)
385 {"GenerateManifest", "MANIFEST:NO",
386 "disable manifest generation", "FALSE", 0},
387 {"GenerateManifest", "MANIFEST", "enable manifest generation", "TRUE", 0},
388 {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
389 {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
390 {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
391 cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
392 {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
393 "TRUE", 0},
394 {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
395 cmVS7FlagTable::UserValue},
396 {0,0,0,0,0}
399 //----------------------------------------------------------------------------
400 class cmLocalVisualStudio7GeneratorOptions
402 public:
403 // Construct an options table for a given tool.
404 enum Tool
406 Compiler,
407 Linker
409 cmLocalVisualStudio7GeneratorOptions(cmLocalVisualStudio7Generator* lg,
410 Tool tool,
411 cmVS7FlagTable const* extraTable = 0);
413 // Store options from command line flags.
414 void Parse(const char* flags);
416 // Fix the ExceptionHandling option to default to off.
417 void FixExceptionHandlingDefault();
419 // Store options for verbose builds.
420 void SetVerboseMakefile(bool verbose);
422 // Store definitions and flags.
423 void AddDefine(const std::string& define);
424 void AddDefines(const char* defines);
425 void AddFlag(const char* flag, const char* value);
427 // Check for specific options.
428 bool UsingUnicode();
430 bool IsDebug();
431 // Write options to output.
432 void OutputPreprocessorDefinitions(std::ostream& fout,
433 const char* prefix,
434 const char* suffix);
435 void OutputFlagMap(std::ostream& fout, const char* indent);
436 void OutputAdditionalOptions(std::ostream& fout,
437 const char* prefix,
438 const char* suffix);
440 private:
441 cmLocalVisualStudio7Generator* LocalGenerator;
443 // create a map of xml tags to the values they should have in the output
444 // for example, "BufferSecurityCheck" = "TRUE"
445 // first fill this table with the values for the configuration
446 // Debug, Release, etc,
447 // Then parse the command line flags specified in CMAKE_CXX_FLAGS
448 // and CMAKE_C_FLAGS
449 // and overwrite or add new values to this map
450 std::map<cmStdString, cmStdString> FlagMap;
452 // Preprocessor definitions.
453 std::vector<std::string> Defines;
455 // Unrecognized flags that get no special handling.
456 cmStdString FlagString;
458 Tool CurrentTool;
459 bool DoingDefine;
460 cmVS7FlagTable const* FlagTable;
461 cmVS7FlagTable const* ExtraFlagTable;
462 void HandleFlag(const char* flag);
463 bool CheckFlagTable(cmVS7FlagTable const* table, const char* flag,
464 bool& flag_handled);
467 void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
468 const char* configName,
469 const char *libName,
470 cmTarget &target)
472 const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
473 if(!mfcFlag)
475 mfcFlag = "0";
477 fout << "\t\t<Configuration\n"
478 << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n"
479 << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
480 // This is an internal type to Visual Studio, it seems that:
481 // 4 == static library
482 // 2 == dll
483 // 1 == executable
484 // 10 == utility
485 const char* configType = "10";
486 switch(target.GetType())
488 case cmTarget::STATIC_LIBRARY:
489 configType = "4";
490 break;
491 case cmTarget::SHARED_LIBRARY:
492 case cmTarget::MODULE_LIBRARY:
493 configType = "2";
494 break;
495 case cmTarget::EXECUTABLE:
496 configType = "1";
497 break;
498 case cmTarget::UTILITY:
499 case cmTarget::GLOBAL_TARGET:
500 configType = "10";
501 default:
502 break;
505 std::string flags;
506 if(strcmp(configType, "10") != 0)
508 const char* linkLanguage =
509 target.GetLinkerLanguage(this->GetGlobalGenerator());
510 if(!linkLanguage)
512 cmSystemTools::Error
513 ("CMake can not determine linker language for target:",
514 target.GetName());
515 return;
517 if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0)
519 std::string baseFlagVar = "CMAKE_";
520 baseFlagVar += linkLanguage;
521 baseFlagVar += "_FLAGS";
522 flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
523 std::string flagVar = baseFlagVar + std::string("_") +
524 cmSystemTools::UpperCase(configName);
525 flags += " ";
526 flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
528 // set the correct language
529 if(strcmp(linkLanguage, "C") == 0)
531 flags += " /TC ";
533 if(strcmp(linkLanguage, "CXX") == 0)
535 flags += " /TP ";
539 // Add the target-specific flags.
540 if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
542 flags += " ";
543 flags += targetFlags;
546 std::string configUpper = cmSystemTools::UpperCase(configName);
547 std::string defPropName = "COMPILE_DEFINITIONS_";
548 defPropName += configUpper;
550 // Get preprocessor definitions for this directory.
551 std::string defineFlags = this->Makefile->GetDefineFlags();
553 // Construct a set of build options for this target.
554 Options targetOptions(this, Options::Compiler, this->ExtraFlagTable);
555 targetOptions.FixExceptionHandlingDefault();
556 targetOptions.Parse(flags.c_str());
557 targetOptions.Parse(defineFlags.c_str());
558 targetOptions.AddDefines
559 (this->Makefile->GetProperty("COMPILE_DEFINITIONS"));
560 targetOptions.AddDefines(target.GetProperty("COMPILE_DEFINITIONS"));
561 targetOptions.AddDefines(this->Makefile->GetProperty(defPropName.c_str()));
562 targetOptions.AddDefines(target.GetProperty(defPropName.c_str()));
563 targetOptions.SetVerboseMakefile(
564 this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
566 // Add a definition for the configuration name.
567 std::string configDefine = "CMAKE_INTDIR=\"";
568 configDefine += configName;
569 configDefine += "\"";
570 targetOptions.AddDefine(configDefine);
572 // Add the export symbol definition for shared library objects.
573 if(const char* exportMacro = target.GetExportMacro())
575 targetOptions.AddDefine(exportMacro);
578 // The intermediate directory name consists of a directory for the
579 // target and a subdirectory for the configuration name.
580 std::string intermediateDir = this->GetTargetDirectory(target);
581 intermediateDir += "/";
582 intermediateDir += configName;
583 fout << "\t\t\tIntermediateDirectory=\""
584 << this->ConvertToXMLOutputPath(intermediateDir.c_str())
585 << "\"\n"
586 << "\t\t\tConfigurationType=\"" << configType << "\"\n"
587 << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
588 << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
590 // If unicode is enabled change the character set to unicode, if not
591 // then default to MBCS.
592 if(targetOptions.UsingUnicode())
594 fout << "\t\t\tCharacterSet=\"1\">\n";
596 else
598 fout << "\t\t\tCharacterSet=\"2\">\n";
601 fout << "\t\t\t<Tool\n"
602 << "\t\t\t\tName=\"VCCLCompilerTool\"\n";
603 targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
604 fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
605 std::vector<std::string> includes;
606 this->GetIncludeDirectories(includes);
607 std::vector<std::string>::iterator i = includes.begin();
608 for(;i != includes.end(); ++i)
610 std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
611 fout << ipath << ";";
613 fout << "\"\n";
614 targetOptions.OutputFlagMap(fout, "\t\t\t\t");
615 targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
616 fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
617 fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
618 if(target.GetType() == cmTarget::EXECUTABLE ||
619 target.GetType() == cmTarget::STATIC_LIBRARY ||
620 target.GetType() == cmTarget::SHARED_LIBRARY ||
621 target.GetType() == cmTarget::MODULE_LIBRARY)
623 // We need to specify a program database file name even for
624 // non-debug configurations because VS still creates .idb files.
625 fout << "\t\t\t\tProgramDataBaseFileName=\""
626 << target.GetDirectory(configName) << "/"
627 << target.GetPDBName(configName) << "\"\n";
629 fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
630 fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
631 fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
632 << "\t\t\t\tAdditionalIncludeDirectories=\"";
633 for(i = includes.begin();i != includes.end(); ++i)
635 std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
636 fout << ipath << ";";
638 // add the -D flags to the RC tool
639 fout << "\"";
640 targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "");
641 fout << "/>\n";
643 fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"\n";
644 targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
645 fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
646 if( this->PlatformName == "x64" )
648 fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
650 else if( this->PlatformName == "ia64" )
652 fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
654 else
656 fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
658 fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
659 fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
660 fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
661 fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
662 fout << "\t\t\t\tDLLDataFileName=\"\"\n";
663 fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
664 fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
665 // end of <Tool Name=VCMIDLTool
667 // Check if we need the FAT32 workaround.
668 if ( this->Version >= 8 )
670 // Check the filesystem type where the target will be written.
671 if(cmLVS6G_IsFAT(target.GetDirectory(configName)))
673 // Add a flag telling the manifest tool to use a workaround
674 // for FAT32 file systems, which can cause an empty manifest
675 // to be embedded into the resulting executable. See CMake
676 // bug #2617.
677 fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCManifestTool\"\n"
678 << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
679 << "\t\t\t/>\n";
683 this->OutputTargetRules(fout, configName, target, libName);
684 this->OutputBuildTool(fout, configName, target, targetOptions.IsDebug());
685 fout << "\t\t</Configuration>\n";
688 //----------------------------------------------------------------------------
689 std::string
690 cmLocalVisualStudio7Generator
691 ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
693 std::string configTypeUpper = cmSystemTools::UpperCase(configName);
694 std::string extraLinkOptionsBuildTypeDef =
695 rootLinkerFlags + "_" + configTypeUpper;
697 std::string extraLinkOptionsBuildType =
698 this->Makefile->GetRequiredDefinition
699 (extraLinkOptionsBuildTypeDef.c_str());
701 return extraLinkOptionsBuildType;
704 void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
705 const char* configName,
706 cmTarget &target,
707 bool isDebug)
709 std::string temp;
710 std::string extraLinkOptions;
711 if(target.GetType() == cmTarget::EXECUTABLE)
713 extraLinkOptions =
714 this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
715 + std::string(" ")
716 + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
718 if(target.GetType() == cmTarget::SHARED_LIBRARY)
720 extraLinkOptions =
721 this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
722 + std::string(" ")
723 + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
725 if(target.GetType() == cmTarget::MODULE_LIBRARY)
727 extraLinkOptions =
728 this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
729 + std::string(" ")
730 + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
733 const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
734 if(targetLinkFlags)
736 extraLinkOptions += " ";
737 extraLinkOptions += targetLinkFlags;
739 std::string configTypeUpper = cmSystemTools::UpperCase(configName);
740 std::string linkFlagsConfig = "LINK_FLAGS_";
741 linkFlagsConfig += configTypeUpper;
742 targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
743 if(targetLinkFlags)
745 extraLinkOptions += " ";
746 extraLinkOptions += targetLinkFlags;
748 Options linkOptions(this, Options::Linker);
749 linkOptions.Parse(extraLinkOptions.c_str());
750 switch(target.GetType())
752 case cmTarget::STATIC_LIBRARY:
754 std::string targetNameFull = target.GetFullName(configName);
755 std::string libpath = target.GetDirectory(configName);
756 libpath += "/";
757 libpath += targetNameFull;
758 fout << "\t\t\t<Tool\n"
759 << "\t\t\t\tName=\"VCLibrarianTool\"\n";
760 if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
762 fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
764 fout << "\t\t\t\tOutputFile=\""
765 << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
766 break;
768 case cmTarget::SHARED_LIBRARY:
769 case cmTarget::MODULE_LIBRARY:
771 std::string targetName;
772 std::string targetNameSO;
773 std::string targetNameFull;
774 std::string targetNameImport;
775 std::string targetNamePDB;
776 target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
777 targetNameImport, targetNamePDB, configName);
779 // Compute the link library and directory information.
780 cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
781 if(!pcli)
783 return;
785 cmComputeLinkInformation& cli = *pcli;
786 const char* linkLanguage = cli.GetLinkLanguage();
788 // Compute the variable name to lookup standard libraries for this
789 // language.
790 std::string standardLibsVar = "CMAKE_";
791 standardLibsVar += linkLanguage;
792 standardLibsVar += "_STANDARD_LIBRARIES";
794 fout << "\t\t\t<Tool\n"
795 << "\t\t\t\tName=\"VCLinkerTool\"\n";
796 linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
797 // Use the NOINHERIT macro to avoid getting VS project default
798 // libraries which may be set by the user to something bad.
799 fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
800 << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
801 << " ";
802 this->Internal->OutputLibraries(fout, cli.GetItems());
803 fout << "\"\n";
804 temp = target.GetDirectory(configName);
805 temp += "/";
806 temp += targetNameFull;
807 fout << "\t\t\t\tOutputFile=\""
808 << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
809 this->WriteTargetVersionAttribute(fout, target);
810 linkOptions.OutputFlagMap(fout, "\t\t\t\t");
811 fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
812 this->OutputLibraryDirectories(fout, cli.GetDirectories());
813 fout << "\"\n";
814 this->OutputModuleDefinitionFile(fout, target);
815 temp = target.GetDirectory(configName);
816 temp += "/";
817 temp += targetNamePDB;
818 fout << "\t\t\t\tProgramDataBaseFile=\"" <<
819 this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
820 if(isDebug)
822 fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
824 std::string stackVar = "CMAKE_";
825 stackVar += linkLanguage;
826 stackVar += "_STACK_SIZE";
827 const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
828 if(stackVal)
830 fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
832 temp = target.GetDirectory(configName, true);
833 temp += "/";
834 temp += targetNameImport;
835 fout << "\t\t\t\tImportLibrary=\""
836 << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
838 break;
839 case cmTarget::EXECUTABLE:
841 std::string targetName;
842 std::string targetNameFull;
843 std::string targetNameImport;
844 std::string targetNamePDB;
845 target.GetExecutableNames(targetName, targetNameFull,
846 targetNameImport, targetNamePDB, configName);
848 // Compute the link library and directory information.
849 cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
850 if(!pcli)
852 return;
854 cmComputeLinkInformation& cli = *pcli;
855 const char* linkLanguage = cli.GetLinkLanguage();
857 // Compute the variable name to lookup standard libraries for this
858 // language.
859 std::string standardLibsVar = "CMAKE_";
860 standardLibsVar += linkLanguage;
861 standardLibsVar += "_STANDARD_LIBRARIES";
863 fout << "\t\t\t<Tool\n"
864 << "\t\t\t\tName=\"VCLinkerTool\"\n";
865 linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
866 // Use the NOINHERIT macro to avoid getting VS project default
867 // libraries which may be set by the user to something bad.
868 fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
869 << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
870 << " ";
871 this->Internal->OutputLibraries(fout, cli.GetItems());
872 fout << "\"\n";
873 temp = target.GetDirectory(configName);
874 temp += "/";
875 temp += targetNameFull;
876 fout << "\t\t\t\tOutputFile=\""
877 << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
878 this->WriteTargetVersionAttribute(fout, target);
879 linkOptions.OutputFlagMap(fout, "\t\t\t\t");
880 fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
881 this->OutputLibraryDirectories(fout, cli.GetDirectories());
882 fout << "\"\n";
883 fout << "\t\t\t\tProgramDataBaseFile=\""
884 << target.GetDirectory(configName) << "/" << targetNamePDB
885 << "\"\n";
886 if(isDebug)
888 fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
890 if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
892 fout << "\t\t\t\tSubSystem=\"2\"\n";
894 else
896 fout << "\t\t\t\tSubSystem=\"1\"\n";
898 std::string stackVar = "CMAKE_";
899 stackVar += linkLanguage;
900 stackVar += "_STACK_SIZE";
901 const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
902 if(stackVal)
904 fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
906 temp = target.GetDirectory(configName, true);
907 temp += "/";
908 temp += targetNameImport;
909 fout << "\t\t\t\tImportLibrary=\""
910 << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
911 break;
913 case cmTarget::UTILITY:
914 case cmTarget::GLOBAL_TARGET:
915 break;
919 //----------------------------------------------------------------------------
920 void
921 cmLocalVisualStudio7Generator
922 ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
924 int major;
925 int minor;
926 target.GetTargetVersion(major, minor);
927 fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
930 void cmLocalVisualStudio7Generator
931 ::OutputModuleDefinitionFile(std::ostream& fout,
932 cmTarget &target)
934 std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
935 for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
936 i != classes.end(); i++)
938 cmSourceFile* sf = *i;
939 if(cmSystemTools::UpperCase(sf->GetExtension()) == "DEF")
941 fout << "\t\t\t\tModuleDefinitionFile=\""
942 << this->ConvertToXMLOutputPath(sf->GetFullPath().c_str())
943 << "\"\n";
944 return;
950 //----------------------------------------------------------------------------
951 void
952 cmLocalVisualStudio7GeneratorInternals
953 ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
955 cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
956 for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
958 if(l->IsPath)
960 std::string rel = lg->Convert(l->Value.c_str(),
961 cmLocalGenerator::START_OUTPUT,
962 cmLocalGenerator::UNCHANGED);
963 fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
965 else
967 fout << l->Value << " ";
972 //----------------------------------------------------------------------------
973 void
974 cmLocalVisualStudio7Generator
975 ::OutputLibraryDirectories(std::ostream& fout,
976 std::vector<std::string> const& dirs)
978 const char* comma = "";
979 for(std::vector<std::string>::const_iterator d = dirs.begin();
980 d != dirs.end(); ++d)
982 // Remove any trailing slash and skip empty paths.
983 std::string dir = *d;
984 if(dir[dir.size()-1] == '/')
986 dir = dir.substr(0, dir.size()-1);
988 if(dir.empty())
990 continue;
993 // Switch to a relative path specification if it is shorter.
994 if(cmSystemTools::FileIsFullPath(dir.c_str()))
996 std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
997 if(rel.size() < dir.size())
999 dir = rel;
1003 // First search a configuration-specific subdirectory and then the
1004 // original directory.
1005 fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
1006 << "," << this->ConvertToXMLOutputPath(dir.c_str());
1007 comma = ",";
1011 void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
1012 const char *libName,
1013 cmTarget &target)
1015 // get the configurations
1016 std::vector<std::string> *configs =
1017 static_cast<cmGlobalVisualStudio7Generator *>
1018 (this->GlobalGenerator)->GetConfigurations();
1020 // We may be modifying the source groups temporarily, so make a copy.
1021 std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
1023 // get the classes from the source lists then add them to the groups
1024 std::vector<cmSourceFile*>const & classes = target.GetSourceFiles();
1025 for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
1026 i != classes.end(); i++)
1028 // Add the file to the list of sources.
1029 std::string source = (*i)->GetFullPath();
1030 if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
1032 this->ModuleDefinitionFile = (*i)->GetFullPath();
1034 cmSourceGroup& sourceGroup =
1035 this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
1036 sourceGroup.AssignSource(*i);
1039 // Compute which sources need unique object computation.
1040 this->ComputeObjectNameRequirements(sourceGroups);
1042 // open the project
1043 this->WriteProjectStart(fout, libName, target, sourceGroups);
1044 // write the configuration information
1045 this->WriteConfigurations(fout, libName, target);
1047 fout << "\t<Files>\n";
1050 // Loop through every source group.
1051 for(unsigned int i = 0; i < sourceGroups.size(); ++i)
1053 cmSourceGroup sg = sourceGroups[i];
1054 this->WriteGroup(&sg, target, fout, libName, configs);
1059 fout << "\t</Files>\n";
1061 // Write the VCProj file's footer.
1062 this->WriteVCProjFooter(fout);
1065 struct cmLVS7GFileConfig
1067 std::string ObjectName;
1068 std::string CompileFlags;
1069 std::string CompileDefs;
1070 std::string CompileDefsConfig;
1071 std::string AdditionalDeps;
1072 bool ExcludedFromBuild;
1075 class cmLocalVisualStudio7GeneratorFCInfo
1077 public:
1078 cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
1079 cmTarget& target,
1080 cmSourceFile const& sf,
1081 std::vector<std::string>* configs,
1082 std::string::size_type dir_len);
1083 std::map<cmStdString, cmLVS7GFileConfig> FileConfigMap;
1086 cmLocalVisualStudio7GeneratorFCInfo
1087 ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
1088 cmTarget& target,
1089 cmSourceFile const& sf,
1090 std::vector<std::string>* configs,
1091 std::string::size_type dir_len)
1093 std::string objectName;
1094 if(lg->NeedObjectName.find(&sf) != lg->NeedObjectName.end())
1096 objectName = lg->GetObjectFileNameWithoutTarget(sf, dir_len);
1099 // Compute per-source, per-config information.
1100 for(std::vector<std::string>::iterator i = configs->begin();
1101 i != configs->end(); ++i)
1103 std::string configUpper = cmSystemTools::UpperCase(*i);
1104 cmLVS7GFileConfig fc;
1105 bool needfc = false;
1106 if(!objectName.empty())
1108 fc.ObjectName = objectName;
1109 needfc = true;
1111 if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
1113 fc.CompileFlags = cflags;
1114 needfc = true;
1116 if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
1118 fc.CompileDefs = cdefs;
1119 needfc = true;
1121 std::string defPropName = "COMPILE_DEFINITIONS_";
1122 defPropName += configUpper;
1123 if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
1125 fc.CompileDefsConfig = ccdefs;
1126 needfc = true;
1129 // Check for extra object-file dependencies.
1130 if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
1132 std::vector<std::string> depends;
1133 cmSystemTools::ExpandListArgument(deps, depends);
1134 const char* sep = "";
1135 for(std::vector<std::string>::iterator j = depends.begin();
1136 j != depends.end(); ++j)
1138 fc.AdditionalDeps += sep;
1139 fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
1140 sep = ";";
1141 needfc = true;
1145 const char* lang =
1146 lg->GlobalGenerator->GetLanguageFromExtension
1147 (sf.GetExtension().c_str());
1148 const char* sourceLang = lg->GetSourceFileLanguage(sf);
1149 const char* linkLanguage = target.GetLinkerLanguage
1150 (lg->GetGlobalGenerator());
1151 bool needForceLang = false;
1152 // source file does not match its extension language
1153 if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
1155 needForceLang = true;
1156 lang = sourceLang;
1158 // If lang is set, the compiler will generate code automatically.
1159 // If HEADER_FILE_ONLY is set, we must suppress this generation in
1160 // the project file
1161 fc.ExcludedFromBuild =
1162 (lang && sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
1163 if(fc.ExcludedFromBuild)
1165 needfc = true;
1168 // if the source file does not match the linker language
1169 // then force c or c++
1170 if(needForceLang || (linkLanguage && lang
1171 && strcmp(lang, linkLanguage) != 0))
1173 if(strcmp(lang, "CXX") == 0)
1175 // force a C++ file type
1176 fc.CompileFlags += " /TP ";
1177 needfc = true;
1179 else if(strcmp(lang, "C") == 0)
1181 // force to c
1182 fc.CompileFlags += " /TC ";
1183 needfc = true;
1187 if(needfc)
1189 this->FileConfigMap[*i] = fc;
1194 void cmLocalVisualStudio7Generator
1195 ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
1196 std::ostream &fout, const char *libName,
1197 std::vector<std::string> *configs)
1199 const std::vector<const cmSourceFile *> &sourceFiles =
1200 sg->GetSourceFiles();
1201 // If the group is empty, don't write it at all.
1202 if(sourceFiles.empty() && sg->GetGroupChildren().empty())
1204 return;
1207 // If the group has a name, write the header.
1208 std::string name = sg->GetName();
1209 if(name != "")
1211 this->WriteVCProjBeginGroup(fout, name.c_str(), "");
1214 // Compute the maximum length of a configuration name.
1215 std::string::size_type config_len_max = 0;
1216 for(std::vector<std::string>::iterator i = configs->begin();
1217 i != configs->end(); ++i)
1219 if(i->size() > config_len_max)
1221 config_len_max = i->size();
1225 // Compute the maximum length of the full path to the intermediate
1226 // files directory for any configuration. This is used to construct
1227 // object file names that do not produce paths that are too long.
1228 std::string::size_type dir_len = 0;
1229 dir_len += strlen(this->Makefile->GetCurrentOutputDirectory());
1230 dir_len += 1;
1231 dir_len += this->GetTargetDirectory(target).size();
1232 dir_len += 1;
1233 dir_len += config_len_max;
1234 dir_len += 1;
1236 // Loop through each source in the source group.
1237 std::string objectName;
1238 for(std::vector<const cmSourceFile *>::const_iterator sf =
1239 sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
1241 std::string source = (*sf)->GetFullPath();
1242 FCInfo fcinfo(this, target, *(*sf), configs, dir_len);
1244 if (source != libName || target.GetType() == cmTarget::UTILITY ||
1245 target.GetType() == cmTarget::GLOBAL_TARGET )
1247 fout << "\t\t\t<File\n";
1248 std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
1249 // Tell MS-Dev what the source is. If the compiler knows how to
1250 // build it, then it will.
1251 fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
1252 if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
1254 this->WriteCustomRule(fout, source.c_str(), *command, fcinfo);
1256 else if(!fcinfo.FileConfigMap.empty())
1258 const char* aCompilerTool = "VCCLCompilerTool";
1259 std::string ext = (*sf)->GetExtension();
1260 ext = cmSystemTools::LowerCase(ext);
1261 if(ext == "idl")
1263 aCompilerTool = "VCMIDLTool";
1265 if(ext == "rc")
1267 aCompilerTool = "VCResourceCompilerTool";
1269 if(ext == "def")
1271 aCompilerTool = "VCCustomBuildTool";
1273 for(std::map<cmStdString, cmLVS7GFileConfig>::const_iterator
1274 fci = fcinfo.FileConfigMap.begin();
1275 fci != fcinfo.FileConfigMap.end(); ++fci)
1277 cmLVS7GFileConfig const& fc = fci->second;
1278 fout << "\t\t\t\t<FileConfiguration\n"
1279 << "\t\t\t\t\tName=\"" << fci->first
1280 << "|" << this->PlatformName << "\"";
1281 if(fc.ExcludedFromBuild)
1283 fout << " ExcludedFromBuild=\"true\"";
1285 fout << ">\n";
1286 fout << "\t\t\t\t\t<Tool\n"
1287 << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
1288 if(!fc.CompileFlags.empty() ||
1289 !fc.CompileDefs.empty() ||
1290 !fc.CompileDefsConfig.empty())
1292 Options fileOptions(this, Options::Compiler,
1293 this->ExtraFlagTable);
1294 fileOptions.Parse(fc.CompileFlags.c_str());
1295 fileOptions.AddDefines(fc.CompileDefs.c_str());
1296 fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
1297 fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
1298 fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
1299 fileOptions.OutputPreprocessorDefinitions(fout,
1300 "\t\t\t\t\t", "\n");
1302 if(!fc.AdditionalDeps.empty())
1304 fout << "\t\t\t\t\tAdditionalDependencies=\""
1305 << fc.AdditionalDeps.c_str() << "\"\n";
1307 if(!fc.ObjectName.empty())
1309 fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
1310 << fc.ObjectName.c_str() << "\"\n";
1312 fout << "\t\t\t\t\t/>\n"
1313 << "\t\t\t\t</FileConfiguration>\n";
1316 fout << "\t\t\t</File>\n";
1320 std::vector<cmSourceGroup> children = sg->GetGroupChildren();
1322 for(unsigned int i=0;i<children.size();++i)
1324 this->WriteGroup(&children[i], target, fout, libName, configs);
1327 // If the group has a name, write the footer.
1328 if(name != "")
1330 this->WriteVCProjEndGroup(fout);
1334 void cmLocalVisualStudio7Generator::
1335 WriteCustomRule(std::ostream& fout,
1336 const char* source,
1337 const cmCustomCommand& command,
1338 FCInfo& fcinfo)
1340 std::string comment = this->ConstructComment(command);
1342 // Write the rule for each configuration.
1343 std::vector<std::string>::iterator i;
1344 std::vector<std::string> *configs =
1345 static_cast<cmGlobalVisualStudio7Generator *>
1346 (this->GlobalGenerator)->GetConfigurations();
1348 for(i = configs->begin(); i != configs->end(); ++i)
1350 cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
1351 fout << "\t\t\t\t<FileConfiguration\n";
1352 fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
1353 if(!fc.CompileFlags.empty())
1355 fout << "\t\t\t\t\t<Tool\n"
1356 << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
1357 << "\t\t\t\t\tAdditionalOptions=\""
1358 << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
1361 std::string script =
1362 this->ConstructScript(command.GetCommandLines(),
1363 command.GetWorkingDirectory(),
1364 i->c_str(),
1365 command.GetEscapeOldStyle(),
1366 command.GetEscapeAllowMakeVars());
1367 fout << "\t\t\t\t\t<Tool\n"
1368 << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
1369 << "\t\t\t\t\tDescription=\""
1370 << this->EscapeForXML(comment.c_str()) << "\"\n"
1371 << "\t\t\t\t\tCommandLine=\""
1372 << this->EscapeForXML(script.c_str()) << "\"\n"
1373 << "\t\t\t\t\tAdditionalDependencies=\"";
1374 if(command.GetDepends().empty())
1376 // There are no real dependencies. Produce an artificial one to
1377 // make sure the rule runs reliably.
1378 if(!cmSystemTools::FileExists(source))
1380 std::ofstream depout(source);
1381 depout << "Artificial dependency for a custom command.\n";
1383 fout << this->ConvertToXMLOutputPath(source);
1385 else
1387 // Write out the dependencies for the rule.
1388 for(std::vector<std::string>::const_iterator d =
1389 command.GetDepends().begin();
1390 d != command.GetDepends().end();
1391 ++d)
1393 // Get the real name of the dependency in case it is a CMake target.
1394 std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
1395 fout << this->ConvertToXMLOutputPath(dep.c_str())
1396 << ";";
1399 fout << "\"\n";
1400 fout << "\t\t\t\t\tOutputs=\"";
1401 if(command.GetOutputs().empty())
1403 fout << source << "_force";
1405 else
1407 // Write a rule for the output generated by this command.
1408 const char* sep = "";
1409 for(std::vector<std::string>::const_iterator o =
1410 command.GetOutputs().begin();
1411 o != command.GetOutputs().end();
1412 ++o)
1414 fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
1415 sep = ";";
1418 fout << "\"/>\n";
1419 fout << "\t\t\t\t</FileConfiguration>\n";
1424 void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
1425 const char* group,
1426 const char* )
1428 fout << "\t\t<Filter\n"
1429 << "\t\t\tName=\"" << group << "\"\n"
1430 << "\t\t\tFilter=\"\">\n";
1434 void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
1436 fout << "\t\t</Filter>\n";
1440 // look for custom rules on a target and collect them together
1441 void cmLocalVisualStudio7Generator
1442 ::OutputTargetRules(std::ostream& fout,
1443 const char* configName,
1444 cmTarget &target,
1445 const char * /*libName*/)
1447 if (target.GetType() > cmTarget::GLOBAL_TARGET)
1449 return;
1452 // add the pre build rules
1453 fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"";
1454 bool init = false;
1455 for (std::vector<cmCustomCommand>::const_iterator cr =
1456 target.GetPreBuildCommands().begin();
1457 cr != target.GetPreBuildCommands().end(); ++cr)
1459 if(!init)
1461 const char* comment = cr->GetComment();
1462 if(comment && *comment)
1464 fout << "\nDescription=\""
1465 << this->EscapeForXML(comment) << "\"";
1467 fout << "\nCommandLine=\"";
1468 init = true;
1470 else
1472 fout << this->EscapeForXML("\n");
1474 std::string script =
1475 this->ConstructScript(cr->GetCommandLines(),
1476 cr->GetWorkingDirectory(),
1477 configName,
1478 cr->GetEscapeOldStyle(),
1479 cr->GetEscapeAllowMakeVars());
1480 fout << this->EscapeForXML(script.c_str()).c_str();
1482 if (init)
1484 fout << "\"";
1486 fout << "/>\n";
1488 // add the pre Link rules
1489 fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"";
1490 init = false;
1491 for (std::vector<cmCustomCommand>::const_iterator cr =
1492 target.GetPreLinkCommands().begin();
1493 cr != target.GetPreLinkCommands().end(); ++cr)
1495 if(!init)
1497 const char* comment = cr->GetComment();
1498 if(comment && *comment)
1500 fout << "\nDescription=\""
1501 << this->EscapeForXML(comment) << "\"";
1503 fout << "\nCommandLine=\"";
1504 init = true;
1506 else
1508 fout << this->EscapeForXML("\n");
1510 std::string script =
1511 this->ConstructScript(cr->GetCommandLines(),
1512 cr->GetWorkingDirectory(),
1513 configName,
1514 cr->GetEscapeOldStyle(),
1515 cr->GetEscapeAllowMakeVars());
1516 fout << this->EscapeForXML(script.c_str()).c_str();
1518 if (init)
1520 fout << "\"";
1522 fout << "/>\n";
1524 // add the PostBuild rules
1525 fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
1526 init = false;
1527 for (std::vector<cmCustomCommand>::const_iterator cr =
1528 target.GetPostBuildCommands().begin();
1529 cr != target.GetPostBuildCommands().end(); ++cr)
1531 if(!init)
1533 const char* comment = cr->GetComment();
1534 if(comment && *comment)
1536 fout << "\nDescription=\""
1537 << this->EscapeForXML(comment) << "\"";
1539 fout << "\nCommandLine=\"";
1540 init = true;
1542 else
1544 fout << this->EscapeForXML("\n");
1546 std::string script =
1547 this->ConstructScript(cr->GetCommandLines(),
1548 cr->GetWorkingDirectory(),
1549 configName,
1550 cr->GetEscapeOldStyle(),
1551 cr->GetEscapeAllowMakeVars());
1552 fout << this->EscapeForXML(script.c_str()).c_str();
1554 if (init)
1556 fout << "\"";
1558 fout << "/>\n";
1561 void
1562 cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
1563 const char *libName,
1564 cmTarget & target,
1565 std::vector<cmSourceGroup> &)
1567 fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
1568 << "<VisualStudioProject\n"
1569 << "\tProjectType=\"Visual C++\"\n";
1570 if(this->Version == 71)
1572 fout << "\tVersion=\"7.10\"\n";
1574 else
1576 fout << "\tVersion=\"" << this->Version << ".00\"\n";
1578 const char* projLabel = target.GetProperty("PROJECT_LABEL");
1579 if(!projLabel)
1581 projLabel = libName;
1583 const char* keyword = target.GetProperty("VS_KEYWORD");
1584 if(!keyword)
1586 keyword = "Win32Proj";
1588 cmGlobalVisualStudio7Generator* gg =
1589 static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
1590 fout << "\tName=\"" << projLabel << "\"\n";
1591 if(this->Version >= 8)
1593 fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n";
1595 fout << "\tSccProjectName=\"\"\n"
1596 << "\tSccLocalPath=\"\"\n"
1597 << "\tKeyword=\"" << keyword << "\">\n"
1598 << "\t<Platforms>\n"
1599 << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
1600 << "\t</Platforms>\n";
1604 void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
1606 fout << "\t<Globals>\n"
1607 << "\t</Globals>\n"
1608 << "</VisualStudioProject>\n";
1611 std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
1613 std::string ret = s;
1614 cmSystemTools::ReplaceString(ret, "&", "&amp;");
1615 cmSystemTools::ReplaceString(ret, "\"", "&quot;");
1616 cmSystemTools::ReplaceString(ret, "<", "&lt;");
1617 cmSystemTools::ReplaceString(ret, ">", "&gt;");
1618 cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
1619 return ret;
1622 std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
1624 return cmLocalVisualStudio7GeneratorEscapeForXML(s);
1627 std::string cmLocalVisualStudio7Generator
1628 ::ConvertToXMLOutputPath(const char* path)
1630 std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
1631 cmSystemTools::ReplaceString(ret, "&", "&amp;");
1632 cmSystemTools::ReplaceString(ret, "\"", "&quot;");
1633 cmSystemTools::ReplaceString(ret, "<", "&lt;");
1634 cmSystemTools::ReplaceString(ret, ">", "&gt;");
1635 return ret;
1638 std::string cmLocalVisualStudio7Generator
1639 ::ConvertToXMLOutputPathSingle(const char* path)
1641 std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
1642 cmSystemTools::ReplaceString(ret, "\"", "");
1643 cmSystemTools::ReplaceString(ret, "&", "&amp;");
1644 cmSystemTools::ReplaceString(ret, "<", "&lt;");
1645 cmSystemTools::ReplaceString(ret, ">", "&gt;");
1646 return ret;
1650 // This class is used to parse an existing vs 7 project
1651 // and extract the GUID
1652 class cmVS7XMLParser : public cmXMLParser
1654 public:
1655 virtual void EndElement(const char* /* name */)
1658 virtual void StartElement(const char* name, const char** atts)
1660 // once the GUID is found do nothing
1661 if(this->GUID.size())
1663 return;
1665 int i =0;
1666 if(strcmp("VisualStudioProject", name) == 0)
1668 while(atts[i])
1670 if(strcmp(atts[i], "ProjectGUID") == 0)
1672 if(atts[i+1])
1674 this->GUID = atts[i+1];
1675 this->GUID = this->GUID.substr(1, this->GUID.size()-2);
1677 else
1679 this->GUID = "";
1681 return;
1683 ++i;
1687 int InitializeParser()
1689 int ret = cmXMLParser::InitializeParser();
1690 if(ret == 0)
1692 return ret;
1694 // visual studio projects have a strange encoding, but it is
1695 // really utf-8
1696 XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
1697 return 1;
1699 std::string GUID;
1702 void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
1703 const char* name,
1704 const char* path)
1706 cmVS7XMLParser parser;
1707 parser.ParseFile(path);
1708 // if we can not find a GUID then create one
1709 if(parser.GUID.size() == 0)
1711 cmGlobalVisualStudio7Generator* gg =
1712 static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
1713 gg->CreateGUID(name);
1714 return;
1716 std::string guidStoreName = name;
1717 guidStoreName += "_GUID_CMAKE";
1718 // save the GUID in the cache
1719 this->GlobalGenerator->GetCMakeInstance()->
1720 AddCacheEntry(guidStoreName.c_str(),
1721 parser.GUID.c_str(),
1722 "Stored GUID",
1723 cmCacheManager::INTERNAL);
1727 void cmLocalVisualStudio7Generator::ConfigureFinalPass()
1729 cmLocalGenerator::ConfigureFinalPass();
1730 cmTargets &tgts = this->Makefile->GetTargets();
1732 cmGlobalVisualStudio7Generator* gg =
1733 static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
1734 for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
1736 if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
1738 cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
1739 const cmCustomCommandLines& cmds = cc.GetCommandLines();
1740 std::string project_name = cmds[0][0];
1741 this->ReadAndStoreExternalGUID(project_name.c_str(),
1742 cmds[0][1].c_str());
1744 else
1746 gg->CreateGUID(l->first.c_str());
1752 //----------------------------------------------------------------------------
1753 std::string cmLocalVisualStudio7Generator
1754 ::GetTargetDirectory(cmTarget const& target) const
1756 std::string dir;
1757 dir += target.GetName();
1758 dir += ".dir";
1759 return dir;
1762 //----------------------------------------------------------------------------
1763 cmLocalVisualStudio7GeneratorOptions
1764 ::cmLocalVisualStudio7GeneratorOptions(cmLocalVisualStudio7Generator* lg,
1765 Tool tool,
1766 cmVS7FlagTable const* extraTable):
1767 LocalGenerator(lg), CurrentTool(tool),
1768 DoingDefine(false), FlagTable(0), ExtraFlagTable(extraTable)
1770 // Choose the flag table for the requested tool.
1771 switch(tool)
1773 case Compiler:
1774 this->FlagTable = cmLocalVisualStudio7GeneratorFlagTable; break;
1775 case Linker:
1776 this->FlagTable = cmLocalVisualStudio7GeneratorLinkFlagTable; break;
1777 default: break;
1781 //----------------------------------------------------------------------------
1782 void cmLocalVisualStudio7GeneratorOptions::FixExceptionHandlingDefault()
1784 // Exception handling is on by default because the platform file has
1785 // "/EHsc" in the flags. Normally, that will override this
1786 // initialization to off, but the user has the option of removing
1787 // the flag to disable exception handling. When the user does
1788 // remove the flag we need to override the IDE default of on.
1789 this->FlagMap["ExceptionHandling"] = "FALSE";
1792 //----------------------------------------------------------------------------
1793 void cmLocalVisualStudio7GeneratorOptions::SetVerboseMakefile(bool verbose)
1795 // If verbose makefiles have been requested and the /nologo option
1796 // was not given explicitly in the flags we want to add an attribute
1797 // to the generated project to disable logo suppression. Otherwise
1798 // the GUI default is to enable suppression.
1799 if(verbose &&
1800 this->FlagMap.find("SuppressStartupBanner") == this->FlagMap.end())
1802 this->FlagMap["SuppressStartupBanner"] = "FALSE";
1806 //----------------------------------------------------------------------------
1807 void cmLocalVisualStudio7GeneratorOptions::AddDefine(const std::string& def)
1809 this->Defines.push_back(def);
1812 //----------------------------------------------------------------------------
1813 void cmLocalVisualStudio7GeneratorOptions::AddDefines(const char* defines)
1815 if(defines)
1817 // Expand the list of definitions.
1818 cmSystemTools::ExpandListArgument(defines, this->Defines);
1822 //----------------------------------------------------------------------------
1823 void cmLocalVisualStudio7GeneratorOptions::AddFlag(const char* flag,
1824 const char* value)
1826 this->FlagMap[flag] = value;
1830 bool cmLocalVisualStudio7GeneratorOptions::IsDebug()
1832 return this->FlagMap.find("DebugInformationFormat") != this->FlagMap.end();
1835 //----------------------------------------------------------------------------
1836 bool cmLocalVisualStudio7GeneratorOptions::UsingUnicode()
1838 // Look for the a _UNICODE definition.
1839 for(std::vector<std::string>::const_iterator di = this->Defines.begin();
1840 di != this->Defines.end(); ++di)
1842 if(*di == "_UNICODE")
1844 return true;
1847 return false;
1850 //----------------------------------------------------------------------------
1851 void cmLocalVisualStudio7GeneratorOptions::Parse(const char* flags)
1853 // Parse the input string as a windows command line since the string
1854 // is intended for writing directly into the build files.
1855 std::vector<std::string> args;
1856 cmSystemTools::ParseWindowsCommandLine(flags, args);
1858 // Process flags that need to be represented specially in the IDE
1859 // project file.
1860 for(std::vector<std::string>::iterator ai = args.begin();
1861 ai != args.end(); ++ai)
1863 this->HandleFlag(ai->c_str());
1867 //----------------------------------------------------------------------------
1868 void cmLocalVisualStudio7GeneratorOptions::HandleFlag(const char* flag)
1870 // If the last option was -D then this option is the definition.
1871 if(this->DoingDefine)
1873 this->DoingDefine = false;
1874 this->Defines.push_back(flag);
1875 return;
1878 // Look for known arguments.
1879 if(flag[0] == '-' || flag[0] == '/')
1881 // Look for preprocessor definitions.
1882 if(this->CurrentTool == Compiler && flag[1] == 'D')
1884 if(flag[2] == '\0')
1886 // The next argument will have the definition.
1887 this->DoingDefine = true;
1889 else
1891 // Store this definition.
1892 this->Defines.push_back(flag+2);
1894 return;
1897 // Look through the available flag tables.
1898 bool flag_handled = false;
1899 if(this->FlagTable &&
1900 this->CheckFlagTable(this->FlagTable, flag, flag_handled))
1902 return;
1904 if(this->ExtraFlagTable &&
1905 this->CheckFlagTable(this->ExtraFlagTable, flag, flag_handled))
1907 return;
1910 // If any map entry handled the flag we are done.
1911 if(flag_handled)
1913 return;
1916 // This option is not known. Store it in the output flags.
1917 this->FlagString += " ";
1918 this->FlagString +=
1919 cmSystemTools::EscapeWindowsShellArgument(flag,
1920 cmsysSystem_Shell_Flag_VSIDE);
1923 //----------------------------------------------------------------------------
1924 bool
1925 cmLocalVisualStudio7GeneratorOptions
1926 ::CheckFlagTable(cmVS7FlagTable const* table, const char* flag,
1927 bool& flag_handled)
1929 // Look for an entry in the flag table matching this flag.
1930 for(cmVS7FlagTable const* entry = table; entry->IDEName; ++entry)
1932 bool entry_found = false;
1933 if(entry->special & cmVS7FlagTable::UserValue)
1935 // This flag table entry accepts a user-specified value. If
1936 // the entry specifies UserRequired we must match only if a
1937 // non-empty value is given.
1938 int n = static_cast<int>(strlen(entry->commandFlag));
1939 if(strncmp(flag+1, entry->commandFlag, n) == 0 &&
1940 (!(entry->special & cmVS7FlagTable::UserRequired) ||
1941 static_cast<int>(strlen(flag+1)) > n))
1943 if(entry->special & cmVS7FlagTable::UserIgnored)
1945 // Ignore the user-specified value.
1946 this->FlagMap[entry->IDEName] = entry->value;
1948 else if(entry->special & cmVS7FlagTable::SemicolonAppendable)
1950 const char *new_value = flag+1+n;
1952 std::map<cmStdString,cmStdString>::iterator itr;
1953 itr = this->FlagMap.find(entry->IDEName);
1954 if(itr != this->FlagMap.end())
1956 // Append to old value (if present) with semicolons;
1957 itr->second += ";";
1958 itr->second += new_value;
1960 else
1962 this->FlagMap[entry->IDEName] = new_value;
1965 else
1967 // Use the user-specified value.
1968 this->FlagMap[entry->IDEName] = flag+1+n;
1970 entry_found = true;
1973 else if(strcmp(flag+1, entry->commandFlag) == 0)
1975 // This flag table entry provides a fixed value.
1976 this->FlagMap[entry->IDEName] = entry->value;
1977 entry_found = true;
1980 // If the flag has been handled by an entry not requesting a
1981 // search continuation we are done.
1982 if(entry_found && !(entry->special & cmVS7FlagTable::Continue))
1984 return true;
1987 // If the entry was found the flag has been handled.
1988 flag_handled = flag_handled || entry_found;
1991 return false;
1994 //----------------------------------------------------------------------------
1995 void
1996 cmLocalVisualStudio7GeneratorOptions
1997 ::OutputPreprocessorDefinitions(std::ostream& fout,
1998 const char* prefix,
1999 const char* suffix)
2001 if(this->Defines.empty())
2003 return;
2006 fout << prefix << "PreprocessorDefinitions=\"";
2007 const char* comma = "";
2008 for(std::vector<std::string>::const_iterator di = this->Defines.begin();
2009 di != this->Defines.end(); ++di)
2011 // Escape the definition for the compiler.
2012 std::string define =
2013 this->LocalGenerator->EscapeForShell(di->c_str(), true);
2015 // Escape this flag for the IDE.
2016 define = cmLocalVisualStudio7GeneratorEscapeForXML(define.c_str());
2018 // Store the flag in the project file.
2019 fout << comma << define;
2020 comma = ",";
2022 fout << "\"" << suffix;
2025 //----------------------------------------------------------------------------
2026 void
2027 cmLocalVisualStudio7GeneratorOptions
2028 ::OutputFlagMap(std::ostream& fout, const char* indent)
2030 for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
2031 m != this->FlagMap.end(); ++m)
2033 fout << indent << m->first << "=\"" << m->second << "\"\n";
2037 //----------------------------------------------------------------------------
2038 void
2039 cmLocalVisualStudio7GeneratorOptions
2040 ::OutputAdditionalOptions(std::ostream& fout,
2041 const char* prefix,
2042 const char* suffix)
2044 if(!this->FlagString.empty())
2046 fout << prefix << "AdditionalOptions=\"";
2047 fout <<
2048 cmLocalVisualStudio7GeneratorEscapeForXML(this->FlagString.c_str());
2049 fout << "\"" << suffix;
2052 void cmLocalVisualStudio7Generator::
2053 GetTargetObjectFileDirectories(cmTarget* target,
2054 std::vector<std::string>&
2055 dirs)
2057 std::string dir = this->Makefile->GetCurrentOutputDirectory();
2058 dir += "/";
2059 dir += this->GetTargetDirectory(*target);
2060 dir += "/";
2061 dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
2062 dirs.push_back(dir);
2065 //----------------------------------------------------------------------------
2066 #include <windows.h>
2067 static bool cmLVS6G_IsFAT(const char* dir)
2069 if(dir[0] && dir[1] == ':')
2071 char volRoot[4] = "_:/";
2072 volRoot[0] = dir[0];
2073 char fsName[16];
2074 if(GetVolumeInformation(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
2075 strstr(fsName, "FAT") != 0)
2077 return true;
2080 return false;