cmLocalVisualStudio7Generator.cxx 80 KB

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