1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalVisualStudio7Generator.cxx,v $
6 Date: $Date: 2009-03-28 17:02:29 $
7 Version: $Revision: 1.238 $
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"
21 #include "cmMakefile.h"
22 #include "cmSystemTools.h"
23 #include "cmSourceFile.h"
24 #include "cmCacheManager.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
39 cmLocalVisualStudio7GeneratorInternals(cmLocalVisualStudio7Generator
* e
):
41 typedef cmComputeLinkInformation::ItemVector ItemVector
;
42 void OutputLibraries(std::ostream
& fout
, ItemVector
const& libs
);
44 cmLocalVisualStudio7Generator
* LocalGenerator
;
47 extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable
[];
49 //----------------------------------------------------------------------------
50 cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator()
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
;
71 lang
.insert("Fortran");
72 this->CreateCustomTargetsAndCommands(lang
);
73 this->FixGlobalTargets();
76 void cmLocalVisualStudio7Generator::Generate()
78 this->WriteProjectFiles();
79 this->WriteStampFiles();
82 void cmLocalVisualStudio7Generator::FixGlobalTargets()
84 // Visual Studio .NET 2003 Service Pack 1 will not run post-build
85 // commands for targets in which no sources are built. Add dummy
86 // rules to force these targets to build.
87 cmTargets
&tgts
= this->Makefile
->GetTargets();
88 for(cmTargets::iterator l
= tgts
.begin();
91 cmTarget
& tgt
= l
->second
;
92 if(tgt
.GetType() == cmTarget::GLOBAL_TARGET
)
94 std::vector
<std::string
> no_depends
;
95 cmCustomCommandLine force_command
;
96 force_command
.push_back("cd");
97 force_command
.push_back(".");
98 cmCustomCommandLines force_commands
;
99 force_commands
.push_back(force_command
);
100 const char* no_main_dependency
= 0;
101 std::string force
= this->Makefile
->GetStartOutputDirectory();
102 force
+= cmake::GetCMakeFilesDirectory();
104 force
+= tgt
.GetName();
106 this->Makefile
->AddCustomCommandToOutput(force
.c_str(), no_depends
,
108 force_commands
, " ", 0, true);
109 if(cmSourceFile
* file
=
110 this->Makefile
->GetSourceFileWithOutput(force
.c_str()))
112 tgt
.AddSourceFile(file
);
119 // for CommandLine= need to repleace quotes with "
120 // write out configurations
121 void cmLocalVisualStudio7Generator::WriteProjectFiles()
123 // If not an in source build, then create the output directory
124 if(strcmp(this->Makefile
->GetStartOutputDirectory(),
125 this->Makefile
->GetHomeDirectory()) != 0)
127 if(!cmSystemTools::MakeDirectory
128 (this->Makefile
->GetStartOutputDirectory()))
130 cmSystemTools::Error("Error creating directory ",
131 this->Makefile
->GetStartOutputDirectory());
135 // Get the set of targets in this directory.
136 cmTargets
&tgts
= this->Makefile
->GetTargets();
138 // Create the regeneration custom rule.
139 if(!this->Makefile
->IsOn("CMAKE_SUPPRESS_REGENERATION"))
141 // Create a rule to regenerate the build system when the target
142 // specification source changes.
143 if(cmSourceFile
* sf
= this->CreateVCProjBuildRule())
145 // Add the rule to targets that need it.
146 for(cmTargets::iterator l
= tgts
.begin(); l
!= tgts
.end(); ++l
)
148 if(l
->first
!= CMAKE_CHECK_BUILD_SYSTEM_TARGET
)
150 l
->second
.AddSourceFile(sf
);
156 // Create the project file for each target.
157 for(cmTargets::iterator l
= tgts
.begin();
158 l
!= tgts
.end(); l
++)
160 // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
161 // so don't build a projectfile for it
162 if (strncmp(l
->first
.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)
164 this->CreateSingleVCProj(l
->first
.c_str(),l
->second
);
169 //----------------------------------------------------------------------------
170 void cmLocalVisualStudio7Generator::WriteStampFiles()
172 // Touch a timestamp file used to determine when the project file is
174 std::string stampName
= this->Makefile
->GetStartOutputDirectory();
175 stampName
+= cmake::GetCMakeFilesDirectory();
176 cmSystemTools::MakeDirectory(stampName
.c_str());
178 stampName
+= "generate.stamp";
179 std::ofstream
stamp(stampName
.c_str());
180 stamp
<< "# CMake generation timestamp file this directory.\n";
182 // Create a helper file so CMake can determine when it is run
183 // through the rule created by CreateVCProjBuildRule whether it
184 // really needs to regenerate the project. This file lists its own
185 // dependencies. If any file listed in it is newer than itself then
186 // CMake must rerun. Otherwise the project files are up to date and
187 // the stamp file can just be touched.
188 std::string depName
= stampName
;
189 depName
+= ".depend";
190 std::ofstream
depFile(depName
.c_str());
191 depFile
<< "# CMake generation dependency list for this directory.\n";
192 std::vector
<std::string
> const& listFiles
= this->Makefile
->GetListFiles();
193 for(std::vector
<std::string
>::const_iterator lf
= listFiles
.begin();
194 lf
!= listFiles
.end(); ++lf
)
196 depFile
<< *lf
<< std::endl
;
200 //----------------------------------------------------------------------------
201 void cmLocalVisualStudio7Generator
202 ::CreateSingleVCProj(const char *lname
, cmTarget
&target
)
204 this->FortranProject
=
205 static_cast<cmGlobalVisualStudioGenerator
*>(this->GlobalGenerator
)
206 ->TargetIsFortranOnly(target
);
207 // add to the list of projects
208 std::string pname
= lname
;
209 target
.SetProperty("GENERATOR_FILE_NAME",lname
);
210 // create the dsp.cmake file
212 fname
= this->Makefile
->GetStartOutputDirectory();
215 if(this->FortranProject
)
224 // Generate the project file and replace it atomically with
225 // copy-if-different. We use a separate timestamp so that the IDE
226 // does not reload project files unnecessarily.
227 cmGeneratedFileStream
fout(fname
.c_str());
228 fout
.SetCopyIfDifferent(true);
229 this->WriteVCProjFile(fout
,lname
,target
);
232 this->GlobalGenerator
->FileReplacedDuringGenerate(fname
);
236 //----------------------------------------------------------------------------
237 cmSourceFile
* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
239 std::string stampName
= cmake::GetCMakeFilesDirectoryPostSlash();
240 stampName
+= "generate.stamp";
241 const char* dsprule
=
242 this->Makefile
->GetRequiredDefinition("CMAKE_COMMAND");
243 cmCustomCommandLine commandLine
;
244 commandLine
.push_back(dsprule
);
245 std::string makefileIn
= this->Makefile
->GetStartDirectory();
247 makefileIn
+= "CMakeLists.txt";
248 makefileIn
= cmSystemTools::CollapseFullPath(makefileIn
.c_str());
249 std::string comment
= "Building Custom Rule ";
250 comment
+= makefileIn
;
253 args
+= this->Convert(this->Makefile
->GetHomeDirectory(),
254 START_OUTPUT
, UNCHANGED
, true);
255 commandLine
.push_back(args
);
258 this->Convert(this->Makefile
->GetHomeOutputDirectory(),
259 START_OUTPUT
, UNCHANGED
, true);
260 commandLine
.push_back(args
);
261 commandLine
.push_back("--check-stamp-file");
262 commandLine
.push_back(stampName
.c_str());
264 std::vector
<std::string
> const& listFiles
= this->Makefile
->GetListFiles();
266 cmCustomCommandLines commandLines
;
267 commandLines
.push_back(commandLine
);
268 const char* no_working_directory
= 0;
269 this->Makefile
->AddCustomCommandToOutput(stampName
.c_str(), listFiles
,
270 makefileIn
.c_str(), commandLines
,
272 no_working_directory
, true);
273 if(cmSourceFile
* file
= this->Makefile
->GetSource(makefileIn
.c_str()))
279 cmSystemTools::Error("Error adding rule for ", makefileIn
.c_str());
284 void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream
& fout
,
288 std::vector
<std::string
> *configs
=
289 static_cast<cmGlobalVisualStudio7Generator
*>
290 (this->GlobalGenerator
)->GetConfigurations();
292 fout
<< "\t<Configurations>\n";
293 for( std::vector
<std::string
>::iterator i
= configs
->begin();
294 i
!= configs
->end(); ++i
)
296 this->WriteConfiguration(fout
, i
->c_str(), libName
, target
);
298 fout
<< "\t</Configurations>\n";
300 cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranFlagTable
[] =
302 {"Preprocess", "fpp", "Run Preprocessor on files", "preprocessYes", 0},
303 {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
304 {"DebugInformationFormat", "Zi", "full debug", "debugEnabled", 0},
305 {"DebugInformationFormat", "debug:full", "full debug", "debugEnabled", 0},
306 {"DebugInformationFormat", "Z7", "c7 compat", "debugOldStyleInfo", 0},
307 {"DebugInformationFormat", "Zd", "line numbers", "debugLineInfoOnly", 0},
308 {"Optimization", "Od", "disable optimization", "optimizeDisabled", 0},
309 {"Optimization", "O1", "min space", "optimizeMinSpace", 0},
310 {"Optimization", "O3", "full optimize", "optimizeFull", 0},
311 {"GlobalOptimizations", "Og", "global optimize", "true", 0},
312 {"InlineFunctionExpansion", "Ob0", "", "expandDisable", 0},
313 {"InlineFunctionExpansion", "Ob1", "", "expandOnlyInline", 0},
314 {"FavorSizeOrSpeed", "Os", "", "favorSize", 0},
315 {"OmitFramePointers", "Oy-", "", "false", 0},
316 {"OptimizeForProcessor", "GB", "", "procOptimizeBlended", 0},
317 {"OptimizeForProcessor", "G5", "", "procOptimizePentium", 0},
318 {"OptimizeForProcessor", "G6", "", "procOptimizePentiumProThruIII", 0},
319 {"UseProcessorExtensions", "QzxK", "", "codeForStreamingSIMD", 0},
320 {"OptimizeForProcessor", "QaxN", "", "codeForPentium4", 0},
321 {"OptimizeForProcessor", "QaxB", "", "codeForPentiumM", 0},
322 {"OptimizeForProcessor", "QaxP", "", "codeForCodeNamedPrescott", 0},
323 {"OptimizeForProcessor", "QaxT", "", "codeForCore2Duo", 0},
324 {"OptimizeForProcessor", "QxK", "", "codeExclusivelyStreamingSIMD", 0},
325 {"OptimizeForProcessor", "QxN", "", "codeExclusivelyPentium4", 0},
326 {"OptimizeForProcessor", "QxB", "", "codeExclusivelyPentiumM", 0},
327 {"OptimizeForProcessor", "QxP", "", "codeExclusivelyCodeNamedPrescott", 0},
328 {"OptimizeForProcessor", "QxT", "", "codeExclusivelyCore2Duo", 0},
329 {"OptimizeForProcessor", "QxO", "", "codeExclusivelyCore2StreamingSIMD", 0},
330 {"OptimizeForProcessor", "QxS", "", "codeExclusivelyCore2StreamingSIMD4", 0},
332 {"ModulePath", "module:", "", "",
333 cmVS7FlagTable::UserValueRequired
},
334 {"LoopUnrolling", "Qunroll:", "", "",
335 cmVS7FlagTable::UserValueRequired
},
336 {"AutoParallelThreshold", "Qpar-threshold:", "", "",
337 cmVS7FlagTable::UserValueRequired
},
338 {"HeapArrays", "heap-arrays:", "", "",
339 cmVS7FlagTable::UserValueRequired
},
340 {"ObjectText", "bintext:", "", "",
341 cmVS7FlagTable::UserValueRequired
},
342 {"Parallelization", "Qparallel", "", "true", 0},
343 {"PrefetchInsertion", "Qprefetch-", "", "false", 0},
344 {"BufferedIO", "assume:buffered_io", "", "true", 0},
345 {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
346 {"CallingConvention", "iface:cref", "", "callConventionCRef", 0},
347 {"CallingConvention", "iface:stdref", "", "callConventionStdRef", 0},
348 {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
349 {"CallingConvention", "iface:cvf", "", "callConventionCVF", 0},
350 {"EnableRecursion", "recursive", "", "true", 0},
351 {"ReentrantCode", "reentrancy", "", "true", 0},
352 // done up to Language
355 // fill the table here currently the comment field is not used for
356 // anything other than documentation NOTE: Make sure the longer
357 // commandFlag comes FIRST!
358 cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable
[] =
360 // option flags (some flags map to the same option)
361 {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
362 {"BasicRuntimeChecks", "RTCsu",
363 "Both stack and uninitialized checks", "3", 0},
364 {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
365 {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
366 {"BasicRuntimeChecks", "RTC1",
367 "Both stack and uninitialized checks", "3", 0},
368 {"DebugInformationFormat", "Z7", "debug format", "1", 0},
369 {"DebugInformationFormat", "Zd", "debug format", "2", 0},
370 {"DebugInformationFormat", "Zi", "debug format", "3", 0},
371 {"DebugInformationFormat", "ZI", "debug format", "4", 0},
372 {"EnableEnhancedInstructionSet", "arch:SSE2",
373 "Use sse2 instructions", "2", 0},
374 {"EnableEnhancedInstructionSet", "arch:SSE",
375 "Use sse instructions", "1", 0},
376 {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
377 {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
378 {"CompileAs", "TC", "Compile as c code", "1", 0},
379 {"CompileAs", "TP", "Compile as c++ code", "2", 0},
380 {"Optimization", "Od", "Non Debug", "0", 0},
381 {"Optimization", "O1", "Min Size", "1", 0},
382 {"Optimization", "O2", "Max Speed", "2", 0},
383 {"Optimization", "Ox", "Max Optimization", "3", 0},
384 {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
385 {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
386 {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
387 {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
388 {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
389 {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
390 {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
391 {"RuntimeLibrary", "MTd", "Multithreded debug", "1", 0},
392 {"RuntimeLibrary", "MT", "Multithreded", "0", 0},
393 {"RuntimeLibrary", "MDd", "Multithreded dll debug", "3", 0},
394 {"RuntimeLibrary", "MD", "Multithreded dll", "2", 0},
395 {"RuntimeLibrary", "MLd", "Sinble Thread debug", "5", 0},
396 {"RuntimeLibrary", "ML", "Sinble Thread", "4", 0},
397 {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
398 {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
399 {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
400 {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
401 {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
402 {"WarningLevel", "W0", "Warning level", "0", 0},
403 {"WarningLevel", "W1", "Warning level", "1", 0},
404 {"WarningLevel", "W2", "Warning level", "2", 0},
405 {"WarningLevel", "W3", "Warning level", "3", 0},
406 {"WarningLevel", "W4", "Warning level", "4", 0},
407 {"DisableSpecificWarnings", "wd", "Disable specific warnings", "",
408 cmVS7FlagTable::UserValue
| cmVS7FlagTable::SemicolonAppendable
},
410 // Precompiled header and related options. Note that the
411 // UsePrecompiledHeader entries are marked as "Continue" so that the
412 // corresponding PrecompiledHeaderThrough entry can be found.
413 {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
414 cmVS7FlagTable::UserValueIgnored
| cmVS7FlagTable::Continue
},
415 {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
416 cmVS7FlagTable::UserValueRequired
},
417 {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
418 cmVS7FlagTable::UserValue
},
419 // The YX and Yu options are in a per-global-generator table because
420 // their values differ based on the VS IDE version.
421 {"ForcedIncludeFiles", "FI", "Forced include files", "",
422 cmVS7FlagTable::UserValueRequired
},
425 {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE", 0},
426 {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "FALSE", 0},
427 {"Detect64BitPortabilityProblems", "Wp64",
428 "Detect 64-bit Portability Problems", "TRUE", 0},
429 {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
431 {"EnableFunctionLevelLinking", "Gy",
432 "EnableFunctionLevelLinking", "TRUE", 0},
433 {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE", 0},
434 {"GlobalOptimizations", "Og", "Global Optimize", "TRUE", 0},
435 {"ImproveFloatingPointConsistency", "Op",
436 "ImproveFloatingPointConsistency", "TRUE", 0},
437 {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE", 0},
438 {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE", 0},
439 {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE", 0},
440 {"RuntimeTypeInfo", "GR",
441 "Turn on Run time type information for c++", "TRUE", 0},
442 {"RuntimeTypeInfo", "GR-",
443 "Turn off Run time type information for c++", "FALSE", 0},
444 {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE", 0},
445 {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "TRUE", 0},
446 {"WarnAsError", "WX", "Treat warnings as errors", "TRUE", 0},
452 cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable
[] =
454 // option flags (some flags map to the same option)
455 {"GenerateManifest", "MANIFEST:NO",
456 "disable manifest generation", "FALSE", 0},
457 {"GenerateManifest", "MANIFEST", "enable manifest generation", "TRUE", 0},
458 {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
459 {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
460 {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
461 cmVS7FlagTable::UserValue
| cmVS7FlagTable::SemicolonAppendable
},
462 {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
464 {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
465 {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
467 {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
469 {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
470 {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
471 {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
472 {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
473 {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
474 {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
475 {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
476 cmVS7FlagTable::UserValue
},
477 {"GenerateMapFile", "MAP", "enable generation of map file", "TRUE", 0},
481 //----------------------------------------------------------------------------
482 class cmLocalVisualStudio7GeneratorOptions
485 // Construct an options table for a given tool.
492 cmLocalVisualStudio7GeneratorOptions(cmLocalVisualStudio7Generator
* lg
,
495 cmVS7FlagTable
const* extraTable
= 0);
497 // Store options from command line flags.
498 void Parse(const char* flags
);
500 // Fix the ExceptionHandling option to default to off.
501 void FixExceptionHandlingDefault();
503 // Store options for verbose builds.
504 void SetVerboseMakefile(bool verbose
);
506 // Store definitions and flags.
507 void AddDefine(const std::string
& define
);
508 void AddDefines(const char* defines
);
509 void AddFlag(const char* flag
, const char* value
);
511 // Check for specific options.
515 // Write options to output.
516 void OutputPreprocessorDefinitions(std::ostream
& fout
,
519 void OutputFlagMap(std::ostream
& fout
, const char* indent
);
520 void OutputAdditionalOptions(std::ostream
& fout
,
525 cmLocalVisualStudio7Generator
* LocalGenerator
;
528 // create a map of xml tags to the values they should have in the output
529 // for example, "BufferSecurityCheck" = "TRUE"
530 // first fill this table with the values for the configuration
531 // Debug, Release, etc,
532 // Then parse the command line flags specified in CMAKE_CXX_FLAGS
534 // and overwrite or add new values to this map
535 std::map
<cmStdString
, cmStdString
> FlagMap
;
537 // Preprocessor definitions.
538 std::vector
<std::string
> Defines
;
540 // Unrecognized flags that get no special handling.
541 cmStdString FlagString
;
545 cmVS7FlagTable
const* FlagTable
;
546 cmVS7FlagTable
const* ExtraFlagTable
;
547 void HandleFlag(const char* flag
);
548 bool CheckFlagTable(cmVS7FlagTable
const* table
, const char* flag
,
552 void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream
& fout
,
553 const char* configName
,
557 const char* mfcFlag
= this->Makefile
->GetDefinition("CMAKE_MFC_FLAG");
562 fout
<< "\t\t<Configuration\n"
563 << "\t\t\tName=\"" << configName
<< "|" << this->PlatformName
<< "\"\n"
564 << "\t\t\tOutputDirectory=\"" << configName
<< "\"\n";
565 // This is an internal type to Visual Studio, it seems that:
566 // 4 == static library
570 const char* configType
= "10";
571 const char* projectType
= 0;
572 switch(target
.GetType())
574 case cmTarget::STATIC_LIBRARY
:
575 projectType
= "typeStaticLibrary";
578 case cmTarget::SHARED_LIBRARY
:
579 case cmTarget::MODULE_LIBRARY
:
580 projectType
= "typeDynamicLibrary";
583 case cmTarget::EXECUTABLE
:
586 case cmTarget::UTILITY
:
587 case cmTarget::GLOBAL_TARGET
:
592 if(this->FortranProject
&& projectType
)
594 configType
= projectType
;
597 if(strcmp(configType
, "10") != 0)
599 const char* linkLanguage
=
600 target
.GetLinkerLanguage(this->GetGlobalGenerator());
604 ("CMake can not determine linker language for target:",
608 if(strcmp(linkLanguage
, "C") == 0 || strcmp(linkLanguage
, "CXX") == 0
609 || strcmp(linkLanguage
, "Fortran") == 0)
611 std::string baseFlagVar
= "CMAKE_";
612 baseFlagVar
+= linkLanguage
;
613 baseFlagVar
+= "_FLAGS";
614 flags
= this->Makefile
->GetRequiredDefinition(baseFlagVar
.c_str());
615 std::string flagVar
= baseFlagVar
+ std::string("_") +
616 cmSystemTools::UpperCase(configName
);
618 flags
+= this->Makefile
->GetRequiredDefinition(flagVar
.c_str());
620 // set the correct language
621 if(strcmp(linkLanguage
, "C") == 0)
625 if(strcmp(linkLanguage
, "CXX") == 0)
631 // Add the target-specific flags.
632 if(const char* targetFlags
= target
.GetProperty("COMPILE_FLAGS"))
635 flags
+= targetFlags
;
638 std::string configUpper
= cmSystemTools::UpperCase(configName
);
639 std::string defPropName
= "COMPILE_DEFINITIONS_";
640 defPropName
+= configUpper
;
642 // Get preprocessor definitions for this directory.
643 std::string defineFlags
= this->Makefile
->GetDefineFlags();
644 Options::Tool t
= Options::Compiler
;
645 if(this->FortranProject
)
647 t
= Options::FortranCompiler
;
649 Options
targetOptions(this, this->Version
, t
, this->ExtraFlagTable
);
650 targetOptions
.FixExceptionHandlingDefault();
651 targetOptions
.Parse(flags
.c_str());
652 targetOptions
.Parse(defineFlags
.c_str());
653 targetOptions
.AddDefines
654 (this->Makefile
->GetProperty("COMPILE_DEFINITIONS"));
655 targetOptions
.AddDefines(target
.GetProperty("COMPILE_DEFINITIONS"));
656 targetOptions
.AddDefines(this->Makefile
->GetProperty(defPropName
.c_str()));
657 targetOptions
.AddDefines(target
.GetProperty(defPropName
.c_str()));
658 targetOptions
.SetVerboseMakefile(
659 this->Makefile
->IsOn("CMAKE_VERBOSE_MAKEFILE"));
661 // Add a definition for the configuration name.
662 std::string configDefine
= "CMAKE_INTDIR=\"";
663 configDefine
+= configName
;
664 configDefine
+= "\"";
665 targetOptions
.AddDefine(configDefine
);
667 // Add the export symbol definition for shared library objects.
668 if(const char* exportMacro
= target
.GetExportMacro())
670 targetOptions
.AddDefine(exportMacro
);
673 // The intermediate directory name consists of a directory for the
674 // target and a subdirectory for the configuration name.
675 std::string intermediateDir
= this->GetTargetDirectory(target
);
676 intermediateDir
+= "/";
677 intermediateDir
+= configName
;
678 fout
<< "\t\t\tIntermediateDirectory=\""
679 << this->ConvertToXMLOutputPath(intermediateDir
.c_str())
681 << "\t\t\tConfigurationType=\"" << configType
<< "\"\n"
682 << "\t\t\tUseOfMFC=\"" << mfcFlag
<< "\"\n"
683 << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
685 // If unicode is enabled change the character set to unicode, if not
686 // then default to MBCS.
687 if(targetOptions
.UsingUnicode())
689 fout
<< "\t\t\tCharacterSet=\"1\">\n";
693 fout
<< "\t\t\tCharacterSet=\"2\">\n";
695 const char* tool
= "VCCLCompilerTool";
696 if(this->FortranProject
)
698 tool
= "VFFortranCompilerTool";
700 fout
<< "\t\t\t<Tool\n"
701 << "\t\t\t\tName=\"" << tool
<< "\"\n";
702 if(this->FortranProject
)
704 const char* target_mod_dir
=
705 target
.GetProperty("Fortran_MODULE_DIRECTORY");
709 modDir
= this->Convert(target_mod_dir
,
710 cmLocalGenerator::START_OUTPUT
,
711 cmLocalGenerator::UNCHANGED
);
717 fout
<< "\t\t\t\tModulePath=\""
718 << this->ConvertToXMLOutputPath(modDir
.c_str())
719 << "\\$(ConfigurationName)\"\n";
721 targetOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t", "\n");
722 fout
<< "\t\t\t\tAdditionalIncludeDirectories=\"";
723 std::vector
<std::string
> includes
;
724 this->GetIncludeDirectories(includes
);
725 std::vector
<std::string
>::iterator i
= includes
.begin();
726 for(;i
!= includes
.end(); ++i
)
728 // output the include path
729 std::string ipath
= this->ConvertToXMLOutputPath(i
->c_str());
730 fout
<< ipath
<< ";";
731 // if this is fortran then output the include with
732 // a ConfigurationName on the end of it.
733 if(this->FortranProject
)
736 ipath
+= "/$(ConfigurationName)";
737 ipath
= this->ConvertToXMLOutputPath(ipath
.c_str());
738 fout
<< ipath
<< ";";
742 targetOptions
.OutputFlagMap(fout
, "\t\t\t\t");
743 targetOptions
.OutputPreprocessorDefinitions(fout
, "\t\t\t\t", "\n");
744 fout
<< "\t\t\t\tAssemblerListingLocation=\"" << configName
<< "\"\n";
745 fout
<< "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
746 if(target
.GetType() == cmTarget::EXECUTABLE
||
747 target
.GetType() == cmTarget::STATIC_LIBRARY
||
748 target
.GetType() == cmTarget::SHARED_LIBRARY
||
749 target
.GetType() == cmTarget::MODULE_LIBRARY
)
751 // We need to specify a program database file name even for
752 // non-debug configurations because VS still creates .idb files.
753 fout
<< "\t\t\t\tProgramDataBaseFileName=\""
754 << target
.GetDirectory(configName
) << "/"
755 << target
.GetPDBName(configName
) << "\"\n";
757 fout
<< "/>\n"; // end of <Tool Name=VCCLCompilerTool
758 tool
= "VCCustomBuildTool";
759 if(this->FortranProject
)
761 tool
= "VFCustomBuildTool";
763 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"/>\n";
764 tool
= "VCResourceCompilerTool";
765 if(this->FortranProject
)
767 tool
= "VFResourceCompilerTool";
769 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"\n"
770 << "\t\t\t\tAdditionalIncludeDirectories=\"";
771 for(i
= includes
.begin();i
!= includes
.end(); ++i
)
773 std::string ipath
= this->ConvertToXMLOutputPath(i
->c_str());
774 fout
<< ipath
<< ";";
776 // add the -D flags to the RC tool
778 targetOptions
.OutputPreprocessorDefinitions(fout
, "\n\t\t\t\t", "");
781 if(this->FortranProject
)
785 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"\n";
786 targetOptions
.OutputPreprocessorDefinitions(fout
, "\t\t\t\t", "\n");
787 fout
<< "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
788 if( this->PlatformName
== "x64" )
790 fout
<< "\t\t\t\tTargetEnvironment=\"3\"\n";
792 else if( this->PlatformName
== "ia64" )
794 fout
<< "\t\t\t\tTargetEnvironment=\"2\"\n";
798 fout
<< "\t\t\t\tTargetEnvironment=\"1\"\n";
800 fout
<< "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
801 fout
<< "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
802 fout
<< "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
803 fout
<< "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
804 fout
<< "\t\t\t\tDLLDataFileName=\"\"\n";
805 fout
<< "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
806 fout
<< "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
807 // end of <Tool Name=VCMIDLTool
809 // Check if we need the FAT32 workaround.
810 if ( this->Version
>= 8 )
812 // Check the filesystem type where the target will be written.
813 if(cmLVS6G_IsFAT(target
.GetDirectory(configName
).c_str()))
815 // Add a flag telling the manifest tool to use a workaround
816 // for FAT32 file systems, which can cause an empty manifest
817 // to be embedded into the resulting executable. See CMake
819 const char* tool
= "VCManifestTool";
820 if(this->FortranProject
)
822 tool
= "VFManifestTool";
824 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"\n"
825 << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
830 this->OutputTargetRules(fout
, configName
, target
, libName
);
831 this->OutputBuildTool(fout
, configName
, target
, targetOptions
.IsDebug());
832 fout
<< "\t\t</Configuration>\n";
835 //----------------------------------------------------------------------------
837 cmLocalVisualStudio7Generator
838 ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags
, const char* configName
)
840 std::string configTypeUpper
= cmSystemTools::UpperCase(configName
);
841 std::string extraLinkOptionsBuildTypeDef
=
842 rootLinkerFlags
+ "_" + configTypeUpper
;
844 std::string extraLinkOptionsBuildType
=
845 this->Makefile
->GetRequiredDefinition
846 (extraLinkOptionsBuildTypeDef
.c_str());
848 return extraLinkOptionsBuildType
;
851 void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream
& fout
,
852 const char* configName
,
857 std::string extraLinkOptions
;
858 if(target
.GetType() == cmTarget::EXECUTABLE
)
861 this->Makefile
->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
863 + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName
);
865 if(target
.GetType() == cmTarget::SHARED_LIBRARY
)
868 this->Makefile
->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
870 + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName
);
872 if(target
.GetType() == cmTarget::MODULE_LIBRARY
)
875 this->Makefile
->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
877 + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName
);
880 const char* targetLinkFlags
= target
.GetProperty("LINK_FLAGS");
883 extraLinkOptions
+= " ";
884 extraLinkOptions
+= targetLinkFlags
;
886 std::string configTypeUpper
= cmSystemTools::UpperCase(configName
);
887 std::string linkFlagsConfig
= "LINK_FLAGS_";
888 linkFlagsConfig
+= configTypeUpper
;
889 targetLinkFlags
= target
.GetProperty(linkFlagsConfig
.c_str());
892 extraLinkOptions
+= " ";
893 extraLinkOptions
+= targetLinkFlags
;
895 Options
linkOptions(this, this->Version
, Options::Linker
);
896 linkOptions
.Parse(extraLinkOptions
.c_str());
897 switch(target
.GetType())
899 case cmTarget::STATIC_LIBRARY
:
901 std::string targetNameFull
= target
.GetFullName(configName
);
902 std::string libpath
= target
.GetDirectory(configName
);
904 libpath
+= targetNameFull
;
905 const char* tool
= "VCLibrarianTool";
906 if(this->FortranProject
)
908 tool
= "VFLibrarianTool";
910 fout
<< "\t\t\t<Tool\n"
911 << "\t\t\t\tName=\"" << tool
<< "\"\n";
912 if(const char* libflags
= target
.GetProperty("STATIC_LIBRARY_FLAGS"))
914 fout
<< "\t\t\t\tAdditionalOptions=\"" << libflags
<< "\"\n";
916 fout
<< "\t\t\t\tOutputFile=\""
917 << this->ConvertToXMLOutputPathSingle(libpath
.c_str()) << "\"/>\n";
920 case cmTarget::SHARED_LIBRARY
:
921 case cmTarget::MODULE_LIBRARY
:
923 std::string targetName
;
924 std::string targetNameSO
;
925 std::string targetNameFull
;
926 std::string targetNameImport
;
927 std::string targetNamePDB
;
928 target
.GetLibraryNames(targetName
, targetNameSO
, targetNameFull
,
929 targetNameImport
, targetNamePDB
, configName
);
931 // Compute the link library and directory information.
932 cmComputeLinkInformation
* pcli
= target
.GetLinkInformation(configName
);
937 cmComputeLinkInformation
& cli
= *pcli
;
938 const char* linkLanguage
= cli
.GetLinkLanguage();
940 // Compute the variable name to lookup standard libraries for this
942 std::string standardLibsVar
= "CMAKE_";
943 standardLibsVar
+= linkLanguage
;
944 standardLibsVar
+= "_STANDARD_LIBRARIES";
945 const char* tool
= "VCLinkerTool";
946 if(this->FortranProject
)
948 tool
= "VFLinkerTool";
950 fout
<< "\t\t\t<Tool\n"
951 << "\t\t\t\tName=\"" << tool
<< "\"\n";
952 linkOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t", "\n");
953 // Use the NOINHERIT macro to avoid getting VS project default
954 // libraries which may be set by the user to something bad.
955 fout
<< "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
956 << this->Makefile
->GetSafeDefinition(standardLibsVar
.c_str())
958 this->Internal
->OutputLibraries(fout
, cli
.GetItems());
960 temp
= target
.GetDirectory(configName
);
962 temp
+= targetNameFull
;
963 fout
<< "\t\t\t\tOutputFile=\""
964 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"\n";
965 this->WriteTargetVersionAttribute(fout
, target
);
966 linkOptions
.OutputFlagMap(fout
, "\t\t\t\t");
967 fout
<< "\t\t\t\tAdditionalLibraryDirectories=\"";
968 this->OutputLibraryDirectories(fout
, cli
.GetDirectories());
970 this->OutputModuleDefinitionFile(fout
, target
);
971 temp
= target
.GetDirectory(configName
);
973 temp
+= targetNamePDB
;
974 fout
<< "\t\t\t\tProgramDataBaseFile=\"" <<
975 this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"\n";
978 fout
<< "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
980 std::string stackVar
= "CMAKE_";
981 stackVar
+= linkLanguage
;
982 stackVar
+= "_STACK_SIZE";
983 const char* stackVal
= this->Makefile
->GetDefinition(stackVar
.c_str());
986 fout
<< "\t\t\t\tStackReserveSize=\"" << stackVal
<< "\"\n";
988 temp
= target
.GetDirectory(configName
, true);
990 temp
+= targetNameImport
;
991 fout
<< "\t\t\t\tImportLibrary=\""
992 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"/>\n";
995 case cmTarget::EXECUTABLE
:
997 std::string targetName
;
998 std::string targetNameFull
;
999 std::string targetNameImport
;
1000 std::string targetNamePDB
;
1001 target
.GetExecutableNames(targetName
, targetNameFull
,
1002 targetNameImport
, targetNamePDB
, configName
);
1004 // Compute the link library and directory information.
1005 cmComputeLinkInformation
* pcli
= target
.GetLinkInformation(configName
);
1010 cmComputeLinkInformation
& cli
= *pcli
;
1011 const char* linkLanguage
= cli
.GetLinkLanguage();
1013 // Compute the variable name to lookup standard libraries for this
1015 std::string standardLibsVar
= "CMAKE_";
1016 standardLibsVar
+= linkLanguage
;
1017 standardLibsVar
+= "_STANDARD_LIBRARIES";
1018 const char* tool
= "VCLinkerTool";
1019 if(this->FortranProject
)
1021 tool
= "VFLinkerTool";
1023 fout
<< "\t\t\t<Tool\n"
1024 << "\t\t\t\tName=\"" << tool
<< "\"\n";
1025 linkOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t", "\n");
1026 // Use the NOINHERIT macro to avoid getting VS project default
1027 // libraries which may be set by the user to something bad.
1028 fout
<< "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
1029 << this->Makefile
->GetSafeDefinition(standardLibsVar
.c_str())
1031 this->Internal
->OutputLibraries(fout
, cli
.GetItems());
1033 temp
= target
.GetDirectory(configName
);
1035 temp
+= targetNameFull
;
1036 fout
<< "\t\t\t\tOutputFile=\""
1037 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"\n";
1038 this->WriteTargetVersionAttribute(fout
, target
);
1039 linkOptions
.OutputFlagMap(fout
, "\t\t\t\t");
1040 fout
<< "\t\t\t\tAdditionalLibraryDirectories=\"";
1041 this->OutputLibraryDirectories(fout
, cli
.GetDirectories());
1043 fout
<< "\t\t\t\tProgramDataBaseFile=\""
1044 << target
.GetDirectory(configName
) << "/" << targetNamePDB
1048 fout
<< "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
1050 if ( target
.GetPropertyAsBool("WIN32_EXECUTABLE") )
1052 fout
<< "\t\t\t\tSubSystem=\"2\"\n";
1056 fout
<< "\t\t\t\tSubSystem=\"1\"\n";
1058 std::string stackVar
= "CMAKE_";
1059 stackVar
+= linkLanguage
;
1060 stackVar
+= "_STACK_SIZE";
1061 const char* stackVal
= this->Makefile
->GetDefinition(stackVar
.c_str());
1064 fout
<< "\t\t\t\tStackReserveSize=\"" << stackVal
<< "\"";
1066 temp
= target
.GetDirectory(configName
, true);
1068 temp
+= targetNameImport
;
1069 fout
<< "\t\t\t\tImportLibrary=\""
1070 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"/>\n";
1073 case cmTarget::UTILITY
:
1074 case cmTarget::GLOBAL_TARGET
:
1079 //----------------------------------------------------------------------------
1081 cmLocalVisualStudio7Generator
1082 ::WriteTargetVersionAttribute(std::ostream
& fout
, cmTarget
& target
)
1086 target
.GetTargetVersion(major
, minor
);
1087 fout
<< "\t\t\t\tVersion=\"" << major
<< "." << minor
<< "\"\n";
1090 void cmLocalVisualStudio7Generator
1091 ::OutputModuleDefinitionFile(std::ostream
& fout
,
1094 std::vector
<cmSourceFile
*> const& classes
= target
.GetSourceFiles();
1095 for(std::vector
<cmSourceFile
*>::const_iterator i
= classes
.begin();
1096 i
!= classes
.end(); i
++)
1098 cmSourceFile
* sf
= *i
;
1099 if(cmSystemTools::UpperCase(sf
->GetExtension()) == "DEF")
1101 fout
<< "\t\t\t\tModuleDefinitionFile=\""
1102 << this->ConvertToXMLOutputPath(sf
->GetFullPath().c_str())
1110 //----------------------------------------------------------------------------
1112 cmLocalVisualStudio7GeneratorInternals
1113 ::OutputLibraries(std::ostream
& fout
, ItemVector
const& libs
)
1115 cmLocalVisualStudio7Generator
* lg
= this->LocalGenerator
;
1116 for(ItemVector::const_iterator l
= libs
.begin(); l
!= libs
.end(); ++l
)
1120 std::string rel
= lg
->Convert(l
->Value
.c_str(),
1121 cmLocalGenerator::START_OUTPUT
,
1122 cmLocalGenerator::UNCHANGED
);
1123 fout
<< lg
->ConvertToXMLOutputPath(rel
.c_str()) << " ";
1127 fout
<< l
->Value
<< " ";
1132 //----------------------------------------------------------------------------
1134 cmLocalVisualStudio7Generator
1135 ::OutputLibraryDirectories(std::ostream
& fout
,
1136 std::vector
<std::string
> const& dirs
)
1138 const char* comma
= "";
1139 for(std::vector
<std::string
>::const_iterator d
= dirs
.begin();
1140 d
!= dirs
.end(); ++d
)
1142 // Remove any trailing slash and skip empty paths.
1143 std::string dir
= *d
;
1144 if(dir
[dir
.size()-1] == '/')
1146 dir
= dir
.substr(0, dir
.size()-1);
1153 // Switch to a relative path specification if it is shorter.
1154 if(cmSystemTools::FileIsFullPath(dir
.c_str()))
1156 std::string rel
= this->Convert(dir
.c_str(), START_OUTPUT
, UNCHANGED
);
1157 if(rel
.size() < dir
.size())
1163 // First search a configuration-specific subdirectory and then the
1164 // original directory.
1165 fout
<< comma
<< this->ConvertToXMLOutputPath((dir
+"/$(OutDir)").c_str())
1166 << "," << this->ConvertToXMLOutputPath(dir
.c_str());
1171 void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream
& fout
,
1172 const char *libName
,
1175 // get the configurations
1176 std::vector
<std::string
> *configs
=
1177 static_cast<cmGlobalVisualStudio7Generator
*>
1178 (this->GlobalGenerator
)->GetConfigurations();
1180 // We may be modifying the source groups temporarily, so make a copy.
1181 std::vector
<cmSourceGroup
> sourceGroups
= this->Makefile
->GetSourceGroups();
1183 // get the classes from the source lists then add them to the groups
1184 std::vector
<cmSourceFile
*>const & classes
= target
.GetSourceFiles();
1185 for(std::vector
<cmSourceFile
*>::const_iterator i
= classes
.begin();
1186 i
!= classes
.end(); i
++)
1188 // Add the file to the list of sources.
1189 std::string source
= (*i
)->GetFullPath();
1190 if(cmSystemTools::UpperCase((*i
)->GetExtension()) == "DEF")
1192 this->ModuleDefinitionFile
= (*i
)->GetFullPath();
1194 cmSourceGroup
& sourceGroup
=
1195 this->Makefile
->FindSourceGroup(source
.c_str(), sourceGroups
);
1196 sourceGroup
.AssignSource(*i
);
1199 // Compute which sources need unique object computation.
1200 this->ComputeObjectNameRequirements(sourceGroups
);
1203 this->WriteProjectStart(fout
, libName
, target
, sourceGroups
);
1204 // write the configuration information
1205 this->WriteConfigurations(fout
, libName
, target
);
1207 fout
<< "\t<Files>\n";
1210 // Loop through every source group.
1211 for(unsigned int i
= 0; i
< sourceGroups
.size(); ++i
)
1213 cmSourceGroup sg
= sourceGroups
[i
];
1214 this->WriteGroup(&sg
, target
, fout
, libName
, configs
);
1219 fout
<< "\t</Files>\n";
1221 // Write the VCProj file's footer.
1222 this->WriteVCProjFooter(fout
);
1225 struct cmLVS7GFileConfig
1227 std::string ObjectName
;
1228 std::string CompileFlags
;
1229 std::string CompileDefs
;
1230 std::string CompileDefsConfig
;
1231 std::string AdditionalDeps
;
1232 bool ExcludedFromBuild
;
1235 class cmLocalVisualStudio7GeneratorFCInfo
1238 cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator
* lg
,
1240 cmSourceFile
const& sf
,
1241 std::vector
<std::string
>* configs
,
1242 std::string
const& dir_max
);
1243 std::map
<cmStdString
, cmLVS7GFileConfig
> FileConfigMap
;
1246 cmLocalVisualStudio7GeneratorFCInfo
1247 ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator
* lg
,
1249 cmSourceFile
const& sf
,
1250 std::vector
<std::string
>* configs
,
1251 std::string
const& dir_max
)
1253 std::string objectName
;
1254 if(lg
->NeedObjectName
.find(&sf
) != lg
->NeedObjectName
.end())
1256 objectName
= lg
->GetObjectFileNameWithoutTarget(sf
, dir_max
);
1259 // Compute per-source, per-config information.
1260 for(std::vector
<std::string
>::iterator i
= configs
->begin();
1261 i
!= configs
->end(); ++i
)
1263 std::string configUpper
= cmSystemTools::UpperCase(*i
);
1264 cmLVS7GFileConfig fc
;
1265 bool needfc
= false;
1266 if(!objectName
.empty())
1268 fc
.ObjectName
= objectName
;
1271 if(const char* cflags
= sf
.GetProperty("COMPILE_FLAGS"))
1273 fc
.CompileFlags
= cflags
;
1276 if(const char* cdefs
= sf
.GetProperty("COMPILE_DEFINITIONS"))
1278 fc
.CompileDefs
= cdefs
;
1281 std::string defPropName
= "COMPILE_DEFINITIONS_";
1282 defPropName
+= configUpper
;
1283 if(const char* ccdefs
= sf
.GetProperty(defPropName
.c_str()))
1285 fc
.CompileDefsConfig
= ccdefs
;
1289 // Check for extra object-file dependencies.
1290 if(const char* deps
= sf
.GetProperty("OBJECT_DEPENDS"))
1292 std::vector
<std::string
> depends
;
1293 cmSystemTools::ExpandListArgument(deps
, depends
);
1294 const char* sep
= "";
1295 for(std::vector
<std::string
>::iterator j
= depends
.begin();
1296 j
!= depends
.end(); ++j
)
1298 fc
.AdditionalDeps
+= sep
;
1299 fc
.AdditionalDeps
+= lg
->ConvertToXMLOutputPath(j
->c_str());
1306 lg
->GlobalGenerator
->GetLanguageFromExtension
1307 (sf
.GetExtension().c_str());
1308 const char* sourceLang
= lg
->GetSourceFileLanguage(sf
);
1309 const char* linkLanguage
= target
.GetLinkerLanguage
1310 (lg
->GetGlobalGenerator());
1311 bool needForceLang
= false;
1312 // source file does not match its extension language
1313 if(lang
&& sourceLang
&& strcmp(lang
, sourceLang
) != 0)
1315 needForceLang
= true;
1318 // If HEADER_FILE_ONLY is set, we must suppress this generation in
1320 fc
.ExcludedFromBuild
=
1321 (sf
.GetPropertyAsBool("HEADER_FILE_ONLY"));
1322 if(fc
.ExcludedFromBuild
)
1327 // if the source file does not match the linker language
1328 // then force c or c++
1329 if(needForceLang
|| (linkLanguage
&& lang
1330 && strcmp(lang
, linkLanguage
) != 0))
1332 if(strcmp(lang
, "CXX") == 0)
1334 // force a C++ file type
1335 fc
.CompileFlags
+= " /TP ";
1338 else if(strcmp(lang
, "C") == 0)
1341 fc
.CompileFlags
+= " /TC ";
1348 this->FileConfigMap
[*i
] = fc
;
1353 void cmLocalVisualStudio7Generator
1354 ::WriteGroup(const cmSourceGroup
*sg
, cmTarget
& target
,
1355 std::ostream
&fout
, const char *libName
,
1356 std::vector
<std::string
> *configs
)
1358 const std::vector
<const cmSourceFile
*> &sourceFiles
=
1359 sg
->GetSourceFiles();
1360 // If the group is empty, don't write it at all.
1361 if(sourceFiles
.empty() && sg
->GetGroupChildren().empty())
1366 // If the group has a name, write the header.
1367 std::string name
= sg
->GetName();
1370 this->WriteVCProjBeginGroup(fout
, name
.c_str(), "");
1373 // Compute the maximum length configuration name.
1374 std::string config_max
;
1375 for(std::vector
<std::string
>::iterator i
= configs
->begin();
1376 i
!= configs
->end(); ++i
)
1378 if(i
->size() > config_max
.size())
1384 // Compute the maximum length full path to the intermediate
1385 // files directory for any configuration. This is used to construct
1386 // object file names that do not produce paths that are too long.
1387 std::string dir_max
;
1388 dir_max
+= this->Makefile
->GetCurrentOutputDirectory();
1390 dir_max
+= this->GetTargetDirectory(target
);
1392 dir_max
+= config_max
;
1395 // Loop through each source in the source group.
1396 std::string objectName
;
1397 for(std::vector
<const cmSourceFile
*>::const_iterator sf
=
1398 sourceFiles
.begin(); sf
!= sourceFiles
.end(); ++sf
)
1400 std::string source
= (*sf
)->GetFullPath();
1401 FCInfo
fcinfo(this, target
, *(*sf
), configs
, dir_max
);
1403 if (source
!= libName
|| target
.GetType() == cmTarget::UTILITY
||
1404 target
.GetType() == cmTarget::GLOBAL_TARGET
)
1406 fout
<< "\t\t\t<File\n";
1407 std::string d
= this->ConvertToXMLOutputPathSingle(source
.c_str());
1408 // Tell MS-Dev what the source is. If the compiler knows how to
1409 // build it, then it will.
1410 fout
<< "\t\t\t\tRelativePath=\"" << d
<< "\">\n";
1411 if(cmCustomCommand
const* command
= (*sf
)->GetCustomCommand())
1413 this->WriteCustomRule(fout
, source
.c_str(), *command
, fcinfo
);
1415 else if(!fcinfo
.FileConfigMap
.empty())
1417 const char* aCompilerTool
= "VCCLCompilerTool";
1418 std::string ext
= (*sf
)->GetExtension();
1419 ext
= cmSystemTools::LowerCase(ext
);
1422 aCompilerTool
= "VCMIDLTool";
1423 if(this->FortranProject
)
1425 aCompilerTool
= "VFMIDLTool";
1430 aCompilerTool
= "VCResourceCompilerTool";
1431 if(this->FortranProject
)
1433 aCompilerTool
= "VFResourceCompilerTool";
1438 aCompilerTool
= "VCCustomBuildTool";
1439 if(this->FortranProject
)
1441 aCompilerTool
= "VFCustomBuildTool";
1444 for(std::map
<cmStdString
, cmLVS7GFileConfig
>::const_iterator
1445 fci
= fcinfo
.FileConfigMap
.begin();
1446 fci
!= fcinfo
.FileConfigMap
.end(); ++fci
)
1448 cmLVS7GFileConfig
const& fc
= fci
->second
;
1449 fout
<< "\t\t\t\t<FileConfiguration\n"
1450 << "\t\t\t\t\tName=\"" << fci
->first
1451 << "|" << this->PlatformName
<< "\"";
1452 if(fc
.ExcludedFromBuild
)
1454 fout
<< " ExcludedFromBuild=\"true\"";
1457 fout
<< "\t\t\t\t\t<Tool\n"
1458 << "\t\t\t\t\tName=\"" << aCompilerTool
<< "\"\n";
1459 if(!fc
.CompileFlags
.empty() ||
1460 !fc
.CompileDefs
.empty() ||
1461 !fc
.CompileDefsConfig
.empty())
1463 Options
fileOptions(this, this->Version
, Options::Compiler
,
1464 this->ExtraFlagTable
);
1465 fileOptions
.Parse(fc
.CompileFlags
.c_str());
1466 fileOptions
.AddDefines(fc
.CompileDefs
.c_str());
1467 fileOptions
.AddDefines(fc
.CompileDefsConfig
.c_str());
1468 fileOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t\t", "\n");
1469 fileOptions
.OutputFlagMap(fout
, "\t\t\t\t\t");
1470 fileOptions
.OutputPreprocessorDefinitions(fout
,
1471 "\t\t\t\t\t", "\n");
1473 if(!fc
.AdditionalDeps
.empty())
1475 fout
<< "\t\t\t\t\tAdditionalDependencies=\""
1476 << fc
.AdditionalDeps
.c_str() << "\"\n";
1478 if(!fc
.ObjectName
.empty())
1480 fout
<< "\t\t\t\t\tObjectFile=\"$(IntDir)/"
1481 << fc
.ObjectName
.c_str() << "\"\n";
1483 fout
<< "\t\t\t\t\t/>\n"
1484 << "\t\t\t\t</FileConfiguration>\n";
1487 fout
<< "\t\t\t</File>\n";
1491 std::vector
<cmSourceGroup
> const& children
= sg
->GetGroupChildren();
1493 for(unsigned int i
=0;i
<children
.size();++i
)
1495 this->WriteGroup(&children
[i
], target
, fout
, libName
, configs
);
1498 // If the group has a name, write the footer.
1501 this->WriteVCProjEndGroup(fout
);
1505 void cmLocalVisualStudio7Generator::
1506 WriteCustomRule(std::ostream
& fout
,
1508 const cmCustomCommand
& command
,
1511 std::string comment
= this->ConstructComment(command
);
1513 // Write the rule for each configuration.
1514 std::vector
<std::string
>::iterator i
;
1515 std::vector
<std::string
> *configs
=
1516 static_cast<cmGlobalVisualStudio7Generator
*>
1517 (this->GlobalGenerator
)->GetConfigurations();
1518 const char* compileTool
= "VCCLCompilerTool";
1519 if(this->FortranProject
)
1521 compileTool
= "VFCLCompilerTool";
1523 const char* customTool
= "VCCustomBuildTool";
1524 if(this->FortranProject
)
1526 customTool
= "VFCustomBuildTool";
1528 for(i
= configs
->begin(); i
!= configs
->end(); ++i
)
1530 cmLVS7GFileConfig
const& fc
= fcinfo
.FileConfigMap
[*i
];
1531 fout
<< "\t\t\t\t<FileConfiguration\n";
1532 fout
<< "\t\t\t\t\tName=\"" << *i
<< "|" << this->PlatformName
<< "\">\n";
1533 if(!fc
.CompileFlags
.empty())
1535 fout
<< "\t\t\t\t\t<Tool\n"
1536 << "\t\t\t\t\tName=\"" << compileTool
<< "\"\n"
1537 << "\t\t\t\t\tAdditionalOptions=\""
1538 << this->EscapeForXML(fc
.CompileFlags
.c_str()) << "\"/>\n";
1541 std::string script
=
1542 this->ConstructScript(command
.GetCommandLines(),
1543 command
.GetWorkingDirectory(),
1545 command
.GetEscapeOldStyle(),
1546 command
.GetEscapeAllowMakeVars());
1547 fout
<< "\t\t\t\t\t<Tool\n"
1548 << "\t\t\t\t\tName=\"" << customTool
<< "\"\n"
1549 << "\t\t\t\t\tDescription=\""
1550 << this->EscapeForXML(comment
.c_str()) << "\"\n"
1551 << "\t\t\t\t\tCommandLine=\""
1552 << this->EscapeForXML(script
.c_str()) << "\"\n"
1553 << "\t\t\t\t\tAdditionalDependencies=\"";
1554 if(command
.GetDepends().empty())
1556 // There are no real dependencies. Produce an artificial one to
1557 // make sure the rule runs reliably.
1558 if(!cmSystemTools::FileExists(source
))
1560 std::ofstream
depout(source
);
1561 depout
<< "Artificial dependency for a custom command.\n";
1563 fout
<< this->ConvertToXMLOutputPath(source
);
1567 // Write out the dependencies for the rule.
1568 for(std::vector
<std::string
>::const_iterator d
=
1569 command
.GetDepends().begin();
1570 d
!= command
.GetDepends().end();
1573 // Get the real name of the dependency in case it is a CMake target.
1574 std::string dep
= this->GetRealDependency(d
->c_str(), i
->c_str());
1575 fout
<< this->ConvertToXMLOutputPath(dep
.c_str())
1580 fout
<< "\t\t\t\t\tOutputs=\"";
1581 if(command
.GetOutputs().empty())
1583 fout
<< source
<< "_force";
1587 // Write a rule for the output generated by this command.
1588 const char* sep
= "";
1589 for(std::vector
<std::string
>::const_iterator o
=
1590 command
.GetOutputs().begin();
1591 o
!= command
.GetOutputs().end();
1594 fout
<< sep
<< this->ConvertToXMLOutputPathSingle(o
->c_str());
1599 fout
<< "\t\t\t\t</FileConfiguration>\n";
1604 void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream
& fout
,
1608 fout
<< "\t\t<Filter\n"
1609 << "\t\t\tName=\"" << group
<< "\"\n"
1610 << "\t\t\tFilter=\"\">\n";
1614 void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream
& fout
)
1616 fout
<< "\t\t</Filter>\n";
1620 // look for custom rules on a target and collect them together
1621 void cmLocalVisualStudio7Generator
1622 ::OutputTargetRules(std::ostream
& fout
,
1623 const char* configName
,
1625 const char * /*libName*/)
1627 if (target
.GetType() > cmTarget::GLOBAL_TARGET
)
1631 const char* tool
= "VCPreBuildEventTool";
1632 if(this->FortranProject
)
1634 tool
= "VFPreBuildEventTool";
1636 // add the pre build rules
1637 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"";
1639 for (std::vector
<cmCustomCommand
>::const_iterator cr
=
1640 target
.GetPreBuildCommands().begin();
1641 cr
!= target
.GetPreBuildCommands().end(); ++cr
)
1645 const char* comment
= cr
->GetComment();
1646 if(comment
&& *comment
)
1648 fout
<< "\nDescription=\""
1649 << this->EscapeForXML(comment
) << "\"";
1651 fout
<< "\nCommandLine=\"";
1656 fout
<< this->EscapeForXML("\n");
1658 std::string script
=
1659 this->ConstructScript(cr
->GetCommandLines(),
1660 cr
->GetWorkingDirectory(),
1662 cr
->GetEscapeOldStyle(),
1663 cr
->GetEscapeAllowMakeVars());
1664 fout
<< this->EscapeForXML(script
.c_str()).c_str();
1672 // add the pre Link rules
1673 tool
= "VCPreLinkEventTool";
1674 if(this->FortranProject
)
1676 tool
= "VFPreLinkEventTool";
1678 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"";
1680 for (std::vector
<cmCustomCommand
>::const_iterator cr
=
1681 target
.GetPreLinkCommands().begin();
1682 cr
!= target
.GetPreLinkCommands().end(); ++cr
)
1686 const char* comment
= cr
->GetComment();
1687 if(comment
&& *comment
)
1689 fout
<< "\nDescription=\""
1690 << this->EscapeForXML(comment
) << "\"";
1692 fout
<< "\nCommandLine=\"";
1697 fout
<< this->EscapeForXML("\n");
1699 std::string script
=
1700 this->ConstructScript(cr
->GetCommandLines(),
1701 cr
->GetWorkingDirectory(),
1703 cr
->GetEscapeOldStyle(),
1704 cr
->GetEscapeAllowMakeVars());
1705 fout
<< this->EscapeForXML(script
.c_str()).c_str();
1713 // add the PostBuild rules
1714 tool
= "VCPostBuildEventTool";
1715 if(this->FortranProject
)
1717 tool
= "VFPostBuildEventTool";
1719 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"";
1721 for (std::vector
<cmCustomCommand
>::const_iterator cr
=
1722 target
.GetPostBuildCommands().begin();
1723 cr
!= target
.GetPostBuildCommands().end(); ++cr
)
1727 const char* comment
= cr
->GetComment();
1728 if(comment
&& *comment
)
1730 fout
<< "\nDescription=\""
1731 << this->EscapeForXML(comment
) << "\"";
1733 fout
<< "\nCommandLine=\"";
1738 fout
<< this->EscapeForXML("\n");
1740 std::string script
=
1741 this->ConstructScript(cr
->GetCommandLines(),
1742 cr
->GetWorkingDirectory(),
1744 cr
->GetEscapeOldStyle(),
1745 cr
->GetEscapeAllowMakeVars());
1746 fout
<< this->EscapeForXML(script
.c_str()).c_str();
1756 cmLocalVisualStudio7Generator
1757 ::WriteProjectStartFortran(std::ostream
& fout
,
1758 const char *libName
,
1762 cmGlobalVisualStudio7Generator
* gg
=
1763 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
1764 fout
<< "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
1765 << "<VisualStudioProject\n"
1766 << "\tProjectCreator=\"Intel Fortran\"\n"
1767 << "\tVersion=\"9.10\"\n";
1768 const char* keyword
= target
.GetProperty("VS_KEYWORD");
1771 keyword
= "Console Application";
1773 const char* projectType
= 0;
1774 switch(target
.GetType())
1776 case cmTarget::STATIC_LIBRARY
:
1777 projectType
= "typeStaticLibrary";
1780 keyword
= "Static Library";
1783 case cmTarget::SHARED_LIBRARY
:
1784 case cmTarget::MODULE_LIBRARY
:
1785 projectType
= "typeDynamicLibrary";
1791 case cmTarget::EXECUTABLE
:
1794 keyword
= "Console Application";
1798 case cmTarget::UTILITY
:
1799 case cmTarget::GLOBAL_TARGET
:
1805 fout
<< "\tProjectType=\"" << projectType
<< "\"\n";
1807 fout
<< "\tKeyword=\"" << keyword
<< "\">\n"
1808 << "\tProjectGUID=\"{" << gg
->GetGUID(libName
) << "}\">\n"
1809 << "\t<Platforms>\n"
1810 << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName
<< "\"/>\n"
1811 << "\t</Platforms>\n";
1816 cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream
& fout
,
1817 const char *libName
,
1819 std::vector
<cmSourceGroup
> &)
1821 if(this->FortranProject
)
1823 this->WriteProjectStartFortran(fout
, libName
, target
);
1826 fout
<< "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
1827 << "<VisualStudioProject\n"
1828 << "\tProjectType=\"Visual C++\"\n";
1829 if(this->Version
== 71)
1831 fout
<< "\tVersion=\"7.10\"\n";
1835 fout
<< "\tVersion=\"" << this->Version
<< ".00\"\n";
1837 const char* projLabel
= target
.GetProperty("PROJECT_LABEL");
1840 projLabel
= libName
;
1842 const char* keyword
= target
.GetProperty("VS_KEYWORD");
1845 keyword
= "Win32Proj";
1847 const char* vsProjectname
= target
.GetProperty("VS_SCC_PROJECTNAME");
1848 const char* vsLocalpath
= target
.GetProperty("VS_SCC_LOCALPATH");
1849 const char* vsProvider
= target
.GetProperty("VS_SCC_PROVIDER");
1850 cmGlobalVisualStudio7Generator
* gg
=
1851 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
1852 fout
<< "\tName=\"" << projLabel
<< "\"\n";
1853 if(this->Version
>= 8)
1855 fout
<< "\tProjectGUID=\"{" << gg
->GetGUID(libName
) << "}\"\n";
1857 // if we have all the required Source code control tags
1858 // then add that to the project
1859 if(vsProvider
&& vsLocalpath
&& vsProjectname
)
1861 fout
<< "\tSccProjectName=\"" << vsProjectname
<< "\"\n"
1862 << "\tSccLocalPath=\"" << vsLocalpath
<< "\"\n"
1863 << "\tSccProvider=\"" << vsProvider
<< "\"\n";
1865 fout
<< "\tKeyword=\"" << keyword
<< "\">\n"
1866 << "\t<Platforms>\n"
1867 << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName
<< "\"/>\n"
1868 << "\t</Platforms>\n";
1872 void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream
& fout
)
1874 fout
<< "\t<Globals>\n"
1876 << "</VisualStudioProject>\n";
1879 std::string
cmLocalVisualStudio7GeneratorEscapeForXML(const char* s
)
1881 std::string ret
= s
;
1882 cmSystemTools::ReplaceString(ret
, "&", "&");
1883 cmSystemTools::ReplaceString(ret
, "\"", """);
1884 cmSystemTools::ReplaceString(ret
, "<", "<");
1885 cmSystemTools::ReplaceString(ret
, ">", ">");
1886 cmSystemTools::ReplaceString(ret
, "\n", "
");
1890 std::string
cmLocalVisualStudio7Generator::EscapeForXML(const char* s
)
1892 return cmLocalVisualStudio7GeneratorEscapeForXML(s
);
1895 std::string cmLocalVisualStudio7Generator
1896 ::ConvertToXMLOutputPath(const char* path
)
1898 std::string ret
= this->ConvertToOptionallyRelativeOutputPath(path
);
1899 cmSystemTools::ReplaceString(ret
, "&", "&");
1900 cmSystemTools::ReplaceString(ret
, "\"", """);
1901 cmSystemTools::ReplaceString(ret
, "<", "<");
1902 cmSystemTools::ReplaceString(ret
, ">", ">");
1906 std::string cmLocalVisualStudio7Generator
1907 ::ConvertToXMLOutputPathSingle(const char* path
)
1909 std::string ret
= this->ConvertToOptionallyRelativeOutputPath(path
);
1910 cmSystemTools::ReplaceString(ret
, "\"", "");
1911 cmSystemTools::ReplaceString(ret
, "&", "&");
1912 cmSystemTools::ReplaceString(ret
, "<", "<");
1913 cmSystemTools::ReplaceString(ret
, ">", ">");
1918 // This class is used to parse an existing vs 7 project
1919 // and extract the GUID
1920 class cmVS7XMLParser
: public cmXMLParser
1923 virtual void EndElement(const char* /* name */)
1926 virtual void StartElement(const char* name
, const char** atts
)
1928 // once the GUID is found do nothing
1929 if(this->GUID
.size())
1934 if(strcmp("VisualStudioProject", name
) == 0)
1938 if(strcmp(atts
[i
], "ProjectGUID") == 0)
1942 this->GUID
= atts
[i
+1];
1943 this->GUID
= this->GUID
.substr(1, this->GUID
.size()-2);
1955 int InitializeParser()
1957 int ret
= cmXMLParser::InitializeParser();
1962 // visual studio projects have a strange encoding, but it is
1964 XML_SetEncoding(static_cast<XML_Parser
>(this->Parser
), "utf-8");
1970 void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
1974 cmVS7XMLParser parser
;
1975 parser
.ParseFile(path
);
1976 // if we can not find a GUID then create one
1977 if(parser
.GUID
.size() == 0)
1979 cmGlobalVisualStudio7Generator
* gg
=
1980 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
1981 gg
->CreateGUID(name
);
1984 std::string guidStoreName
= name
;
1985 guidStoreName
+= "_GUID_CMAKE";
1986 // save the GUID in the cache
1987 this->GlobalGenerator
->GetCMakeInstance()->
1988 AddCacheEntry(guidStoreName
.c_str(),
1989 parser
.GUID
.c_str(),
1991 cmCacheManager::INTERNAL
);
1995 void cmLocalVisualStudio7Generator::ConfigureFinalPass()
1997 cmLocalGenerator::ConfigureFinalPass();
1998 cmTargets
&tgts
= this->Makefile
->GetTargets();
2000 cmGlobalVisualStudio7Generator
* gg
=
2001 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
2002 for(cmTargets::iterator l
= tgts
.begin(); l
!= tgts
.end(); l
++)
2004 if (strncmp(l
->first
.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
2006 cmCustomCommand cc
= l
->second
.GetPostBuildCommands()[0];
2007 const cmCustomCommandLines
& cmds
= cc
.GetCommandLines();
2008 std::string project_name
= cmds
[0][0];
2009 this->ReadAndStoreExternalGUID(project_name
.c_str(),
2010 cmds
[0][1].c_str());
2014 gg
->CreateGUID(l
->first
.c_str());
2020 //----------------------------------------------------------------------------
2021 std::string cmLocalVisualStudio7Generator
2022 ::GetTargetDirectory(cmTarget
const& target
) const
2025 dir
+= target
.GetName();
2030 //----------------------------------------------------------------------------
2031 cmLocalVisualStudio7GeneratorOptions
2032 ::cmLocalVisualStudio7GeneratorOptions(cmLocalVisualStudio7Generator
* lg
,
2035 cmVS7FlagTable
const* extraTable
):
2036 LocalGenerator(lg
), Version(version
), CurrentTool(tool
),
2037 DoingDefine(false), FlagTable(0), ExtraFlagTable(extraTable
)
2039 // Choose the flag table for the requested tool.
2043 this->FlagTable
= cmLocalVisualStudio7GeneratorFlagTable
; break;
2045 this->FlagTable
= cmLocalVisualStudio7GeneratorLinkFlagTable
; break;
2046 case FortranCompiler
:
2047 this->FlagTable
= cmLocalVisualStudio7GeneratorFortranFlagTable
;
2052 //----------------------------------------------------------------------------
2053 void cmLocalVisualStudio7GeneratorOptions::FixExceptionHandlingDefault()
2055 // Exception handling is on by default because the platform file has
2056 // "/EHsc" in the flags. Normally, that will override this
2057 // initialization to off, but the user has the option of removing
2058 // the flag to disable exception handling. When the user does
2059 // remove the flag we need to override the IDE default of on.
2060 switch (this->Version
)
2064 this->FlagMap
["ExceptionHandling"] = "FALSE";
2068 this->FlagMap
["ExceptionHandling"] = "0";
2073 //----------------------------------------------------------------------------
2074 void cmLocalVisualStudio7GeneratorOptions::SetVerboseMakefile(bool verbose
)
2076 // If verbose makefiles have been requested and the /nologo option
2077 // was not given explicitly in the flags we want to add an attribute
2078 // to the generated project to disable logo suppression. Otherwise
2079 // the GUI default is to enable suppression.
2081 this->FlagMap
.find("SuppressStartupBanner") == this->FlagMap
.end())
2083 this->FlagMap
["SuppressStartupBanner"] = "FALSE";
2087 //----------------------------------------------------------------------------
2088 void cmLocalVisualStudio7GeneratorOptions::AddDefine(const std::string
& def
)
2090 this->Defines
.push_back(def
);
2093 //----------------------------------------------------------------------------
2094 void cmLocalVisualStudio7GeneratorOptions::AddDefines(const char* defines
)
2098 // Expand the list of definitions.
2099 cmSystemTools::ExpandListArgument(defines
, this->Defines
);
2103 //----------------------------------------------------------------------------
2104 void cmLocalVisualStudio7GeneratorOptions::AddFlag(const char* flag
,
2107 this->FlagMap
[flag
] = value
;
2111 bool cmLocalVisualStudio7GeneratorOptions::IsDebug()
2113 return this->FlagMap
.find("DebugInformationFormat") != this->FlagMap
.end();
2116 //----------------------------------------------------------------------------
2117 bool cmLocalVisualStudio7GeneratorOptions::UsingUnicode()
2119 // Look for the a _UNICODE definition.
2120 for(std::vector
<std::string
>::const_iterator di
= this->Defines
.begin();
2121 di
!= this->Defines
.end(); ++di
)
2123 if(*di
== "_UNICODE")
2131 //----------------------------------------------------------------------------
2132 void cmLocalVisualStudio7GeneratorOptions::Parse(const char* flags
)
2134 // Parse the input string as a windows command line since the string
2135 // is intended for writing directly into the build files.
2136 std::vector
<std::string
> args
;
2137 cmSystemTools::ParseWindowsCommandLine(flags
, args
);
2139 // Process flags that need to be represented specially in the IDE
2141 for(std::vector
<std::string
>::iterator ai
= args
.begin();
2142 ai
!= args
.end(); ++ai
)
2144 this->HandleFlag(ai
->c_str());
2148 //----------------------------------------------------------------------------
2149 void cmLocalVisualStudio7GeneratorOptions::HandleFlag(const char* flag
)
2151 // If the last option was -D then this option is the definition.
2152 if(this->DoingDefine
)
2154 this->DoingDefine
= false;
2155 this->Defines
.push_back(flag
);
2159 // Look for known arguments.
2160 if(flag
[0] == '-' || flag
[0] == '/')
2162 // Look for preprocessor definitions.
2163 if(this->CurrentTool
== Compiler
&& flag
[1] == 'D')
2167 // The next argument will have the definition.
2168 this->DoingDefine
= true;
2172 // Store this definition.
2173 this->Defines
.push_back(flag
+2);
2178 // Look through the available flag tables.
2179 bool flag_handled
= false;
2180 if(this->FlagTable
&&
2181 this->CheckFlagTable(this->FlagTable
, flag
, flag_handled
))
2185 if(this->ExtraFlagTable
&&
2186 this->CheckFlagTable(this->ExtraFlagTable
, flag
, flag_handled
))
2191 // If any map entry handled the flag we are done.
2197 // This option is not known. Store it in the output flags.
2198 this->FlagString
+= " ";
2200 cmSystemTools::EscapeWindowsShellArgument(
2202 cmsysSystem_Shell_Flag_AllowMakeVariables
|
2203 cmsysSystem_Shell_Flag_VSIDE
);
2206 //----------------------------------------------------------------------------
2208 cmLocalVisualStudio7GeneratorOptions
2209 ::CheckFlagTable(cmVS7FlagTable
const* table
, const char* flag
,
2212 // Look for an entry in the flag table matching this flag.
2213 for(cmVS7FlagTable
const* entry
= table
; entry
->IDEName
; ++entry
)
2215 bool entry_found
= false;
2216 if(entry
->special
& cmVS7FlagTable::UserValue
)
2218 // This flag table entry accepts a user-specified value. If
2219 // the entry specifies UserRequired we must match only if a
2220 // non-empty value is given.
2221 int n
= static_cast<int>(strlen(entry
->commandFlag
));
2222 if(strncmp(flag
+1, entry
->commandFlag
, n
) == 0 &&
2223 (!(entry
->special
& cmVS7FlagTable::UserRequired
) ||
2224 static_cast<int>(strlen(flag
+1)) > n
))
2226 if(entry
->special
& cmVS7FlagTable::UserIgnored
)
2228 // Ignore the user-specified value.
2229 this->FlagMap
[entry
->IDEName
] = entry
->value
;
2231 else if(entry
->special
& cmVS7FlagTable::SemicolonAppendable
)
2233 const char *new_value
= flag
+1+n
;
2235 std::map
<cmStdString
,cmStdString
>::iterator itr
;
2236 itr
= this->FlagMap
.find(entry
->IDEName
);
2237 if(itr
!= this->FlagMap
.end())
2239 // Append to old value (if present) with semicolons;
2241 itr
->second
+= new_value
;
2245 this->FlagMap
[entry
->IDEName
] = new_value
;
2250 // Use the user-specified value.
2251 this->FlagMap
[entry
->IDEName
] = flag
+1+n
;
2256 else if(strcmp(flag
+1, entry
->commandFlag
) == 0)
2258 // This flag table entry provides a fixed value.
2259 this->FlagMap
[entry
->IDEName
] = entry
->value
;
2263 // If the flag has been handled by an entry not requesting a
2264 // search continuation we are done.
2265 if(entry_found
&& !(entry
->special
& cmVS7FlagTable::Continue
))
2270 // If the entry was found the flag has been handled.
2271 flag_handled
= flag_handled
|| entry_found
;
2277 //----------------------------------------------------------------------------
2279 cmLocalVisualStudio7GeneratorOptions
2280 ::OutputPreprocessorDefinitions(std::ostream
& fout
,
2284 if(this->Defines
.empty())
2289 fout
<< prefix
<< "PreprocessorDefinitions=\"";
2290 const char* comma
= "";
2291 for(std::vector
<std::string
>::const_iterator di
= this->Defines
.begin();
2292 di
!= this->Defines
.end(); ++di
)
2294 // Escape the definition for the compiler.
2295 std::string define
=
2296 this->LocalGenerator
->EscapeForShell(di
->c_str(), true);
2298 // Escape this flag for the IDE.
2299 define
= cmLocalVisualStudio7GeneratorEscapeForXML(define
.c_str());
2301 // Store the flag in the project file.
2302 fout
<< comma
<< define
;
2305 fout
<< "\"" << suffix
;
2308 //----------------------------------------------------------------------------
2310 cmLocalVisualStudio7GeneratorOptions
2311 ::OutputFlagMap(std::ostream
& fout
, const char* indent
)
2313 for(std::map
<cmStdString
, cmStdString
>::iterator m
= this->FlagMap
.begin();
2314 m
!= this->FlagMap
.end(); ++m
)
2316 fout
<< indent
<< m
->first
<< "=\"" << m
->second
<< "\"\n";
2320 //----------------------------------------------------------------------------
2322 cmLocalVisualStudio7GeneratorOptions
2323 ::OutputAdditionalOptions(std::ostream
& fout
,
2327 if(!this->FlagString
.empty())
2329 fout
<< prefix
<< "AdditionalOptions=\"";
2331 cmLocalVisualStudio7GeneratorEscapeForXML(this->FlagString
.c_str());
2332 fout
<< "\"" << suffix
;
2335 void cmLocalVisualStudio7Generator::
2336 GetTargetObjectFileDirectories(cmTarget
* target
,
2337 std::vector
<std::string
>&
2340 std::string dir
= this->Makefile
->GetCurrentOutputDirectory();
2342 dir
+= this->GetTargetDirectory(*target
);
2344 dir
+= this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
2345 dirs
.push_back(dir
);
2348 //----------------------------------------------------------------------------
2349 #include <windows.h>
2350 static bool cmLVS6G_IsFAT(const char* dir
)
2352 if(dir
[0] && dir
[1] == ':')
2354 char volRoot
[4] = "_:/";
2355 volRoot
[0] = dir
[0];
2357 if(GetVolumeInformation(volRoot
, 0, 0, 0, 0, 0, fsName
, 16) &&
2358 strstr(fsName
, "FAT") != 0)