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