cmLocalVisualStudio7Generator.cxx 79 KB

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