cmLocalVisualStudio7Generator.cxx 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408
  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 cmLVS7G_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);
  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->GetType() < cmState::UTILITY)
  739. {
  740. std::string const& outDir =
  741. 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->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->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 (cmLVS7G_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. this->OutputDeploymentDebuggerTool(fout, configName, target);
  961. fout << "\t\t</Configuration>\n";
  962. }
  963. //----------------------------------------------------------------------------
  964. std::string
  965. cmLocalVisualStudio7Generator
  966. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
  967. const std::string& configName)
  968. {
  969. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  970. std::string extraLinkOptionsBuildTypeDef =
  971. rootLinkerFlags + "_" + configTypeUpper;
  972. std::string extraLinkOptionsBuildType =
  973. this->Makefile->GetRequiredDefinition
  974. (extraLinkOptionsBuildTypeDef.c_str());
  975. return extraLinkOptionsBuildType;
  976. }
  977. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  978. const std::string& configName, cmGeneratorTarget* target,
  979. const Options& targetOptions)
  980. {
  981. cmGlobalVisualStudio7Generator* gg =
  982. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  983. std::string temp;
  984. std::string extraLinkOptions;
  985. if(target->GetType() == cmState::EXECUTABLE)
  986. {
  987. extraLinkOptions =
  988. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  989. + std::string(" ")
  990. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  991. }
  992. if(target->GetType() == cmState::SHARED_LIBRARY)
  993. {
  994. extraLinkOptions =
  995. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  996. + std::string(" ")
  997. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  998. }
  999. if(target->GetType() == cmState::MODULE_LIBRARY)
  1000. {
  1001. extraLinkOptions =
  1002. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  1003. + std::string(" ")
  1004. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  1005. }
  1006. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  1007. if(targetLinkFlags)
  1008. {
  1009. extraLinkOptions += " ";
  1010. extraLinkOptions += targetLinkFlags;
  1011. }
  1012. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  1013. std::string linkFlagsConfig = "LINK_FLAGS_";
  1014. linkFlagsConfig += configTypeUpper;
  1015. targetLinkFlags = target->GetProperty(linkFlagsConfig.c_str());
  1016. if(targetLinkFlags)
  1017. {
  1018. extraLinkOptions += " ";
  1019. extraLinkOptions += targetLinkFlags;
  1020. }
  1021. Options linkOptions(this, Options::Linker);
  1022. if(this->FortranProject)
  1023. {
  1024. linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
  1025. }
  1026. linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
  1027. linkOptions.Parse(extraLinkOptions.c_str());
  1028. if(!this->ModuleDefinitionFile.empty())
  1029. {
  1030. std::string defFile =
  1031. this->ConvertToOutputFormat(this->ModuleDefinitionFile, SHELL);
  1032. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  1033. }
  1034. if (target->GetType() == cmState::SHARED_LIBRARY &&
  1035. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
  1036. {
  1037. if (target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
  1038. {
  1039. linkOptions.AddFlag("ModuleDefinitionFile", "$(IntDir)/exportall.def");
  1040. }
  1041. }
  1042. switch(target->GetType())
  1043. {
  1044. case cmState::UNKNOWN_LIBRARY:
  1045. break;
  1046. case cmState::OBJECT_LIBRARY:
  1047. {
  1048. std::string libpath = this->GetTargetDirectory(target);
  1049. libpath += "/";
  1050. libpath += configName;
  1051. libpath += "/";
  1052. libpath += target->GetName();
  1053. libpath += ".lib";
  1054. const char* tool =
  1055. this->FortranProject? "VFLibrarianTool":"VCLibrarianTool";
  1056. fout << "\t\t\t<Tool\n"
  1057. << "\t\t\t\tName=\"" << tool << "\"\n";
  1058. fout << "\t\t\t\tOutputFile=\""
  1059. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1060. break;
  1061. }
  1062. case cmState::STATIC_LIBRARY:
  1063. {
  1064. std::string targetNameFull = target->GetFullName(configName);
  1065. std::string libpath = target->GetDirectory(configName);
  1066. libpath += "/";
  1067. libpath += targetNameFull;
  1068. const char* tool = "VCLibrarianTool";
  1069. if(this->FortranProject)
  1070. {
  1071. tool = "VFLibrarianTool";
  1072. }
  1073. fout << "\t\t\t<Tool\n"
  1074. << "\t\t\t\tName=\"" << tool << "\"\n";
  1075. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1076. || this->FortranProject)
  1077. {
  1078. std::ostringstream libdeps;
  1079. this->Internal->OutputObjects(libdeps, target);
  1080. if(!libdeps.str().empty())
  1081. {
  1082. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str() << "\"\n";
  1083. }
  1084. }
  1085. std::string libflags;
  1086. this->GetStaticLibraryFlags(libflags, configTypeUpper, target);
  1087. if(!libflags.empty())
  1088. {
  1089. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  1090. }
  1091. fout << "\t\t\t\tOutputFile=\""
  1092. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1093. break;
  1094. }
  1095. case cmState::SHARED_LIBRARY:
  1096. case cmState::MODULE_LIBRARY:
  1097. {
  1098. std::string targetName;
  1099. std::string targetNameSO;
  1100. std::string targetNameFull;
  1101. std::string targetNameImport;
  1102. std::string targetNamePDB;
  1103. target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1104. targetNameImport, targetNamePDB, configName);
  1105. // Compute the link library and directory information.
  1106. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
  1107. if(!pcli)
  1108. {
  1109. return;
  1110. }
  1111. cmComputeLinkInformation& cli = *pcli;
  1112. std::string linkLanguage = cli.GetLinkLanguage();
  1113. // Compute the variable name to lookup standard libraries for this
  1114. // language.
  1115. std::string standardLibsVar = "CMAKE_";
  1116. standardLibsVar += linkLanguage;
  1117. standardLibsVar += "_STANDARD_LIBRARIES";
  1118. const char* tool = "VCLinkerTool";
  1119. if(this->FortranProject)
  1120. {
  1121. tool = "VFLinkerTool";
  1122. }
  1123. fout << "\t\t\t<Tool\n"
  1124. << "\t\t\t\tName=\"" << tool << "\"\n";
  1125. if(!gg->NeedLinkLibraryDependencies(target))
  1126. {
  1127. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1128. }
  1129. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1130. // Use the NOINHERIT macro to avoid getting VS project default
  1131. // libraries which may be set by the user to something bad.
  1132. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1133. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1134. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1135. || this->FortranProject)
  1136. {
  1137. this->Internal->OutputObjects(fout, target, " ");
  1138. }
  1139. fout << " ";
  1140. this->Internal->OutputLibraries(fout, cli.GetItems());
  1141. fout << "\"\n";
  1142. temp = target->GetDirectory(configName);
  1143. temp += "/";
  1144. temp += targetNameFull;
  1145. fout << "\t\t\t\tOutputFile=\""
  1146. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1147. this->WriteTargetVersionAttribute(fout, target);
  1148. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1149. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1150. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1151. fout << "\"\n";
  1152. temp = target->GetPDBDirectory(configName);
  1153. temp += "/";
  1154. temp += targetNamePDB;
  1155. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  1156. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1157. if(targetOptions.IsDebug())
  1158. {
  1159. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1160. }
  1161. if(this->WindowsCEProject)
  1162. {
  1163. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS9)
  1164. {
  1165. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1166. }
  1167. else
  1168. {
  1169. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1170. }
  1171. }
  1172. std::string stackVar = "CMAKE_";
  1173. stackVar += linkLanguage;
  1174. stackVar += "_STACK_SIZE";
  1175. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1176. if(stackVal)
  1177. {
  1178. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1179. }
  1180. temp = target->GetDirectory(configName, true);
  1181. temp += "/";
  1182. temp += targetNameImport;
  1183. fout << "\t\t\t\tImportLibrary=\""
  1184. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1185. if(this->FortranProject)
  1186. {
  1187. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1188. }
  1189. fout << "/>\n";
  1190. }
  1191. break;
  1192. case cmState::EXECUTABLE:
  1193. {
  1194. std::string targetName;
  1195. std::string targetNameFull;
  1196. std::string targetNameImport;
  1197. std::string targetNamePDB;
  1198. target->GetExecutableNames(targetName, targetNameFull,
  1199. targetNameImport, targetNamePDB, configName);
  1200. // Compute the link library and directory information.
  1201. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
  1202. if(!pcli)
  1203. {
  1204. return;
  1205. }
  1206. cmComputeLinkInformation& cli = *pcli;
  1207. std::string linkLanguage = cli.GetLinkLanguage();
  1208. bool isWin32Executable = target->GetPropertyAsBool("WIN32_EXECUTABLE");
  1209. // Compute the variable name to lookup standard libraries for this
  1210. // language.
  1211. std::string standardLibsVar = "CMAKE_";
  1212. standardLibsVar += linkLanguage;
  1213. standardLibsVar += "_STANDARD_LIBRARIES";
  1214. const char* tool = "VCLinkerTool";
  1215. if(this->FortranProject)
  1216. {
  1217. tool = "VFLinkerTool";
  1218. }
  1219. fout << "\t\t\t<Tool\n"
  1220. << "\t\t\t\tName=\"" << tool << "\"\n";
  1221. if(!gg->NeedLinkLibraryDependencies(target))
  1222. {
  1223. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1224. }
  1225. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1226. // Use the NOINHERIT macro to avoid getting VS project default
  1227. // libraries which may be set by the user to something bad.
  1228. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1229. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1230. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS8
  1231. || this->FortranProject)
  1232. {
  1233. this->Internal->OutputObjects(fout, target, " ");
  1234. }
  1235. fout << " ";
  1236. this->Internal->OutputLibraries(fout, cli.GetItems());
  1237. fout << "\"\n";
  1238. temp = target->GetDirectory(configName);
  1239. temp += "/";
  1240. temp += targetNameFull;
  1241. fout << "\t\t\t\tOutputFile=\""
  1242. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1243. this->WriteTargetVersionAttribute(fout, target);
  1244. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1245. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1246. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1247. fout << "\"\n";
  1248. std::string path = this->ConvertToXMLOutputPathSingle(
  1249. target->GetPDBDirectory(configName).c_str());
  1250. fout << "\t\t\t\tProgramDatabaseFile=\""
  1251. << path << "/" << targetNamePDB
  1252. << "\"\n";
  1253. if(targetOptions.IsDebug())
  1254. {
  1255. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1256. }
  1257. if ( this->WindowsCEProject )
  1258. {
  1259. if(this->GetVersion() < cmGlobalVisualStudioGenerator::VS9)
  1260. {
  1261. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1262. }
  1263. else
  1264. {
  1265. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1266. }
  1267. if(!linkOptions.GetFlag("EntryPointSymbol"))
  1268. {
  1269. const char* entryPointSymbol = targetOptions.UsingUnicode() ?
  1270. (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup") :
  1271. (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1272. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1273. }
  1274. }
  1275. else if ( this->FortranProject )
  1276. {
  1277. fout << "\t\t\t\tSubSystem=\""
  1278. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1279. << "\"\n";
  1280. }
  1281. else
  1282. {
  1283. fout << "\t\t\t\tSubSystem=\""
  1284. << (isWin32Executable ? "2" : "1")
  1285. << "\"\n";
  1286. }
  1287. std::string stackVar = "CMAKE_";
  1288. stackVar += linkLanguage;
  1289. stackVar += "_STACK_SIZE";
  1290. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1291. if(stackVal)
  1292. {
  1293. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1294. }
  1295. temp = target->GetDirectory(configName, true);
  1296. temp += "/";
  1297. temp += targetNameImport;
  1298. fout << "\t\t\t\tImportLibrary=\""
  1299. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1300. break;
  1301. }
  1302. case cmState::UTILITY:
  1303. case cmState::GLOBAL_TARGET:
  1304. case cmState::INTERFACE_LIBRARY:
  1305. break;
  1306. }
  1307. }
  1308. void cmLocalVisualStudio7Generator::OutputDeploymentDebuggerTool(
  1309. std::ostream& fout, std::string const& config, cmGeneratorTarget* target)
  1310. {
  1311. if (this->WindowsCEProject)
  1312. {
  1313. if (const char* dir = target->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY"))
  1314. {
  1315. fout <<
  1316. "\t\t\t<DeploymentTool\n"
  1317. "\t\t\t\tForceDirty=\"-1\"\n"
  1318. "\t\t\t\tRemoteDirectory=\"" << this->EscapeForXML(dir) << "\"\n"
  1319. "\t\t\t\tRegisterOutput=\"0\"\n"
  1320. "\t\t\t\tAdditionalFiles=\"\"/>\n"
  1321. ;
  1322. std::string const exe = dir + std::string("\\") + target->GetFullName();
  1323. fout <<
  1324. "\t\t\t<DebuggerTool\n"
  1325. "\t\t\t\tRemoteExecutable=\"" << this->EscapeForXML(exe) << "\"\n"
  1326. "\t\t\t\tArguments=\"\"\n"
  1327. "\t\t\t/>\n"
  1328. ;
  1329. }
  1330. }
  1331. }
  1332. //----------------------------------------------------------------------------
  1333. void
  1334. cmLocalVisualStudio7Generator
  1335. ::WriteTargetVersionAttribute(std::ostream& fout, cmGeneratorTarget* gt)
  1336. {
  1337. int major;
  1338. int minor;
  1339. gt->GetTargetVersion(major, minor);
  1340. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1341. }
  1342. //----------------------------------------------------------------------------
  1343. void
  1344. cmLocalVisualStudio7GeneratorInternals
  1345. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1346. {
  1347. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1348. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1349. {
  1350. if(l->IsPath)
  1351. {
  1352. std::string rel = lg->Convert(l->Value.c_str(),
  1353. cmLocalGenerator::START_OUTPUT,
  1354. cmLocalGenerator::UNCHANGED);
  1355. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1356. }
  1357. else if (!l->Target
  1358. || l->Target->GetType() != cmState::INTERFACE_LIBRARY)
  1359. {
  1360. fout << l->Value << " ";
  1361. }
  1362. }
  1363. }
  1364. //----------------------------------------------------------------------------
  1365. void
  1366. cmLocalVisualStudio7GeneratorInternals
  1367. ::OutputObjects(std::ostream& fout, cmGeneratorTarget* gt, const char* isep)
  1368. {
  1369. // VS < 8 does not support per-config source locations so we
  1370. // list object library content on the link line instead.
  1371. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1372. std::vector<std::string> objs;
  1373. gt->UseObjectLibraries(objs, "");
  1374. const char* sep = isep? isep : "";
  1375. for(std::vector<std::string>::const_iterator
  1376. oi = objs.begin(); oi != objs.end(); ++oi)
  1377. {
  1378. std::string rel = lg->Convert(oi->c_str(),
  1379. cmLocalGenerator::START_OUTPUT,
  1380. cmLocalGenerator::UNCHANGED);
  1381. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1382. sep = " ";
  1383. }
  1384. }
  1385. //----------------------------------------------------------------------------
  1386. void
  1387. cmLocalVisualStudio7Generator
  1388. ::OutputLibraryDirectories(std::ostream& fout,
  1389. std::vector<std::string> const& dirs)
  1390. {
  1391. const char* comma = "";
  1392. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1393. d != dirs.end(); ++d)
  1394. {
  1395. // Remove any trailing slash and skip empty paths.
  1396. std::string dir = *d;
  1397. if(dir[dir.size()-1] == '/')
  1398. {
  1399. dir = dir.substr(0, dir.size()-1);
  1400. }
  1401. if(dir.empty())
  1402. {
  1403. continue;
  1404. }
  1405. // Switch to a relative path specification if it is shorter.
  1406. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1407. {
  1408. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1409. if(rel.size() < dir.size())
  1410. {
  1411. dir = rel;
  1412. }
  1413. }
  1414. // First search a configuration-specific subdirectory and then the
  1415. // original directory.
  1416. fout << comma
  1417. << this->ConvertToXMLOutputPath((dir+"/$(ConfigurationName)").c_str())
  1418. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1419. comma = ",";
  1420. }
  1421. }
  1422. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1423. const std::string& libName,
  1424. cmGeneratorTarget* target)
  1425. {
  1426. std::vector<std::string> configs;
  1427. this->Makefile->GetConfigurations(configs);
  1428. // We may be modifying the source groups temporarily, so make a copy.
  1429. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1430. // get the classes from the source lists then add them to the groups
  1431. this->ModuleDefinitionFile = "";
  1432. std::vector<cmSourceFile*> classes;
  1433. if (!target->GetConfigCommonSourceFiles(classes))
  1434. {
  1435. return;
  1436. }
  1437. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1438. i != classes.end(); i++)
  1439. {
  1440. if (!(*i)->GetObjectLibrary().empty())
  1441. {
  1442. continue;
  1443. }
  1444. // Add the file to the list of sources.
  1445. std::string source = (*i)->GetFullPath();
  1446. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1447. {
  1448. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1449. }
  1450. cmSourceGroup* sourceGroup =
  1451. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1452. sourceGroup->AssignSource(*i);
  1453. }
  1454. // open the project
  1455. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1456. // write the configuration information
  1457. this->WriteConfigurations(fout, configs, libName, target);
  1458. fout << "\t<Files>\n";
  1459. // Loop through every source group.
  1460. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1461. {
  1462. cmSourceGroup sg = sourceGroups[i];
  1463. this->WriteGroup(&sg, target, fout, libName, configs);
  1464. }
  1465. if(this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8
  1466. && !this->FortranProject)
  1467. {
  1468. // VS >= 8 support per-config source locations so we
  1469. // list object library content as external objects.
  1470. std::vector<std::string> objs;
  1471. target->UseObjectLibraries(objs, "");
  1472. if(!objs.empty())
  1473. {
  1474. // TODO: Separate sub-filter for each object library used?
  1475. fout << "\t\t<Filter Name=\"Object Libraries\">\n";
  1476. for(std::vector<std::string>::const_iterator
  1477. oi = objs.begin(); oi != objs.end(); ++oi)
  1478. {
  1479. std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str());
  1480. fout << "\t\t\t<File RelativePath=\"" << o << "\" />\n";
  1481. }
  1482. fout << "\t\t</Filter>\n";
  1483. }
  1484. }
  1485. fout << "\t</Files>\n";
  1486. // Write the VCProj file's footer.
  1487. this->WriteVCProjFooter(fout, target);
  1488. }
  1489. struct cmLVS7GFileConfig
  1490. {
  1491. std::string ObjectName;
  1492. std::string CompileFlags;
  1493. std::string CompileDefs;
  1494. std::string CompileDefsConfig;
  1495. std::string AdditionalDeps;
  1496. bool ExcludedFromBuild;
  1497. };
  1498. class cmLocalVisualStudio7GeneratorFCInfo
  1499. {
  1500. public:
  1501. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1502. cmGeneratorTarget* target,
  1503. cmSourceFile const& sf,
  1504. std::vector<std::string> const& configs);
  1505. std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
  1506. };
  1507. cmLocalVisualStudio7GeneratorFCInfo
  1508. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1509. cmGeneratorTarget* gt,
  1510. cmSourceFile const& sf,
  1511. std::vector<std::string> const& configs)
  1512. {
  1513. std::string objectName;
  1514. if(gt->HasExplicitObjectName(&sf))
  1515. {
  1516. objectName = gt->GetObjectName(&sf);
  1517. }
  1518. // Compute per-source, per-config information.
  1519. for(std::vector<std::string>::const_iterator i = configs.begin();
  1520. i != configs.end(); ++i)
  1521. {
  1522. std::string configUpper = cmSystemTools::UpperCase(*i);
  1523. cmLVS7GFileConfig fc;
  1524. bool needfc = false;
  1525. if(!objectName.empty())
  1526. {
  1527. fc.ObjectName = objectName;
  1528. needfc = true;
  1529. }
  1530. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1531. {
  1532. fc.CompileFlags = cflags;
  1533. needfc = true;
  1534. }
  1535. if(lg->FortranProject)
  1536. {
  1537. switch(lg->GetFortranFormat(sf.GetProperty("Fortran_FORMAT")))
  1538. {
  1539. case cmLocalGenerator::FortranFormatFixed:
  1540. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1541. needfc = true;
  1542. break;
  1543. case cmLocalGenerator::FortranFormatFree:
  1544. fc.CompileFlags = "-free " + fc.CompileFlags;
  1545. needfc = true;
  1546. break;
  1547. default: break;
  1548. }
  1549. }
  1550. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1551. {
  1552. fc.CompileDefs = cdefs;
  1553. needfc = true;
  1554. }
  1555. std::string defPropName = "COMPILE_DEFINITIONS_";
  1556. defPropName += configUpper;
  1557. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1558. {
  1559. fc.CompileDefsConfig = ccdefs;
  1560. needfc = true;
  1561. }
  1562. // Check for extra object-file dependencies.
  1563. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1564. {
  1565. std::vector<std::string> depends;
  1566. cmSystemTools::ExpandListArgument(deps, depends);
  1567. const char* sep = "";
  1568. for(std::vector<std::string>::iterator j = depends.begin();
  1569. j != depends.end(); ++j)
  1570. {
  1571. fc.AdditionalDeps += sep;
  1572. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1573. sep = ";";
  1574. needfc = true;
  1575. }
  1576. }
  1577. std::string lang =
  1578. lg->GlobalGenerator->GetLanguageFromExtension
  1579. (sf.GetExtension().c_str());
  1580. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1581. const std::string& linkLanguage = gt->GetLinkerLanguage(i->c_str());
  1582. bool needForceLang = false;
  1583. // source file does not match its extension language
  1584. if(lang != sourceLang)
  1585. {
  1586. needForceLang = true;
  1587. lang = sourceLang;
  1588. }
  1589. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1590. // the project file
  1591. fc.ExcludedFromBuild =
  1592. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1593. if(fc.ExcludedFromBuild)
  1594. {
  1595. needfc = true;
  1596. }
  1597. // if the source file does not match the linker language
  1598. // then force c or c++
  1599. if(needForceLang || (linkLanguage != lang))
  1600. {
  1601. if(lang == "CXX")
  1602. {
  1603. // force a C++ file type
  1604. fc.CompileFlags += " /TP ";
  1605. needfc = true;
  1606. }
  1607. else if(lang == "C")
  1608. {
  1609. // force to c
  1610. fc.CompileFlags += " /TC ";
  1611. needfc = true;
  1612. }
  1613. }
  1614. if(needfc)
  1615. {
  1616. this->FileConfigMap[*i] = fc;
  1617. }
  1618. }
  1619. }
  1620. //----------------------------------------------------------------------------
  1621. std::string
  1622. cmLocalVisualStudio7Generator
  1623. ::ComputeLongestObjectDirectory(cmGeneratorTarget const* target) const
  1624. {
  1625. std::vector<std::string> configs;
  1626. target->Target->GetMakefile()->GetConfigurations(configs);
  1627. // Compute the maximum length configuration name.
  1628. std::string config_max;
  1629. for(std::vector<std::string>::iterator i = configs.begin();
  1630. i != configs.end(); ++i)
  1631. {
  1632. if(i->size() > config_max.size())
  1633. {
  1634. config_max = *i;
  1635. }
  1636. }
  1637. // Compute the maximum length full path to the intermediate
  1638. // files directory for any configuration. This is used to construct
  1639. // object file names that do not produce paths that are too long.
  1640. std::string dir_max;
  1641. dir_max += this->GetCurrentBinaryDirectory();
  1642. dir_max += "/";
  1643. dir_max += this->GetTargetDirectory(target);
  1644. dir_max += "/";
  1645. dir_max += config_max;
  1646. dir_max += "/";
  1647. return dir_max;
  1648. }
  1649. bool cmLocalVisualStudio7Generator
  1650. ::WriteGroup(const cmSourceGroup *sg, cmGeneratorTarget* target,
  1651. std::ostream &fout, const std::string& libName,
  1652. std::vector<std::string> const& configs)
  1653. {
  1654. cmGlobalVisualStudio7Generator* gg =
  1655. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1656. const std::vector<const cmSourceFile *> &sourceFiles =
  1657. sg->GetSourceFiles();
  1658. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1659. // Write the children to temporary output.
  1660. bool hasChildrenWithSources = false;
  1661. std::ostringstream tmpOut;
  1662. for(unsigned int i=0;i<children.size();++i)
  1663. {
  1664. if(this->WriteGroup(&children[i], target, tmpOut, libName, configs))
  1665. {
  1666. hasChildrenWithSources = true;
  1667. }
  1668. }
  1669. // If the group is empty, don't write it at all.
  1670. if(sourceFiles.empty() && !hasChildrenWithSources)
  1671. {
  1672. return false;
  1673. }
  1674. // If the group has a name, write the header.
  1675. std::string name = sg->GetName();
  1676. if(name != "")
  1677. {
  1678. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1679. }
  1680. // Loop through each source in the source group.
  1681. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1682. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1683. {
  1684. std::string source = (*sf)->GetFullPath();
  1685. FCInfo fcinfo(this, target, *(*sf), configs);
  1686. if (source != libName || target->GetType() == cmState::UTILITY ||
  1687. target->GetType() == cmState::GLOBAL_TARGET )
  1688. {
  1689. fout << "\t\t\t<File\n";
  1690. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1691. // Tell MS-Dev what the source is. If the compiler knows how to
  1692. // build it, then it will.
  1693. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1694. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1695. {
  1696. this->WriteCustomRule(fout, configs, source.c_str(),
  1697. *command, fcinfo);
  1698. }
  1699. else if(!fcinfo.FileConfigMap.empty())
  1700. {
  1701. const char* aCompilerTool = "VCCLCompilerTool";
  1702. const char* ppLang = "CXX";
  1703. if(this->FortranProject)
  1704. {
  1705. aCompilerTool = "VFFortranCompilerTool";
  1706. }
  1707. std::string const& lang = (*sf)->GetLanguage();
  1708. std::string ext = (*sf)->GetExtension();
  1709. ext = cmSystemTools::LowerCase(ext);
  1710. if(ext == "idl")
  1711. {
  1712. aCompilerTool = "VCMIDLTool";
  1713. if(this->FortranProject)
  1714. {
  1715. aCompilerTool = "VFMIDLTool";
  1716. }
  1717. }
  1718. if(ext == "rc")
  1719. {
  1720. aCompilerTool = "VCResourceCompilerTool";
  1721. ppLang = "RC";
  1722. if(this->FortranProject)
  1723. {
  1724. aCompilerTool = "VFResourceCompilerTool";
  1725. }
  1726. }
  1727. if(ext == "def")
  1728. {
  1729. aCompilerTool = "VCCustomBuildTool";
  1730. if(this->FortranProject)
  1731. {
  1732. aCompilerTool = "VFCustomBuildTool";
  1733. }
  1734. }
  1735. if (gg->IsMasmEnabled() && !this->FortranProject &&
  1736. lang == "ASM_MASM")
  1737. {
  1738. aCompilerTool = "MASM";
  1739. }
  1740. for(std::map<std::string, cmLVS7GFileConfig>::const_iterator
  1741. fci = fcinfo.FileConfigMap.begin();
  1742. fci != fcinfo.FileConfigMap.end(); ++fci)
  1743. {
  1744. cmLVS7GFileConfig const& fc = fci->second;
  1745. fout << "\t\t\t\t<FileConfiguration\n"
  1746. << "\t\t\t\t\tName=\"" << fci->first
  1747. << "|" << gg->GetPlatformName() << "\"";
  1748. if(fc.ExcludedFromBuild)
  1749. {
  1750. fout << " ExcludedFromBuild=\"true\"";
  1751. }
  1752. fout << ">\n";
  1753. fout << "\t\t\t\t\t<Tool\n"
  1754. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1755. if(!fc.CompileFlags.empty() ||
  1756. !fc.CompileDefs.empty() ||
  1757. !fc.CompileDefsConfig.empty())
  1758. {
  1759. Options::Tool tool = Options::Compiler;
  1760. cmVS7FlagTable const* table =
  1761. cmLocalVisualStudio7GeneratorFlagTable;
  1762. if(this->FortranProject)
  1763. {
  1764. tool = Options::FortranCompiler;
  1765. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1766. }
  1767. Options fileOptions(this, tool, table,
  1768. gg->ExtraFlagTable);
  1769. fileOptions.Parse(fc.CompileFlags.c_str());
  1770. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1771. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1772. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1773. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1774. fileOptions.OutputPreprocessorDefinitions(fout,
  1775. "\t\t\t\t\t", "\n",
  1776. ppLang);
  1777. }
  1778. if(!fc.AdditionalDeps.empty())
  1779. {
  1780. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1781. << fc.AdditionalDeps.c_str() << "\"\n";
  1782. }
  1783. if(!fc.ObjectName.empty())
  1784. {
  1785. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1786. << fc.ObjectName.c_str() << "\"\n";
  1787. }
  1788. fout << "\t\t\t\t\t/>\n"
  1789. << "\t\t\t\t</FileConfiguration>\n";
  1790. }
  1791. }
  1792. fout << "\t\t\t</File>\n";
  1793. }
  1794. }
  1795. // If the group has children with source files, write the children.
  1796. if(hasChildrenWithSources)
  1797. {
  1798. fout << tmpOut.str();
  1799. }
  1800. // If the group has a name, write the footer.
  1801. if(name != "")
  1802. {
  1803. this->WriteVCProjEndGroup(fout);
  1804. }
  1805. return true;
  1806. }
  1807. void cmLocalVisualStudio7Generator::
  1808. WriteCustomRule(std::ostream& fout,
  1809. std::vector<std::string> const& configs,
  1810. const char* source,
  1811. const cmCustomCommand& command,
  1812. FCInfo& fcinfo)
  1813. {
  1814. cmGlobalVisualStudio7Generator* gg =
  1815. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1816. // Write the rule for each configuration.
  1817. const char* compileTool = "VCCLCompilerTool";
  1818. if(this->FortranProject)
  1819. {
  1820. compileTool = "VFCLCompilerTool";
  1821. }
  1822. const char* customTool = "VCCustomBuildTool";
  1823. if(this->FortranProject)
  1824. {
  1825. customTool = "VFCustomBuildTool";
  1826. }
  1827. for (std::vector<std::string>::const_iterator i = configs.begin();
  1828. i != configs.end(); ++i)
  1829. {
  1830. cmCustomCommandGenerator ccg(command, *i, this);
  1831. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1832. fout << "\t\t\t\t<FileConfiguration\n";
  1833. fout << "\t\t\t\t\tName=\"" << *i << "|"
  1834. << gg->GetPlatformName() << "\">\n";
  1835. if(!fc.CompileFlags.empty())
  1836. {
  1837. fout << "\t\t\t\t\t<Tool\n"
  1838. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1839. << "\t\t\t\t\tAdditionalOptions=\""
  1840. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1841. }
  1842. std::string comment = this->ConstructComment(ccg);
  1843. std::string script = this->ConstructScript(ccg);
  1844. if(this->FortranProject)
  1845. {
  1846. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1847. }
  1848. fout << "\t\t\t\t\t<Tool\n"
  1849. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1850. << "\t\t\t\t\tDescription=\""
  1851. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1852. << "\t\t\t\t\tCommandLine=\""
  1853. << this->EscapeForXML(script.c_str()) << "\"\n"
  1854. << "\t\t\t\t\tAdditionalDependencies=\"";
  1855. if(ccg.GetDepends().empty())
  1856. {
  1857. // There are no real dependencies. Produce an artificial one to
  1858. // make sure the rule runs reliably.
  1859. if(!cmSystemTools::FileExists(source))
  1860. {
  1861. cmsys::ofstream depout(source);
  1862. depout << "Artificial dependency for a custom command.\n";
  1863. }
  1864. fout << this->ConvertToXMLOutputPath(source);
  1865. }
  1866. else
  1867. {
  1868. // Write out the dependencies for the rule.
  1869. for(std::vector<std::string>::const_iterator d =
  1870. ccg.GetDepends().begin();
  1871. d != ccg.GetDepends().end();
  1872. ++d)
  1873. {
  1874. // Get the real name of the dependency in case it is a CMake target.
  1875. std::string dep;
  1876. if(this->GetRealDependency(d->c_str(), i->c_str(), dep))
  1877. {
  1878. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1879. << ";";
  1880. }
  1881. }
  1882. }
  1883. fout << "\"\n";
  1884. fout << "\t\t\t\t\tOutputs=\"";
  1885. if(ccg.GetOutputs().empty())
  1886. {
  1887. fout << source << "_force";
  1888. }
  1889. else
  1890. {
  1891. // Write a rule for the output generated by this command.
  1892. const char* sep = "";
  1893. for(std::vector<std::string>::const_iterator o =
  1894. ccg.GetOutputs().begin();
  1895. o != ccg.GetOutputs().end();
  1896. ++o)
  1897. {
  1898. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1899. sep = ";";
  1900. }
  1901. }
  1902. fout << "\"/>\n";
  1903. fout << "\t\t\t\t</FileConfiguration>\n";
  1904. }
  1905. }
  1906. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1907. const char* group,
  1908. const char* )
  1909. {
  1910. fout << "\t\t<Filter\n"
  1911. << "\t\t\tName=\"" << group << "\"\n"
  1912. << "\t\t\tFilter=\"\">\n";
  1913. }
  1914. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1915. {
  1916. fout << "\t\t</Filter>\n";
  1917. }
  1918. // look for custom rules on a target and collect them together
  1919. void cmLocalVisualStudio7Generator
  1920. ::OutputTargetRules(std::ostream& fout,
  1921. const std::string& configName,
  1922. cmGeneratorTarget *target,
  1923. const std::string& /*libName*/)
  1924. {
  1925. if (target->GetType() > cmState::GLOBAL_TARGET)
  1926. {
  1927. return;
  1928. }
  1929. EventWriter event(this, configName, fout);
  1930. // Add pre-build event.
  1931. const char* tool =
  1932. this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
  1933. event.Start(tool);
  1934. event.Write(target->GetPreBuildCommands());
  1935. event.Finish();
  1936. // Add pre-link event.
  1937. tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
  1938. event.Start(tool);
  1939. bool addedPrelink = false;
  1940. if (target->GetType() == cmState::SHARED_LIBRARY &&
  1941. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
  1942. {
  1943. if (target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
  1944. {
  1945. addedPrelink = true;
  1946. std::vector<cmCustomCommand> commands =
  1947. target->GetPreLinkCommands();
  1948. cmGlobalVisualStudioGenerator* gg
  1949. = static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  1950. gg->AddSymbolExportCommand(
  1951. target, commands, configName);
  1952. event.Write(commands);
  1953. }
  1954. }
  1955. if (!addedPrelink)
  1956. {
  1957. event.Write(target->GetPreLinkCommands());
  1958. }
  1959. cmsys::auto_ptr<cmCustomCommand> pcc(
  1960. this->MaybeCreateImplibDir(target,
  1961. configName, this->FortranProject));
  1962. if(pcc.get())
  1963. {
  1964. event.Write(*pcc);
  1965. }
  1966. event.Finish();
  1967. // Add post-build event.
  1968. tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
  1969. event.Start(tool);
  1970. event.Write(target->GetPostBuildCommands());
  1971. event.Finish();
  1972. }
  1973. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1974. cmGeneratorTarget* target)
  1975. {
  1976. // if we have all the required Source code control tags
  1977. // then add that to the project
  1978. const char* vsProjectname = target->GetProperty("VS_SCC_PROJECTNAME");
  1979. const char* vsLocalpath = target->GetProperty("VS_SCC_LOCALPATH");
  1980. const char* vsProvider = target->GetProperty("VS_SCC_PROVIDER");
  1981. if(vsProvider && vsLocalpath && vsProjectname)
  1982. {
  1983. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1984. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1985. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1986. const char* vsAuxPath = target->GetProperty("VS_SCC_AUXPATH");
  1987. if(vsAuxPath)
  1988. {
  1989. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1990. }
  1991. }
  1992. }
  1993. void
  1994. cmLocalVisualStudio7Generator
  1995. ::WriteProjectStartFortran(std::ostream& fout,
  1996. const std::string& libName,
  1997. cmGeneratorTarget *target)
  1998. {
  1999. cmGlobalVisualStudio7Generator* gg =
  2000. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  2001. fout << "<?xml version=\"1.0\" encoding = \""
  2002. << gg->Encoding() << "\"?>\n"
  2003. << "<VisualStudioProject\n"
  2004. << "\tProjectCreator=\"Intel Fortran\"\n"
  2005. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  2006. const char* keyword = target->GetProperty("VS_KEYWORD");
  2007. if(!keyword)
  2008. {
  2009. keyword = "Console Application";
  2010. }
  2011. const char* projectType = 0;
  2012. switch(target->GetType())
  2013. {
  2014. case cmState::STATIC_LIBRARY:
  2015. projectType = "typeStaticLibrary";
  2016. if(keyword)
  2017. {
  2018. keyword = "Static Library";
  2019. }
  2020. break;
  2021. case cmState::SHARED_LIBRARY:
  2022. case cmState::MODULE_LIBRARY:
  2023. projectType = "typeDynamicLibrary";
  2024. if(!keyword)
  2025. {
  2026. keyword = "Dll";
  2027. }
  2028. break;
  2029. case cmState::EXECUTABLE:
  2030. if(!keyword)
  2031. {
  2032. keyword = "Console Application";
  2033. }
  2034. projectType = 0;
  2035. break;
  2036. case cmState::UTILITY:
  2037. case cmState::GLOBAL_TARGET:
  2038. default:
  2039. break;
  2040. }
  2041. if(projectType)
  2042. {
  2043. fout << "\tProjectType=\"" << projectType << "\"\n";
  2044. }
  2045. this->WriteProjectSCC(fout, target);
  2046. fout<< "\tKeyword=\"" << keyword << "\">\n"
  2047. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  2048. << "\t<Platforms>\n"
  2049. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  2050. << "\t</Platforms>\n";
  2051. }
  2052. void
  2053. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  2054. const std::string& libName,
  2055. cmGeneratorTarget *target,
  2056. std::vector<cmSourceGroup> &)
  2057. {
  2058. if(this->FortranProject)
  2059. {
  2060. this->WriteProjectStartFortran(fout, libName, target);
  2061. return;
  2062. }
  2063. cmGlobalVisualStudio7Generator* gg =
  2064. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  2065. fout << "<?xml version=\"1.0\" encoding = \""
  2066. << gg->Encoding() << "\"?>\n"
  2067. << "<VisualStudioProject\n"
  2068. << "\tProjectType=\"Visual C++\"\n";
  2069. if(gg->GetVersion() == cmGlobalVisualStudioGenerator::VS71)
  2070. {
  2071. fout << "\tVersion=\"7.10\"\n";
  2072. }
  2073. else
  2074. {
  2075. fout << "\tVersion=\"" << (gg->GetVersion()/10) << ".00\"\n";
  2076. }
  2077. const char* projLabel = target->GetProperty("PROJECT_LABEL");
  2078. if(!projLabel)
  2079. {
  2080. projLabel = libName.c_str();
  2081. }
  2082. const char* keyword = target->GetProperty("VS_KEYWORD");
  2083. if(!keyword)
  2084. {
  2085. keyword = "Win32Proj";
  2086. }
  2087. fout << "\tName=\"" << projLabel << "\"\n";
  2088. if(gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS8)
  2089. {
  2090. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  2091. }
  2092. this->WriteProjectSCC(fout, target);
  2093. if(const char* targetFrameworkVersion =
  2094. target->GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
  2095. {
  2096. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  2097. }
  2098. fout << "\tKeyword=\"" << keyword << "\">\n"
  2099. << "\t<Platforms>\n"
  2100. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  2101. << "\t</Platforms>\n";
  2102. if(gg->IsMasmEnabled())
  2103. {
  2104. fout <<
  2105. "\t<ToolFiles>\n"
  2106. "\t\t<DefaultToolFile\n"
  2107. "\t\t\tFileName=\"masm.rules\"\n"
  2108. "\t\t/>\n"
  2109. "\t</ToolFiles>\n"
  2110. ;
  2111. }
  2112. }
  2113. void cmLocalVisualStudio7Generator::WriteVCProjFooter(
  2114. std::ostream& fout,
  2115. cmGeneratorTarget *target)
  2116. {
  2117. fout << "\t<Globals>\n";
  2118. std::vector<std::string> const& props = target->GetPropertyKeys();
  2119. for(std::vector<std::string>::const_iterator i = props.begin();
  2120. i != props.end(); ++i)
  2121. {
  2122. if(i->find("VS_GLOBAL_") == 0)
  2123. {
  2124. std::string name = i->substr(10);
  2125. if(name != "")
  2126. {
  2127. fout << "\t\t<Global\n"
  2128. << "\t\t\tName=\"" << name << "\"\n"
  2129. << "\t\t\tValue=\"" << target->GetProperty(*i) << "\"\n"
  2130. << "\t\t/>\n";
  2131. }
  2132. }
  2133. }
  2134. fout << "\t</Globals>\n"
  2135. << "</VisualStudioProject>\n";
  2136. }
  2137. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
  2138. {
  2139. std::string ret = s;
  2140. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2141. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2142. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2143. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2144. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  2145. return ret;
  2146. }
  2147. std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
  2148. {
  2149. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  2150. }
  2151. std::string cmLocalVisualStudio7Generator
  2152. ::ConvertToXMLOutputPath(const char* path)
  2153. {
  2154. std::string ret = this->ConvertToOutputFormat(path, SHELL);
  2155. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2156. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2157. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2158. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2159. return ret;
  2160. }
  2161. std::string cmLocalVisualStudio7Generator
  2162. ::ConvertToXMLOutputPathSingle(const char* path)
  2163. {
  2164. std::string ret = this->ConvertToOutputFormat(path, SHELL);
  2165. cmSystemTools::ReplaceString(ret, "\"", "");
  2166. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2167. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2168. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2169. return ret;
  2170. }
  2171. // This class is used to parse an existing vs 7 project
  2172. // and extract the GUID
  2173. class cmVS7XMLParser : public cmXMLParser
  2174. {
  2175. public:
  2176. virtual void EndElement(const std::string& /* name */)
  2177. {
  2178. }
  2179. virtual void StartElement(const std::string& name, const char** atts)
  2180. {
  2181. // once the GUID is found do nothing
  2182. if(!this->GUID.empty())
  2183. {
  2184. return;
  2185. }
  2186. int i =0;
  2187. if("VisualStudioProject" == name)
  2188. {
  2189. while(atts[i])
  2190. {
  2191. if(strcmp(atts[i], "ProjectGUID") == 0)
  2192. {
  2193. if(atts[i+1])
  2194. {
  2195. this->GUID = atts[i+1];
  2196. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  2197. }
  2198. else
  2199. {
  2200. this->GUID = "";
  2201. }
  2202. return;
  2203. }
  2204. ++i;
  2205. }
  2206. }
  2207. }
  2208. int InitializeParser()
  2209. {
  2210. int ret = cmXMLParser::InitializeParser();
  2211. if(ret == 0)
  2212. {
  2213. return ret;
  2214. }
  2215. // visual studio projects have a strange encoding, but it is
  2216. // really utf-8
  2217. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  2218. return 1;
  2219. }
  2220. std::string GUID;
  2221. };
  2222. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  2223. const std::string& name,
  2224. const char* path)
  2225. {
  2226. cmVS7XMLParser parser;
  2227. parser.ParseFile(path);
  2228. // if we can not find a GUID then we will generate one later
  2229. if(parser.GUID.empty())
  2230. {
  2231. return;
  2232. }
  2233. std::string guidStoreName = name;
  2234. guidStoreName += "_GUID_CMAKE";
  2235. // save the GUID in the cache
  2236. this->GlobalGenerator->GetCMakeInstance()->
  2237. AddCacheEntry(guidStoreName.c_str(),
  2238. parser.GUID.c_str(),
  2239. "Stored GUID",
  2240. cmState::INTERNAL);
  2241. }
  2242. //----------------------------------------------------------------------------
  2243. std::string cmLocalVisualStudio7Generator
  2244. ::GetTargetDirectory(cmGeneratorTarget const* target) const
  2245. {
  2246. std::string dir;
  2247. dir += target->GetName();
  2248. dir += ".dir";
  2249. return dir;
  2250. }
  2251. //----------------------------------------------------------------------------
  2252. #include <windows.h>
  2253. static bool cmLVS7G_IsFAT(const char* dir)
  2254. {
  2255. if(dir[0] && dir[1] == ':')
  2256. {
  2257. char volRoot[4] = "_:/";
  2258. volRoot[0] = dir[0];
  2259. char fsName[16];
  2260. if(GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2261. strstr(fsName, "FAT") != 0)
  2262. {
  2263. return true;
  2264. }
  2265. }
  2266. return false;
  2267. }