cmLocalVisualStudio7Generator.cxx 79 KB

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