cmLocalVisualStudio7Generator.cxx 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGlobalVisualStudio7Generator.h"
  11. #include "cmLocalVisualStudio7Generator.h"
  12. #include "cmXMLParser.h"
  13. #include <cm_expat.h>
  14. #include "cmMakefile.h"
  15. #include "cmSystemTools.h"
  16. #include "cmSourceFile.h"
  17. #include "cmGeneratorTarget.h"
  18. #include "cmCustomCommandGenerator.h"
  19. #include "cmake.h"
  20. #include "cmComputeLinkInformation.h"
  21. #include "cmGeneratedFileStream.h"
  22. #include <ctype.h> // for isspace
  23. static bool cmLVS6G_IsFAT(const char* dir);
  24. class cmLocalVisualStudio7GeneratorInternals
  25. {
  26. public:
  27. cmLocalVisualStudio7GeneratorInternals(cmLocalVisualStudio7Generator* e):
  28. LocalGenerator(e) {}
  29. typedef cmComputeLinkInformation::ItemVector ItemVector;
  30. void OutputLibraries(std::ostream& fout, ItemVector const& libs);
  31. void OutputObjects(std::ostream& fout, cmTarget* t, const char* isep = 0);
  32. private:
  33. cmLocalVisualStudio7Generator* LocalGenerator;
  34. };
  35. extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
  36. static void cmConvertToWindowsSlash(std::string& s)
  37. {
  38. std::string::size_type pos = 0;
  39. while((pos = s.find('/', pos)) != std::string::npos)
  40. {
  41. s[pos] = '\\';
  42. pos++;
  43. }
  44. }
  45. //----------------------------------------------------------------------------
  46. cmLocalVisualStudio7Generator
  47. ::cmLocalVisualStudio7Generator(cmGlobalGenerator* gg,
  48. cmLocalGenerator* parent,
  49. cmState::Snapshot snapshot):
  50. cmLocalVisualStudioGenerator(gg, parent, snapshot)
  51. {
  52. this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
  53. }
  54. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  55. {
  56. delete this->Internal;
  57. }
  58. void cmLocalVisualStudio7Generator::AddHelperCommands()
  59. {
  60. // Now create GUIDs for targets
  61. cmTargets &tgts = this->Makefile->GetTargets();
  62. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  63. {
  64. if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  65. {
  66. continue;
  67. }
  68. const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT");
  69. if(path)
  70. {
  71. this->ReadAndStoreExternalGUID(
  72. l->second.GetName().c_str(), path);
  73. }
  74. }
  75. this->FixGlobalTargets();
  76. }
  77. void cmLocalVisualStudio7Generator::Generate()
  78. {
  79. this->WriteProjectFiles();
  80. this->WriteStampFiles();
  81. }
  82. void cmLocalVisualStudio7Generator::AddCMakeListsRules()
  83. {
  84. cmTargets &tgts = this->Makefile->GetTargets();
  85. // Create the regeneration custom rule.
  86. if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
  87. {
  88. // Create a rule to regenerate the build system when the target
  89. // specification source changes.
  90. if(cmSourceFile* sf = this->CreateVCProjBuildRule())
  91. {
  92. // Add the rule to targets that need it.
  93. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  94. {
  95. if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
  96. {
  97. l->second.AddSource(sf->GetFullPath());
  98. }
  99. }
  100. }
  101. }
  102. }
  103. void cmLocalVisualStudio7Generator::FixGlobalTargets()
  104. {
  105. // Visual Studio .NET 2003 Service Pack 1 will not run post-build
  106. // commands for targets in which no sources are built. Add dummy
  107. // rules to force these targets to build.
  108. cmTargets &tgts = this->Makefile->GetTargets();
  109. for(cmTargets::iterator l = tgts.begin();
  110. l != tgts.end(); l++)
  111. {
  112. cmTarget& tgt = l->second;
  113. if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
  114. {
  115. std::vector<std::string> no_depends;
  116. cmCustomCommandLine force_command;
  117. force_command.push_back("cd");
  118. force_command.push_back(".");
  119. cmCustomCommandLines force_commands;
  120. force_commands.push_back(force_command);
  121. std::string no_main_dependency = "";
  122. std::string force = this->Makefile->GetCurrentBinaryDirectory();
  123. force += cmake::GetCMakeFilesDirectory();
  124. force += "/";
  125. force += tgt.GetName();
  126. force += "_force";
  127. if(cmSourceFile* file =
  128. this->Makefile->AddCustomCommandToOutput(
  129. force.c_str(), no_depends, no_main_dependency,
  130. force_commands, " ", 0, true))
  131. {
  132. tgt.AddSource(file->GetFullPath());
  133. }
  134. }
  135. }
  136. }
  137. // TODO
  138. // for CommandLine= need to repleace quotes with &quot
  139. // write out configurations
  140. void cmLocalVisualStudio7Generator::WriteProjectFiles()
  141. {
  142. // If not an in source build, then create the output directory
  143. if(strcmp(this->Makefile->GetCurrentBinaryDirectory(),
  144. this->Makefile->GetHomeDirectory()) != 0)
  145. {
  146. if(!cmSystemTools::MakeDirectory
  147. (this->Makefile->GetCurrentBinaryDirectory()))
  148. {
  149. cmSystemTools::Error("Error creating directory ",
  150. this->Makefile->GetCurrentBinaryDirectory());
  151. }
  152. }
  153. // Get the set of targets in this directory.
  154. cmTargets &tgts = this->Makefile->GetTargets();
  155. // Create the project file for each target.
  156. for(cmTargets::iterator l = tgts.begin();
  157. l != tgts.end(); l++)
  158. {
  159. if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  160. {
  161. continue;
  162. }
  163. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  164. // so don't build a projectfile for it
  165. if(!l->second.GetProperty("EXTERNAL_MSPROJECT"))
  166. {
  167. this->CreateSingleVCProj(l->first.c_str(),l->second);
  168. }
  169. }
  170. }
  171. //----------------------------------------------------------------------------
  172. void cmLocalVisualStudio7Generator::WriteStampFiles()
  173. {
  174. // Touch a timestamp file used to determine when the project file is
  175. // out of date.
  176. std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
  177. stampName += cmake::GetCMakeFilesDirectory();
  178. cmSystemTools::MakeDirectory(stampName.c_str());
  179. stampName += "/";
  180. stampName += "generate.stamp";
  181. cmsys::ofstream stamp(stampName.c_str());
  182. stamp << "# CMake generation timestamp file for this directory.\n";
  183. // Create a helper file so CMake can determine when it is run
  184. // through the rule created by CreateVCProjBuildRule whether it
  185. // really needs to regenerate the project. This file lists its own
  186. // dependencies. If any file listed in it is newer than itself then
  187. // CMake must rerun. Otherwise the project files are up to date and
  188. // the stamp file can just be touched.
  189. std::string depName = stampName;
  190. depName += ".depend";
  191. cmsys::ofstream depFile(depName.c_str());
  192. depFile << "# CMake generation dependency list for this directory.\n";
  193. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  194. for(std::vector<std::string>::const_iterator lf = listFiles.begin();
  195. lf != listFiles.end(); ++lf)
  196. {
  197. depFile << *lf << std::endl;
  198. }
  199. }
  200. //----------------------------------------------------------------------------
  201. void cmLocalVisualStudio7Generator
  202. ::CreateSingleVCProj(const std::string& lname, cmTarget &target)
  203. {
  204. cmGlobalVisualStudioGenerator* gg
  205. = static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  206. this->FortranProject = gg->TargetIsFortranOnly(target);
  207. this->WindowsCEProject = gg->TargetsWindowsCE();
  208. // Intel Fortran for VS10 uses VS9 format ".vfproj" files.
  209. cmGlobalVisualStudioGenerator::VSVersion realVersion = gg->GetVersion();
  210. if(this->FortranProject
  211. && gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS10)
  212. {
  213. gg->SetVersion(cmGlobalVisualStudioGenerator::VS9);
  214. }
  215. // add to the list of projects
  216. target.SetProperty("GENERATOR_FILE_NAME",lname.c_str());
  217. // create the dsp.cmake file
  218. std::string fname;
  219. fname = this->Makefile->GetCurrentBinaryDirectory();
  220. fname += "/";
  221. fname += lname;
  222. if(this->FortranProject)
  223. {
  224. fname += ".vfproj";
  225. }
  226. else
  227. {
  228. fname += ".vcproj";
  229. }
  230. // Generate the project file and replace it atomically with
  231. // copy-if-different. We use a separate timestamp so that the IDE
  232. // does not reload project files unnecessarily.
  233. cmGeneratedFileStream fout(fname.c_str());
  234. fout.SetCopyIfDifferent(true);
  235. this->WriteVCProjFile(fout,lname,target);
  236. if (fout.Close())
  237. {
  238. this->GlobalGenerator->FileReplacedDuringGenerate(fname);
  239. }
  240. gg->SetVersion(realVersion);
  241. }
  242. //----------------------------------------------------------------------------
  243. cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
  244. {
  245. std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
  246. stampName += "/";
  247. stampName += cmake::GetCMakeFilesDirectoryPostSlash();
  248. stampName += "generate.stamp";
  249. cmCustomCommandLine commandLine;
  250. commandLine.push_back(cmSystemTools::GetCMakeCommand());
  251. std::string makefileIn = this->Makefile->GetCurrentSourceDirectory();
  252. makefileIn += "/";
  253. makefileIn += "CMakeLists.txt";
  254. makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
  255. if(!cmSystemTools::FileExists(makefileIn.c_str()))
  256. {
  257. return 0;
  258. }
  259. std::string comment = "Building Custom Rule ";
  260. comment += makefileIn;
  261. std::string args;
  262. args = "-H";
  263. args += this->Makefile->GetHomeDirectory();
  264. commandLine.push_back(args);
  265. args = "-B";
  266. args += this->Makefile->GetHomeOutputDirectory();
  267. commandLine.push_back(args);
  268. commandLine.push_back("--check-stamp-file");
  269. std::string stampFilename = this->Convert(stampName.c_str(), FULL,
  270. SHELL);
  271. commandLine.push_back(stampFilename.c_str());
  272. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  273. cmCustomCommandLines commandLines;
  274. commandLines.push_back(commandLine);
  275. const char* no_working_directory = 0;
  276. std::string fullpathStampName = this->Convert(stampName.c_str(), FULL,
  277. UNCHANGED);
  278. this->Makefile->AddCustomCommandToOutput(fullpathStampName.c_str(),
  279. listFiles, makefileIn.c_str(),
  280. commandLines, comment.c_str(),
  281. no_working_directory, true);
  282. if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
  283. {
  284. return file;
  285. }
  286. else
  287. {
  288. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  289. return 0;
  290. }
  291. }
  292. void cmLocalVisualStudio7Generator::WriteConfigurations(
  293. std::ostream& fout, std::vector<std::string> const& configs,
  294. const std::string& libName, cmTarget &target
  295. )
  296. {
  297. fout << "\t<Configurations>\n";
  298. for (std::vector<std::string>::const_iterator i = configs.begin();
  299. i != configs.end(); ++i)
  300. {
  301. this->WriteConfiguration(fout, i->c_str(), libName, target);
  302. }
  303. fout << "\t</Configurations>\n";
  304. }
  305. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranFlagTable[] =
  306. {
  307. {"Preprocess", "fpp", "Run Preprocessor on files", "preprocessYes", 0},
  308. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  309. {"SourceFileFormat", "fixed", "Use Fixed Format", "fileFormatFixed", 0},
  310. {"SourceFileFormat", "free", "Use Free Format", "fileFormatFree", 0},
  311. {"DebugInformationFormat", "Zi", "full debug", "debugEnabled", 0},
  312. {"DebugInformationFormat", "debug:full", "full debug", "debugEnabled", 0},
  313. {"DebugInformationFormat", "Z7", "c7 compat", "debugOldStyleInfo", 0},
  314. {"DebugInformationFormat", "Zd", "line numbers", "debugLineInfoOnly", 0},
  315. {"Optimization", "Od", "disable optimization", "optimizeDisabled", 0},
  316. {"Optimization", "O1", "min space", "optimizeMinSpace", 0},
  317. {"Optimization", "O3", "full optimize", "optimizeFull", 0},
  318. {"GlobalOptimizations", "Og", "global optimize", "true", 0},
  319. {"InlineFunctionExpansion", "Ob0", "", "expandDisable", 0},
  320. {"InlineFunctionExpansion", "Ob1", "", "expandOnlyInline", 0},
  321. {"FavorSizeOrSpeed", "Os", "", "favorSize", 0},
  322. {"OmitFramePointers", "Oy-", "", "false", 0},
  323. {"OptimizeForProcessor", "GB", "", "procOptimizeBlended", 0},
  324. {"OptimizeForProcessor", "G5", "", "procOptimizePentium", 0},
  325. {"OptimizeForProcessor", "G6", "", "procOptimizePentiumProThruIII", 0},
  326. {"UseProcessorExtensions", "QzxK", "", "codeForStreamingSIMD", 0},
  327. {"OptimizeForProcessor", "QaxN", "", "codeForPentium4", 0},
  328. {"OptimizeForProcessor", "QaxB", "", "codeForPentiumM", 0},
  329. {"OptimizeForProcessor", "QaxP", "", "codeForCodeNamedPrescott", 0},
  330. {"OptimizeForProcessor", "QaxT", "", "codeForCore2Duo", 0},
  331. {"OptimizeForProcessor", "QxK", "", "codeExclusivelyStreamingSIMD", 0},
  332. {"OptimizeForProcessor", "QxN", "", "codeExclusivelyPentium4", 0},
  333. {"OptimizeForProcessor", "QxB", "", "codeExclusivelyPentiumM", 0},
  334. {"OptimizeForProcessor", "QxP", "", "codeExclusivelyCodeNamedPrescott", 0},
  335. {"OptimizeForProcessor", "QxT", "", "codeExclusivelyCore2Duo", 0},
  336. {"OptimizeForProcessor", "QxO", "", "codeExclusivelyCore2StreamingSIMD", 0},
  337. {"OptimizeForProcessor", "QxS", "", "codeExclusivelyCore2StreamingSIMD4", 0},
  338. {"OpenMP", "Qopenmp", "", "OpenMPParallelCode", 0},
  339. {"OpenMP", "Qopenmp-stubs", "", "OpenMPSequentialCode", 0},
  340. {"Traceback", "traceback", "", "true", 0},
  341. {"Traceback", "notraceback", "", "false", 0},
  342. {"FloatingPointExceptionHandling", "fpe:0", "", "fpe0", 0},
  343. {"FloatingPointExceptionHandling", "fpe:1", "", "fpe1", 0},
  344. {"FloatingPointExceptionHandling", "fpe:3", "", "fpe3", 0},
  345. {"ModulePath", "module:", "", "",
  346. cmVS7FlagTable::UserValueRequired},
  347. {"LoopUnrolling", "Qunroll:", "", "",
  348. cmVS7FlagTable::UserValueRequired},
  349. {"AutoParallelThreshold", "Qpar-threshold:", "", "",
  350. cmVS7FlagTable::UserValueRequired},
  351. {"HeapArrays", "heap-arrays:", "", "",
  352. cmVS7FlagTable::UserValueRequired},
  353. {"ObjectText", "bintext:", "", "",
  354. cmVS7FlagTable::UserValueRequired},
  355. {"Parallelization", "Qparallel", "", "true", 0},
  356. {"PrefetchInsertion", "Qprefetch-", "", "false", 0},
  357. {"BufferedIO", "assume:buffered_io", "", "true", 0},
  358. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  359. {"CallingConvention", "iface:cref", "", "callConventionCRef", 0},
  360. {"CallingConvention", "iface:stdref", "", "callConventionStdRef", 0},
  361. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  362. {"CallingConvention", "iface:cvf", "", "callConventionCVF", 0},
  363. {"EnableRecursion", "recursive", "", "true", 0},
  364. {"ReentrantCode", "reentrancy", "", "true", 0},
  365. // done up to Language
  366. {0,0,0,0,0}
  367. };
  368. // fill the table here currently the comment field is not used for
  369. // anything other than documentation NOTE: Make sure the longer
  370. // commandFlag comes FIRST!
  371. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  372. {
  373. // option flags (some flags map to the same option)
  374. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
  375. {"BasicRuntimeChecks", "RTCsu",
  376. "Both stack and uninitialized checks", "3", 0},
  377. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
  378. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
  379. {"BasicRuntimeChecks", "RTC1",
  380. "Both stack and uninitialized checks", "3", 0},
  381. {"DebugInformationFormat", "Z7", "debug format", "1", 0},
  382. {"DebugInformationFormat", "Zd", "debug format", "2", 0},
  383. {"DebugInformationFormat", "Zi", "debug format", "3", 0},
  384. {"DebugInformationFormat", "ZI", "debug format", "4", 0},
  385. {"EnableEnhancedInstructionSet", "arch:SSE2",
  386. "Use sse2 instructions", "2", 0},
  387. {"EnableEnhancedInstructionSet", "arch:SSE",
  388. "Use sse instructions", "1", 0},
  389. {"FloatingPointModel", "fp:precise",
  390. "Use precise floating point model", "0", 0},
  391. {"FloatingPointModel", "fp:strict",
  392. "Use strict floating point model", "1", 0},
  393. {"FloatingPointModel", "fp:fast", "Use fast floating point model", "2", 0},
  394. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
  395. {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
  396. {"CompileAs", "TC", "Compile as c code", "1", 0},
  397. {"CompileAs", "TP", "Compile as c++ code", "2", 0},
  398. {"Optimization", "Od", "Non Debug", "0", 0},
  399. {"Optimization", "O1", "Min Size", "1", 0},
  400. {"Optimization", "O2", "Max Speed", "2", 0},
  401. {"Optimization", "Ox", "Max Optimization", "3", 0},
  402. {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
  403. {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
  404. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
  405. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
  406. {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
  407. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
  408. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
  409. {"RuntimeLibrary", "MTd", "Multithreaded debug", "1", 0},
  410. {"RuntimeLibrary", "MT", "Multithreaded", "0", 0},
  411. {"RuntimeLibrary", "MDd", "Multithreaded dll debug", "3", 0},
  412. {"RuntimeLibrary", "MD", "Multithreaded dll", "2", 0},
  413. {"RuntimeLibrary", "MLd", "Single Thread debug", "5", 0},
  414. {"RuntimeLibrary", "ML", "Single Thread", "4", 0},
  415. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
  416. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
  417. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
  418. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
  419. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
  420. {"WarningLevel", "W0", "Warning level", "0", 0},
  421. {"WarningLevel", "W1", "Warning level", "1", 0},
  422. {"WarningLevel", "W2", "Warning level", "2", 0},
  423. {"WarningLevel", "W3", "Warning level", "3", 0},
  424. {"WarningLevel", "W4", "Warning level", "4", 0},
  425. {"DisableSpecificWarnings", "wd", "Disable specific warnings", "",
  426. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  427. // Precompiled header and related options. Note that the
  428. // UsePrecompiledHeader entries are marked as "Continue" so that the
  429. // corresponding PrecompiledHeaderThrough entry can be found.
  430. {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
  431. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  432. {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
  433. cmVS7FlagTable::UserValueRequired},
  434. {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
  435. cmVS7FlagTable::UserValue},
  436. // The YX and Yu options are in a per-global-generator table because
  437. // their values differ based on the VS IDE version.
  438. {"ForcedIncludeFiles", "FI", "Forced include files", "",
  439. cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SemicolonAppendable},
  440. {"AssemblerListingLocation", "Fa", "ASM List Location", "",
  441. cmVS7FlagTable::UserValue},
  442. {"ProgramDataBaseFileName", "Fd", "Program Database File Name", "",
  443. cmVS7FlagTable::UserValue},
  444. // boolean flags
  445. {"BufferSecurityCheck", "GS", "Buffer security check", "true", 0},
  446. {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "false", 0},
  447. {"Detect64BitPortabilityProblems", "Wp64",
  448. "Detect 64-bit Portability Problems", "true", 0},
  449. {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
  450. "true", 0},
  451. {"EnableFunctionLevelLinking", "Gy",
  452. "EnableFunctionLevelLinking", "true", 0},
  453. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "true", 0},
  454. {"GlobalOptimizations", "Og", "Global Optimize", "true", 0},
  455. {"ImproveFloatingPointConsistency", "Op",
  456. "ImproveFloatingPointConsistency", "true", 0},
  457. {"MinimalRebuild", "Gm", "minimal rebuild", "true", 0},
  458. {"OmitFramePointers", "Oy", "OmitFramePointers", "true", 0},
  459. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "true", 0},
  460. {"RuntimeTypeInfo", "GR",
  461. "Turn on Run time type information for c++", "true", 0},
  462. {"RuntimeTypeInfo", "GR-",
  463. "Turn off Run time type information for c++", "false", 0},
  464. {"SmallerTypeCheck", "RTCc", "smaller type check", "true", 0},
  465. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  466. {"WholeProgramOptimization", "GL",
  467. "Enables whole program optimization", "true", 0},
  468. {"WholeProgramOptimization", "GL-",
  469. "Disables whole program optimization", "false", 0},
  470. {"WarnAsError", "WX", "Treat warnings as errors", "true", 0},
  471. {"BrowseInformation", "FR", "Generate browse information", "1", 0},
  472. {"StringPooling", "GF", "Enable StringPooling", "true", 0},
  473. {0,0,0,0,0}
  474. };
  475. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  476. {
  477. // option flags (some flags map to the same option)
  478. {"GenerateManifest", "MANIFEST:NO",
  479. "disable manifest generation", "false", 0},
  480. {"GenerateManifest", "MANIFEST", "enable manifest generation", "true", 0},
  481. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
  482. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
  483. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
  484. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
  485. {"DataExecutionPrevention", "NXCOMPAT:NO",
  486. "Not known to work with Windows Data Execution Prevention", "1", 0},
  487. {"DataExecutionPrevention", "NXCOMPAT",
  488. "Known to work with Windows Data Execution Prevention", "2", 0},
  489. {"DelaySign", "DELAYSIGN:NO", "", "false", 0},
  490. {"DelaySign", "DELAYSIGN", "", "true", 0},
  491. {"EntryPointSymbol", "ENTRY:", "sets the starting address", "",
  492. cmVS7FlagTable::UserValue},
  493. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  494. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  495. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  496. "true", 0},
  497. {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
  498. {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
  499. "2", 0},
  500. {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
  501. "1", 0},
  502. {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
  503. {"ResourceOnlyDLL", "NOENTRY", "Create DLL with no entry point", "true", 0},
  504. {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
  505. {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
  506. {"Profile", "PROFILE", "", "true", 0},
  507. {"RandomizedBaseAddress", "DYNAMICBASE:NO",
  508. "Image may not be rebased at load-time", "1", 0},
  509. {"RandomizedBaseAddress", "DYNAMICBASE",
  510. "Image may be rebased at load-time", "2", 0},
  511. {"SetChecksum", "RELEASE", "Enable setting checksum in header", "true", 0},
  512. {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
  513. {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
  514. {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
  515. {"TargetMachine", "MACHINE:AM33", "Machine AM33", "2", 0},
  516. {"TargetMachine", "MACHINE:ARM", "Machine ARM", "3", 0},
  517. {"TargetMachine", "MACHINE:EBC", "Machine EBC", "4", 0},
  518. {"TargetMachine", "MACHINE:IA64", "Machine IA64", "5", 0},
  519. {"TargetMachine", "MACHINE:M32R", "Machine M32R", "6", 0},
  520. {"TargetMachine", "MACHINE:MIPS", "Machine MIPS", "7", 0},
  521. {"TargetMachine", "MACHINE:MIPS16", "Machine MIPS16", "8", 0},
  522. {"TargetMachine", "MACHINE:MIPSFPU)", "Machine MIPSFPU", "9", 0},
  523. {"TargetMachine", "MACHINE:MIPSFPU16", "Machine MIPSFPU16", "10", 0},
  524. {"TargetMachine", "MACHINE:MIPSR41XX", "Machine MIPSR41XX", "11", 0},
  525. {"TargetMachine", "MACHINE:SH3", "Machine SH3", "12", 0},
  526. {"TargetMachine", "MACHINE:SH3DSP", "Machine SH3DSP", "13", 0},
  527. {"TargetMachine", "MACHINE:SH4", "Machine SH4", "14", 0},
  528. {"TargetMachine", "MACHINE:SH5", "Machine SH5", "15", 0},
  529. {"TargetMachine", "MACHINE:THUMB", "Machine THUMB", "16", 0},
  530. {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
  531. {"TurnOffAssemblyGeneration", "NOASSEMBLY",
  532. "No assembly even if CLR information is present in objects.", "true", 0},
  533. {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
  534. cmVS7FlagTable::UserValue},
  535. {"GenerateMapFile", "MAP", "enable generation of map file", "true", 0},
  536. {0,0,0,0,0}
  537. };
  538. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranLinkFlagTable[] =
  539. {
  540. {"LinkIncremental", "INCREMENTAL:NO", "link incremental",
  541. "linkIncrementalNo", 0},
  542. {"LinkIncremental", "INCREMENTAL:YES", "link incremental",
  543. "linkIncrementalYes", 0},
  544. {0,0,0,0,0}
  545. };
  546. //----------------------------------------------------------------------------
  547. // Helper class to write build event <Tool .../> elements.
  548. class cmLocalVisualStudio7Generator::EventWriter
  549. {
  550. public:
  551. EventWriter(cmLocalVisualStudio7Generator* lg,
  552. const std::string& config, std::ostream& os):
  553. LG(lg), Config(config), Stream(os), First(true) {}
  554. void Start(const char* tool)
  555. {
  556. this->First = true;
  557. this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
  558. }
  559. void Finish()
  560. {
  561. this->Stream << (this->First? "" : "\"") << "/>\n";
  562. }
  563. void Write(std::vector<cmCustomCommand> const& ccs)
  564. {
  565. for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  566. ci != ccs.end(); ++ci)
  567. {
  568. this->Write(*ci);
  569. }
  570. }
  571. void Write(cmCustomCommand const& cc)
  572. {
  573. cmCustomCommandGenerator ccg(cc, this->Config, this->LG);
  574. if(this->First)
  575. {
  576. const char* comment = ccg.GetComment();
  577. if(comment && *comment)
  578. {
  579. this->Stream << "\nDescription=\""
  580. << this->LG->EscapeForXML(comment) << "\"";
  581. }
  582. this->Stream << "\nCommandLine=\"";
  583. this->First = false;
  584. }
  585. else
  586. {
  587. this->Stream << this->LG->EscapeForXML("\n");
  588. }
  589. std::string script = this->LG->ConstructScript(ccg);
  590. this->Stream << this->LG->EscapeForXML(script.c_str());
  591. }
  592. private:
  593. cmLocalVisualStudio7Generator* LG;
  594. std::string Config;
  595. std::ostream& Stream;
  596. bool First;
  597. };
  598. //----------------------------------------------------------------------------
  599. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  600. const std::string& configName,
  601. const std::string& libName,
  602. cmTarget &target)
  603. {
  604. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  605. if(!mfcFlag)
  606. {
  607. mfcFlag = "0";
  608. }
  609. cmGlobalVisualStudio7Generator* gg =
  610. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  611. fout << "\t\t<Configuration\n"
  612. << "\t\t\tName=\"" << configName
  613. << "|" << gg->GetPlatformName() << "\"\n";
  614. // This is an internal type to Visual Studio, it seems that:
  615. // 4 == static library
  616. // 2 == dll
  617. // 1 == executable
  618. // 10 == utility
  619. const char* configType = "10";
  620. const char* projectType = 0;
  621. bool targetBuilds = true;
  622. switch(target.GetType())
  623. {
  624. case cmTarget::OBJECT_LIBRARY:
  625. targetBuilds = false; // no manifest tool for object library
  626. case cmTarget::STATIC_LIBRARY:
  627. projectType = "typeStaticLibrary";
  628. configType = "4";
  629. break;
  630. case cmTarget::SHARED_LIBRARY:
  631. case cmTarget::MODULE_LIBRARY:
  632. projectType = "typeDynamicLibrary";
  633. configType = "2";
  634. break;
  635. case cmTarget::EXECUTABLE:
  636. configType = "1";
  637. break;
  638. case cmTarget::UTILITY:
  639. case cmTarget::GLOBAL_TARGET:
  640. configType = "10";
  641. default:
  642. targetBuilds = false;
  643. break;
  644. }
  645. if(this->FortranProject && projectType)
  646. {
  647. configType = projectType;
  648. }
  649. std::string flags;
  650. if(strcmp(configType, "10") != 0)
  651. {
  652. const std::string& linkLanguage = (this->FortranProject?
  653. std::string("Fortran"):
  654. target.GetLinkerLanguage(configName));
  655. if(linkLanguage.empty())
  656. {
  657. cmSystemTools::Error
  658. ("CMake can not determine linker language for target: ",
  659. target.GetName().c_str());
  660. return;
  661. }
  662. if(linkLanguage == "C" || linkLanguage == "CXX"
  663. || linkLanguage == "Fortran")
  664. {
  665. std::string baseFlagVar = "CMAKE_";
  666. baseFlagVar += linkLanguage;
  667. baseFlagVar += "_FLAGS";
  668. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  669. std::string flagVar = baseFlagVar + std::string("_") +
  670. cmSystemTools::UpperCase(configName);
  671. flags += " ";
  672. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  673. }
  674. // set the correct language
  675. if(linkLanguage == "C")
  676. {
  677. flags += " /TC ";
  678. }
  679. if(linkLanguage == "CXX")
  680. {
  681. flags += " /TP ";
  682. }
  683. // Add the target-specific flags.
  684. this->AddCompileOptions(flags, &target, linkLanguage, configName);
  685. }
  686. if(this->FortranProject)
  687. {
  688. switch(this->GetFortranFormat(target.GetProperty("Fortran_FORMAT")))
  689. {
  690. case FortranFormatFixed: flags += " -fixed"; break;
  691. case FortranFormatFree: flags += " -free"; break;
  692. default: break;
  693. }
  694. }
  695. // Get preprocessor definitions for this directory.
  696. std::string defineFlags = this->Makefile->GetDefineFlags();
  697. Options::Tool t = Options::Compiler;
  698. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  699. if(this->FortranProject)
  700. {
  701. t = Options::FortranCompiler;
  702. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  703. }
  704. Options targetOptions(this, t,
  705. table,
  706. gg->ExtraFlagTable);
  707. targetOptions.FixExceptionHandlingDefault();
  708. std::string asmLocation = configName + "/";
  709. targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  710. targetOptions.Parse(flags.c_str());
  711. targetOptions.Parse(defineFlags.c_str());
  712. targetOptions.ParseFinish();
  713. cmGeneratorTarget* gt =
  714. this->GlobalGenerator->GetGeneratorTarget(&target);
  715. std::vector<std::string> targetDefines;
  716. target.GetCompileDefinitions(targetDefines, configName, "CXX");
  717. targetOptions.AddDefines(targetDefines);
  718. targetOptions.SetVerboseMakefile(
  719. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  720. // Add a definition for the configuration name.
  721. std::string configDefine = "CMAKE_INTDIR=\"";
  722. configDefine += configName;
  723. configDefine += "\"";
  724. targetOptions.AddDefine(configDefine);
  725. // Add the export symbol definition for shared library objects.
  726. if(const char* exportMacro = target.GetExportMacro())
  727. {
  728. targetOptions.AddDefine(exportMacro);
  729. }
  730. // The intermediate directory name consists of a directory for the
  731. // target and a subdirectory for the configuration name.
  732. std::string intermediateDir = this->GetTargetDirectory(target);
  733. intermediateDir += "/";
  734. intermediateDir += configName;
  735. if (target.GetType() < cmTarget::UTILITY)
  736. {
  737. std::string const& outDir =
  738. target.GetType() == cmTarget::OBJECT_LIBRARY?
  739. intermediateDir : target.GetDirectory(configName);
  740. fout << "\t\t\tOutputDirectory=\""
  741. << this->ConvertToXMLOutputPathSingle(outDir.c_str()) << "\"\n";
  742. }
  743. fout << "\t\t\tIntermediateDirectory=\""
  744. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  745. << "\"\n"
  746. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  747. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  748. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
  749. if (this->FortranProject)
  750. {
  751. // Intel Fortran >= 15.0 uses TargetName property.
  752. std::string targetNameFull = target.GetFullName(configName);
  753. std::string targetName =
  754. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  755. std::string targetExt =
  756. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  757. fout <<
  758. "\t\t\tTargetName=\"" << this->EscapeForXML(targetName) << "\"\n"
  759. "\t\t\tTargetExt=\"" << this->EscapeForXML(targetExt) << "\"\n"
  760. ;
  761. }
  762. // If unicode is enabled change the character set to unicode, if not
  763. // then default to MBCS.
  764. if(targetOptions.UsingUnicode())
  765. {
  766. fout << "\t\t\tCharacterSet=\"1\">\n";
  767. }
  768. else if(targetOptions.UsingSBCS())
  769. {
  770. fout << "\t\t\tCharacterSet=\"0\">\n";
  771. }
  772. else
  773. {
  774. fout << "\t\t\tCharacterSet=\"2\">\n";
  775. }
  776. const char* tool = "VCCLCompilerTool";
  777. if(this->FortranProject)
  778. {
  779. tool = "VFFortranCompilerTool";
  780. }
  781. fout << "\t\t\t<Tool\n"
  782. << "\t\t\t\tName=\"" << tool << "\"\n";
  783. if(this->FortranProject)
  784. {
  785. const char* target_mod_dir =
  786. target.GetProperty("Fortran_MODULE_DIRECTORY");
  787. std::string modDir;
  788. if(target_mod_dir)
  789. {
  790. modDir = this->Convert(target_mod_dir,
  791. cmLocalGenerator::START_OUTPUT,
  792. cmLocalGenerator::UNCHANGED);
  793. }
  794. else
  795. {
  796. modDir = ".";
  797. }
  798. fout << "\t\t\t\tModulePath=\""
  799. << this->ConvertToXMLOutputPath(modDir.c_str())
  800. << "\\$(ConfigurationName)\"\n";
  801. }
  802. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  803. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  804. std::vector<std::string> includes;
  805. this->GetIncludeDirectories(includes, gt, "C", configName);
  806. std::vector<std::string>::iterator i = includes.begin();
  807. for(;i != includes.end(); ++i)
  808. {
  809. // output the include path
  810. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  811. fout << ipath << ";";
  812. // if this is fortran then output the include with
  813. // a ConfigurationName on the end of it.
  814. if(this->FortranProject)
  815. {
  816. ipath = i->c_str();
  817. ipath += "/$(ConfigurationName)";
  818. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  819. fout << ipath << ";";
  820. }
  821. }
  822. fout << "\"\n";
  823. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  824. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  825. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  826. if(target.GetType() <= cmTarget::OBJECT_LIBRARY)
  827. {
  828. // Specify the compiler program database file if configured.
  829. std::string pdb = target.GetCompilePDBPath(configName);
  830. if(!pdb.empty())
  831. {
  832. fout << "\t\t\t\tProgramDataBaseFileName=\""
  833. << this->ConvertToXMLOutputPathSingle(pdb.c_str())
  834. << "\"\n";
  835. }
  836. }
  837. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  838. if(gg->IsMasmEnabled() && !this->FortranProject)
  839. {
  840. Options masmOptions(this, Options::MasmCompiler, 0, 0);
  841. fout <<
  842. "\t\t\t<Tool\n"
  843. "\t\t\t\tName=\"MASM\"\n"
  844. "\t\t\t\tIncludePaths=\""
  845. ;
  846. const char* sep = "";
  847. for(i = includes.begin(); i != includes.end(); ++i)
  848. {
  849. std::string inc = *i;
  850. cmConvertToWindowsSlash(inc);
  851. fout << sep << this->EscapeForXML(inc);
  852. sep = ";";
  853. }
  854. fout << "\"\n";
  855. // Use same preprocessor definitions as VCCLCompilerTool.
  856. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
  857. "ASM_MASM");
  858. masmOptions.OutputFlagMap(fout, "\t\t\t\t");
  859. fout <<
  860. "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
  861. "\t\t\t/>\n";
  862. }
  863. tool = "VCCustomBuildTool";
  864. if(this->FortranProject)
  865. {
  866. tool = "VFCustomBuildTool";
  867. }
  868. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  869. tool = "VCResourceCompilerTool";
  870. if(this->FortranProject)
  871. {
  872. tool = "VFResourceCompilerTool";
  873. }
  874. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  875. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  876. for(i = includes.begin();i != includes.end(); ++i)
  877. {
  878. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  879. fout << ipath << ";";
  880. }
  881. // add the -D flags to the RC tool
  882. fout << "\"";
  883. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  884. fout << "/>\n";
  885. tool = "VCMIDLTool";
  886. if(this->FortranProject)
  887. {
  888. tool = "VFMIDLTool";
  889. }
  890. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  891. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  892. for(i = includes.begin(); i != includes.end(); ++i)
  893. {
  894. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  895. fout << ipath << ";";
  896. }
  897. fout << "\"\n";
  898. fout << "\t\t\t\tMkTypLibCompatible=\"false\"\n";
  899. if( gg->GetPlatformName() == "x64" )
  900. {
  901. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  902. }
  903. else if( gg->GetPlatformName() == "ia64" )
  904. {
  905. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  906. }
  907. else
  908. {
  909. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  910. }
  911. fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n";
  912. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  913. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  914. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  915. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  916. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  917. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  918. // end of <Tool Name=VCMIDLTool
  919. // Check if we need the FAT32 workaround.
  920. if(targetBuilds && this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8)
  921. {
  922. // Check the filesystem type where the target will be written.
  923. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  924. {
  925. // Add a flag telling the manifest tool to use a workaround
  926. // for FAT32 file systems, which can cause an empty manifest
  927. // to be embedded into the resulting executable. See CMake
  928. // bug #2617.
  929. const char* manifestTool = "VCManifestTool";
  930. if(this->FortranProject)
  931. {
  932. manifestTool = "VFManifestTool";
  933. }
  934. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << manifestTool << "\"\n"
  935. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  936. << "\t\t\t/>\n";
  937. }
  938. }
  939. this->OutputTargetRules(fout, configName, target, libName);
  940. this->OutputBuildTool(fout, configName, target, targetOptions);
  941. fout << "\t\t</Configuration>\n";
  942. }
  943. //----------------------------------------------------------------------------
  944. std::string
  945. cmLocalVisualStudio7Generator
  946. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
  947. const std::string& configName)
  948. {
  949. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  950. std::string extraLinkOptionsBuildTypeDef =
  951. rootLinkerFlags + "_" + configTypeUpper;
  952. std::string extraLinkOptionsBuildType =
  953. this->Makefile->GetRequiredDefinition
  954. (extraLinkOptionsBuildTypeDef.c_str());
  955. return extraLinkOptionsBuildType;
  956. }
  957. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  958. const std::string& configName, cmTarget &target,
  959. const Options& targetOptions)
  960. {
  961. cmGlobalVisualStudio7Generator* gg =
  962. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  963. std::string temp;
  964. std::string extraLinkOptions;
  965. if(target.GetType() == cmTarget::EXECUTABLE)
  966. {
  967. extraLinkOptions =
  968. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  969. + std::string(" ")
  970. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  971. }
  972. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  973. {
  974. extraLinkOptions =
  975. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  976. + std::string(" ")
  977. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  978. }
  979. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  980. {
  981. extraLinkOptions =
  982. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  983. + std::string(" ")
  984. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  985. }
  986. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  987. if(targetLinkFlags)
  988. {
  989. extraLinkOptions += " ";
  990. extraLinkOptions += targetLinkFlags;
  991. }
  992. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  993. std::string linkFlagsConfig = "LINK_FLAGS_";
  994. linkFlagsConfig += configTypeUpper;
  995. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  996. if(targetLinkFlags)
  997. {
  998. extraLinkOptions += " ";
  999. extraLinkOptions += targetLinkFlags;
  1000. }
  1001. Options linkOptions(this, Options::Linker);
  1002. if(this->FortranProject)
  1003. {
  1004. linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
  1005. }
  1006. linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
  1007. linkOptions.Parse(extraLinkOptions.c_str());
  1008. if(!this->ModuleDefinitionFile.empty())
  1009. {
  1010. std::string defFile =
  1011. this->ConvertToOutputFormat(this->ModuleDefinitionFile, SHELL);
  1012. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  1013. }
  1014. if (target.GetType() == cmTarget::SHARED_LIBRARY &&
  1015. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
  1016. {
  1017. if (target.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
  1018. {
  1019. linkOptions.AddFlag("ModuleDefinitionFile", "$(IntDir)/exportall.def");
  1020. }
  1021. }
  1022. switch(target.GetType())
  1023. {
  1024. case cmTarget::UNKNOWN_LIBRARY:
  1025. break;
  1026. case cmTarget::OBJECT_LIBRARY:
  1027. {
  1028. std::string libpath = this->GetTargetDirectory(target);
  1029. libpath += "/";
  1030. libpath += configName;
  1031. libpath += "/";
  1032. libpath += target.GetName();
  1033. libpath += ".lib";
  1034. const char* tool =
  1035. this->FortranProject? "VFLibrarianTool":"VCLibrarianTool";
  1036. fout << "\t\t\t<Tool\n"
  1037. << "\t\t\t\tName=\"" << tool << "\"\n";
  1038. fout << "\t\t\t\tOutputFile=\""
  1039. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1040. break;
  1041. }
  1042. case cmTarget::STATIC_LIBRARY:
  1043. {
  1044. std::string targetNameFull = target.GetFullName(configName);
  1045. std::string libpath = target.GetDirectory(configName);
  1046. libpath += "/";
  1047. libpath += targetNameFull;
  1048. const char* tool = "VCLibrarianTool";
  1049. if(this->FortranProject)
  1050. {
  1051. tool = "VFLibrarianTool";
  1052. }
  1053. fout << "\t\t\t<Tool\n"
  1054. << "\t\t\t\tName=\"" << tool << "\"\n";
  1055. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1056. || this->FortranProject)
  1057. {
  1058. std::ostringstream libdeps;
  1059. this->Internal->OutputObjects(libdeps, &target);
  1060. if(!libdeps.str().empty())
  1061. {
  1062. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str() << "\"\n";
  1063. }
  1064. }
  1065. std::string libflags;
  1066. this->GetStaticLibraryFlags(libflags, configTypeUpper, &target);
  1067. if(!libflags.empty())
  1068. {
  1069. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  1070. }
  1071. fout << "\t\t\t\tOutputFile=\""
  1072. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1073. break;
  1074. }
  1075. case cmTarget::SHARED_LIBRARY:
  1076. case cmTarget::MODULE_LIBRARY:
  1077. {
  1078. std::string targetName;
  1079. std::string targetNameSO;
  1080. std::string targetNameFull;
  1081. std::string targetNameImport;
  1082. std::string targetNamePDB;
  1083. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1084. targetNameImport, targetNamePDB, configName);
  1085. // Compute the link library and directory information.
  1086. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1087. if(!pcli)
  1088. {
  1089. return;
  1090. }
  1091. cmComputeLinkInformation& cli = *pcli;
  1092. std::string linkLanguage = cli.GetLinkLanguage();
  1093. // Compute the variable name to lookup standard libraries for this
  1094. // language.
  1095. std::string standardLibsVar = "CMAKE_";
  1096. standardLibsVar += linkLanguage;
  1097. standardLibsVar += "_STANDARD_LIBRARIES";
  1098. const char* tool = "VCLinkerTool";
  1099. if(this->FortranProject)
  1100. {
  1101. tool = "VFLinkerTool";
  1102. }
  1103. fout << "\t\t\t<Tool\n"
  1104. << "\t\t\t\tName=\"" << tool << "\"\n";
  1105. if(!gg->NeedLinkLibraryDependencies(target))
  1106. {
  1107. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1108. }
  1109. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1110. // Use the NOINHERIT macro to avoid getting VS project default
  1111. // libraries which may be set by the user to something bad.
  1112. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1113. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1114. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1115. || this->FortranProject)
  1116. {
  1117. this->Internal->OutputObjects(fout, &target, " ");
  1118. }
  1119. fout << " ";
  1120. this->Internal->OutputLibraries(fout, cli.GetItems());
  1121. fout << "\"\n";
  1122. temp = target.GetDirectory(configName);
  1123. temp += "/";
  1124. temp += targetNameFull;
  1125. fout << "\t\t\t\tOutputFile=\""
  1126. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1127. this->WriteTargetVersionAttribute(fout, target);
  1128. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1129. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1130. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1131. fout << "\"\n";
  1132. temp = target.GetPDBDirectory(configName);
  1133. temp += "/";
  1134. temp += targetNamePDB;
  1135. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  1136. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1137. if(targetOptions.IsDebug())
  1138. {
  1139. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1140. }
  1141. if(this->WindowsCEProject)
  1142. {
  1143. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS9)
  1144. {
  1145. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1146. }
  1147. else
  1148. {
  1149. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1150. }
  1151. }
  1152. std::string stackVar = "CMAKE_";
  1153. stackVar += linkLanguage;
  1154. stackVar += "_STACK_SIZE";
  1155. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1156. if(stackVal)
  1157. {
  1158. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1159. }
  1160. temp = target.GetDirectory(configName, true);
  1161. temp += "/";
  1162. temp += targetNameImport;
  1163. fout << "\t\t\t\tImportLibrary=\""
  1164. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1165. if(this->FortranProject)
  1166. {
  1167. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1168. }
  1169. fout << "/>\n";
  1170. }
  1171. break;
  1172. case cmTarget::EXECUTABLE:
  1173. {
  1174. std::string targetName;
  1175. std::string targetNameFull;
  1176. std::string targetNameImport;
  1177. std::string targetNamePDB;
  1178. target.GetExecutableNames(targetName, targetNameFull,
  1179. targetNameImport, targetNamePDB, configName);
  1180. // Compute the link library and directory information.
  1181. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1182. if(!pcli)
  1183. {
  1184. return;
  1185. }
  1186. cmComputeLinkInformation& cli = *pcli;
  1187. std::string linkLanguage = cli.GetLinkLanguage();
  1188. bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE");
  1189. // Compute the variable name to lookup standard libraries for this
  1190. // language.
  1191. std::string standardLibsVar = "CMAKE_";
  1192. standardLibsVar += linkLanguage;
  1193. standardLibsVar += "_STANDARD_LIBRARIES";
  1194. const char* tool = "VCLinkerTool";
  1195. if(this->FortranProject)
  1196. {
  1197. tool = "VFLinkerTool";
  1198. }
  1199. fout << "\t\t\t<Tool\n"
  1200. << "\t\t\t\tName=\"" << tool << "\"\n";
  1201. if(!gg->NeedLinkLibraryDependencies(target))
  1202. {
  1203. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1204. }
  1205. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1206. // Use the NOINHERIT macro to avoid getting VS project default
  1207. // libraries which may be set by the user to something bad.
  1208. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1209. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1210. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1211. || this->FortranProject)
  1212. {
  1213. this->Internal->OutputObjects(fout, &target, " ");
  1214. }
  1215. fout << " ";
  1216. this->Internal->OutputLibraries(fout, cli.GetItems());
  1217. fout << "\"\n";
  1218. temp = target.GetDirectory(configName);
  1219. temp += "/";
  1220. temp += targetNameFull;
  1221. fout << "\t\t\t\tOutputFile=\""
  1222. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1223. this->WriteTargetVersionAttribute(fout, target);
  1224. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1225. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1226. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1227. fout << "\"\n";
  1228. std::string path = this->ConvertToXMLOutputPathSingle(
  1229. target.GetPDBDirectory(configName).c_str());
  1230. fout << "\t\t\t\tProgramDatabaseFile=\""
  1231. << path << "/" << targetNamePDB
  1232. << "\"\n";
  1233. if(targetOptions.IsDebug())
  1234. {
  1235. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1236. }
  1237. if ( this->WindowsCEProject )
  1238. {
  1239. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS9)
  1240. {
  1241. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1242. }
  1243. else
  1244. {
  1245. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1246. }
  1247. if(!linkOptions.GetFlag("EntryPointSymbol"))
  1248. {
  1249. const char* entryPointSymbol = targetOptions.UsingUnicode() ?
  1250. (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup") :
  1251. (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1252. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1253. }
  1254. }
  1255. else if ( this->FortranProject )
  1256. {
  1257. fout << "\t\t\t\tSubSystem=\""
  1258. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1259. << "\"\n";
  1260. }
  1261. else
  1262. {
  1263. fout << "\t\t\t\tSubSystem=\""
  1264. << (isWin32Executable ? "2" : "1")
  1265. << "\"\n";
  1266. }
  1267. std::string stackVar = "CMAKE_";
  1268. stackVar += linkLanguage;
  1269. stackVar += "_STACK_SIZE";
  1270. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1271. if(stackVal)
  1272. {
  1273. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1274. }
  1275. temp = target.GetDirectory(configName, true);
  1276. temp += "/";
  1277. temp += targetNameImport;
  1278. fout << "\t\t\t\tImportLibrary=\""
  1279. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1280. break;
  1281. }
  1282. case cmTarget::UTILITY:
  1283. case cmTarget::GLOBAL_TARGET:
  1284. case cmTarget::INTERFACE_LIBRARY:
  1285. break;
  1286. }
  1287. }
  1288. //----------------------------------------------------------------------------
  1289. void
  1290. cmLocalVisualStudio7Generator
  1291. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1292. {
  1293. int major;
  1294. int minor;
  1295. target.GetTargetVersion(major, minor);
  1296. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1297. }
  1298. //----------------------------------------------------------------------------
  1299. void
  1300. cmLocalVisualStudio7GeneratorInternals
  1301. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1302. {
  1303. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1304. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1305. {
  1306. if(l->IsPath)
  1307. {
  1308. std::string rel = lg->Convert(l->Value.c_str(),
  1309. cmLocalGenerator::START_OUTPUT,
  1310. cmLocalGenerator::UNCHANGED);
  1311. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1312. }
  1313. else if (!l->Target
  1314. || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1315. {
  1316. fout << l->Value << " ";
  1317. }
  1318. }
  1319. }
  1320. //----------------------------------------------------------------------------
  1321. void
  1322. cmLocalVisualStudio7GeneratorInternals
  1323. ::OutputObjects(std::ostream& fout, cmTarget* t, const char* isep)
  1324. {
  1325. // VS < 8 does not support per-config source locations so we
  1326. // list object library content on the link line instead.
  1327. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1328. cmGeneratorTarget* gt =
  1329. lg->GetGlobalGenerator()->GetGeneratorTarget(t);
  1330. std::vector<std::string> objs;
  1331. gt->UseObjectLibraries(objs, "");
  1332. const char* sep = isep? isep : "";
  1333. for(std::vector<std::string>::const_iterator
  1334. oi = objs.begin(); oi != objs.end(); ++oi)
  1335. {
  1336. std::string rel = lg->Convert(oi->c_str(),
  1337. cmLocalGenerator::START_OUTPUT,
  1338. cmLocalGenerator::UNCHANGED);
  1339. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1340. sep = " ";
  1341. }
  1342. }
  1343. //----------------------------------------------------------------------------
  1344. void
  1345. cmLocalVisualStudio7Generator
  1346. ::OutputLibraryDirectories(std::ostream& fout,
  1347. std::vector<std::string> const& dirs)
  1348. {
  1349. const char* comma = "";
  1350. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1351. d != dirs.end(); ++d)
  1352. {
  1353. // Remove any trailing slash and skip empty paths.
  1354. std::string dir = *d;
  1355. if(dir[dir.size()-1] == '/')
  1356. {
  1357. dir = dir.substr(0, dir.size()-1);
  1358. }
  1359. if(dir.empty())
  1360. {
  1361. continue;
  1362. }
  1363. // Switch to a relative path specification if it is shorter.
  1364. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1365. {
  1366. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1367. if(rel.size() < dir.size())
  1368. {
  1369. dir = rel;
  1370. }
  1371. }
  1372. // First search a configuration-specific subdirectory and then the
  1373. // original directory.
  1374. fout << comma
  1375. << this->ConvertToXMLOutputPath((dir+"/$(ConfigurationName)").c_str())
  1376. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1377. comma = ",";
  1378. }
  1379. }
  1380. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1381. const std::string& libName,
  1382. cmTarget &target)
  1383. {
  1384. std::vector<std::string> configs;
  1385. this->Makefile->GetConfigurations(configs);
  1386. // We may be modifying the source groups temporarily, so make a copy.
  1387. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1388. // get the classes from the source lists then add them to the groups
  1389. this->ModuleDefinitionFile = "";
  1390. std::vector<cmSourceFile*> classes;
  1391. if (!target.GetConfigCommonSourceFiles(classes))
  1392. {
  1393. return;
  1394. }
  1395. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1396. i != classes.end(); i++)
  1397. {
  1398. if (!(*i)->GetObjectLibrary().empty())
  1399. {
  1400. continue;
  1401. }
  1402. // Add the file to the list of sources.
  1403. std::string source = (*i)->GetFullPath();
  1404. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1405. {
  1406. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1407. }
  1408. cmSourceGroup* sourceGroup =
  1409. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1410. sourceGroup->AssignSource(*i);
  1411. }
  1412. // open the project
  1413. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1414. // write the configuration information
  1415. this->WriteConfigurations(fout, configs, libName, target);
  1416. fout << "\t<Files>\n";
  1417. // Loop through every source group.
  1418. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1419. {
  1420. cmSourceGroup sg = sourceGroups[i];
  1421. this->WriteGroup(&sg, target, fout, libName, configs);
  1422. }
  1423. if(this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8
  1424. && !this->FortranProject)
  1425. {
  1426. // VS >= 8 support per-config source locations so we
  1427. // list object library content as external objects.
  1428. cmGeneratorTarget* gt =
  1429. this->GlobalGenerator->GetGeneratorTarget(&target);
  1430. std::vector<std::string> objs;
  1431. gt->UseObjectLibraries(objs, "");
  1432. if(!objs.empty())
  1433. {
  1434. // TODO: Separate sub-filter for each object library used?
  1435. fout << "\t\t<Filter Name=\"Object Libraries\">\n";
  1436. for(std::vector<std::string>::const_iterator
  1437. oi = objs.begin(); oi != objs.end(); ++oi)
  1438. {
  1439. std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str());
  1440. fout << "\t\t\t<File RelativePath=\"" << o << "\" />\n";
  1441. }
  1442. fout << "\t\t</Filter>\n";
  1443. }
  1444. }
  1445. fout << "\t</Files>\n";
  1446. // Write the VCProj file's footer.
  1447. this->WriteVCProjFooter(fout, target);
  1448. }
  1449. struct cmLVS7GFileConfig
  1450. {
  1451. std::string ObjectName;
  1452. std::string CompileFlags;
  1453. std::string CompileDefs;
  1454. std::string CompileDefsConfig;
  1455. std::string AdditionalDeps;
  1456. bool ExcludedFromBuild;
  1457. };
  1458. class cmLocalVisualStudio7GeneratorFCInfo
  1459. {
  1460. public:
  1461. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1462. cmTarget& target,
  1463. cmSourceFile const& sf,
  1464. std::vector<std::string> const& configs);
  1465. std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
  1466. };
  1467. cmLocalVisualStudio7GeneratorFCInfo
  1468. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1469. cmTarget& target,
  1470. cmSourceFile const& sf,
  1471. std::vector<std::string> const& configs)
  1472. {
  1473. cmGeneratorTarget* gt =
  1474. lg->GetGlobalGenerator()->GetGeneratorTarget(&target);
  1475. std::string objectName;
  1476. if(gt->HasExplicitObjectName(&sf))
  1477. {
  1478. objectName = gt->GetObjectName(&sf);
  1479. }
  1480. // Compute per-source, per-config information.
  1481. for(std::vector<std::string>::const_iterator i = configs.begin();
  1482. i != configs.end(); ++i)
  1483. {
  1484. std::string configUpper = cmSystemTools::UpperCase(*i);
  1485. cmLVS7GFileConfig fc;
  1486. bool needfc = false;
  1487. if(!objectName.empty())
  1488. {
  1489. fc.ObjectName = objectName;
  1490. needfc = true;
  1491. }
  1492. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1493. {
  1494. fc.CompileFlags = cflags;
  1495. needfc = true;
  1496. }
  1497. if(lg->FortranProject)
  1498. {
  1499. switch(lg->GetFortranFormat(sf.GetProperty("Fortran_FORMAT")))
  1500. {
  1501. case cmLocalGenerator::FortranFormatFixed:
  1502. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1503. needfc = true;
  1504. break;
  1505. case cmLocalGenerator::FortranFormatFree:
  1506. fc.CompileFlags = "-free " + fc.CompileFlags;
  1507. needfc = true;
  1508. break;
  1509. default: break;
  1510. }
  1511. }
  1512. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1513. {
  1514. fc.CompileDefs = cdefs;
  1515. needfc = true;
  1516. }
  1517. std::string defPropName = "COMPILE_DEFINITIONS_";
  1518. defPropName += configUpper;
  1519. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1520. {
  1521. fc.CompileDefsConfig = ccdefs;
  1522. needfc = true;
  1523. }
  1524. // Check for extra object-file dependencies.
  1525. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1526. {
  1527. std::vector<std::string> depends;
  1528. cmSystemTools::ExpandListArgument(deps, depends);
  1529. const char* sep = "";
  1530. for(std::vector<std::string>::iterator j = depends.begin();
  1531. j != depends.end(); ++j)
  1532. {
  1533. fc.AdditionalDeps += sep;
  1534. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1535. sep = ";";
  1536. needfc = true;
  1537. }
  1538. }
  1539. std::string lang =
  1540. lg->GlobalGenerator->GetLanguageFromExtension
  1541. (sf.GetExtension().c_str());
  1542. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1543. const std::string& linkLanguage = target.GetLinkerLanguage(i->c_str());
  1544. bool needForceLang = false;
  1545. // source file does not match its extension language
  1546. if(lang != sourceLang)
  1547. {
  1548. needForceLang = true;
  1549. lang = sourceLang;
  1550. }
  1551. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1552. // the project file
  1553. fc.ExcludedFromBuild =
  1554. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1555. if(fc.ExcludedFromBuild)
  1556. {
  1557. needfc = true;
  1558. }
  1559. // if the source file does not match the linker language
  1560. // then force c or c++
  1561. if(needForceLang || (linkLanguage != lang))
  1562. {
  1563. if(lang == "CXX")
  1564. {
  1565. // force a C++ file type
  1566. fc.CompileFlags += " /TP ";
  1567. needfc = true;
  1568. }
  1569. else if(lang == "C")
  1570. {
  1571. // force to c
  1572. fc.CompileFlags += " /TC ";
  1573. needfc = true;
  1574. }
  1575. }
  1576. if(needfc)
  1577. {
  1578. this->FileConfigMap[*i] = fc;
  1579. }
  1580. }
  1581. }
  1582. //----------------------------------------------------------------------------
  1583. std::string
  1584. cmLocalVisualStudio7Generator
  1585. ::ComputeLongestObjectDirectory(cmTarget& target) const
  1586. {
  1587. std::vector<std::string> configs;
  1588. target.GetMakefile()->GetConfigurations(configs);
  1589. // Compute the maximum length configuration name.
  1590. std::string config_max;
  1591. for(std::vector<std::string>::iterator i = configs.begin();
  1592. i != configs.end(); ++i)
  1593. {
  1594. if(i->size() > config_max.size())
  1595. {
  1596. config_max = *i;
  1597. }
  1598. }
  1599. // Compute the maximum length full path to the intermediate
  1600. // files directory for any configuration. This is used to construct
  1601. // object file names that do not produce paths that are too long.
  1602. std::string dir_max;
  1603. dir_max += this->Makefile->GetCurrentBinaryDirectory();
  1604. dir_max += "/";
  1605. dir_max += this->GetTargetDirectory(target);
  1606. dir_max += "/";
  1607. dir_max += config_max;
  1608. dir_max += "/";
  1609. return dir_max;
  1610. }
  1611. bool cmLocalVisualStudio7Generator
  1612. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  1613. std::ostream &fout, const std::string& libName,
  1614. std::vector<std::string> const& configs)
  1615. {
  1616. cmGlobalVisualStudio7Generator* gg =
  1617. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1618. const std::vector<const cmSourceFile *> &sourceFiles =
  1619. sg->GetSourceFiles();
  1620. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1621. // Write the children to temporary output.
  1622. bool hasChildrenWithSources = false;
  1623. std::ostringstream tmpOut;
  1624. for(unsigned int i=0;i<children.size();++i)
  1625. {
  1626. if(this->WriteGroup(&children[i], target, tmpOut, libName, configs))
  1627. {
  1628. hasChildrenWithSources = true;
  1629. }
  1630. }
  1631. // If the group is empty, don't write it at all.
  1632. if(sourceFiles.empty() && !hasChildrenWithSources)
  1633. {
  1634. return false;
  1635. }
  1636. // If the group has a name, write the header.
  1637. std::string name = sg->GetName();
  1638. if(name != "")
  1639. {
  1640. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1641. }
  1642. // Loop through each source in the source group.
  1643. std::string objectName;
  1644. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1645. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1646. {
  1647. std::string source = (*sf)->GetFullPath();
  1648. FCInfo fcinfo(this, target, *(*sf), configs);
  1649. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1650. target.GetType() == cmTarget::GLOBAL_TARGET )
  1651. {
  1652. fout << "\t\t\t<File\n";
  1653. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1654. // Tell MS-Dev what the source is. If the compiler knows how to
  1655. // build it, then it will.
  1656. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1657. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1658. {
  1659. this->WriteCustomRule(fout, configs, source.c_str(),
  1660. *command, fcinfo);
  1661. }
  1662. else if(!fcinfo.FileConfigMap.empty())
  1663. {
  1664. const char* aCompilerTool = "VCCLCompilerTool";
  1665. const char* ppLang = "CXX";
  1666. if(this->FortranProject)
  1667. {
  1668. aCompilerTool = "VFFortranCompilerTool";
  1669. }
  1670. std::string const& lang = (*sf)->GetLanguage();
  1671. std::string ext = (*sf)->GetExtension();
  1672. ext = cmSystemTools::LowerCase(ext);
  1673. if(ext == "idl")
  1674. {
  1675. aCompilerTool = "VCMIDLTool";
  1676. if(this->FortranProject)
  1677. {
  1678. aCompilerTool = "VFMIDLTool";
  1679. }
  1680. }
  1681. if(ext == "rc")
  1682. {
  1683. aCompilerTool = "VCResourceCompilerTool";
  1684. ppLang = "RC";
  1685. if(this->FortranProject)
  1686. {
  1687. aCompilerTool = "VFResourceCompilerTool";
  1688. }
  1689. }
  1690. if(ext == "def")
  1691. {
  1692. aCompilerTool = "VCCustomBuildTool";
  1693. if(this->FortranProject)
  1694. {
  1695. aCompilerTool = "VFCustomBuildTool";
  1696. }
  1697. }
  1698. if (gg->IsMasmEnabled() && !this->FortranProject &&
  1699. lang == "ASM_MASM")
  1700. {
  1701. aCompilerTool = "MASM";
  1702. }
  1703. for(std::map<std::string, cmLVS7GFileConfig>::const_iterator
  1704. fci = fcinfo.FileConfigMap.begin();
  1705. fci != fcinfo.FileConfigMap.end(); ++fci)
  1706. {
  1707. cmLVS7GFileConfig const& fc = fci->second;
  1708. fout << "\t\t\t\t<FileConfiguration\n"
  1709. << "\t\t\t\t\tName=\"" << fci->first
  1710. << "|" << gg->GetPlatformName() << "\"";
  1711. if(fc.ExcludedFromBuild)
  1712. {
  1713. fout << " ExcludedFromBuild=\"true\"";
  1714. }
  1715. fout << ">\n";
  1716. fout << "\t\t\t\t\t<Tool\n"
  1717. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1718. if(!fc.CompileFlags.empty() ||
  1719. !fc.CompileDefs.empty() ||
  1720. !fc.CompileDefsConfig.empty())
  1721. {
  1722. Options::Tool tool = Options::Compiler;
  1723. cmVS7FlagTable const* table =
  1724. cmLocalVisualStudio7GeneratorFlagTable;
  1725. if(this->FortranProject)
  1726. {
  1727. tool = Options::FortranCompiler;
  1728. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1729. }
  1730. Options fileOptions(this, tool, table,
  1731. gg->ExtraFlagTable);
  1732. fileOptions.Parse(fc.CompileFlags.c_str());
  1733. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1734. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1735. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1736. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1737. fileOptions.OutputPreprocessorDefinitions(fout,
  1738. "\t\t\t\t\t", "\n",
  1739. ppLang);
  1740. }
  1741. if(!fc.AdditionalDeps.empty())
  1742. {
  1743. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1744. << fc.AdditionalDeps.c_str() << "\"\n";
  1745. }
  1746. if(!fc.ObjectName.empty())
  1747. {
  1748. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1749. << fc.ObjectName.c_str() << "\"\n";
  1750. }
  1751. fout << "\t\t\t\t\t/>\n"
  1752. << "\t\t\t\t</FileConfiguration>\n";
  1753. }
  1754. }
  1755. fout << "\t\t\t</File>\n";
  1756. }
  1757. }
  1758. // If the group has children with source files, write the children.
  1759. if(hasChildrenWithSources)
  1760. {
  1761. fout << tmpOut.str();
  1762. }
  1763. // If the group has a name, write the footer.
  1764. if(name != "")
  1765. {
  1766. this->WriteVCProjEndGroup(fout);
  1767. }
  1768. return true;
  1769. }
  1770. void cmLocalVisualStudio7Generator::
  1771. WriteCustomRule(std::ostream& fout,
  1772. std::vector<std::string> const& configs,
  1773. const char* source,
  1774. const cmCustomCommand& command,
  1775. FCInfo& fcinfo)
  1776. {
  1777. cmGlobalVisualStudio7Generator* gg =
  1778. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1779. // Write the rule for each configuration.
  1780. const char* compileTool = "VCCLCompilerTool";
  1781. if(this->FortranProject)
  1782. {
  1783. compileTool = "VFCLCompilerTool";
  1784. }
  1785. const char* customTool = "VCCustomBuildTool";
  1786. if(this->FortranProject)
  1787. {
  1788. customTool = "VFCustomBuildTool";
  1789. }
  1790. for (std::vector<std::string>::const_iterator i = configs.begin();
  1791. i != configs.end(); ++i)
  1792. {
  1793. cmCustomCommandGenerator ccg(command, *i, this);
  1794. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1795. fout << "\t\t\t\t<FileConfiguration\n";
  1796. fout << "\t\t\t\t\tName=\"" << *i << "|"
  1797. << gg->GetPlatformName() << "\">\n";
  1798. if(!fc.CompileFlags.empty())
  1799. {
  1800. fout << "\t\t\t\t\t<Tool\n"
  1801. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1802. << "\t\t\t\t\tAdditionalOptions=\""
  1803. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1804. }
  1805. std::string comment = this->ConstructComment(ccg);
  1806. std::string script = this->ConstructScript(ccg);
  1807. if(this->FortranProject)
  1808. {
  1809. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1810. }
  1811. fout << "\t\t\t\t\t<Tool\n"
  1812. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1813. << "\t\t\t\t\tDescription=\""
  1814. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1815. << "\t\t\t\t\tCommandLine=\""
  1816. << this->EscapeForXML(script.c_str()) << "\"\n"
  1817. << "\t\t\t\t\tAdditionalDependencies=\"";
  1818. if(ccg.GetDepends().empty())
  1819. {
  1820. // There are no real dependencies. Produce an artificial one to
  1821. // make sure the rule runs reliably.
  1822. if(!cmSystemTools::FileExists(source))
  1823. {
  1824. cmsys::ofstream depout(source);
  1825. depout << "Artificial dependency for a custom command.\n";
  1826. }
  1827. fout << this->ConvertToXMLOutputPath(source);
  1828. }
  1829. else
  1830. {
  1831. // Write out the dependencies for the rule.
  1832. for(std::vector<std::string>::const_iterator d =
  1833. ccg.GetDepends().begin();
  1834. d != ccg.GetDepends().end();
  1835. ++d)
  1836. {
  1837. // Get the real name of the dependency in case it is a CMake target.
  1838. std::string dep;
  1839. if(this->GetRealDependency(d->c_str(), i->c_str(), dep))
  1840. {
  1841. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1842. << ";";
  1843. }
  1844. }
  1845. }
  1846. fout << "\"\n";
  1847. fout << "\t\t\t\t\tOutputs=\"";
  1848. if(ccg.GetOutputs().empty())
  1849. {
  1850. fout << source << "_force";
  1851. }
  1852. else
  1853. {
  1854. // Write a rule for the output generated by this command.
  1855. const char* sep = "";
  1856. for(std::vector<std::string>::const_iterator o =
  1857. ccg.GetOutputs().begin();
  1858. o != ccg.GetOutputs().end();
  1859. ++o)
  1860. {
  1861. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1862. sep = ";";
  1863. }
  1864. }
  1865. fout << "\"/>\n";
  1866. fout << "\t\t\t\t</FileConfiguration>\n";
  1867. }
  1868. }
  1869. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1870. const char* group,
  1871. const char* )
  1872. {
  1873. fout << "\t\t<Filter\n"
  1874. << "\t\t\tName=\"" << group << "\"\n"
  1875. << "\t\t\tFilter=\"\">\n";
  1876. }
  1877. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1878. {
  1879. fout << "\t\t</Filter>\n";
  1880. }
  1881. // look for custom rules on a target and collect them together
  1882. void cmLocalVisualStudio7Generator
  1883. ::OutputTargetRules(std::ostream& fout,
  1884. const std::string& configName,
  1885. cmTarget &target,
  1886. const std::string& /*libName*/)
  1887. {
  1888. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1889. {
  1890. return;
  1891. }
  1892. EventWriter event(this, configName, fout);
  1893. // Add pre-build event.
  1894. const char* tool =
  1895. this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
  1896. event.Start(tool);
  1897. event.Write(target.GetPreBuildCommands());
  1898. event.Finish();
  1899. // Add pre-link event.
  1900. tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
  1901. event.Start(tool);
  1902. bool addedPrelink = false;
  1903. if (target.GetType() == cmTarget::SHARED_LIBRARY &&
  1904. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
  1905. {
  1906. if (target.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
  1907. {
  1908. addedPrelink = true;
  1909. std::vector<cmCustomCommand> commands =
  1910. target.GetPreLinkCommands();
  1911. cmGlobalVisualStudioGenerator* gg
  1912. = static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  1913. cmGeneratorTarget* gt =
  1914. this->GlobalGenerator->GetGeneratorTarget(&target);
  1915. gg->AddSymbolExportCommand(
  1916. gt, commands, configName);
  1917. event.Write(commands);
  1918. }
  1919. }
  1920. if (!addedPrelink)
  1921. {
  1922. event.Write(target.GetPreLinkCommands());
  1923. }
  1924. cmsys::auto_ptr<cmCustomCommand> pcc(
  1925. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1926. if(pcc.get())
  1927. {
  1928. event.Write(*pcc);
  1929. }
  1930. event.Finish();
  1931. // Add post-build event.
  1932. tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
  1933. event.Start(tool);
  1934. event.Write(target.GetPostBuildCommands());
  1935. event.Finish();
  1936. }
  1937. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1938. cmTarget& target)
  1939. {
  1940. // if we have all the required Source code control tags
  1941. // then add that to the project
  1942. const char* vsProjectname = target.GetProperty("VS_SCC_PROJECTNAME");
  1943. const char* vsLocalpath = target.GetProperty("VS_SCC_LOCALPATH");
  1944. const char* vsProvider = target.GetProperty("VS_SCC_PROVIDER");
  1945. if(vsProvider && vsLocalpath && vsProjectname)
  1946. {
  1947. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1948. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1949. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1950. const char* vsAuxPath = target.GetProperty("VS_SCC_AUXPATH");
  1951. if(vsAuxPath)
  1952. {
  1953. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1954. }
  1955. }
  1956. }
  1957. void
  1958. cmLocalVisualStudio7Generator
  1959. ::WriteProjectStartFortran(std::ostream& fout,
  1960. const std::string& libName,
  1961. cmTarget & target)
  1962. {
  1963. cmGlobalVisualStudio7Generator* gg =
  1964. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1965. fout << "<?xml version=\"1.0\" encoding = \""
  1966. << gg->Encoding() << "\"?>\n"
  1967. << "<VisualStudioProject\n"
  1968. << "\tProjectCreator=\"Intel Fortran\"\n"
  1969. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  1970. const char* keyword = target.GetProperty("VS_KEYWORD");
  1971. if(!keyword)
  1972. {
  1973. keyword = "Console Application";
  1974. }
  1975. const char* projectType = 0;
  1976. switch(target.GetType())
  1977. {
  1978. case cmTarget::STATIC_LIBRARY:
  1979. projectType = "typeStaticLibrary";
  1980. if(keyword)
  1981. {
  1982. keyword = "Static Library";
  1983. }
  1984. break;
  1985. case cmTarget::SHARED_LIBRARY:
  1986. case cmTarget::MODULE_LIBRARY:
  1987. projectType = "typeDynamicLibrary";
  1988. if(!keyword)
  1989. {
  1990. keyword = "Dll";
  1991. }
  1992. break;
  1993. case cmTarget::EXECUTABLE:
  1994. if(!keyword)
  1995. {
  1996. keyword = "Console Application";
  1997. }
  1998. projectType = 0;
  1999. break;
  2000. case cmTarget::UTILITY:
  2001. case cmTarget::GLOBAL_TARGET:
  2002. default:
  2003. break;
  2004. }
  2005. if(projectType)
  2006. {
  2007. fout << "\tProjectType=\"" << projectType << "\"\n";
  2008. }
  2009. this->WriteProjectSCC(fout, target);
  2010. fout<< "\tKeyword=\"" << keyword << "\">\n"
  2011. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  2012. << "\t<Platforms>\n"
  2013. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  2014. << "\t</Platforms>\n";
  2015. }
  2016. void
  2017. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  2018. const std::string& libName,
  2019. cmTarget & target,
  2020. std::vector<cmSourceGroup> &)
  2021. {
  2022. if(this->FortranProject)
  2023. {
  2024. this->WriteProjectStartFortran(fout, libName, target);
  2025. return;
  2026. }
  2027. cmGlobalVisualStudio7Generator* gg =
  2028. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  2029. fout << "<?xml version=\"1.0\" encoding = \""
  2030. << gg->Encoding() << "\"?>\n"
  2031. << "<VisualStudioProject\n"
  2032. << "\tProjectType=\"Visual C++\"\n";
  2033. if(gg->GetVersion() == cmGlobalVisualStudioGenerator::VS71)
  2034. {
  2035. fout << "\tVersion=\"7.10\"\n";
  2036. }
  2037. else
  2038. {
  2039. fout << "\tVersion=\"" << (gg->GetVersion()/10) << ".00\"\n";
  2040. }
  2041. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  2042. if(!projLabel)
  2043. {
  2044. projLabel = libName.c_str();
  2045. }
  2046. const char* keyword = target.GetProperty("VS_KEYWORD");
  2047. if(!keyword)
  2048. {
  2049. keyword = "Win32Proj";
  2050. }
  2051. fout << "\tName=\"" << projLabel << "\"\n";
  2052. if(gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS8)
  2053. {
  2054. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  2055. }
  2056. this->WriteProjectSCC(fout, target);
  2057. if(const char* targetFrameworkVersion =
  2058. target.GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
  2059. {
  2060. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  2061. }
  2062. fout << "\tKeyword=\"" << keyword << "\">\n"
  2063. << "\t<Platforms>\n"
  2064. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  2065. << "\t</Platforms>\n";
  2066. if(gg->IsMasmEnabled())
  2067. {
  2068. fout <<
  2069. "\t<ToolFiles>\n"
  2070. "\t\t<DefaultToolFile\n"
  2071. "\t\t\tFileName=\"masm.rules\"\n"
  2072. "\t\t/>\n"
  2073. "\t</ToolFiles>\n"
  2074. ;
  2075. }
  2076. }
  2077. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout,
  2078. cmTarget &target)
  2079. {
  2080. fout << "\t<Globals>\n";
  2081. cmPropertyMap const& props = target.GetProperties();
  2082. for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
  2083. {
  2084. if(i->first.find("VS_GLOBAL_") == 0)
  2085. {
  2086. std::string name = i->first.substr(10);
  2087. if(name != "")
  2088. {
  2089. fout << "\t\t<Global\n"
  2090. << "\t\t\tName=\"" << name << "\"\n"
  2091. << "\t\t\tValue=\"" << i->second.GetValue() << "\"\n"
  2092. << "\t\t/>\n";
  2093. }
  2094. }
  2095. }
  2096. fout << "\t</Globals>\n"
  2097. << "</VisualStudioProject>\n";
  2098. }
  2099. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
  2100. {
  2101. std::string ret = s;
  2102. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2103. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2104. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2105. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2106. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  2107. return ret;
  2108. }
  2109. std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
  2110. {
  2111. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  2112. }
  2113. std::string cmLocalVisualStudio7Generator
  2114. ::ConvertToXMLOutputPath(const char* path)
  2115. {
  2116. std::string ret = this->ConvertToOutputFormat(path, SHELL);
  2117. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2118. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2119. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2120. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2121. return ret;
  2122. }
  2123. std::string cmLocalVisualStudio7Generator
  2124. ::ConvertToXMLOutputPathSingle(const char* path)
  2125. {
  2126. std::string ret = this->ConvertToOutputFormat(path, SHELL);
  2127. cmSystemTools::ReplaceString(ret, "\"", "");
  2128. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2129. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2130. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2131. return ret;
  2132. }
  2133. // This class is used to parse an existing vs 7 project
  2134. // and extract the GUID
  2135. class cmVS7XMLParser : public cmXMLParser
  2136. {
  2137. public:
  2138. virtual void EndElement(const std::string& /* name */)
  2139. {
  2140. }
  2141. virtual void StartElement(const std::string& name, const char** atts)
  2142. {
  2143. // once the GUID is found do nothing
  2144. if(this->GUID.size())
  2145. {
  2146. return;
  2147. }
  2148. int i =0;
  2149. if("VisualStudioProject" == name)
  2150. {
  2151. while(atts[i])
  2152. {
  2153. if(strcmp(atts[i], "ProjectGUID") == 0)
  2154. {
  2155. if(atts[i+1])
  2156. {
  2157. this->GUID = atts[i+1];
  2158. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  2159. }
  2160. else
  2161. {
  2162. this->GUID = "";
  2163. }
  2164. return;
  2165. }
  2166. ++i;
  2167. }
  2168. }
  2169. }
  2170. int InitializeParser()
  2171. {
  2172. int ret = cmXMLParser::InitializeParser();
  2173. if(ret == 0)
  2174. {
  2175. return ret;
  2176. }
  2177. // visual studio projects have a strange encoding, but it is
  2178. // really utf-8
  2179. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  2180. return 1;
  2181. }
  2182. std::string GUID;
  2183. };
  2184. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  2185. const std::string& name,
  2186. const char* path)
  2187. {
  2188. cmVS7XMLParser parser;
  2189. parser.ParseFile(path);
  2190. // if we can not find a GUID then we will generate one later
  2191. if(parser.GUID.size() == 0)
  2192. {
  2193. return;
  2194. }
  2195. std::string guidStoreName = name;
  2196. guidStoreName += "_GUID_CMAKE";
  2197. // save the GUID in the cache
  2198. this->GlobalGenerator->GetCMakeInstance()->
  2199. AddCacheEntry(guidStoreName.c_str(),
  2200. parser.GUID.c_str(),
  2201. "Stored GUID",
  2202. cmState::INTERNAL);
  2203. }
  2204. //----------------------------------------------------------------------------
  2205. std::string cmLocalVisualStudio7Generator
  2206. ::GetTargetDirectory(cmTarget const& target) const
  2207. {
  2208. std::string dir;
  2209. dir += target.GetName();
  2210. dir += ".dir";
  2211. return dir;
  2212. }
  2213. //----------------------------------------------------------------------------
  2214. #include <windows.h>
  2215. static bool cmLVS6G_IsFAT(const char* dir)
  2216. {
  2217. if(dir[0] && dir[1] == ':')
  2218. {
  2219. char volRoot[4] = "_:/";
  2220. volRoot[0] = dir[0];
  2221. char fsName[16];
  2222. if(GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2223. strstr(fsName, "FAT") != 0)
  2224. {
  2225. return true;
  2226. }
  2227. }
  2228. return false;
  2229. }