cmLocalVisualStudio7Generator.cxx 80 KB

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