1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalVisualStudio7Generator.cxx,v $
6 Date: $Date: 2009-07-28 18:30:15 $
7 Version: $Revision: 1.249 $
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(!l
->second
.GetProperty("EXTERNAL_MSPROJECT"))
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 // Helper class to write build event <Tool .../> elements.
483 class cmLocalVisualStudio7Generator::EventWriter
486 EventWriter(cmLocalVisualStudio7Generator
* lg
,
487 const char* config
, std::ostream
& os
):
488 LG(lg
), Config(config
), Stream(os
), First(true) {}
489 void Start(const char* tool
)
492 this->Stream
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"";
496 this->Stream
<< (this->First
? "" : "\"") << "/>\n";
498 void Write(std::vector
<cmCustomCommand
> const& ccs
)
500 for(std::vector
<cmCustomCommand
>::const_iterator ci
= ccs
.begin();
501 ci
!= ccs
.end(); ++ci
)
506 void Write(cmCustomCommand
const& cc
)
510 const char* comment
= cc
.GetComment();
511 if(comment
&& *comment
)
513 this->Stream
<< "\nDescription=\""
514 << this->LG
->EscapeForXML(comment
) << "\"";
516 this->Stream
<< "\nCommandLine=\"";
521 this->Stream
<< this->LG
->EscapeForXML("\n");
524 this->LG
->ConstructScript(cc
.GetCommandLines(),
525 cc
.GetWorkingDirectory(),
527 cc
.GetEscapeOldStyle(),
528 cc
.GetEscapeAllowMakeVars());
529 this->Stream
<< this->LG
->EscapeForXML(script
.c_str());
532 cmLocalVisualStudio7Generator
* LG
;
534 std::ostream
& Stream
;
538 //----------------------------------------------------------------------------
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 bool targetBuilds
= true;
560 switch(target
.GetType())
562 case cmTarget::STATIC_LIBRARY
:
563 projectType
= "typeStaticLibrary";
566 case cmTarget::SHARED_LIBRARY
:
567 case cmTarget::MODULE_LIBRARY
:
568 projectType
= "typeDynamicLibrary";
571 case cmTarget::EXECUTABLE
:
574 case cmTarget::UTILITY
:
575 case cmTarget::GLOBAL_TARGET
:
578 targetBuilds
= false;
581 if(this->FortranProject
&& projectType
)
583 configType
= projectType
;
586 if(strcmp(configType
, "10") != 0)
588 const char* linkLanguage
= target
.GetLinkerLanguage(configName
);
592 ("CMake can not determine linker language for target:",
596 if(strcmp(linkLanguage
, "C") == 0 || strcmp(linkLanguage
, "CXX") == 0
597 || strcmp(linkLanguage
, "Fortran") == 0)
599 std::string baseFlagVar
= "CMAKE_";
600 baseFlagVar
+= linkLanguage
;
601 baseFlagVar
+= "_FLAGS";
602 flags
= this->Makefile
->GetRequiredDefinition(baseFlagVar
.c_str());
603 std::string flagVar
= baseFlagVar
+ std::string("_") +
604 cmSystemTools::UpperCase(configName
);
606 flags
+= this->Makefile
->GetRequiredDefinition(flagVar
.c_str());
608 // set the correct language
609 if(strcmp(linkLanguage
, "C") == 0)
613 if(strcmp(linkLanguage
, "CXX") == 0)
619 // Add the target-specific flags.
620 if(const char* targetFlags
= target
.GetProperty("COMPILE_FLAGS"))
623 flags
+= targetFlags
;
626 std::string configUpper
= cmSystemTools::UpperCase(configName
);
627 std::string defPropName
= "COMPILE_DEFINITIONS_";
628 defPropName
+= configUpper
;
630 // Get preprocessor definitions for this directory.
631 std::string defineFlags
= this->Makefile
->GetDefineFlags();
632 Options::Tool t
= Options::Compiler
;
633 cmVS7FlagTable
const* table
= cmLocalVisualStudio7GeneratorFlagTable
;
634 if(this->FortranProject
)
636 t
= Options::FortranCompiler
;
637 table
= cmLocalVisualStudio7GeneratorFortranFlagTable
;
639 Options
targetOptions(this, this->Version
, t
,
641 this->ExtraFlagTable
);
642 targetOptions
.FixExceptionHandlingDefault();
643 targetOptions
.Parse(flags
.c_str());
644 targetOptions
.Parse(defineFlags
.c_str());
645 targetOptions
.AddDefines
646 (this->Makefile
->GetProperty("COMPILE_DEFINITIONS"));
647 targetOptions
.AddDefines(target
.GetProperty("COMPILE_DEFINITIONS"));
648 targetOptions
.AddDefines(this->Makefile
->GetProperty(defPropName
.c_str()));
649 targetOptions
.AddDefines(target
.GetProperty(defPropName
.c_str()));
650 targetOptions
.SetVerboseMakefile(
651 this->Makefile
->IsOn("CMAKE_VERBOSE_MAKEFILE"));
653 // Add a definition for the configuration name.
654 std::string configDefine
= "CMAKE_INTDIR=\"";
655 configDefine
+= configName
;
656 configDefine
+= "\"";
657 targetOptions
.AddDefine(configDefine
);
659 // Add the export symbol definition for shared library objects.
660 if(const char* exportMacro
= target
.GetExportMacro())
662 targetOptions
.AddDefine(exportMacro
);
665 // The intermediate directory name consists of a directory for the
666 // target and a subdirectory for the configuration name.
667 std::string intermediateDir
= this->GetTargetDirectory(target
);
668 intermediateDir
+= "/";
669 intermediateDir
+= configName
;
670 fout
<< "\t\t\tIntermediateDirectory=\""
671 << this->ConvertToXMLOutputPath(intermediateDir
.c_str())
673 << "\t\t\tConfigurationType=\"" << configType
<< "\"\n"
674 << "\t\t\tUseOfMFC=\"" << mfcFlag
<< "\"\n"
675 << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
677 // If unicode is enabled change the character set to unicode, if not
678 // then default to MBCS.
679 if(targetOptions
.UsingUnicode())
681 fout
<< "\t\t\tCharacterSet=\"1\">\n";
685 fout
<< "\t\t\tCharacterSet=\"2\">\n";
687 const char* tool
= "VCCLCompilerTool";
688 if(this->FortranProject
)
690 tool
= "VFFortranCompilerTool";
692 fout
<< "\t\t\t<Tool\n"
693 << "\t\t\t\tName=\"" << tool
<< "\"\n";
694 if(this->FortranProject
)
696 const char* target_mod_dir
=
697 target
.GetProperty("Fortran_MODULE_DIRECTORY");
701 modDir
= this->Convert(target_mod_dir
,
702 cmLocalGenerator::START_OUTPUT
,
703 cmLocalGenerator::UNCHANGED
);
709 fout
<< "\t\t\t\tModulePath=\""
710 << this->ConvertToXMLOutputPath(modDir
.c_str())
711 << "\\$(ConfigurationName)\"\n";
713 targetOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t", "\n");
714 fout
<< "\t\t\t\tAdditionalIncludeDirectories=\"";
715 std::vector
<std::string
> includes
;
716 this->GetIncludeDirectories(includes
);
717 std::vector
<std::string
>::iterator i
= includes
.begin();
718 for(;i
!= includes
.end(); ++i
)
720 // output the include path
721 std::string ipath
= this->ConvertToXMLOutputPath(i
->c_str());
722 fout
<< ipath
<< ";";
723 // if this is fortran then output the include with
724 // a ConfigurationName on the end of it.
725 if(this->FortranProject
)
728 ipath
+= "/$(ConfigurationName)";
729 ipath
= this->ConvertToXMLOutputPath(ipath
.c_str());
730 fout
<< ipath
<< ";";
734 targetOptions
.OutputFlagMap(fout
, "\t\t\t\t");
735 targetOptions
.OutputPreprocessorDefinitions(fout
, "\t\t\t\t", "\n");
736 fout
<< "\t\t\t\tAssemblerListingLocation=\"" << configName
<< "\"\n";
737 fout
<< "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
740 // We need to specify a program database file name even for
741 // non-debug configurations because VS still creates .idb files.
742 fout
<< "\t\t\t\tProgramDataBaseFileName=\""
743 << target
.GetDirectory(configName
) << "/"
744 << target
.GetPDBName(configName
) << "\"\n";
746 fout
<< "/>\n"; // end of <Tool Name=VCCLCompilerTool
747 tool
= "VCCustomBuildTool";
748 if(this->FortranProject
)
750 tool
= "VFCustomBuildTool";
752 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"/>\n";
753 tool
= "VCResourceCompilerTool";
754 if(this->FortranProject
)
756 tool
= "VFResourceCompilerTool";
758 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"\n"
759 << "\t\t\t\tAdditionalIncludeDirectories=\"";
760 for(i
= includes
.begin();i
!= includes
.end(); ++i
)
762 std::string ipath
= this->ConvertToXMLOutputPath(i
->c_str());
763 fout
<< ipath
<< ";";
765 // add the -D flags to the RC tool
767 targetOptions
.OutputPreprocessorDefinitions(fout
, "\n\t\t\t\t", "");
770 if(this->FortranProject
)
774 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"\n";
775 targetOptions
.OutputPreprocessorDefinitions(fout
, "\t\t\t\t", "\n");
776 fout
<< "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
777 if( this->PlatformName
== "x64" )
779 fout
<< "\t\t\t\tTargetEnvironment=\"3\"\n";
781 else if( this->PlatformName
== "ia64" )
783 fout
<< "\t\t\t\tTargetEnvironment=\"2\"\n";
787 fout
<< "\t\t\t\tTargetEnvironment=\"1\"\n";
789 fout
<< "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
790 fout
<< "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
791 fout
<< "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
792 fout
<< "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
793 fout
<< "\t\t\t\tDLLDataFileName=\"\"\n";
794 fout
<< "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
795 fout
<< "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
796 // end of <Tool Name=VCMIDLTool
798 // Check if we need the FAT32 workaround.
799 if(targetBuilds
&& this->Version
>= 8)
801 // Check the filesystem type where the target will be written.
802 if(cmLVS6G_IsFAT(target
.GetDirectory(configName
).c_str()))
804 // Add a flag telling the manifest tool to use a workaround
805 // for FAT32 file systems, which can cause an empty manifest
806 // to be embedded into the resulting executable. See CMake
808 const char* tool
= "VCManifestTool";
809 if(this->FortranProject
)
811 tool
= "VFManifestTool";
813 fout
<< "\t\t\t<Tool\n\t\t\t\tName=\"" << tool
<< "\"\n"
814 << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
819 this->OutputTargetRules(fout
, configName
, target
, libName
);
820 this->OutputBuildTool(fout
, configName
, target
, targetOptions
.IsDebug());
821 fout
<< "\t\t</Configuration>\n";
824 //----------------------------------------------------------------------------
826 cmLocalVisualStudio7Generator
827 ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags
, const char* configName
)
829 std::string configTypeUpper
= cmSystemTools::UpperCase(configName
);
830 std::string extraLinkOptionsBuildTypeDef
=
831 rootLinkerFlags
+ "_" + configTypeUpper
;
833 std::string extraLinkOptionsBuildType
=
834 this->Makefile
->GetRequiredDefinition
835 (extraLinkOptionsBuildTypeDef
.c_str());
837 return extraLinkOptionsBuildType
;
840 void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream
& fout
,
841 const char* configName
,
846 std::string extraLinkOptions
;
847 if(target
.GetType() == cmTarget::EXECUTABLE
)
850 this->Makefile
->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
852 + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName
);
854 if(target
.GetType() == cmTarget::SHARED_LIBRARY
)
857 this->Makefile
->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
859 + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName
);
861 if(target
.GetType() == cmTarget::MODULE_LIBRARY
)
864 this->Makefile
->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
866 + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName
);
869 const char* targetLinkFlags
= target
.GetProperty("LINK_FLAGS");
872 extraLinkOptions
+= " ";
873 extraLinkOptions
+= targetLinkFlags
;
875 std::string configTypeUpper
= cmSystemTools::UpperCase(configName
);
876 std::string linkFlagsConfig
= "LINK_FLAGS_";
877 linkFlagsConfig
+= configTypeUpper
;
878 targetLinkFlags
= target
.GetProperty(linkFlagsConfig
.c_str());
881 extraLinkOptions
+= " ";
882 extraLinkOptions
+= targetLinkFlags
;
884 Options
linkOptions(this, this->Version
, Options::Linker
,
885 cmLocalVisualStudio7GeneratorLinkFlagTable
);
886 linkOptions
.Parse(extraLinkOptions
.c_str());
887 switch(target
.GetType())
889 case cmTarget::STATIC_LIBRARY
:
891 std::string targetNameFull
= target
.GetFullName(configName
);
892 std::string libpath
= target
.GetDirectory(configName
);
894 libpath
+= targetNameFull
;
895 const char* tool
= "VCLibrarianTool";
896 if(this->FortranProject
)
898 tool
= "VFLibrarianTool";
900 fout
<< "\t\t\t<Tool\n"
901 << "\t\t\t\tName=\"" << tool
<< "\"\n";
902 if(const char* libflags
= target
.GetProperty("STATIC_LIBRARY_FLAGS"))
904 fout
<< "\t\t\t\tAdditionalOptions=\"" << libflags
<< "\"\n";
906 fout
<< "\t\t\t\tOutputFile=\""
907 << this->ConvertToXMLOutputPathSingle(libpath
.c_str()) << "\"/>\n";
910 case cmTarget::SHARED_LIBRARY
:
911 case cmTarget::MODULE_LIBRARY
:
913 std::string targetName
;
914 std::string targetNameSO
;
915 std::string targetNameFull
;
916 std::string targetNameImport
;
917 std::string targetNamePDB
;
918 target
.GetLibraryNames(targetName
, targetNameSO
, targetNameFull
,
919 targetNameImport
, targetNamePDB
, configName
);
921 // Compute the link library and directory information.
922 cmComputeLinkInformation
* pcli
= target
.GetLinkInformation(configName
);
927 cmComputeLinkInformation
& cli
= *pcli
;
928 const char* linkLanguage
= cli
.GetLinkLanguage();
930 // Compute the variable name to lookup standard libraries for this
932 std::string standardLibsVar
= "CMAKE_";
933 standardLibsVar
+= linkLanguage
;
934 standardLibsVar
+= "_STANDARD_LIBRARIES";
935 const char* tool
= "VCLinkerTool";
936 if(this->FortranProject
)
938 tool
= "VFLinkerTool";
940 fout
<< "\t\t\t<Tool\n"
941 << "\t\t\t\tName=\"" << tool
<< "\"\n";
942 linkOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t", "\n");
943 // Use the NOINHERIT macro to avoid getting VS project default
944 // libraries which may be set by the user to something bad.
945 fout
<< "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
946 << this->Makefile
->GetSafeDefinition(standardLibsVar
.c_str())
948 this->Internal
->OutputLibraries(fout
, cli
.GetItems());
950 temp
= target
.GetDirectory(configName
);
952 temp
+= targetNameFull
;
953 fout
<< "\t\t\t\tOutputFile=\""
954 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"\n";
955 this->WriteTargetVersionAttribute(fout
, target
);
956 linkOptions
.OutputFlagMap(fout
, "\t\t\t\t");
957 fout
<< "\t\t\t\tAdditionalLibraryDirectories=\"";
958 this->OutputLibraryDirectories(fout
, cli
.GetDirectories());
960 this->OutputModuleDefinitionFile(fout
, target
);
961 temp
= target
.GetDirectory(configName
);
963 temp
+= targetNamePDB
;
964 fout
<< "\t\t\t\tProgramDataBaseFile=\"" <<
965 this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"\n";
968 fout
<< "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
970 std::string stackVar
= "CMAKE_";
971 stackVar
+= linkLanguage
;
972 stackVar
+= "_STACK_SIZE";
973 const char* stackVal
= this->Makefile
->GetDefinition(stackVar
.c_str());
976 fout
<< "\t\t\t\tStackReserveSize=\"" << stackVal
<< "\"\n";
978 temp
= target
.GetDirectory(configName
, true);
980 temp
+= targetNameImport
;
981 fout
<< "\t\t\t\tImportLibrary=\""
982 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"/>\n";
985 case cmTarget::EXECUTABLE
:
987 std::string targetName
;
988 std::string targetNameFull
;
989 std::string targetNameImport
;
990 std::string targetNamePDB
;
991 target
.GetExecutableNames(targetName
, targetNameFull
,
992 targetNameImport
, targetNamePDB
, configName
);
994 // Compute the link library and directory information.
995 cmComputeLinkInformation
* pcli
= target
.GetLinkInformation(configName
);
1000 cmComputeLinkInformation
& cli
= *pcli
;
1001 const char* linkLanguage
= cli
.GetLinkLanguage();
1003 // Compute the variable name to lookup standard libraries for this
1005 std::string standardLibsVar
= "CMAKE_";
1006 standardLibsVar
+= linkLanguage
;
1007 standardLibsVar
+= "_STANDARD_LIBRARIES";
1008 const char* tool
= "VCLinkerTool";
1009 if(this->FortranProject
)
1011 tool
= "VFLinkerTool";
1013 fout
<< "\t\t\t<Tool\n"
1014 << "\t\t\t\tName=\"" << tool
<< "\"\n";
1015 linkOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t", "\n");
1016 // Use the NOINHERIT macro to avoid getting VS project default
1017 // libraries which may be set by the user to something bad.
1018 fout
<< "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
1019 << this->Makefile
->GetSafeDefinition(standardLibsVar
.c_str())
1021 this->Internal
->OutputLibraries(fout
, cli
.GetItems());
1023 temp
= target
.GetDirectory(configName
);
1025 temp
+= targetNameFull
;
1026 fout
<< "\t\t\t\tOutputFile=\""
1027 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"\n";
1028 this->WriteTargetVersionAttribute(fout
, target
);
1029 linkOptions
.OutputFlagMap(fout
, "\t\t\t\t");
1030 fout
<< "\t\t\t\tAdditionalLibraryDirectories=\"";
1031 this->OutputLibraryDirectories(fout
, cli
.GetDirectories());
1033 fout
<< "\t\t\t\tProgramDataBaseFile=\""
1034 << target
.GetDirectory(configName
) << "/" << targetNamePDB
1038 fout
<< "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
1040 if ( target
.GetPropertyAsBool("WIN32_EXECUTABLE") )
1042 fout
<< "\t\t\t\tSubSystem=\"2\"\n";
1046 fout
<< "\t\t\t\tSubSystem=\"1\"\n";
1048 std::string stackVar
= "CMAKE_";
1049 stackVar
+= linkLanguage
;
1050 stackVar
+= "_STACK_SIZE";
1051 const char* stackVal
= this->Makefile
->GetDefinition(stackVar
.c_str());
1054 fout
<< "\t\t\t\tStackReserveSize=\"" << stackVal
<< "\"";
1056 temp
= target
.GetDirectory(configName
, true);
1058 temp
+= targetNameImport
;
1059 fout
<< "\t\t\t\tImportLibrary=\""
1060 << this->ConvertToXMLOutputPathSingle(temp
.c_str()) << "\"/>\n";
1063 case cmTarget::UTILITY
:
1064 case cmTarget::GLOBAL_TARGET
:
1069 //----------------------------------------------------------------------------
1071 cmLocalVisualStudio7Generator
1072 ::WriteTargetVersionAttribute(std::ostream
& fout
, cmTarget
& target
)
1076 target
.GetTargetVersion(major
, minor
);
1077 fout
<< "\t\t\t\tVersion=\"" << major
<< "." << minor
<< "\"\n";
1080 void cmLocalVisualStudio7Generator
1081 ::OutputModuleDefinitionFile(std::ostream
& fout
,
1084 std::vector
<cmSourceFile
*> const& classes
= target
.GetSourceFiles();
1085 for(std::vector
<cmSourceFile
*>::const_iterator i
= classes
.begin();
1086 i
!= classes
.end(); i
++)
1088 cmSourceFile
* sf
= *i
;
1089 if(cmSystemTools::UpperCase(sf
->GetExtension()) == "DEF")
1091 fout
<< "\t\t\t\tModuleDefinitionFile=\""
1092 << this->ConvertToXMLOutputPath(sf
->GetFullPath().c_str())
1100 //----------------------------------------------------------------------------
1102 cmLocalVisualStudio7GeneratorInternals
1103 ::OutputLibraries(std::ostream
& fout
, ItemVector
const& libs
)
1105 cmLocalVisualStudio7Generator
* lg
= this->LocalGenerator
;
1106 for(ItemVector::const_iterator l
= libs
.begin(); l
!= libs
.end(); ++l
)
1110 std::string rel
= lg
->Convert(l
->Value
.c_str(),
1111 cmLocalGenerator::START_OUTPUT
,
1112 cmLocalGenerator::UNCHANGED
);
1113 fout
<< lg
->ConvertToXMLOutputPath(rel
.c_str()) << " ";
1117 fout
<< l
->Value
<< " ";
1122 //----------------------------------------------------------------------------
1124 cmLocalVisualStudio7Generator
1125 ::OutputLibraryDirectories(std::ostream
& fout
,
1126 std::vector
<std::string
> const& dirs
)
1128 const char* comma
= "";
1129 for(std::vector
<std::string
>::const_iterator d
= dirs
.begin();
1130 d
!= dirs
.end(); ++d
)
1132 // Remove any trailing slash and skip empty paths.
1133 std::string dir
= *d
;
1134 if(dir
[dir
.size()-1] == '/')
1136 dir
= dir
.substr(0, dir
.size()-1);
1143 // Switch to a relative path specification if it is shorter.
1144 if(cmSystemTools::FileIsFullPath(dir
.c_str()))
1146 std::string rel
= this->Convert(dir
.c_str(), START_OUTPUT
, UNCHANGED
);
1147 if(rel
.size() < dir
.size())
1153 // First search a configuration-specific subdirectory and then the
1154 // original directory.
1155 fout
<< comma
<< this->ConvertToXMLOutputPath((dir
+"/$(OutDir)").c_str())
1156 << "," << this->ConvertToXMLOutputPath(dir
.c_str());
1161 void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream
& fout
,
1162 const char *libName
,
1165 // get the configurations
1166 std::vector
<std::string
> *configs
=
1167 static_cast<cmGlobalVisualStudio7Generator
*>
1168 (this->GlobalGenerator
)->GetConfigurations();
1170 // We may be modifying the source groups temporarily, so make a copy.
1171 std::vector
<cmSourceGroup
> sourceGroups
= this->Makefile
->GetSourceGroups();
1173 // get the classes from the source lists then add them to the groups
1174 std::vector
<cmSourceFile
*>const & classes
= target
.GetSourceFiles();
1175 for(std::vector
<cmSourceFile
*>::const_iterator i
= classes
.begin();
1176 i
!= classes
.end(); i
++)
1178 // Add the file to the list of sources.
1179 std::string source
= (*i
)->GetFullPath();
1180 if(cmSystemTools::UpperCase((*i
)->GetExtension()) == "DEF")
1182 this->ModuleDefinitionFile
= (*i
)->GetFullPath();
1184 cmSourceGroup
& sourceGroup
=
1185 this->Makefile
->FindSourceGroup(source
.c_str(), sourceGroups
);
1186 sourceGroup
.AssignSource(*i
);
1189 // Compute which sources need unique object computation.
1190 this->ComputeObjectNameRequirements(sourceGroups
);
1193 this->WriteProjectStart(fout
, libName
, target
, sourceGroups
);
1194 // write the configuration information
1195 this->WriteConfigurations(fout
, libName
, target
);
1197 fout
<< "\t<Files>\n";
1200 // Loop through every source group.
1201 for(unsigned int i
= 0; i
< sourceGroups
.size(); ++i
)
1203 cmSourceGroup sg
= sourceGroups
[i
];
1204 this->WriteGroup(&sg
, target
, fout
, libName
, configs
);
1209 fout
<< "\t</Files>\n";
1211 // Write the VCProj file's footer.
1212 this->WriteVCProjFooter(fout
);
1215 struct cmLVS7GFileConfig
1217 std::string ObjectName
;
1218 std::string CompileFlags
;
1219 std::string CompileDefs
;
1220 std::string CompileDefsConfig
;
1221 std::string AdditionalDeps
;
1222 bool ExcludedFromBuild
;
1225 class cmLocalVisualStudio7GeneratorFCInfo
1228 cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator
* lg
,
1230 cmSourceFile
const& sf
,
1231 std::vector
<std::string
>* configs
,
1232 std::string
const& dir_max
);
1233 std::map
<cmStdString
, cmLVS7GFileConfig
> FileConfigMap
;
1236 cmLocalVisualStudio7GeneratorFCInfo
1237 ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator
* lg
,
1239 cmSourceFile
const& sf
,
1240 std::vector
<std::string
>* configs
,
1241 std::string
const& dir_max
)
1243 std::string objectName
;
1244 if(lg
->NeedObjectName
.find(&sf
) != lg
->NeedObjectName
.end())
1246 objectName
= lg
->GetObjectFileNameWithoutTarget(sf
, dir_max
);
1249 // Compute per-source, per-config information.
1250 for(std::vector
<std::string
>::iterator i
= configs
->begin();
1251 i
!= configs
->end(); ++i
)
1253 std::string configUpper
= cmSystemTools::UpperCase(*i
);
1254 cmLVS7GFileConfig fc
;
1255 bool needfc
= false;
1256 if(!objectName
.empty())
1258 fc
.ObjectName
= objectName
;
1261 if(const char* cflags
= sf
.GetProperty("COMPILE_FLAGS"))
1263 fc
.CompileFlags
= cflags
;
1266 if(const char* cdefs
= sf
.GetProperty("COMPILE_DEFINITIONS"))
1268 fc
.CompileDefs
= cdefs
;
1271 std::string defPropName
= "COMPILE_DEFINITIONS_";
1272 defPropName
+= configUpper
;
1273 if(const char* ccdefs
= sf
.GetProperty(defPropName
.c_str()))
1275 fc
.CompileDefsConfig
= ccdefs
;
1279 // Check for extra object-file dependencies.
1280 if(const char* deps
= sf
.GetProperty("OBJECT_DEPENDS"))
1282 std::vector
<std::string
> depends
;
1283 cmSystemTools::ExpandListArgument(deps
, depends
);
1284 const char* sep
= "";
1285 for(std::vector
<std::string
>::iterator j
= depends
.begin();
1286 j
!= depends
.end(); ++j
)
1288 fc
.AdditionalDeps
+= sep
;
1289 fc
.AdditionalDeps
+= lg
->ConvertToXMLOutputPath(j
->c_str());
1296 lg
->GlobalGenerator
->GetLanguageFromExtension
1297 (sf
.GetExtension().c_str());
1298 const char* sourceLang
= lg
->GetSourceFileLanguage(sf
);
1299 const char* linkLanguage
= target
.GetLinkerLanguage(i
->c_str());
1300 bool needForceLang
= false;
1301 // source file does not match its extension language
1302 if(lang
&& sourceLang
&& strcmp(lang
, sourceLang
) != 0)
1304 needForceLang
= true;
1307 // If HEADER_FILE_ONLY is set, we must suppress this generation in
1309 fc
.ExcludedFromBuild
=
1310 (sf
.GetPropertyAsBool("HEADER_FILE_ONLY"));
1311 if(fc
.ExcludedFromBuild
)
1316 // if the source file does not match the linker language
1317 // then force c or c++
1318 if(needForceLang
|| (linkLanguage
&& lang
1319 && strcmp(lang
, linkLanguage
) != 0))
1321 if(strcmp(lang
, "CXX") == 0)
1323 // force a C++ file type
1324 fc
.CompileFlags
+= " /TP ";
1327 else if(strcmp(lang
, "C") == 0)
1330 fc
.CompileFlags
+= " /TC ";
1337 this->FileConfigMap
[*i
] = fc
;
1343 void cmLocalVisualStudio7Generator
1344 ::ComputeMaxDirectoryLength(std::string
& maxdir
,
1347 std::vector
<std::string
> *configs
=
1348 static_cast<cmGlobalVisualStudio7Generator
*>
1349 (this->GlobalGenerator
)->GetConfigurations();
1350 // Compute the maximum length configuration name.
1351 std::string config_max
;
1352 for(std::vector
<std::string
>::iterator i
= configs
->begin();
1353 i
!= configs
->end(); ++i
)
1355 if(i
->size() > config_max
.size())
1361 // Compute the maximum length full path to the intermediate
1362 // files directory for any configuration. This is used to construct
1363 // object file names that do not produce paths that are too long.
1364 std::string dir_max
;
1365 dir_max
+= this->Makefile
->GetCurrentOutputDirectory();
1367 dir_max
+= this->GetTargetDirectory(target
);
1369 dir_max
+= config_max
;
1374 void cmLocalVisualStudio7Generator
1375 ::WriteGroup(const cmSourceGroup
*sg
, cmTarget
& target
,
1376 std::ostream
&fout
, const char *libName
,
1377 std::vector
<std::string
> *configs
)
1379 const std::vector
<const cmSourceFile
*> &sourceFiles
=
1380 sg
->GetSourceFiles();
1381 // If the group is empty, don't write it at all.
1382 if(sourceFiles
.empty() && sg
->GetGroupChildren().empty())
1387 // If the group has a name, write the header.
1388 std::string name
= sg
->GetName();
1391 this->WriteVCProjBeginGroup(fout
, name
.c_str(), "");
1394 // Compute the maximum length full path to the intermediate
1395 // files directory for any configuration. This is used to construct
1396 // object file names that do not produce paths that are too long.
1397 std::string dir_max
;
1398 this->ComputeMaxDirectoryLength(dir_max
, target
);
1400 // Loop through each source in the source group.
1401 std::string objectName
;
1402 for(std::vector
<const cmSourceFile
*>::const_iterator sf
=
1403 sourceFiles
.begin(); sf
!= sourceFiles
.end(); ++sf
)
1405 std::string source
= (*sf
)->GetFullPath();
1406 FCInfo
fcinfo(this, target
, *(*sf
), configs
, dir_max
);
1408 if (source
!= libName
|| target
.GetType() == cmTarget::UTILITY
||
1409 target
.GetType() == cmTarget::GLOBAL_TARGET
)
1411 fout
<< "\t\t\t<File\n";
1412 std::string d
= this->ConvertToXMLOutputPathSingle(source
.c_str());
1413 // Tell MS-Dev what the source is. If the compiler knows how to
1414 // build it, then it will.
1415 fout
<< "\t\t\t\tRelativePath=\"" << d
<< "\">\n";
1416 if(cmCustomCommand
const* command
= (*sf
)->GetCustomCommand())
1418 this->WriteCustomRule(fout
, source
.c_str(), *command
, fcinfo
);
1420 else if(!fcinfo
.FileConfigMap
.empty())
1422 const char* aCompilerTool
= "VCCLCompilerTool";
1423 std::string ext
= (*sf
)->GetExtension();
1424 ext
= cmSystemTools::LowerCase(ext
);
1427 aCompilerTool
= "VCMIDLTool";
1428 if(this->FortranProject
)
1430 aCompilerTool
= "VFMIDLTool";
1435 aCompilerTool
= "VCResourceCompilerTool";
1436 if(this->FortranProject
)
1438 aCompilerTool
= "VFResourceCompilerTool";
1443 aCompilerTool
= "VCCustomBuildTool";
1444 if(this->FortranProject
)
1446 aCompilerTool
= "VFCustomBuildTool";
1449 for(std::map
<cmStdString
, cmLVS7GFileConfig
>::const_iterator
1450 fci
= fcinfo
.FileConfigMap
.begin();
1451 fci
!= fcinfo
.FileConfigMap
.end(); ++fci
)
1453 cmLVS7GFileConfig
const& fc
= fci
->second
;
1454 fout
<< "\t\t\t\t<FileConfiguration\n"
1455 << "\t\t\t\t\tName=\"" << fci
->first
1456 << "|" << this->PlatformName
<< "\"";
1457 if(fc
.ExcludedFromBuild
)
1459 fout
<< " ExcludedFromBuild=\"true\"";
1462 fout
<< "\t\t\t\t\t<Tool\n"
1463 << "\t\t\t\t\tName=\"" << aCompilerTool
<< "\"\n";
1464 if(!fc
.CompileFlags
.empty() ||
1465 !fc
.CompileDefs
.empty() ||
1466 !fc
.CompileDefsConfig
.empty())
1468 Options
fileOptions(this, this->Version
, Options::Compiler
,
1469 cmLocalVisualStudio7GeneratorFlagTable
,
1470 this->ExtraFlagTable
);
1471 fileOptions
.Parse(fc
.CompileFlags
.c_str());
1472 fileOptions
.AddDefines(fc
.CompileDefs
.c_str());
1473 fileOptions
.AddDefines(fc
.CompileDefsConfig
.c_str());
1474 fileOptions
.OutputAdditionalOptions(fout
, "\t\t\t\t\t", "\n");
1475 fileOptions
.OutputFlagMap(fout
, "\t\t\t\t\t");
1476 fileOptions
.OutputPreprocessorDefinitions(fout
,
1477 "\t\t\t\t\t", "\n");
1479 if(!fc
.AdditionalDeps
.empty())
1481 fout
<< "\t\t\t\t\tAdditionalDependencies=\""
1482 << fc
.AdditionalDeps
.c_str() << "\"\n";
1484 if(!fc
.ObjectName
.empty())
1486 fout
<< "\t\t\t\t\tObjectFile=\"$(IntDir)/"
1487 << fc
.ObjectName
.c_str() << "\"\n";
1489 fout
<< "\t\t\t\t\t/>\n"
1490 << "\t\t\t\t</FileConfiguration>\n";
1493 fout
<< "\t\t\t</File>\n";
1497 std::vector
<cmSourceGroup
> const& children
= sg
->GetGroupChildren();
1499 for(unsigned int i
=0;i
<children
.size();++i
)
1501 this->WriteGroup(&children
[i
], target
, fout
, libName
, configs
);
1504 // If the group has a name, write the footer.
1507 this->WriteVCProjEndGroup(fout
);
1511 void cmLocalVisualStudio7Generator::
1512 WriteCustomRule(std::ostream
& fout
,
1514 const cmCustomCommand
& command
,
1517 std::string comment
= this->ConstructComment(command
);
1519 // Write the rule for each configuration.
1520 std::vector
<std::string
>::iterator i
;
1521 std::vector
<std::string
> *configs
=
1522 static_cast<cmGlobalVisualStudio7Generator
*>
1523 (this->GlobalGenerator
)->GetConfigurations();
1524 const char* compileTool
= "VCCLCompilerTool";
1525 if(this->FortranProject
)
1527 compileTool
= "VFCLCompilerTool";
1529 const char* customTool
= "VCCustomBuildTool";
1530 if(this->FortranProject
)
1532 customTool
= "VFCustomBuildTool";
1534 for(i
= configs
->begin(); i
!= configs
->end(); ++i
)
1536 cmLVS7GFileConfig
const& fc
= fcinfo
.FileConfigMap
[*i
];
1537 fout
<< "\t\t\t\t<FileConfiguration\n";
1538 fout
<< "\t\t\t\t\tName=\"" << *i
<< "|" << this->PlatformName
<< "\">\n";
1539 if(!fc
.CompileFlags
.empty())
1541 fout
<< "\t\t\t\t\t<Tool\n"
1542 << "\t\t\t\t\tName=\"" << compileTool
<< "\"\n"
1543 << "\t\t\t\t\tAdditionalOptions=\""
1544 << this->EscapeForXML(fc
.CompileFlags
.c_str()) << "\"/>\n";
1547 std::string script
=
1548 this->ConstructScript(command
.GetCommandLines(),
1549 command
.GetWorkingDirectory(),
1551 command
.GetEscapeOldStyle(),
1552 command
.GetEscapeAllowMakeVars());
1553 fout
<< "\t\t\t\t\t<Tool\n"
1554 << "\t\t\t\t\tName=\"" << customTool
<< "\"\n"
1555 << "\t\t\t\t\tDescription=\""
1556 << this->EscapeForXML(comment
.c_str()) << "\"\n"
1557 << "\t\t\t\t\tCommandLine=\""
1558 << this->EscapeForXML(script
.c_str()) << "\"\n"
1559 << "\t\t\t\t\tAdditionalDependencies=\"";
1560 if(command
.GetDepends().empty())
1562 // There are no real dependencies. Produce an artificial one to
1563 // make sure the rule runs reliably.
1564 if(!cmSystemTools::FileExists(source
))
1566 std::ofstream
depout(source
);
1567 depout
<< "Artificial dependency for a custom command.\n";
1569 fout
<< this->ConvertToXMLOutputPath(source
);
1573 // Write out the dependencies for the rule.
1574 for(std::vector
<std::string
>::const_iterator d
=
1575 command
.GetDepends().begin();
1576 d
!= command
.GetDepends().end();
1579 // Get the real name of the dependency in case it is a CMake target.
1580 std::string dep
= this->GetRealDependency(d
->c_str(), i
->c_str());
1581 fout
<< this->ConvertToXMLOutputPath(dep
.c_str())
1586 fout
<< "\t\t\t\t\tOutputs=\"";
1587 if(command
.GetOutputs().empty())
1589 fout
<< source
<< "_force";
1593 // Write a rule for the output generated by this command.
1594 const char* sep
= "";
1595 for(std::vector
<std::string
>::const_iterator o
=
1596 command
.GetOutputs().begin();
1597 o
!= command
.GetOutputs().end();
1600 fout
<< sep
<< this->ConvertToXMLOutputPathSingle(o
->c_str());
1605 fout
<< "\t\t\t\t</FileConfiguration>\n";
1610 void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream
& fout
,
1614 fout
<< "\t\t<Filter\n"
1615 << "\t\t\tName=\"" << group
<< "\"\n"
1616 << "\t\t\tFilter=\"\">\n";
1620 void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream
& fout
)
1622 fout
<< "\t\t</Filter>\n";
1626 // look for custom rules on a target and collect them together
1627 void cmLocalVisualStudio7Generator
1628 ::OutputTargetRules(std::ostream
& fout
,
1629 const char* configName
,
1631 const char * /*libName*/)
1633 if (target
.GetType() > cmTarget::GLOBAL_TARGET
)
1637 EventWriter
event(this, configName
, fout
);
1639 // Add pre-build event.
1641 this->FortranProject
? "VFPreBuildEventTool":"VCPreBuildEventTool";
1643 event
.Write(target
.GetPreBuildCommands());
1646 // Add pre-link event.
1647 tool
= this->FortranProject
? "VFPreLinkEventTool":"VCPreLinkEventTool";
1649 event
.Write(target
.GetPreLinkCommands());
1650 cmsys::auto_ptr
<cmCustomCommand
> pcc(
1651 this->MaybeCreateImplibDir(target
, configName
));
1658 // Add post-build event.
1659 tool
= this->FortranProject
? "VFPostBuildEventTool":"VCPostBuildEventTool";
1661 event
.Write(target
.GetPostBuildCommands());
1666 cmLocalVisualStudio7Generator
1667 ::WriteProjectStartFortran(std::ostream
& fout
,
1668 const char *libName
,
1672 cmGlobalVisualStudio7Generator
* gg
=
1673 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
1674 fout
<< "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
1675 << "<VisualStudioProject\n"
1676 << "\tProjectCreator=\"Intel Fortran\"\n"
1677 << "\tVersion=\"9.10\"\n";
1678 const char* keyword
= target
.GetProperty("VS_KEYWORD");
1681 keyword
= "Console Application";
1683 const char* projectType
= 0;
1684 switch(target
.GetType())
1686 case cmTarget::STATIC_LIBRARY
:
1687 projectType
= "typeStaticLibrary";
1690 keyword
= "Static Library";
1693 case cmTarget::SHARED_LIBRARY
:
1694 case cmTarget::MODULE_LIBRARY
:
1695 projectType
= "typeDynamicLibrary";
1701 case cmTarget::EXECUTABLE
:
1704 keyword
= "Console Application";
1708 case cmTarget::UTILITY
:
1709 case cmTarget::GLOBAL_TARGET
:
1715 fout
<< "\tProjectType=\"" << projectType
<< "\"\n";
1717 fout
<< "\tKeyword=\"" << keyword
<< "\">\n"
1718 << "\tProjectGUID=\"{" << gg
->GetGUID(libName
) << "}\">\n"
1719 << "\t<Platforms>\n"
1720 << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName
<< "\"/>\n"
1721 << "\t</Platforms>\n";
1726 cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream
& fout
,
1727 const char *libName
,
1729 std::vector
<cmSourceGroup
> &)
1731 if(this->FortranProject
)
1733 this->WriteProjectStartFortran(fout
, libName
, target
);
1736 fout
<< "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
1737 << "<VisualStudioProject\n"
1738 << "\tProjectType=\"Visual C++\"\n";
1739 if(this->Version
== 71)
1741 fout
<< "\tVersion=\"7.10\"\n";
1745 fout
<< "\tVersion=\"" << this->Version
<< ".00\"\n";
1747 const char* projLabel
= target
.GetProperty("PROJECT_LABEL");
1750 projLabel
= libName
;
1752 const char* keyword
= target
.GetProperty("VS_KEYWORD");
1755 keyword
= "Win32Proj";
1757 const char* vsProjectname
= target
.GetProperty("VS_SCC_PROJECTNAME");
1758 const char* vsLocalpath
= target
.GetProperty("VS_SCC_LOCALPATH");
1759 const char* vsProvider
= target
.GetProperty("VS_SCC_PROVIDER");
1760 cmGlobalVisualStudio7Generator
* gg
=
1761 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
1762 fout
<< "\tName=\"" << projLabel
<< "\"\n";
1763 if(this->Version
>= 8)
1765 fout
<< "\tProjectGUID=\"{" << gg
->GetGUID(libName
) << "}\"\n";
1767 // if we have all the required Source code control tags
1768 // then add that to the project
1769 if(vsProvider
&& vsLocalpath
&& vsProjectname
)
1771 fout
<< "\tSccProjectName=\"" << vsProjectname
<< "\"\n"
1772 << "\tSccLocalPath=\"" << vsLocalpath
<< "\"\n"
1773 << "\tSccProvider=\"" << vsProvider
<< "\"\n";
1775 fout
<< "\tKeyword=\"" << keyword
<< "\">\n"
1776 << "\t<Platforms>\n"
1777 << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName
<< "\"/>\n"
1778 << "\t</Platforms>\n";
1782 void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream
& fout
)
1784 fout
<< "\t<Globals>\n"
1786 << "</VisualStudioProject>\n";
1789 std::string
cmLocalVisualStudio7GeneratorEscapeForXML(const char* s
)
1791 std::string ret
= s
;
1792 cmSystemTools::ReplaceString(ret
, "&", "&");
1793 cmSystemTools::ReplaceString(ret
, "\"", """);
1794 cmSystemTools::ReplaceString(ret
, "<", "<");
1795 cmSystemTools::ReplaceString(ret
, ">", ">");
1796 cmSystemTools::ReplaceString(ret
, "\n", "
");
1800 std::string
cmLocalVisualStudio7Generator::EscapeForXML(const char* s
)
1802 return cmLocalVisualStudio7GeneratorEscapeForXML(s
);
1805 std::string cmLocalVisualStudio7Generator
1806 ::ConvertToXMLOutputPath(const char* path
)
1808 std::string ret
= this->ConvertToOptionallyRelativeOutputPath(path
);
1809 cmSystemTools::ReplaceString(ret
, "&", "&");
1810 cmSystemTools::ReplaceString(ret
, "\"", """);
1811 cmSystemTools::ReplaceString(ret
, "<", "<");
1812 cmSystemTools::ReplaceString(ret
, ">", ">");
1816 std::string cmLocalVisualStudio7Generator
1817 ::ConvertToXMLOutputPathSingle(const char* path
)
1819 std::string ret
= this->ConvertToOptionallyRelativeOutputPath(path
);
1820 cmSystemTools::ReplaceString(ret
, "\"", "");
1821 cmSystemTools::ReplaceString(ret
, "&", "&");
1822 cmSystemTools::ReplaceString(ret
, "<", "<");
1823 cmSystemTools::ReplaceString(ret
, ">", ">");
1828 // This class is used to parse an existing vs 7 project
1829 // and extract the GUID
1830 class cmVS7XMLParser
: public cmXMLParser
1833 virtual void EndElement(const char* /* name */)
1836 virtual void StartElement(const char* name
, const char** atts
)
1838 // once the GUID is found do nothing
1839 if(this->GUID
.size())
1844 if(strcmp("VisualStudioProject", name
) == 0)
1848 if(strcmp(atts
[i
], "ProjectGUID") == 0)
1852 this->GUID
= atts
[i
+1];
1853 this->GUID
= this->GUID
.substr(1, this->GUID
.size()-2);
1865 int InitializeParser()
1867 int ret
= cmXMLParser::InitializeParser();
1872 // visual studio projects have a strange encoding, but it is
1874 XML_SetEncoding(static_cast<XML_Parser
>(this->Parser
), "utf-8");
1880 void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
1884 cmVS7XMLParser parser
;
1885 parser
.ParseFile(path
);
1886 // if we can not find a GUID then create one
1887 if(parser
.GUID
.size() == 0)
1889 cmGlobalVisualStudio7Generator
* gg
=
1890 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
1891 gg
->CreateGUID(name
);
1894 std::string guidStoreName
= name
;
1895 guidStoreName
+= "_GUID_CMAKE";
1896 // save the GUID in the cache
1897 this->GlobalGenerator
->GetCMakeInstance()->
1898 AddCacheEntry(guidStoreName
.c_str(),
1899 parser
.GUID
.c_str(),
1901 cmCacheManager::INTERNAL
);
1905 void cmLocalVisualStudio7Generator::ConfigureFinalPass()
1907 cmLocalGenerator::ConfigureFinalPass();
1908 cmTargets
&tgts
= this->Makefile
->GetTargets();
1910 cmGlobalVisualStudio7Generator
* gg
=
1911 static_cast<cmGlobalVisualStudio7Generator
*>(this->GlobalGenerator
);
1912 for(cmTargets::iterator l
= tgts
.begin(); l
!= tgts
.end(); l
++)
1914 const char* path
= l
->second
.GetProperty("EXTERNAL_MSPROJECT");
1917 this->ReadAndStoreExternalGUID(
1918 l
->second
.GetName(), path
);
1922 gg
->CreateGUID(l
->first
.c_str());
1928 //----------------------------------------------------------------------------
1929 std::string cmLocalVisualStudio7Generator
1930 ::GetTargetDirectory(cmTarget
const& target
) const
1933 dir
+= target
.GetName();
1938 void cmLocalVisualStudio7Generator::
1939 GetTargetObjectFileDirectories(cmTarget
* target
,
1940 std::vector
<std::string
>&
1943 std::string dir
= this->Makefile
->GetCurrentOutputDirectory();
1945 dir
+= this->GetTargetDirectory(*target
);
1947 dir
+= this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
1948 dirs
.push_back(dir
);
1951 //----------------------------------------------------------------------------
1952 #include <windows.h>
1953 static bool cmLVS6G_IsFAT(const char* dir
)
1955 if(dir
[0] && dir
[1] == ':')
1957 char volRoot
[4] = "_:/";
1958 volRoot
[0] = dir
[0];
1960 if(GetVolumeInformation(volRoot
, 0, 0, 0, 0, 0, fsName
, 16) &&
1961 strstr(fsName
, "FAT") != 0)