1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalVisualStudio7Generator.cxx,v $
6 Date: $Date: 2008-10-07 20:23:20 $
7 Version: $Revision: 1.232 $
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},
408 // Precompiled header and related options. Note that the
409 // UsePrecompiledHeader entries are marked as "Continue" so that the
410 // corresponding PrecompiledHeaderThrough entry can be found.
411 {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
412 cmVS7FlagTable::UserValueIgnored
| cmVS7FlagTable::Continue
},
413 {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
414 cmVS7FlagTable::UserValueRequired
},
415 {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
416 cmVS7FlagTable::UserValue
},
417 // The YX and Yu options are in a per-global-generator table because
418 // their values differ based on the VS IDE version.
419 {"ForcedIncludeFiles", "FI", "Forced include files", "",
420 cmVS7FlagTable::UserValueRequired
},
423 {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE", 0},
424 {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "FALSE", 0},
425 {"Detect64BitPortabilityProblems", "Wp64",
426 "Detect 64-bit Portability Problems", "TRUE", 0},
427 {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
429 {"EnableFunctionLevelLinking", "Gy",
430 "EnableFunctionLevelLinking", "TRUE", 0},
431 {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE", 0},
432 {"GlobalOptimizations", "Og", "Global Optimize", "TRUE", 0},
433 {"ImproveFloatingPointConsistency", "Op",
434 "ImproveFloatingPointConsistency", "TRUE", 0},
435 {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE", 0},
436 {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE", 0},
437 {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE", 0},
438 {"RuntimeTypeInfo", "GR",
439 "Turn on Run time type information for c++", "TRUE", 0},
440 {"RuntimeTypeInfo", "GR-",
441 "Turn off Run time type information for c++", "FALSE", 0},
442 {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE", 0},
443 {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "TRUE", 0},
444 {"WarnAsError", "WX", "Treat warnings as errors", "TRUE", 0},
450 cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable
[] =
452 // option flags (some flags map to the same option)
453 {"GenerateManifest", "MANIFEST:NO",
454 "disable manifest generation", "FALSE", 0},
455 {"GenerateManifest", "MANIFEST", "enable manifest generation", "TRUE", 0},
456 {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
457 {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
458 {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
459 cmVS7FlagTable::UserValue
| cmVS7FlagTable::SemicolonAppendable
},
460 {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
462 {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
463 cmVS7FlagTable::UserValue
},
464 {"GenerateMapFile", "MAP", "enable generation of map file", "TRUE", 0},
468 //----------------------------------------------------------------------------
469 class cmLocalVisualStudio7GeneratorOptions
472 // Construct an options table for a given tool.
479 cmLocalVisualStudio7GeneratorOptions(cmLocalVisualStudio7Generator
* lg
,
482 cmVS7FlagTable
const* extraTable
= 0);
484 // Store options from command line flags.
485 void Parse(const char* flags
);
487 // Fix the ExceptionHandling option to default to off.
488 void FixExceptionHandlingDefault();
490 // Store options for verbose builds.
491 void SetVerboseMakefile(bool verbose
);
493 // Store definitions and flags.
494 void AddDefine(const std::string
& define
);
495 void AddDefines(const char* defines
);
496 void AddFlag(const char* flag
, const char* value
);
498 // Check for specific options.
502 // Write options to output.
503 void OutputPreprocessorDefinitions(std::ostream
& fout
,
506 void OutputFlagMap(std::ostream
& fout
, const char* indent
);
507 void OutputAdditionalOptions(std::ostream
& fout
,
512 cmLocalVisualStudio7Generator
* LocalGenerator
;
515 // create a map of xml tags to the values they should have in the output
516 // for example, "BufferSecurityCheck" = "TRUE"
517 // first fill this table with the values for the configuration
518 // Debug, Release, etc,
519 // Then parse the command line flags specified in CMAKE_CXX_FLAGS
521 // and overwrite or add new values to this map
522 std::map
<cmStdString
, cmStdString
> FlagMap
;
524 // Preprocessor definitions.
525 std::vector
<std::string
> Defines
;
527 // Unrecognized flags that get no special handling.
528 cmStdString FlagString
;
532 cmVS7FlagTable
const* FlagTable
;
533 cmVS7FlagTable
const* ExtraFlagTable
;
534 void HandleFlag(const char* flag
);
535 bool CheckFlagTable(cmVS7FlagTable
const* table
, const char* flag
,
539 void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream
& fout
,
540 const char* configName
,
544 const char* mfcFlag
= this->Makefile
->GetDefinition("CMAKE_MFC_FLAG");
549 fout
<< "\t\t<Configuration\n"
550 << "\t\t\tName=\"" << configName
<< "|" << this->PlatformName
<< "\"\n"
551 << "\t\t\tOutputDirectory=\"" << configName
<< "\"\n";
552 // This is an internal type to Visual Studio, it seems that:
553 // 4 == static library
557 const char* configType
= "10";
558 const char* projectType
= 0;
559 switch(target
.GetType())
561 case cmTarget::STATIC_LIBRARY
:
562 projectType
= "typeStaticLibrary";
565 case cmTarget::SHARED_LIBRARY
:
566 case cmTarget::MODULE_LIBRARY
:
567 projectType
= "typeDynamicLibrary";
570 case cmTarget::EXECUTABLE
:
573 case cmTarget::UTILITY
:
574 case cmTarget::GLOBAL_TARGET
:
579 if(this->FortranProject
&& projectType
)
581 configType
= projectType
;
584 if(strcmp(configType
, "10") != 0)
586 const char* linkLanguage
=
587 target
.GetLinkerLanguage(this->GetGlobalGenerator());
591 ("CMake can not determine linker language for target:",
595 if(strcmp(linkLanguage
, "C") == 0 || strcmp(linkLanguage
, "CXX") == 0
596 || strcmp(linkLanguage
, "Fortran") == 0)
598 std::string baseFlagVar
= "CMAKE_";
599 baseFlagVar
+= linkLanguage
;
600 baseFlagVar
+= "_FLAGS";
601 flags
= this->Makefile
->GetRequiredDefinition(baseFlagVar
.c_str());
602 std::string flagVar
= baseFlagVar
+ std::string("_") +
603 cmSystemTools::UpperCase(configName
);
605 flags
+= this->Makefile
->GetRequiredDefinition(flagVar
.c_str());
607 // set the correct language
608 if(strcmp(linkLanguage
, "C") == 0)
612 if(strcmp(linkLanguage
, "CXX") == 0)
618 // Add the target-specific flags.
619 if(const char* targetFlags
= target
.GetProperty("COMPILE_FLAGS"))
622 flags
+= targetFlags
;
625 std::string configUpper
= cmSystemTools::UpperCase(configName
);
626 std::string defPropName
= "COMPILE_DEFINITIONS_";
627 defPropName
+= configUpper
;
629 // Get preprocessor definitions for this directory.
630 std::string defineFlags
= this->Makefile
->GetDefineFlags();
631 Options::Tool t
= Options::Compiler
;
632 if(this->FortranProject
)
634 t
= Options::FortranCompiler
;
636 Options
targetOptions(this, this->Version
, t
, this->ExtraFlagTable
);
637 targetOptions
.FixExceptionHandlingDefault();
638 targetOptions
.Parse(flags
.c_str());
639 targetOptions
.Parse(defineFlags
.c_str());
640 targetOptions
.AddDefines
641 (this->Makefile
->GetProperty("COMPILE_DEFINITIONS"));
642 targetOptions
.AddDefines(target
.GetProperty("COMPILE_DEFINITIONS"));
643 targetOptions
.AddDefines(this->Makefile
->GetProperty(defPropName
.c_str()));
644 targetOptions
.AddDefines(target
.GetProperty(defPropName
.c_str()));
645 targetOptions
.SetVerboseMakefile(
646 this->Makefile
->IsOn("CMAKE_VERBOSE_MAKEFILE"));
648 // Add a definition for the configuration name.
649 std::string configDefine
= "CMAKE_INTDIR=\"";
650 configDefine
+= configName
;
651 configDefine
+= "\"";
652 targetOptions
.AddDefine(configDefine
);
654 // Add the export symbol definition for shared library objects.
655 if(const char* exportMacro
= target
.GetExportMacro())
657 targetOptions
.AddDefine(exportMacro
);
660 // The intermediate directory name consists of a directory for the
661 // target and a subdirectory for the configuration name.
662 std::string intermediateDir
= this->GetTargetDirectory(target
);
663 intermediateDir
+= "/";
664 intermediateDir
+= configName
;
665 fout
<< "\t\t\tIntermediateDirectory=\""
666 << this->ConvertToXMLOutputPath(intermediateDir
.c_str())
668 << "\t\t\tConfigurationType=\"" << configType
<< "\"\n"
669 << "\t\t\tUseOfMFC=\"" << mfcFlag
<< "\"\n"
670 << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
672 // If unicode is enabled change the character set to unicode, if not
673 // then default to MBCS.
674 if(targetOptions
.UsingUnicode())
676 fout
<< "\t\t\tCharacterSet=\"1\">\n";
680 fout
<< "\t\t\tCharacterSet=\"2\">\n";
682 const char* tool
= "VCCLCompilerTool";
683 if(this->FortranProject
)
685 tool
= "VFFortranCompilerTool";
687 fout
<< "\t\t\t<Tool\n"
688 << "\t\t\t\tName=\"" << tool
<< "\"\n";
689 if(this->FortranProject
)
691 const char* target_mod_dir
=
692 target
.GetProperty("Fortran_MODULE_DIRECTORY");
696 modDir
= this->Convert(target_mod_dir
,
697 cmLocalGenerator::START_OUTPUT
,
698 cmLocalGenerator::UNCHANGED
);
704 fout
<< "\t\t\t\tModulePath=\""
705 << this->ConvertToXMLOutputPath(modDir
.c_str())
706 << "\\$(ConfigurationName)\"\n";
708 targetOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t", "\n");
709 fout
<< "\t\t\t\tAdditionalIncludeDirectories=\"";
710 std::vector
<std::string
> includes
;
711 this->GetIncludeDirectories(includes
);
712 std::vector
<std::string
>::iterator i
= includes
.begin();
713 for(;i
!= includes
.end(); ++i
)
715 // output the include path
716 std::string ipath
= this->ConvertToXMLOutputPath(i
->c_str());
717 fout
<< ipath
<< ";";
718 // if this is fortran then output the include with
719 // a ConfigurationName on the end of it.
720 if(this->FortranProject
)
723 ipath
+= "/$(ConfigurationName)";
724 ipath
= this->ConvertToXMLOutputPath(ipath
.c_str());
725 fout
<< ipath
<< ";";
729 targetOptions
.OutputFlagMap(fout
, "\t\t\t\t");
730 targetOptions
.OutputPreprocessorDefinitions(fout
, "\t\t\t\t", "\n");
731 fout
<< "\t\t\t\tAssemblerListingLocation=\"" << configName
<< "\"\n";
732 fout
<< "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
733 if(target
.GetType() == cmTarget::EXECUTABLE
||
734 target
.GetType() == cmTarget::STATIC_LIBRARY
||
735 target
.GetType() == cmTarget::SHARED_LIBRARY
||
736 target
.GetType() == cmTarget::MODULE_LIBRARY
)
738 // We need to specify a program database file name even for
739 // non-debug configurations because VS still creates .idb files.
740 fout
<< "\t\t\t\tProgramDataBaseFileName=\""
741 << target
.GetDirectory(configName
) << "/"
742 << target
.GetPDBName(configName
) << "\"\n";
744 fout
<< "/>\n"; // end of <Tool Name=VCCLCompilerTool
745 tool
= "VCCustomBuildTool";
746 if(this->FortranProject
)
748 tool
= "VFCustomBuildTool";
750 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"/>\n";
751 tool
= "VCResourceCompilerTool";
752 if(this->FortranProject
)
754 tool
= "VFResourceCompilerTool";
756 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"\n"
757 << "\t\t\t\tAdditionalIncludeDirectories=\"";
758 for(i
= includes
.begin();i
!= includes
.end(); ++i
)
760 std::string ipath
= this->ConvertToXMLOutputPath(i
->c_str());
761 fout
<< ipath
<< ";";
763 // add the -D flags to the RC tool
765 targetOptions
.OutputPreprocessorDefinitions(fout
, "\n\t\t\t\t", "");
768 if(this->FortranProject
)
772 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"\n";
773 targetOptions
.OutputPreprocessorDefinitions(fout
, "\t\t\t\t", "\n");
774 fout
<< "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
775 if( this->PlatformName
== "x64" )
777 fout
<< "\t\t\t\tTargetEnvironment=\"3\"\n";
779 else if( this->PlatformName
== "ia64" )
781 fout
<< "\t\t\t\tTargetEnvironment=\"2\"\n";
785 fout
<< "\t\t\t\tTargetEnvironment=\"1\"\n";
787 fout
<< "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
788 fout
<< "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
789 fout
<< "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
790 fout
<< "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
791 fout
<< "\t\t\t\tDLLDataFileName=\"\"\n";
792 fout
<< "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
793 fout
<< "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
794 // end of <Tool Name=VCMIDLTool
796 // Check if we need the FAT32 workaround.
797 if ( this->Version
>= 8 )
799 // Check the filesystem type where the target will be written.
800 if(cmLVS6G_IsFAT(target
.GetDirectory(configName
).c_str()))
802 // Add a flag telling the manifest tool to use a workaround
803 // for FAT32 file systems, which can cause an empty manifest
804 // to be embedded into the resulting executable. See CMake
806 const char* tool
= "VCManifestTool";
807 if(this->FortranProject
)
809 tool
= "VFManifestTool";
811 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"\n"
812 << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
817 this->OutputTargetRules(fout
, configName
, target
, libName
);
818 this->OutputBuildTool(fout
, configName
, target
, targetOptions
.IsDebug());
819 fout
<< "\t\t</Configuration>\n";
822 //----------------------------------------------------------------------------
824 cmLocalVisualStudio7Generator
825 ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags
, const char* configName
)
827 std::string configTypeUpper
= cmSystemTools::UpperCase(configName
);
828 std::string extraLinkOptionsBuildTypeDef
=
829 rootLinkerFlags
+ "_" + configTypeUpper
;
831 std::string extraLinkOptionsBuildType
=
832 this->Makefile
->GetRequiredDefinition
833 (extraLinkOptionsBuildTypeDef
.c_str());
835 return extraLinkOptionsBuildType
;
838 void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream
& fout
,
839 const char* configName
,
844 std::string extraLinkOptions
;
845 if(target
.GetType() == cmTarget::EXECUTABLE
)
848 this->Makefile
->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
850 + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName
);
852 if(target
.GetType() == cmTarget::SHARED_LIBRARY
)
855 this->Makefile
->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
857 + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName
);
859 if(target
.GetType() == cmTarget::MODULE_LIBRARY
)
862 this->Makefile
->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
864 + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName
);
867 const char* targetLinkFlags
= target
.GetProperty("LINK_FLAGS");
870 extraLinkOptions
+= " ";
871 extraLinkOptions
+= targetLinkFlags
;
873 std::string configTypeUpper
= cmSystemTools::UpperCase(configName
);
874 std::string linkFlagsConfig
= "LINK_FLAGS_";
875 linkFlagsConfig
+= configTypeUpper
;
876 targetLinkFlags
= target
.GetProperty(linkFlagsConfig
.c_str());
879 extraLinkOptions
+= " ";
880 extraLinkOptions
+= targetLinkFlags
;
882 Options
linkOptions(this, this->Version
, Options::Linker
);
883 linkOptions
.Parse(extraLinkOptions
.c_str());
884 switch(target
.GetType())
886 case cmTarget::STATIC_LIBRARY
:
888 std::string targetNameFull
= target
.GetFullName(configName
);
889 std::string libpath
= target
.GetDirectory(configName
);
891 libpath
+= targetNameFull
;
892 const char* tool
= "VCLibrarianTool";
893 if(this->FortranProject
)
895 tool
= "VFLibrarianTool";
897 fout
<< "\t\t\t<Tool\n"
898 << "\t\t\t\tName=\"" << tool
<< "\"\n";
899 if(const char* libflags
= target
.GetProperty("STATIC_LIBRARY_FLAGS"))
901 fout
<< "\t\t\t\tAdditionalOptions=\"" << libflags
<< "\"\n";
903 fout
<< "\t\t\t\tOutputFile=\""
904 << this->ConvertToXMLOutputPathSingle(libpath
.c_str()) << "\"/>\n";
907 case cmTarget::SHARED_LIBRARY
:
908 case cmTarget::MODULE_LIBRARY
:
910 std::string targetName
;
911 std::string targetNameSO
;
912 std::string targetNameFull
;
913 std::string targetNameImport
;
914 std::string targetNamePDB
;
915 target
.GetLibraryNames(targetName
, targetNameSO
, targetNameFull
,
916 targetNameImport
, targetNamePDB
, configName
);
918 // Compute the link library and directory information.
919 cmComputeLinkInformation
* pcli
= target
.GetLinkInformation(configName
);
924 cmComputeLinkInformation
& cli
= *pcli
;
925 const char* linkLanguage
= cli
.GetLinkLanguage();
927 // Compute the variable name to lookup standard libraries for this
929 std::string standardLibsVar
= "CMAKE_";
930 standardLibsVar
+= linkLanguage
;
931 standardLibsVar
+= "_STANDARD_LIBRARIES";
932 const char* tool
= "VCLinkerTool";
933 if(this->FortranProject
)
935 tool
= "VFLinkerTool";
937 fout
<< "\t\t\t<Tool\n"
938 << "\t\t\t\tName=\"" << tool
<< "\"\n";
939 linkOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t", "\n");
940 // Use the NOINHERIT macro to avoid getting VS project default
941 // libraries which may be set by the user to something bad.
942 fout
<< "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
943 << this->Makefile
->GetSafeDefinition(standardLibsVar
.c_str())
945 this->Internal
->OutputLibraries(fout
, cli
.GetItems());
947 temp
= target
.GetDirectory(configName
);
949 temp
+= targetNameFull
;
950 fout
<< "\t\t\t\tOutputFile=\""
951 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"\n";
952 this->WriteTargetVersionAttribute(fout
, target
);
953 linkOptions
.OutputFlagMap(fout
, "\t\t\t\t");
954 fout
<< "\t\t\t\tAdditionalLibraryDirectories=\"";
955 this->OutputLibraryDirectories(fout
, cli
.GetDirectories());
957 this->OutputModuleDefinitionFile(fout
, target
);
958 temp
= target
.GetDirectory(configName
);
960 temp
+= targetNamePDB
;
961 fout
<< "\t\t\t\tProgramDataBaseFile=\"" <<
962 this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"\n";
965 fout
<< "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
967 std::string stackVar
= "CMAKE_";
968 stackVar
+= linkLanguage
;
969 stackVar
+= "_STACK_SIZE";
970 const char* stackVal
= this->Makefile
->GetDefinition(stackVar
.c_str());
973 fout
<< "\t\t\t\tStackReserveSize=\"" << stackVal
<< "\"\n";
975 temp
= target
.GetDirectory(configName
, true);
977 temp
+= targetNameImport
;
978 fout
<< "\t\t\t\tImportLibrary=\""
979 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"/>\n";
982 case cmTarget::EXECUTABLE
:
984 std::string targetName
;
985 std::string targetNameFull
;
986 std::string targetNameImport
;
987 std::string targetNamePDB
;
988 target
.GetExecutableNames(targetName
, targetNameFull
,
989 targetNameImport
, targetNamePDB
, configName
);
991 // Compute the link library and directory information.
992 cmComputeLinkInformation
* pcli
= target
.GetLinkInformation(configName
);
997 cmComputeLinkInformation
& cli
= *pcli
;
998 const char* linkLanguage
= cli
.GetLinkLanguage();
1000 // Compute the variable name to lookup standard libraries for this
1002 std::string standardLibsVar
= "CMAKE_";
1003 standardLibsVar
+= linkLanguage
;
1004 standardLibsVar
+= "_STANDARD_LIBRARIES";
1005 const char* tool
= "VCLinkerTool";
1006 if(this->FortranProject
)
1008 tool
= "VFLinkerTool";
1010 fout
<< "\t\t\t<Tool\n"
1011 << "\t\t\t\tName=\"" << tool
<< "\"\n";
1012 linkOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t", "\n");
1013 // Use the NOINHERIT macro to avoid getting VS project default
1014 // libraries which may be set by the user to something bad.
1015 fout
<< "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
1016 << this->Makefile
->GetSafeDefinition(standardLibsVar
.c_str())
1018 this->Internal
->OutputLibraries(fout
, cli
.GetItems());
1020 temp
= target
.GetDirectory(configName
);
1022 temp
+= targetNameFull
;
1023 fout
<< "\t\t\t\tOutputFile=\""
1024 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"\n";
1025 this->WriteTargetVersionAttribute(fout
, target
);
1026 linkOptions
.OutputFlagMap(fout
, "\t\t\t\t");
1027 fout
<< "\t\t\t\tAdditionalLibraryDirectories=\"";
1028 this->OutputLibraryDirectories(fout
, cli
.GetDirectories());
1030 fout
<< "\t\t\t\tProgramDataBaseFile=\""
1031 << target
.GetDirectory(configName
) << "/" << targetNamePDB
1035 fout
<< "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
1037 if ( target
.GetPropertyAsBool("WIN32_EXECUTABLE") )
1039 fout
<< "\t\t\t\tSubSystem=\"2\"\n";
1043 fout
<< "\t\t\t\tSubSystem=\"1\"\n";
1045 std::string stackVar
= "CMAKE_";
1046 stackVar
+= linkLanguage
;
1047 stackVar
+= "_STACK_SIZE";
1048 const char* stackVal
= this->Makefile
->GetDefinition(stackVar
.c_str());
1051 fout
<< "\t\t\t\tStackReserveSize=\"" << stackVal
<< "\"";
1053 temp
= target
.GetDirectory(configName
, true);
1055 temp
+= targetNameImport
;
1056 fout
<< "\t\t\t\tImportLibrary=\""
1057 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"/>\n";
1060 case cmTarget::UTILITY
:
1061 case cmTarget::GLOBAL_TARGET
:
1066 //----------------------------------------------------------------------------
1068 cmLocalVisualStudio7Generator
1069 ::WriteTargetVersionAttribute(std::ostream
& fout
, cmTarget
& target
)
1073 target
.GetTargetVersion(major
, minor
);
1074 fout
<< "\t\t\t\tVersion=\"" << major
<< "." << minor
<< "\"\n";
1077 void cmLocalVisualStudio7Generator
1078 ::OutputModuleDefinitionFile(std::ostream
& fout
,
1081 std::vector
<cmSourceFile
*> const& classes
= target
.GetSourceFiles();
1082 for(std::vector
<cmSourceFile
*>::const_iterator i
= classes
.begin();
1083 i
!= classes
.end(); i
++)
1085 cmSourceFile
* sf
= *i
;
1086 if(cmSystemTools::UpperCase(sf
->GetExtension()) == "DEF")
1088 fout
<< "\t\t\t\tModuleDefinitionFile=\""
1089 << this->ConvertToXMLOutputPath(sf
->GetFullPath().c_str())
1097 //----------------------------------------------------------------------------
1099 cmLocalVisualStudio7GeneratorInternals
1100 ::OutputLibraries(std::ostream
& fout
, ItemVector
const& libs
)
1102 cmLocalVisualStudio7Generator
* lg
= this->LocalGenerator
;
1103 for(ItemVector::const_iterator l
= libs
.begin(); l
!= libs
.end(); ++l
)
1107 std::string rel
= lg
->Convert(l
->Value
.c_str(),
1108 cmLocalGenerator::START_OUTPUT
,
1109 cmLocalGenerator::UNCHANGED
);
1110 fout
<< lg
->ConvertToXMLOutputPath(rel
.c_str()) << " ";
1114 fout
<< l
->Value
<< " ";
1119 //----------------------------------------------------------------------------
1121 cmLocalVisualStudio7Generator
1122 ::OutputLibraryDirectories(std::ostream
& fout
,
1123 std::vector
<std::string
> const& dirs
)
1125 const char* comma
= "";
1126 for(std::vector
<std::string
>::const_iterator d
= dirs
.begin();
1127 d
!= dirs
.end(); ++d
)
1129 // Remove any trailing slash and skip empty paths.
1130 std::string dir
= *d
;
1131 if(dir
[dir
.size()-1] == '/')
1133 dir
= dir
.substr(0, dir
.size()-1);
1140 // Switch to a relative path specification if it is shorter.
1141 if(cmSystemTools::FileIsFullPath(dir
.c_str()))
1143 std::string rel
= this->Convert(dir
.c_str(), START_OUTPUT
, UNCHANGED
);
1144 if(rel
.size() < dir
.size())
1150 // First search a configuration-specific subdirectory and then the
1151 // original directory.
1152 fout
<< comma
<< this->ConvertToXMLOutputPath((dir
+"/$(OutDir)").c_str())
1153 << "," << this->ConvertToXMLOutputPath(dir
.c_str());
1158 void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream
& fout
,
1159 const char *libName
,
1162 // get the configurations
1163 std::vector
<std::string
> *configs
=
1164 static_cast<cmGlobalVisualStudio7Generator
*>
1165 (this->GlobalGenerator
)->GetConfigurations();
1167 // We may be modifying the source groups temporarily, so make a copy.
1168 std::vector
<cmSourceGroup
> sourceGroups
= this->Makefile
->GetSourceGroups();
1170 // get the classes from the source lists then add them to the groups
1171 std::vector
<cmSourceFile
*>const & classes
= target
.GetSourceFiles();
1172 for(std::vector
<cmSourceFile
*>::const_iterator i
= classes
.begin();
1173 i
!= classes
.end(); i
++)
1175 // Add the file to the list of sources.
1176 std::string source
= (*i
)->GetFullPath();
1177 if(cmSystemTools::UpperCase((*i
)->GetExtension()) == "DEF")
1179 this->ModuleDefinitionFile
= (*i
)->GetFullPath();
1181 cmSourceGroup
& sourceGroup
=
1182 this->Makefile
->FindSourceGroup(source
.c_str(), sourceGroups
);
1183 sourceGroup
.AssignSource(*i
);
1186 // Compute which sources need unique object computation.
1187 this->ComputeObjectNameRequirements(sourceGroups
);
1190 this->WriteProjectStart(fout
, libName
, target
, sourceGroups
);
1191 // write the configuration information
1192 this->WriteConfigurations(fout
, libName
, target
);
1194 fout
<< "\t<Files>\n";
1197 // Loop through every source group.
1198 for(unsigned int i
= 0; i
< sourceGroups
.size(); ++i
)
1200 cmSourceGroup sg
= sourceGroups
[i
];
1201 this->WriteGroup(&sg
, target
, fout
, libName
, configs
);
1206 fout
<< "\t</Files>\n";
1208 // Write the VCProj file's footer.
1209 this->WriteVCProjFooter(fout
);
1212 struct cmLVS7GFileConfig
1214 std::string ObjectName
;
1215 std::string CompileFlags
;
1216 std::string CompileDefs
;
1217 std::string CompileDefsConfig
;
1218 std::string AdditionalDeps
;
1219 bool ExcludedFromBuild
;
1222 class cmLocalVisualStudio7GeneratorFCInfo
1225 cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator
* lg
,
1227 cmSourceFile
const& sf
,
1228 std::vector
<std::string
>* configs
,
1229 std::string::size_type dir_len
);
1230 std::map
<cmStdString
, cmLVS7GFileConfig
> FileConfigMap
;
1233 cmLocalVisualStudio7GeneratorFCInfo
1234 ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator
* lg
,
1236 cmSourceFile
const& sf
,
1237 std::vector
<std::string
>* configs
,
1238 std::string::size_type dir_len
)
1240 std::string objectName
;
1241 if(lg
->NeedObjectName
.find(&sf
) != lg
->NeedObjectName
.end())
1243 objectName
= lg
->GetObjectFileNameWithoutTarget(sf
, dir_len
);
1246 // Compute per-source, per-config information.
1247 for(std::vector
<std::string
>::iterator i
= configs
->begin();
1248 i
!= configs
->end(); ++i
)
1250 std::string configUpper
= cmSystemTools::UpperCase(*i
);
1251 cmLVS7GFileConfig fc
;
1252 bool needfc
= false;
1253 if(!objectName
.empty())
1255 fc
.ObjectName
= objectName
;
1258 if(const char* cflags
= sf
.GetProperty("COMPILE_FLAGS"))
1260 fc
.CompileFlags
= cflags
;
1263 if(const char* cdefs
= sf
.GetProperty("COMPILE_DEFINITIONS"))
1265 fc
.CompileDefs
= cdefs
;
1268 std::string defPropName
= "COMPILE_DEFINITIONS_";
1269 defPropName
+= configUpper
;
1270 if(const char* ccdefs
= sf
.GetProperty(defPropName
.c_str()))
1272 fc
.CompileDefsConfig
= ccdefs
;
1276 // Check for extra object-file dependencies.
1277 if(const char* deps
= sf
.GetProperty("OBJECT_DEPENDS"))
1279 std::vector
<std::string
> depends
;
1280 cmSystemTools::ExpandListArgument(deps
, depends
);
1281 const char* sep
= "";
1282 for(std::vector
<std::string
>::iterator j
= depends
.begin();
1283 j
!= depends
.end(); ++j
)
1285 fc
.AdditionalDeps
+= sep
;
1286 fc
.AdditionalDeps
+= lg
->ConvertToXMLOutputPath(j
->c_str());
1293 lg
->GlobalGenerator
->GetLanguageFromExtension
1294 (sf
.GetExtension().c_str());
1295 const char* sourceLang
= lg
->GetSourceFileLanguage(sf
);
1296 const char* linkLanguage
= target
.GetLinkerLanguage
1297 (lg
->GetGlobalGenerator());
1298 bool needForceLang
= false;
1299 // source file does not match its extension language
1300 if(lang
&& sourceLang
&& strcmp(lang
, sourceLang
) != 0)
1302 needForceLang
= true;
1305 // If lang is set, the compiler will generate code automatically.
1306 // If HEADER_FILE_ONLY is set, we must suppress this generation in
1308 fc
.ExcludedFromBuild
=
1309 (lang
&& sf
.GetPropertyAsBool("HEADER_FILE_ONLY"));
1310 if(fc
.ExcludedFromBuild
)
1315 // if the source file does not match the linker language
1316 // then force c or c++
1317 if(needForceLang
|| (linkLanguage
&& lang
1318 && strcmp(lang
, linkLanguage
) != 0))
1320 if(strcmp(lang
, "CXX") == 0)
1322 // force a C++ file type
1323 fc
.CompileFlags
+= " /TP ";
1326 else if(strcmp(lang
, "C") == 0)
1329 fc
.CompileFlags
+= " /TC ";
1336 this->FileConfigMap
[*i
] = fc
;
1341 void cmLocalVisualStudio7Generator
1342 ::WriteGroup(const cmSourceGroup
*sg
, cmTarget
& target
,
1343 std::ostream
&fout
, const char *libName
,
1344 std::vector
<std::string
> *configs
)
1346 const std::vector
<const cmSourceFile
*> &sourceFiles
=
1347 sg
->GetSourceFiles();
1348 // If the group is empty, don't write it at all.
1349 if(sourceFiles
.empty() && sg
->GetGroupChildren().empty())
1354 // If the group has a name, write the header.
1355 std::string name
= sg
->GetName();
1358 this->WriteVCProjBeginGroup(fout
, name
.c_str(), "");
1361 // Compute the maximum length of a configuration name.
1362 std::string::size_type config_len_max
= 0;
1363 for(std::vector
<std::string
>::iterator i
= configs
->begin();
1364 i
!= configs
->end(); ++i
)
1366 if(i
->size() > config_len_max
)
1368 config_len_max
= i
->size();
1372 // Compute the maximum length of the full path to the intermediate
1373 // files directory for any configuration. This is used to construct
1374 // object file names that do not produce paths that are too long.
1375 std::string::size_type dir_len
= 0;
1376 dir_len
+= strlen(this->Makefile
->GetCurrentOutputDirectory());
1378 dir_len
+= this->GetTargetDirectory(target
).size();
1380 dir_len
+= config_len_max
;
1383 // Loop through each source in the source group.
1384 std::string objectName
;
1385 for(std::vector
<const cmSourceFile
*>::const_iterator sf
=
1386 sourceFiles
.begin(); sf
!= sourceFiles
.end(); ++sf
)
1388 std::string source
= (*sf
)->GetFullPath();
1389 FCInfo
fcinfo(this, target
, *(*sf
), configs
, dir_len
);
1391 if (source
!= libName
|| target
.GetType() == cmTarget::UTILITY
||
1392 target
.GetType() == cmTarget::GLOBAL_TARGET
)
1394 fout
<< "\t\t\t<File\n";
1395 std::string d
= this->ConvertToXMLOutputPathSingle(source
.c_str());
1396 // Tell MS-Dev what the source is. If the compiler knows how to
1397 // build it, then it will.
1398 fout
<< "\t\t\t\tRelativePath=\"" << d
<< "\">\n";
1399 if(cmCustomCommand
const* command
= (*sf
)->GetCustomCommand())
1401 this->WriteCustomRule(fout
, source
.c_str(), *command
, fcinfo
);
1403 else if(!fcinfo
.FileConfigMap
.empty())
1405 const char* aCompilerTool
= "VCCLCompilerTool";
1406 std::string ext
= (*sf
)->GetExtension();
1407 ext
= cmSystemTools::LowerCase(ext
);
1410 aCompilerTool
= "VCMIDLTool";
1411 if(this->FortranProject
)
1413 aCompilerTool
= "VFMIDLTool";
1418 aCompilerTool
= "VCResourceCompilerTool";
1419 if(this->FortranProject
)
1421 aCompilerTool
= "VFResourceCompilerTool";
1426 aCompilerTool
= "VCCustomBuildTool";
1427 if(this->FortranProject
)
1429 aCompilerTool
= "VFCustomBuildTool";
1432 for(std::map
<cmStdString
, cmLVS7GFileConfig
>::const_iterator
1433 fci
= fcinfo
.FileConfigMap
.begin();
1434 fci
!= fcinfo
.FileConfigMap
.end(); ++fci
)
1436 cmLVS7GFileConfig
const& fc
= fci
->second
;
1437 fout
<< "\t\t\t\t<FileConfiguration\n"
1438 << "\t\t\t\t\tName=\"" << fci
->first
1439 << "|" << this->PlatformName
<< "\"";
1440 if(fc
.ExcludedFromBuild
)
1442 fout
<< " ExcludedFromBuild=\"true\"";
1445 fout
<< "\t\t\t\t\t<Tool\n"
1446 << "\t\t\t\t\tName=\"" << aCompilerTool
<< "\"\n";
1447 if(!fc
.CompileFlags
.empty() ||
1448 !fc
.CompileDefs
.empty() ||
1449 !fc
.CompileDefsConfig
.empty())
1451 Options
fileOptions(this, this->Version
, Options::Compiler
,
1452 this->ExtraFlagTable
);
1453 fileOptions
.Parse(fc
.CompileFlags
.c_str());
1454 fileOptions
.AddDefines(fc
.CompileDefs
.c_str());
1455 fileOptions
.AddDefines(fc
.CompileDefsConfig
.c_str());
1456 fileOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t\t", "\n");
1457 fileOptions
.OutputFlagMap(fout
, "\t\t\t\t\t");
1458 fileOptions
.OutputPreprocessorDefinitions(fout
,
1459 "\t\t\t\t\t", "\n");
1461 if(!fc
.AdditionalDeps
.empty())
1463 fout
<< "\t\t\t\t\tAdditionalDependencies=\""
1464 << fc
.AdditionalDeps
.c_str() << "\"\n";
1466 if(!fc
.ObjectName
.empty())
1468 fout
<< "\t\t\t\t\tObjectFile=\"$(IntDir)/"
1469 << fc
.ObjectName
.c_str() << "\"\n";
1471 fout
<< "\t\t\t\t\t/>\n"
1472 << "\t\t\t\t</FileConfiguration>\n";
1475 fout
<< "\t\t\t</File>\n";
1479 std::vector
<cmSourceGroup
> const& children
= sg
->GetGroupChildren();
1481 for(unsigned int i
=0;i
<children
.size();++i
)
1483 this->WriteGroup(&children
[i
], target
, fout
, libName
, configs
);
1486 // If the group has a name, write the footer.
1489 this->WriteVCProjEndGroup(fout
);
1493 void cmLocalVisualStudio7Generator::
1494 WriteCustomRule(std::ostream
& fout
,
1496 const cmCustomCommand
& command
,
1499 std::string comment
= this->ConstructComment(command
);
1501 // Write the rule for each configuration.
1502 std::vector
<std::string
>::iterator i
;
1503 std::vector
<std::string
> *configs
=
1504 static_cast<cmGlobalVisualStudio7Generator
*>
1505 (this->GlobalGenerator
)->GetConfigurations();
1506 const char* compileTool
= "VCCLCompilerTool";
1507 if(this->FortranProject
)
1509 compileTool
= "VFCLCompilerTool";
1511 const char* customTool
= "VCCustomBuildTool";
1512 if(this->FortranProject
)
1514 customTool
= "VFCustomBuildTool";
1516 for(i
= configs
->begin(); i
!= configs
->end(); ++i
)
1518 cmLVS7GFileConfig
const& fc
= fcinfo
.FileConfigMap
[*i
];
1519 fout
<< "\t\t\t\t<FileConfiguration\n";
1520 fout
<< "\t\t\t\t\tName=\"" << *i
<< "|" << this->PlatformName
<< "\">\n";
1521 if(!fc
.CompileFlags
.empty())
1523 fout
<< "\t\t\t\t\t<Tool\n"
1524 << "\t\t\t\t\tName=\"" << compileTool
<< "\"\n"
1525 << "\t\t\t\t\tAdditionalOptions=\""
1526 << this->EscapeForXML(fc
.CompileFlags
.c_str()) << "\"/>\n";
1529 std::string script
=
1530 this->ConstructScript(command
.GetCommandLines(),
1531 command
.GetWorkingDirectory(),
1533 command
.GetEscapeOldStyle(),
1534 command
.GetEscapeAllowMakeVars());
1535 fout
<< "\t\t\t\t\t<Tool\n"
1536 << "\t\t\t\t\tName=\"" << customTool
<< "\"\n"
1537 << "\t\t\t\t\tDescription=\""
1538 << this->EscapeForXML(comment
.c_str()) << "\"\n"
1539 << "\t\t\t\t\tCommandLine=\""
1540 << this->EscapeForXML(script
.c_str()) << "\"\n"
1541 << "\t\t\t\t\tAdditionalDependencies=\"";
1542 if(command
.GetDepends().empty())
1544 // There are no real dependencies. Produce an artificial one to
1545 // make sure the rule runs reliably.
1546 if(!cmSystemTools::FileExists(source
))
1548 std::ofstream
depout(source
);
1549 depout
<< "Artificial dependency for a custom command.\n";
1551 fout
<< this->ConvertToXMLOutputPath(source
);
1555 // Write out the dependencies for the rule.
1556 for(std::vector
<std::string
>::const_iterator d
=
1557 command
.GetDepends().begin();
1558 d
!= command
.GetDepends().end();
1561 // Get the real name of the dependency in case it is a CMake target.
1562 std::string dep
= this->GetRealDependency(d
->c_str(), i
->c_str());
1563 fout
<< this->ConvertToXMLOutputPath(dep
.c_str())
1568 fout
<< "\t\t\t\t\tOutputs=\"";
1569 if(command
.GetOutputs().empty())
1571 fout
<< source
<< "_force";
1575 // Write a rule for the output generated by this command.
1576 const char* sep
= "";
1577 for(std::vector
<std::string
>::const_iterator o
=
1578 command
.GetOutputs().begin();
1579 o
!= command
.GetOutputs().end();
1582 fout
<< sep
<< this->ConvertToXMLOutputPathSingle(o
->c_str());
1587 fout
<< "\t\t\t\t</FileConfiguration>\n";
1592 void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream
& fout
,
1596 fout
<< "\t\t<Filter\n"
1597 << "\t\t\tName=\"" << group
<< "\"\n"
1598 << "\t\t\tFilter=\"\">\n";
1602 void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream
& fout
)
1604 fout
<< "\t\t</Filter>\n";
1608 // look for custom rules on a target and collect them together
1609 void cmLocalVisualStudio7Generator
1610 ::OutputTargetRules(std::ostream
& fout
,
1611 const char* configName
,
1613 const char * /*libName*/)
1615 if (target
.GetType() > cmTarget::GLOBAL_TARGET
)
1619 const char* tool
= "VCPreBuildEventTool";
1620 if(this->FortranProject
)
1622 tool
= "VFPreBuildEventTool";
1624 // add the pre build rules
1625 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"";
1627 for (std::vector
<cmCustomCommand
>::const_iterator cr
=
1628 target
.GetPreBuildCommands().begin();
1629 cr
!= target
.GetPreBuildCommands().end(); ++cr
)
1633 const char* comment
= cr
->GetComment();
1634 if(comment
&& *comment
)
1636 fout
<< "\nDescription=\""
1637 << this->EscapeForXML(comment
) << "\"";
1639 fout
<< "\nCommandLine=\"";
1644 fout
<< this->EscapeForXML("\n");
1646 std::string script
=
1647 this->ConstructScript(cr
->GetCommandLines(),
1648 cr
->GetWorkingDirectory(),
1650 cr
->GetEscapeOldStyle(),
1651 cr
->GetEscapeAllowMakeVars());
1652 fout
<< this->EscapeForXML(script
.c_str()).c_str();
1660 // add the pre Link rules
1661 tool
= "VCPreLinkEventTool";
1662 if(this->FortranProject
)
1664 tool
= "VFPreLinkEventTool";
1666 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"";
1668 for (std::vector
<cmCustomCommand
>::const_iterator cr
=
1669 target
.GetPreLinkCommands().begin();
1670 cr
!= target
.GetPreLinkCommands().end(); ++cr
)
1674 const char* comment
= cr
->GetComment();
1675 if(comment
&& *comment
)
1677 fout
<< "\nDescription=\""
1678 << this->EscapeForXML(comment
) << "\"";
1680 fout
<< "\nCommandLine=\"";
1685 fout
<< this->EscapeForXML("\n");
1687 std::string script
=
1688 this->ConstructScript(cr
->GetCommandLines(),
1689 cr
->GetWorkingDirectory(),
1691 cr
->GetEscapeOldStyle(),
1692 cr
->GetEscapeAllowMakeVars());
1693 fout
<< this->EscapeForXML(script
.c_str()).c_str();
1701 // add the PostBuild rules
1702 tool
= "VCPostBuildEventTool";
1703 if(this->FortranProject
)
1705 tool
= "VFPostBuildEventTool";
1707 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"";
1709 for (std::vector
<cmCustomCommand
>::const_iterator cr
=
1710 target
.GetPostBuildCommands().begin();
1711 cr
!= target
.GetPostBuildCommands().end(); ++cr
)
1715 const char* comment
= cr
->GetComment();
1716 if(comment
&& *comment
)
1718 fout
<< "\nDescription=\""
1719 << this->EscapeForXML(comment
) << "\"";
1721 fout
<< "\nCommandLine=\"";
1726 fout
<< this->EscapeForXML("\n");
1728 std::string script
=
1729 this->ConstructScript(cr
->GetCommandLines(),
1730 cr
->GetWorkingDirectory(),
1732 cr
->GetEscapeOldStyle(),
1733 cr
->GetEscapeAllowMakeVars());
1734 fout
<< this->EscapeForXML(script
.c_str()).c_str();
1744 cmLocalVisualStudio7Generator
1745 ::WriteProjectStartFortran(std::ostream
& fout
,
1746 const char *libName
,
1750 cmGlobalVisualStudio7Generator
* gg
=
1751 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
1752 fout
<< "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
1753 << "<VisualStudioProject\n"
1754 << "\tProjectCreator=\"Intel Fortran\"\n"
1755 << "\tVersion=\"9.10\"\n";
1756 const char* keyword
= target
.GetProperty("VS_KEYWORD");
1759 keyword
= "Console Application";
1761 const char* projectType
= 0;
1762 switch(target
.GetType())
1764 case cmTarget::STATIC_LIBRARY
:
1765 projectType
= "typeStaticLibrary";
1768 keyword
= "Static Library";
1771 case cmTarget::SHARED_LIBRARY
:
1772 case cmTarget::MODULE_LIBRARY
:
1773 projectType
= "typeDynamicLibrary";
1779 case cmTarget::EXECUTABLE
:
1782 keyword
= "Console Application";
1786 case cmTarget::UTILITY
:
1787 case cmTarget::GLOBAL_TARGET
:
1793 fout
<< "\tProjectType=\"" << projectType
<< "\"\n";
1795 fout
<< "\tKeyword=\"" << keyword
<< "\">\n"
1796 << "\tProjectGUID=\"{" << gg
->GetGUID(libName
) << "}\">\n"
1797 << "\t<Platforms>\n"
1798 << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName
<< "\"/>\n"
1799 << "\t</Platforms>\n";
1804 cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream
& fout
,
1805 const char *libName
,
1807 std::vector
<cmSourceGroup
> &)
1809 if(this->FortranProject
)
1811 this->WriteProjectStartFortran(fout
, libName
, target
);
1814 fout
<< "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
1815 << "<VisualStudioProject\n"
1816 << "\tProjectType=\"Visual C++\"\n";
1817 if(this->Version
== 71)
1819 fout
<< "\tVersion=\"7.10\"\n";
1823 fout
<< "\tVersion=\"" << this->Version
<< ".00\"\n";
1825 const char* projLabel
= target
.GetProperty("PROJECT_LABEL");
1828 projLabel
= libName
;
1830 const char* keyword
= target
.GetProperty("VS_KEYWORD");
1833 keyword
= "Win32Proj";
1835 const char* vsProjectname
= target
.GetProperty("VS_SCC_PROJECTNAME");
1840 const char* vsLocalpath
= target
.GetProperty("VS_SCC_LOCALPATH");
1845 const char* vsProvider
= target
.GetProperty("VS_SCC_PROVIDER");
1846 std::string providerString
;
1849 providerString
= "";
1853 providerString
= "\tSccProvider=\"" + std::string(vsProvider
) + "\"\n";
1855 cmGlobalVisualStudio7Generator
* gg
=
1856 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
1857 fout
<< "\tName=\"" << projLabel
<< "\"\n";
1858 if(this->Version
>= 8)
1860 fout
<< "\tProjectGUID=\"{" << gg
->GetGUID(libName
) << "}\"\n";
1862 // if we have all the required Source code control tags
1863 // then add that to the project
1864 if(vsProvider
&& vsLocalpath
&& vsProjectname
)
1866 fout
<< "\tSccProjectName=\"" << vsProjectname
<< "\"\n"
1867 << "\tSccLocalPath=\"" << vsLocalpath
<< "\"\n"
1868 << "\tSccProvider=\"" << providerString
<< "\"\n";
1870 fout
<< "\tKeyword=\"" << keyword
<< "\">\n"
1871 << "\t<Platforms>\n"
1872 << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName
<< "\"/>\n"
1873 << "\t</Platforms>\n";
1877 void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream
& fout
)
1879 fout
<< "\t<Globals>\n"
1881 << "</VisualStudioProject>\n";
1884 std::string
cmLocalVisualStudio7GeneratorEscapeForXML(const char* s
)
1886 std::string ret
= s
;
1887 cmSystemTools::ReplaceString(ret
, "&", "&");
1888 cmSystemTools::ReplaceString(ret
, "\"", """);
1889 cmSystemTools::ReplaceString(ret
, "<", "<");
1890 cmSystemTools::ReplaceString(ret
, ">", ">");
1891 cmSystemTools::ReplaceString(ret
, "\n", "
");
1895 std::string
cmLocalVisualStudio7Generator::EscapeForXML(const char* s
)
1897 return cmLocalVisualStudio7GeneratorEscapeForXML(s
);
1900 std::string cmLocalVisualStudio7Generator
1901 ::ConvertToXMLOutputPath(const char* path
)
1903 std::string ret
= this->ConvertToOptionallyRelativeOutputPath(path
);
1904 cmSystemTools::ReplaceString(ret
, "&", "&");
1905 cmSystemTools::ReplaceString(ret
, "\"", """);
1906 cmSystemTools::ReplaceString(ret
, "<", "<");
1907 cmSystemTools::ReplaceString(ret
, ">", ">");
1911 std::string cmLocalVisualStudio7Generator
1912 ::ConvertToXMLOutputPathSingle(const char* path
)
1914 std::string ret
= this->ConvertToOptionallyRelativeOutputPath(path
);
1915 cmSystemTools::ReplaceString(ret
, "\"", "");
1916 cmSystemTools::ReplaceString(ret
, "&", "&");
1917 cmSystemTools::ReplaceString(ret
, "<", "<");
1918 cmSystemTools::ReplaceString(ret
, ">", ">");
1923 // This class is used to parse an existing vs 7 project
1924 // and extract the GUID
1925 class cmVS7XMLParser
: public cmXMLParser
1928 virtual void EndElement(const char* /* name */)
1931 virtual void StartElement(const char* name
, const char** atts
)
1933 // once the GUID is found do nothing
1934 if(this->GUID
.size())
1939 if(strcmp("VisualStudioProject", name
) == 0)
1943 if(strcmp(atts
[i
], "ProjectGUID") == 0)
1947 this->GUID
= atts
[i
+1];
1948 this->GUID
= this->GUID
.substr(1, this->GUID
.size()-2);
1960 int InitializeParser()
1962 int ret
= cmXMLParser::InitializeParser();
1967 // visual studio projects have a strange encoding, but it is
1969 XML_SetEncoding(static_cast<XML_Parser
>(this->Parser
), "utf-8");
1975 void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
1979 cmVS7XMLParser parser
;
1980 parser
.ParseFile(path
);
1981 // if we can not find a GUID then create one
1982 if(parser
.GUID
.size() == 0)
1984 cmGlobalVisualStudio7Generator
* gg
=
1985 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
1986 gg
->CreateGUID(name
);
1989 std::string guidStoreName
= name
;
1990 guidStoreName
+= "_GUID_CMAKE";
1991 // save the GUID in the cache
1992 this->GlobalGenerator
->GetCMakeInstance()->
1993 AddCacheEntry(guidStoreName
.c_str(),
1994 parser
.GUID
.c_str(),
1996 cmCacheManager::INTERNAL
);
2000 void cmLocalVisualStudio7Generator::ConfigureFinalPass()
2002 cmLocalGenerator::ConfigureFinalPass();
2003 cmTargets
&tgts
= this->Makefile
->GetTargets();
2005 cmGlobalVisualStudio7Generator
* gg
=
2006 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
2007 for(cmTargets::iterator l
= tgts
.begin(); l
!= tgts
.end(); l
++)
2009 if (strncmp(l
->first
.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
2011 cmCustomCommand cc
= l
->second
.GetPostBuildCommands()[0];
2012 const cmCustomCommandLines
& cmds
= cc
.GetCommandLines();
2013 std::string project_name
= cmds
[0][0];
2014 this->ReadAndStoreExternalGUID(project_name
.c_str(),
2015 cmds
[0][1].c_str());
2019 gg
->CreateGUID(l
->first
.c_str());
2025 //----------------------------------------------------------------------------
2026 std::string cmLocalVisualStudio7Generator
2027 ::GetTargetDirectory(cmTarget
const& target
) const
2030 dir
+= target
.GetName();
2035 //----------------------------------------------------------------------------
2036 cmLocalVisualStudio7GeneratorOptions
2037 ::cmLocalVisualStudio7GeneratorOptions(cmLocalVisualStudio7Generator
* lg
,
2040 cmVS7FlagTable
const* extraTable
):
2041 LocalGenerator(lg
), Version(version
), CurrentTool(tool
),
2042 DoingDefine(false), FlagTable(0), ExtraFlagTable(extraTable
)
2044 // Choose the flag table for the requested tool.
2048 this->FlagTable
= cmLocalVisualStudio7GeneratorFlagTable
; break;
2050 this->FlagTable
= cmLocalVisualStudio7GeneratorLinkFlagTable
; break;
2051 case FortranCompiler
:
2052 this->FlagTable
= cmLocalVisualStudio7GeneratorFortranFlagTable
;
2057 //----------------------------------------------------------------------------
2058 void cmLocalVisualStudio7GeneratorOptions::FixExceptionHandlingDefault()
2060 // Exception handling is on by default because the platform file has
2061 // "/EHsc" in the flags. Normally, that will override this
2062 // initialization to off, but the user has the option of removing
2063 // the flag to disable exception handling. When the user does
2064 // remove the flag we need to override the IDE default of on.
2065 switch (this->Version
)
2069 this->FlagMap
["ExceptionHandling"] = "FALSE";
2073 this->FlagMap
["ExceptionHandling"] = "0";
2078 //----------------------------------------------------------------------------
2079 void cmLocalVisualStudio7GeneratorOptions::SetVerboseMakefile(bool verbose
)
2081 // If verbose makefiles have been requested and the /nologo option
2082 // was not given explicitly in the flags we want to add an attribute
2083 // to the generated project to disable logo suppression. Otherwise
2084 // the GUI default is to enable suppression.
2086 this->FlagMap
.find("SuppressStartupBanner") == this->FlagMap
.end())
2088 this->FlagMap
["SuppressStartupBanner"] = "FALSE";
2092 //----------------------------------------------------------------------------
2093 void cmLocalVisualStudio7GeneratorOptions::AddDefine(const std::string
& def
)
2095 this->Defines
.push_back(def
);
2098 //----------------------------------------------------------------------------
2099 void cmLocalVisualStudio7GeneratorOptions::AddDefines(const char* defines
)
2103 // Expand the list of definitions.
2104 cmSystemTools::ExpandListArgument(defines
, this->Defines
);
2108 //----------------------------------------------------------------------------
2109 void cmLocalVisualStudio7GeneratorOptions::AddFlag(const char* flag
,
2112 this->FlagMap
[flag
] = value
;
2116 bool cmLocalVisualStudio7GeneratorOptions::IsDebug()
2118 return this->FlagMap
.find("DebugInformationFormat") != this->FlagMap
.end();
2121 //----------------------------------------------------------------------------
2122 bool cmLocalVisualStudio7GeneratorOptions::UsingUnicode()
2124 // Look for the a _UNICODE definition.
2125 for(std::vector
<std::string
>::const_iterator di
= this->Defines
.begin();
2126 di
!= this->Defines
.end(); ++di
)
2128 if(*di
== "_UNICODE")
2136 //----------------------------------------------------------------------------
2137 void cmLocalVisualStudio7GeneratorOptions::Parse(const char* flags
)
2139 // Parse the input string as a windows command line since the string
2140 // is intended for writing directly into the build files.
2141 std::vector
<std::string
> args
;
2142 cmSystemTools::ParseWindowsCommandLine(flags
, args
);
2144 // Process flags that need to be represented specially in the IDE
2146 for(std::vector
<std::string
>::iterator ai
= args
.begin();
2147 ai
!= args
.end(); ++ai
)
2149 this->HandleFlag(ai
->c_str());
2153 //----------------------------------------------------------------------------
2154 void cmLocalVisualStudio7GeneratorOptions::HandleFlag(const char* flag
)
2156 // If the last option was -D then this option is the definition.
2157 if(this->DoingDefine
)
2159 this->DoingDefine
= false;
2160 this->Defines
.push_back(flag
);
2164 // Look for known arguments.
2165 if(flag
[0] == '-' || flag
[0] == '/')
2167 // Look for preprocessor definitions.
2168 if(this->CurrentTool
== Compiler
&& flag
[1] == 'D')
2172 // The next argument will have the definition.
2173 this->DoingDefine
= true;
2177 // Store this definition.
2178 this->Defines
.push_back(flag
+2);
2183 // Look through the available flag tables.
2184 bool flag_handled
= false;
2185 if(this->FlagTable
&&
2186 this->CheckFlagTable(this->FlagTable
, flag
, flag_handled
))
2190 if(this->ExtraFlagTable
&&
2191 this->CheckFlagTable(this->ExtraFlagTable
, flag
, flag_handled
))
2196 // If any map entry handled the flag we are done.
2202 // This option is not known. Store it in the output flags.
2203 this->FlagString
+= " ";
2205 cmSystemTools::EscapeWindowsShellArgument(
2207 cmsysSystem_Shell_Flag_AllowMakeVariables
|
2208 cmsysSystem_Shell_Flag_VSIDE
);
2211 //----------------------------------------------------------------------------
2213 cmLocalVisualStudio7GeneratorOptions
2214 ::CheckFlagTable(cmVS7FlagTable
const* table
, const char* flag
,
2217 // Look for an entry in the flag table matching this flag.
2218 for(cmVS7FlagTable
const* entry
= table
; entry
->IDEName
; ++entry
)
2220 bool entry_found
= false;
2221 if(entry
->special
& cmVS7FlagTable::UserValue
)
2223 // This flag table entry accepts a user-specified value. If
2224 // the entry specifies UserRequired we must match only if a
2225 // non-empty value is given.
2226 int n
= static_cast<int>(strlen(entry
->commandFlag
));
2227 if(strncmp(flag
+1, entry
->commandFlag
, n
) == 0 &&
2228 (!(entry
->special
& cmVS7FlagTable::UserRequired
) ||
2229 static_cast<int>(strlen(flag
+1)) > n
))
2231 if(entry
->special
& cmVS7FlagTable::UserIgnored
)
2233 // Ignore the user-specified value.
2234 this->FlagMap
[entry
->IDEName
] = entry
->value
;
2236 else if(entry
->special
& cmVS7FlagTable::SemicolonAppendable
)
2238 const char *new_value
= flag
+1+n
;
2240 std::map
<cmStdString
,cmStdString
>::iterator itr
;
2241 itr
= this->FlagMap
.find(entry
->IDEName
);
2242 if(itr
!= this->FlagMap
.end())
2244 // Append to old value (if present) with semicolons;
2246 itr
->second
+= new_value
;
2250 this->FlagMap
[entry
->IDEName
] = new_value
;
2255 // Use the user-specified value.
2256 this->FlagMap
[entry
->IDEName
] = flag
+1+n
;
2261 else if(strcmp(flag
+1, entry
->commandFlag
) == 0)
2263 // This flag table entry provides a fixed value.
2264 this->FlagMap
[entry
->IDEName
] = entry
->value
;
2268 // If the flag has been handled by an entry not requesting a
2269 // search continuation we are done.
2270 if(entry_found
&& !(entry
->special
& cmVS7FlagTable::Continue
))
2275 // If the entry was found the flag has been handled.
2276 flag_handled
= flag_handled
|| entry_found
;
2282 //----------------------------------------------------------------------------
2284 cmLocalVisualStudio7GeneratorOptions
2285 ::OutputPreprocessorDefinitions(std::ostream
& fout
,
2289 if(this->Defines
.empty())
2294 fout
<< prefix
<< "PreprocessorDefinitions=\"";
2295 const char* comma
= "";
2296 for(std::vector
<std::string
>::const_iterator di
= this->Defines
.begin();
2297 di
!= this->Defines
.end(); ++di
)
2299 // Escape the definition for the compiler.
2300 std::string define
=
2301 this->LocalGenerator
->EscapeForShell(di
->c_str(), true);
2303 // Escape this flag for the IDE.
2304 define
= cmLocalVisualStudio7GeneratorEscapeForXML(define
.c_str());
2306 // Store the flag in the project file.
2307 fout
<< comma
<< define
;
2310 fout
<< "\"" << suffix
;
2313 //----------------------------------------------------------------------------
2315 cmLocalVisualStudio7GeneratorOptions
2316 ::OutputFlagMap(std::ostream
& fout
, const char* indent
)
2318 for(std::map
<cmStdString
, cmStdString
>::iterator m
= this->FlagMap
.begin();
2319 m
!= this->FlagMap
.end(); ++m
)
2321 fout
<< indent
<< m
->first
<< "=\"" << m
->second
<< "\"\n";
2325 //----------------------------------------------------------------------------
2327 cmLocalVisualStudio7GeneratorOptions
2328 ::OutputAdditionalOptions(std::ostream
& fout
,
2332 if(!this->FlagString
.empty())
2334 fout
<< prefix
<< "AdditionalOptions=\"";
2336 cmLocalVisualStudio7GeneratorEscapeForXML(this->FlagString
.c_str());
2337 fout
<< "\"" << suffix
;
2340 void cmLocalVisualStudio7Generator::
2341 GetTargetObjectFileDirectories(cmTarget
* target
,
2342 std::vector
<std::string
>&
2345 std::string dir
= this->Makefile
->GetCurrentOutputDirectory();
2347 dir
+= this->GetTargetDirectory(*target
);
2349 dir
+= this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
2350 dirs
.push_back(dir
);
2353 //----------------------------------------------------------------------------
2354 #include <windows.h>
2355 static bool cmLVS6G_IsFAT(const char* dir
)
2357 if(dir
[0] && dir
[1] == ':')
2359 char volRoot
[4] = "_:/";
2360 volRoot
[0] = dir
[0];
2362 if(GetVolumeInformation(volRoot
, 0, 0, 0, 0, 0, fsName
, 16) &&
2363 strstr(fsName
, "FAT") != 0)