cmLocalVisualStudio7Generator.cxx 78 KB

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