cmLocalVisualStudio7Generator.cxx 79 KB

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