cmLocalVisualStudio7Generator.cxx 78 KB

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