cmLocalVisualStudio7Generator.cxx 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210
  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().c_str());
  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);
  668. targetOptions.Parse(defineFlags);
  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);
  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. static std::string cmLocalVisualStudio7GeneratorEscapeForXML(
  1160. const std::string& s)
  1161. {
  1162. std::string ret = s;
  1163. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1164. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1165. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1166. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1167. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1168. return ret;
  1169. }
  1170. static std::string GetEscapedPropertyIfValueNotNULL(const char* propertyValue)
  1171. {
  1172. return propertyValue == nullptr
  1173. ? std::string()
  1174. : cmLocalVisualStudio7GeneratorEscapeForXML(propertyValue);
  1175. }
  1176. void cmLocalVisualStudio7Generator::OutputDeploymentDebuggerTool(
  1177. std::ostream& fout, std::string const& config, cmGeneratorTarget* target)
  1178. {
  1179. if (this->WindowsCEProject) {
  1180. const char* dir = target->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY");
  1181. const char* additionalFiles =
  1182. target->GetProperty("DEPLOYMENT_ADDITIONAL_FILES");
  1183. if (dir == nullptr && additionalFiles == nullptr) {
  1184. return;
  1185. }
  1186. fout << "\t\t\t<DeploymentTool\n"
  1187. "\t\t\t\tForceDirty=\"-1\"\n"
  1188. "\t\t\t\tRemoteDirectory=\""
  1189. << GetEscapedPropertyIfValueNotNULL(dir)
  1190. << "\"\n"
  1191. "\t\t\t\tRegisterOutput=\"0\"\n"
  1192. "\t\t\t\tAdditionalFiles=\""
  1193. << GetEscapedPropertyIfValueNotNULL(additionalFiles) << "\"/>\n";
  1194. if (dir != nullptr) {
  1195. std::string const exe =
  1196. dir + std::string("\\") + target->GetFullName(config);
  1197. fout << "\t\t\t<DebuggerTool\n"
  1198. "\t\t\t\tRemoteExecutable=\""
  1199. << this->EscapeForXML(exe)
  1200. << "\"\n"
  1201. "\t\t\t\tArguments=\"\"\n"
  1202. "\t\t\t/>\n";
  1203. }
  1204. }
  1205. }
  1206. void cmLocalVisualStudio7Generator::WriteTargetVersionAttribute(
  1207. std::ostream& fout, cmGeneratorTarget* gt)
  1208. {
  1209. int major;
  1210. int minor;
  1211. gt->GetTargetVersion(major, minor);
  1212. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1213. }
  1214. void cmLocalVisualStudio7GeneratorInternals::OutputLibraries(
  1215. std::ostream& fout, ItemVector const& libs)
  1216. {
  1217. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1218. std::string currentBinDir = lg->GetCurrentBinaryDirectory();
  1219. for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
  1220. if (l->IsPath) {
  1221. std::string rel =
  1222. lg->ConvertToRelativePath(currentBinDir, l->Value.c_str());
  1223. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1224. } else if (!l->Target ||
  1225. l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1226. fout << l->Value << " ";
  1227. }
  1228. }
  1229. }
  1230. void cmLocalVisualStudio7GeneratorInternals::OutputObjects(
  1231. std::ostream& fout, cmGeneratorTarget* gt, std::string const& configName,
  1232. const char* isep)
  1233. {
  1234. // VS < 8 does not support per-config source locations so we
  1235. // list object library content on the link line instead.
  1236. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1237. std::string currentBinDir = lg->GetCurrentBinaryDirectory();
  1238. std::vector<cmSourceFile const*> objs;
  1239. gt->GetExternalObjects(objs, configName);
  1240. const char* sep = isep ? isep : "";
  1241. for (std::vector<cmSourceFile const*>::const_iterator i = objs.begin();
  1242. i != objs.end(); ++i) {
  1243. if (!(*i)->GetObjectLibrary().empty()) {
  1244. std::string const& objFile = (*i)->GetFullPath();
  1245. std::string rel = lg->ConvertToRelativePath(currentBinDir, objFile);
  1246. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1247. sep = " ";
  1248. }
  1249. }
  1250. }
  1251. void cmLocalVisualStudio7Generator::OutputLibraryDirectories(
  1252. std::ostream& fout, std::vector<std::string> const& dirs)
  1253. {
  1254. const char* comma = "";
  1255. std::string currentBinDir = this->GetCurrentBinaryDirectory();
  1256. for (std::vector<std::string>::const_iterator d = dirs.begin();
  1257. d != dirs.end(); ++d) {
  1258. // Remove any trailing slash and skip empty paths.
  1259. std::string dir = *d;
  1260. if (dir[dir.size() - 1] == '/') {
  1261. dir = dir.substr(0, dir.size() - 1);
  1262. }
  1263. if (dir.empty()) {
  1264. continue;
  1265. }
  1266. // Switch to a relative path specification if it is shorter.
  1267. if (cmSystemTools::FileIsFullPath(dir.c_str())) {
  1268. std::string rel =
  1269. this->ConvertToRelativePath(currentBinDir, dir.c_str());
  1270. if (rel.size() < dir.size()) {
  1271. dir = rel;
  1272. }
  1273. }
  1274. // First search a configuration-specific subdirectory and then the
  1275. // original directory.
  1276. fout << comma
  1277. << this->ConvertToXMLOutputPath(
  1278. (dir + "/$(ConfigurationName)").c_str())
  1279. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1280. comma = ",";
  1281. }
  1282. }
  1283. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1284. const std::string& libName,
  1285. cmGeneratorTarget* target)
  1286. {
  1287. std::vector<std::string> configs;
  1288. this->Makefile->GetConfigurations(configs);
  1289. // We may be modifying the source groups temporarily, so make a copy.
  1290. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1291. AllConfigSources sources;
  1292. sources.Sources = target->GetAllConfigSources();
  1293. // Add CMakeLists.txt file with rule to re-run CMake for user convenience.
  1294. if (target->GetType() != cmStateEnums::GLOBAL_TARGET &&
  1295. target->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
  1296. if (cmSourceFile const* sf = this->CreateVCProjBuildRule()) {
  1297. cmGeneratorTarget::AllConfigSource acs;
  1298. acs.Source = sf;
  1299. acs.Kind = cmGeneratorTarget::SourceKindCustomCommand;
  1300. for (size_t ci = 0; ci < configs.size(); ++ci) {
  1301. acs.Configs.push_back(ci);
  1302. }
  1303. bool haveCMakeLists = false;
  1304. for (cmGeneratorTarget::AllConfigSource& si : sources.Sources) {
  1305. if (si.Source == sf) {
  1306. haveCMakeLists = true;
  1307. // Replace the explicit source reference with our generated one.
  1308. si = acs;
  1309. break;
  1310. }
  1311. }
  1312. if (!haveCMakeLists) {
  1313. sources.Sources.emplace_back(std::move(acs));
  1314. }
  1315. }
  1316. }
  1317. for (size_t si = 0; si < sources.Sources.size(); ++si) {
  1318. cmSourceFile const* sf = sources.Sources[si].Source;
  1319. sources.Index[sf] = si;
  1320. if (!sf->GetObjectLibrary().empty()) {
  1321. if (this->FortranProject) {
  1322. // Intel Fortran does not support per-config source locations
  1323. // so we list object library content on the link line instead.
  1324. // See OutputObjects.
  1325. continue;
  1326. }
  1327. }
  1328. // Add the file to the list of sources.
  1329. std::string const source = sf->GetFullPath();
  1330. cmSourceGroup* sourceGroup =
  1331. this->Makefile->FindSourceGroup(source, sourceGroups);
  1332. sourceGroup->AssignSource(sf);
  1333. }
  1334. // open the project
  1335. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1336. // write the configuration information
  1337. this->WriteConfigurations(fout, configs, libName, target);
  1338. fout << "\t<Files>\n";
  1339. // Loop through every source group.
  1340. for (unsigned int i = 0; i < sourceGroups.size(); ++i) {
  1341. cmSourceGroup sg = sourceGroups[i];
  1342. this->WriteGroup(&sg, target, fout, libName, configs, sources);
  1343. }
  1344. fout << "\t</Files>\n";
  1345. // Write the VCProj file's footer.
  1346. this->WriteVCProjFooter(fout, target);
  1347. }
  1348. struct cmLVS7GFileConfig
  1349. {
  1350. std::string ObjectName;
  1351. std::string CompileFlags;
  1352. std::string CompileDefs;
  1353. std::string CompileDefsConfig;
  1354. std::string AdditionalDeps;
  1355. std::string IncludeDirs;
  1356. bool ExcludedFromBuild;
  1357. };
  1358. class cmLocalVisualStudio7GeneratorFCInfo
  1359. {
  1360. public:
  1361. cmLocalVisualStudio7GeneratorFCInfo(
  1362. cmLocalVisualStudio7Generator* lg, cmGeneratorTarget* target,
  1363. cmGeneratorTarget::AllConfigSource const& acs,
  1364. std::vector<std::string> const& configs);
  1365. std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
  1366. };
  1367. cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
  1368. cmLocalVisualStudio7Generator* lg, cmGeneratorTarget* gt,
  1369. cmGeneratorTarget::AllConfigSource const& acs,
  1370. std::vector<std::string> const& configs)
  1371. {
  1372. cmSourceFile const& sf = *acs.Source;
  1373. std::string objectName;
  1374. if (gt->HasExplicitObjectName(&sf)) {
  1375. objectName = gt->GetObjectName(&sf);
  1376. }
  1377. // Compute per-source, per-config information.
  1378. size_t ci = 0;
  1379. for (std::vector<std::string>::const_iterator i = configs.begin();
  1380. i != configs.end(); ++i, ++ci) {
  1381. std::string configUpper = cmSystemTools::UpperCase(*i);
  1382. cmLVS7GFileConfig fc;
  1383. std::string lang =
  1384. lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  1385. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1386. bool needForceLang = false;
  1387. // source file does not match its extension language
  1388. if (lang != sourceLang) {
  1389. needForceLang = true;
  1390. lang = sourceLang;
  1391. }
  1392. cmGeneratorExpressionInterpreter genexInterpreter(lg, gt, *i,
  1393. gt->GetName(), lang);
  1394. bool needfc = false;
  1395. if (!objectName.empty()) {
  1396. fc.ObjectName = objectName;
  1397. needfc = true;
  1398. }
  1399. const std::string COMPILE_FLAGS("COMPILE_FLAGS");
  1400. if (const char* cflags = sf.GetProperty(COMPILE_FLAGS)) {
  1401. fc.CompileFlags = genexInterpreter.Evaluate(cflags, COMPILE_FLAGS);
  1402. needfc = true;
  1403. }
  1404. const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
  1405. if (const char* coptions = sf.GetProperty(COMPILE_OPTIONS)) {
  1406. lg->AppendCompileOptions(
  1407. fc.CompileFlags, genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS));
  1408. needfc = true;
  1409. }
  1410. if (lg->FortranProject) {
  1411. switch (cmOutputConverter::GetFortranFormat(
  1412. sf.GetProperty("Fortran_FORMAT"))) {
  1413. case cmOutputConverter::FortranFormatFixed:
  1414. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1415. needfc = true;
  1416. break;
  1417. case cmOutputConverter::FortranFormatFree:
  1418. fc.CompileFlags = "-free " + fc.CompileFlags;
  1419. needfc = true;
  1420. break;
  1421. default:
  1422. break;
  1423. }
  1424. }
  1425. const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
  1426. if (const char* cdefs = sf.GetProperty(COMPILE_DEFINITIONS)) {
  1427. fc.CompileDefs = genexInterpreter.Evaluate(cdefs, COMPILE_DEFINITIONS);
  1428. needfc = true;
  1429. }
  1430. std::string defPropName = "COMPILE_DEFINITIONS_";
  1431. defPropName += configUpper;
  1432. if (const char* ccdefs = sf.GetProperty(defPropName)) {
  1433. fc.CompileDefsConfig =
  1434. genexInterpreter.Evaluate(ccdefs, COMPILE_DEFINITIONS);
  1435. needfc = true;
  1436. }
  1437. const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
  1438. if (const char* cincs = sf.GetProperty(INCLUDE_DIRECTORIES)) {
  1439. fc.IncludeDirs = genexInterpreter.Evaluate(cincs, INCLUDE_DIRECTORIES);
  1440. needfc = true;
  1441. }
  1442. // Check for extra object-file dependencies.
  1443. if (const char* deps = sf.GetProperty("OBJECT_DEPENDS")) {
  1444. std::vector<std::string> depends;
  1445. cmSystemTools::ExpandListArgument(deps, depends);
  1446. const char* sep = "";
  1447. for (std::vector<std::string>::iterator j = depends.begin();
  1448. j != depends.end(); ++j) {
  1449. fc.AdditionalDeps += sep;
  1450. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1451. sep = ";";
  1452. needfc = true;
  1453. }
  1454. }
  1455. const std::string& linkLanguage = gt->GetLinkerLanguage(i->c_str());
  1456. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1457. // the project file
  1458. fc.ExcludedFromBuild = sf.GetPropertyAsBool("HEADER_FILE_ONLY") ||
  1459. std::find(acs.Configs.begin(), acs.Configs.end(), ci) ==
  1460. acs.Configs.end();
  1461. if (fc.ExcludedFromBuild) {
  1462. needfc = true;
  1463. }
  1464. // if the source file does not match the linker language
  1465. // then force c or c++
  1466. if (needForceLang || (linkLanguage != lang)) {
  1467. if (lang == "CXX") {
  1468. // force a C++ file type
  1469. fc.CompileFlags += " /TP ";
  1470. needfc = true;
  1471. } else if (lang == "C") {
  1472. // force to c
  1473. fc.CompileFlags += " /TC ";
  1474. needfc = true;
  1475. }
  1476. }
  1477. if (needfc) {
  1478. this->FileConfigMap[*i] = fc;
  1479. }
  1480. }
  1481. }
  1482. std::string cmLocalVisualStudio7Generator::ComputeLongestObjectDirectory(
  1483. cmGeneratorTarget const* target) const
  1484. {
  1485. std::vector<std::string> configs;
  1486. target->Target->GetMakefile()->GetConfigurations(configs);
  1487. // Compute the maximum length configuration name.
  1488. std::string config_max;
  1489. for (std::vector<std::string>::iterator i = configs.begin();
  1490. i != configs.end(); ++i) {
  1491. if (i->size() > config_max.size()) {
  1492. config_max = *i;
  1493. }
  1494. }
  1495. // Compute the maximum length full path to the intermediate
  1496. // files directory for any configuration. This is used to construct
  1497. // object file names that do not produce paths that are too long.
  1498. std::string dir_max;
  1499. dir_max += this->GetCurrentBinaryDirectory();
  1500. dir_max += "/";
  1501. dir_max += this->GetTargetDirectory(target);
  1502. dir_max += "/";
  1503. dir_max += config_max;
  1504. dir_max += "/";
  1505. return dir_max;
  1506. }
  1507. bool cmLocalVisualStudio7Generator::WriteGroup(
  1508. const cmSourceGroup* sg, cmGeneratorTarget* target, std::ostream& fout,
  1509. const std::string& libName, std::vector<std::string> const& configs,
  1510. AllConfigSources const& sources)
  1511. {
  1512. cmGlobalVisualStudio7Generator* gg =
  1513. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1514. const std::vector<const cmSourceFile*>& sourceFiles = sg->GetSourceFiles();
  1515. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1516. // Write the children to temporary output.
  1517. bool hasChildrenWithSources = false;
  1518. std::ostringstream tmpOut;
  1519. for (unsigned int i = 0; i < children.size(); ++i) {
  1520. if (this->WriteGroup(&children[i], target, tmpOut, libName, configs,
  1521. sources)) {
  1522. hasChildrenWithSources = true;
  1523. }
  1524. }
  1525. // If the group is empty, don't write it at all.
  1526. if (sourceFiles.empty() && !hasChildrenWithSources) {
  1527. return false;
  1528. }
  1529. // If the group has a name, write the header.
  1530. std::string const& name = sg->GetName();
  1531. if (!name.empty()) {
  1532. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1533. }
  1534. // Loop through each source in the source group.
  1535. for (std::vector<const cmSourceFile*>::const_iterator sf =
  1536. sourceFiles.begin();
  1537. sf != sourceFiles.end(); ++sf) {
  1538. std::string source = (*sf)->GetFullPath();
  1539. if (source != libName || target->GetType() == cmStateEnums::UTILITY ||
  1540. target->GetType() == cmStateEnums::GLOBAL_TARGET) {
  1541. // Look up the source kind and configs.
  1542. std::map<cmSourceFile const*, size_t>::const_iterator map_it =
  1543. sources.Index.find(*sf);
  1544. // The map entry must exist because we populated it earlier.
  1545. assert(map_it != sources.Index.end());
  1546. cmGeneratorTarget::AllConfigSource const& acs =
  1547. sources.Sources[map_it->second];
  1548. FCInfo fcinfo(this, target, acs, configs);
  1549. fout << "\t\t\t<File\n";
  1550. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1551. // Tell MS-Dev what the source is. If the compiler knows how to
  1552. // build it, then it will.
  1553. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1554. if (cmCustomCommand const* command = (*sf)->GetCustomCommand()) {
  1555. this->WriteCustomRule(fout, configs, source.c_str(), *command, fcinfo);
  1556. } else if (!fcinfo.FileConfigMap.empty()) {
  1557. const char* aCompilerTool = "VCCLCompilerTool";
  1558. std::string ppLang = "CXX";
  1559. if (this->FortranProject) {
  1560. aCompilerTool = "VFFortranCompilerTool";
  1561. }
  1562. std::string const& lang = (*sf)->GetLanguage();
  1563. std::string ext = (*sf)->GetExtension();
  1564. ext = cmSystemTools::LowerCase(ext);
  1565. if (ext == "idl") {
  1566. aCompilerTool = "VCMIDLTool";
  1567. if (this->FortranProject) {
  1568. aCompilerTool = "VFMIDLTool";
  1569. }
  1570. }
  1571. if (ext == "rc") {
  1572. aCompilerTool = "VCResourceCompilerTool";
  1573. ppLang = "RC";
  1574. if (this->FortranProject) {
  1575. aCompilerTool = "VFResourceCompilerTool";
  1576. }
  1577. }
  1578. if (ext == "def") {
  1579. aCompilerTool = "VCCustomBuildTool";
  1580. if (this->FortranProject) {
  1581. aCompilerTool = "VFCustomBuildTool";
  1582. }
  1583. }
  1584. if (gg->IsMasmEnabled() && !this->FortranProject &&
  1585. lang == "ASM_MASM") {
  1586. aCompilerTool = "MASM";
  1587. }
  1588. if (acs.Kind == cmGeneratorTarget::SourceKindExternalObject) {
  1589. aCompilerTool = "VCCustomBuildTool";
  1590. }
  1591. for (std::map<std::string, cmLVS7GFileConfig>::const_iterator fci =
  1592. fcinfo.FileConfigMap.begin();
  1593. fci != fcinfo.FileConfigMap.end(); ++fci) {
  1594. cmLVS7GFileConfig const& fc = fci->second;
  1595. fout << "\t\t\t\t<FileConfiguration\n"
  1596. << "\t\t\t\t\tName=\"" << fci->first << "|"
  1597. << gg->GetPlatformName() << "\"";
  1598. if (fc.ExcludedFromBuild) {
  1599. fout << " ExcludedFromBuild=\"true\"";
  1600. }
  1601. fout << ">\n";
  1602. fout << "\t\t\t\t\t<Tool\n"
  1603. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1604. if (!fc.CompileFlags.empty() || !fc.CompileDefs.empty() ||
  1605. !fc.CompileDefsConfig.empty() || !fc.IncludeDirs.empty()) {
  1606. Options::Tool tool = Options::Compiler;
  1607. cmVS7FlagTable const* table =
  1608. cmLocalVisualStudio7GeneratorFlagTable;
  1609. if (this->FortranProject) {
  1610. tool = Options::FortranCompiler;
  1611. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1612. }
  1613. Options fileOptions(this, tool, table, gg->ExtraFlagTable);
  1614. fileOptions.Parse(fc.CompileFlags);
  1615. fileOptions.AddDefines(fc.CompileDefs);
  1616. fileOptions.AddDefines(fc.CompileDefsConfig);
  1617. // validate source level include directories
  1618. std::vector<std::string> includes;
  1619. this->AppendIncludeDirectories(includes, fc.IncludeDirs, **sf);
  1620. fileOptions.AddIncludes(includes);
  1621. fileOptions.OutputFlagMap(fout, 5);
  1622. fileOptions.OutputAdditionalIncludeDirectories(
  1623. fout, 5,
  1624. ppLang == "CXX" && this->FortranProject ? "Fortran" : ppLang);
  1625. fileOptions.OutputPreprocessorDefinitions(fout, 5, ppLang);
  1626. }
  1627. if (!fc.AdditionalDeps.empty()) {
  1628. fout << "\t\t\t\t\tAdditionalDependencies=\"" << fc.AdditionalDeps
  1629. << "\"\n";
  1630. }
  1631. if (!fc.ObjectName.empty()) {
  1632. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/" << fc.ObjectName
  1633. << "\"\n";
  1634. }
  1635. fout << "\t\t\t\t\t/>\n"
  1636. << "\t\t\t\t</FileConfiguration>\n";
  1637. }
  1638. }
  1639. fout << "\t\t\t</File>\n";
  1640. }
  1641. }
  1642. // If the group has children with source files, write the children.
  1643. if (hasChildrenWithSources) {
  1644. fout << tmpOut.str();
  1645. }
  1646. // If the group has a name, write the footer.
  1647. if (!name.empty()) {
  1648. this->WriteVCProjEndGroup(fout);
  1649. }
  1650. return true;
  1651. }
  1652. void cmLocalVisualStudio7Generator::WriteCustomRule(
  1653. std::ostream& fout, std::vector<std::string> const& configs,
  1654. const char* source, const cmCustomCommand& command, FCInfo& fcinfo)
  1655. {
  1656. cmGlobalVisualStudio7Generator* gg =
  1657. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1658. // Write the rule for each configuration.
  1659. const char* compileTool = "VCCLCompilerTool";
  1660. if (this->FortranProject) {
  1661. compileTool = "VFCLCompilerTool";
  1662. }
  1663. const char* customTool = "VCCustomBuildTool";
  1664. if (this->FortranProject) {
  1665. customTool = "VFCustomBuildTool";
  1666. }
  1667. for (std::vector<std::string>::const_iterator i = configs.begin();
  1668. i != configs.end(); ++i) {
  1669. cmCustomCommandGenerator ccg(command, *i, this);
  1670. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1671. fout << "\t\t\t\t<FileConfiguration\n";
  1672. fout << "\t\t\t\t\tName=\"" << *i << "|" << gg->GetPlatformName()
  1673. << "\">\n";
  1674. if (!fc.CompileFlags.empty()) {
  1675. fout << "\t\t\t\t\t<Tool\n"
  1676. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1677. << "\t\t\t\t\tAdditionalOptions=\""
  1678. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1679. }
  1680. std::string comment = this->ConstructComment(ccg);
  1681. std::string script = this->ConstructScript(ccg);
  1682. if (this->FortranProject) {
  1683. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1684. }
  1685. /* clang-format off */
  1686. fout << "\t\t\t\t\t<Tool\n"
  1687. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1688. << "\t\t\t\t\tDescription=\""
  1689. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1690. << "\t\t\t\t\tCommandLine=\""
  1691. << this->EscapeForXML(script.c_str()) << "\"\n"
  1692. << "\t\t\t\t\tAdditionalDependencies=\"";
  1693. /* clang-format on */
  1694. if (ccg.GetDepends().empty()) {
  1695. // There are no real dependencies. Produce an artificial one to
  1696. // make sure the rule runs reliably.
  1697. if (!cmSystemTools::FileExists(source)) {
  1698. cmsys::ofstream depout(source);
  1699. depout << "Artificial dependency for a custom command.\n";
  1700. }
  1701. fout << this->ConvertToXMLOutputPath(source);
  1702. } else {
  1703. // Write out the dependencies for the rule.
  1704. for (std::vector<std::string>::const_iterator d =
  1705. ccg.GetDepends().begin();
  1706. d != ccg.GetDepends().end(); ++d) {
  1707. // Get the real name of the dependency in case it is a CMake target.
  1708. std::string dep;
  1709. if (this->GetRealDependency(d->c_str(), i->c_str(), dep)) {
  1710. fout << this->ConvertToXMLOutputPath(dep.c_str()) << ";";
  1711. }
  1712. }
  1713. }
  1714. fout << "\"\n";
  1715. fout << "\t\t\t\t\tOutputs=\"";
  1716. if (ccg.GetOutputs().empty()) {
  1717. fout << source << "_force";
  1718. } else {
  1719. // Write a rule for the output generated by this command.
  1720. const char* sep = "";
  1721. for (std::vector<std::string>::const_iterator o =
  1722. ccg.GetOutputs().begin();
  1723. o != ccg.GetOutputs().end(); ++o) {
  1724. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1725. sep = ";";
  1726. }
  1727. }
  1728. fout << "\"/>\n";
  1729. fout << "\t\t\t\t</FileConfiguration>\n";
  1730. }
  1731. }
  1732. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1733. const char* group,
  1734. const char*)
  1735. {
  1736. /* clang-format off */
  1737. fout << "\t\t<Filter\n"
  1738. << "\t\t\tName=\"" << group << "\"\n"
  1739. << "\t\t\tFilter=\"\">\n";
  1740. /* clang-format on */
  1741. }
  1742. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1743. {
  1744. fout << "\t\t</Filter>\n";
  1745. }
  1746. // look for custom rules on a target and collect them together
  1747. void cmLocalVisualStudio7Generator::OutputTargetRules(
  1748. std::ostream& fout, const std::string& configName, cmGeneratorTarget* target,
  1749. const std::string& /*libName*/)
  1750. {
  1751. if (target->GetType() > cmStateEnums::GLOBAL_TARGET) {
  1752. return;
  1753. }
  1754. EventWriter event(this, configName, fout);
  1755. // Add pre-build event.
  1756. const char* tool =
  1757. this->FortranProject ? "VFPreBuildEventTool" : "VCPreBuildEventTool";
  1758. event.Start(tool);
  1759. event.Write(target->GetPreBuildCommands());
  1760. event.Finish();
  1761. // Add pre-link event.
  1762. tool = this->FortranProject ? "VFPreLinkEventTool" : "VCPreLinkEventTool";
  1763. event.Start(tool);
  1764. bool addedPrelink = false;
  1765. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  1766. target->GetModuleDefinitionInfo(configName);
  1767. if (mdi && mdi->DefFileGenerated) {
  1768. addedPrelink = true;
  1769. std::vector<cmCustomCommand> commands = target->GetPreLinkCommands();
  1770. cmGlobalVisualStudioGenerator* gg =
  1771. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  1772. gg->AddSymbolExportCommand(target, commands, configName);
  1773. event.Write(commands);
  1774. }
  1775. if (!addedPrelink) {
  1776. event.Write(target->GetPreLinkCommands());
  1777. }
  1778. std::unique_ptr<cmCustomCommand> pcc(
  1779. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1780. if (pcc.get()) {
  1781. event.Write(*pcc);
  1782. }
  1783. event.Finish();
  1784. // Add post-build event.
  1785. tool =
  1786. this->FortranProject ? "VFPostBuildEventTool" : "VCPostBuildEventTool";
  1787. event.Start(tool);
  1788. event.Write(target->GetPostBuildCommands());
  1789. event.Finish();
  1790. }
  1791. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1792. cmGeneratorTarget* target)
  1793. {
  1794. // if we have all the required Source code control tags
  1795. // then add that to the project
  1796. const char* vsProjectname = target->GetProperty("VS_SCC_PROJECTNAME");
  1797. const char* vsLocalpath = target->GetProperty("VS_SCC_LOCALPATH");
  1798. const char* vsProvider = target->GetProperty("VS_SCC_PROVIDER");
  1799. if (vsProvider && vsLocalpath && vsProjectname) {
  1800. /* clang-format off */
  1801. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1802. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1803. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1804. /* clang-format on */
  1805. const char* vsAuxPath = target->GetProperty("VS_SCC_AUXPATH");
  1806. if (vsAuxPath) {
  1807. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1808. }
  1809. }
  1810. }
  1811. void cmLocalVisualStudio7Generator::WriteProjectStartFortran(
  1812. std::ostream& fout, const std::string& libName, cmGeneratorTarget* target)
  1813. {
  1814. cmGlobalVisualStudio7Generator* gg =
  1815. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1816. /* clang-format off */
  1817. fout << "<?xml version=\"1.0\" encoding = \""
  1818. << gg->Encoding() << "\"?>\n"
  1819. << "<VisualStudioProject\n"
  1820. << "\tProjectCreator=\"Intel Fortran\"\n"
  1821. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  1822. /* clang-format on */
  1823. const char* keyword = target->GetProperty("VS_KEYWORD");
  1824. if (!keyword) {
  1825. keyword = "Console Application";
  1826. }
  1827. const char* projectType = 0;
  1828. switch (target->GetType()) {
  1829. case cmStateEnums::STATIC_LIBRARY:
  1830. projectType = "typeStaticLibrary";
  1831. if (keyword) {
  1832. keyword = "Static Library";
  1833. }
  1834. break;
  1835. case cmStateEnums::SHARED_LIBRARY:
  1836. case cmStateEnums::MODULE_LIBRARY:
  1837. projectType = "typeDynamicLibrary";
  1838. if (!keyword) {
  1839. keyword = "Dll";
  1840. }
  1841. break;
  1842. case cmStateEnums::EXECUTABLE:
  1843. if (!keyword) {
  1844. keyword = "Console Application";
  1845. }
  1846. projectType = 0;
  1847. break;
  1848. case cmStateEnums::UTILITY:
  1849. case cmStateEnums::GLOBAL_TARGET:
  1850. default:
  1851. break;
  1852. }
  1853. if (projectType) {
  1854. fout << "\tProjectType=\"" << projectType << "\"\n";
  1855. }
  1856. this->WriteProjectSCC(fout, target);
  1857. /* clang-format off */
  1858. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1859. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  1860. << "\t<Platforms>\n"
  1861. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1862. << "\t</Platforms>\n";
  1863. /* clang-format on */
  1864. }
  1865. void cmLocalVisualStudio7Generator::WriteProjectStart(
  1866. std::ostream& fout, const std::string& libName, cmGeneratorTarget* target,
  1867. std::vector<cmSourceGroup>&)
  1868. {
  1869. if (this->FortranProject) {
  1870. this->WriteProjectStartFortran(fout, libName, target);
  1871. return;
  1872. }
  1873. cmGlobalVisualStudio7Generator* gg =
  1874. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1875. /* clang-format off */
  1876. fout << "<?xml version=\"1.0\" encoding = \""
  1877. << gg->Encoding() << "\"?>\n"
  1878. << "<VisualStudioProject\n"
  1879. << "\tProjectType=\"Visual C++\"\n";
  1880. /* clang-format on */
  1881. fout << "\tVersion=\"" << (gg->GetVersion() / 10) << ".00\"\n";
  1882. const char* projLabel = target->GetProperty("PROJECT_LABEL");
  1883. if (!projLabel) {
  1884. projLabel = libName.c_str();
  1885. }
  1886. const char* keyword = target->GetProperty("VS_KEYWORD");
  1887. if (!keyword) {
  1888. keyword = "Win32Proj";
  1889. }
  1890. fout << "\tName=\"" << projLabel << "\"\n";
  1891. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  1892. this->WriteProjectSCC(fout, target);
  1893. if (const char* targetFrameworkVersion =
  1894. target->GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION")) {
  1895. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  1896. }
  1897. /* clang-format off */
  1898. fout << "\tKeyword=\"" << keyword << "\">\n"
  1899. << "\t<Platforms>\n"
  1900. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1901. << "\t</Platforms>\n";
  1902. /* clang-format on */
  1903. if (gg->IsMasmEnabled()) {
  1904. /* clang-format off */
  1905. fout <<
  1906. "\t<ToolFiles>\n"
  1907. "\t\t<DefaultToolFile\n"
  1908. "\t\t\tFileName=\"masm.rules\"\n"
  1909. "\t\t/>\n"
  1910. "\t</ToolFiles>\n"
  1911. ;
  1912. /* clang-format on */
  1913. }
  1914. }
  1915. void cmLocalVisualStudio7Generator::WriteVCProjFooter(
  1916. std::ostream& fout, cmGeneratorTarget* target)
  1917. {
  1918. fout << "\t<Globals>\n";
  1919. std::vector<std::string> const& props = target->GetPropertyKeys();
  1920. for (std::vector<std::string>::const_iterator i = props.begin();
  1921. i != props.end(); ++i) {
  1922. if (i->find("VS_GLOBAL_") == 0) {
  1923. std::string name = i->substr(10);
  1924. if (!name.empty()) {
  1925. /* clang-format off */
  1926. fout << "\t\t<Global\n"
  1927. << "\t\t\tName=\"" << name << "\"\n"
  1928. << "\t\t\tValue=\"" << target->GetProperty(*i) << "\"\n"
  1929. << "\t\t/>\n";
  1930. /* clang-format on */
  1931. }
  1932. }
  1933. }
  1934. fout << "\t</Globals>\n"
  1935. << "</VisualStudioProject>\n";
  1936. }
  1937. std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
  1938. {
  1939. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1940. }
  1941. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(
  1942. const char* path)
  1943. {
  1944. std::string ret =
  1945. this->ConvertToOutputFormat(path, cmOutputConverter::SHELL);
  1946. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1947. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1948. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1949. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1950. return ret;
  1951. }
  1952. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(
  1953. const char* path)
  1954. {
  1955. std::string ret =
  1956. this->ConvertToOutputFormat(path, cmOutputConverter::SHELL);
  1957. cmSystemTools::ReplaceString(ret, "\"", "");
  1958. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1959. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1960. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1961. return ret;
  1962. }
  1963. void cmVS7GeneratorOptions::OutputFlag(std::ostream& fout, int indent,
  1964. const char* flag,
  1965. const std::string& content)
  1966. {
  1967. fout.fill('\t');
  1968. fout.width(indent);
  1969. // write an empty string to get the fill level indent to print
  1970. fout << "";
  1971. fout << flag << "=\"";
  1972. fout << cmLocalVisualStudio7GeneratorEscapeForXML(content);
  1973. fout << "\"\n";
  1974. }
  1975. // This class is used to parse an existing vs 7 project
  1976. // and extract the GUID
  1977. class cmVS7XMLParser : public cmXMLParser
  1978. {
  1979. public:
  1980. virtual void EndElement(const std::string& /* name */) {}
  1981. virtual void StartElement(const std::string& name, const char** atts)
  1982. {
  1983. // once the GUID is found do nothing
  1984. if (!this->GUID.empty()) {
  1985. return;
  1986. }
  1987. int i = 0;
  1988. if ("VisualStudioProject" == name) {
  1989. while (atts[i]) {
  1990. if (strcmp(atts[i], "ProjectGUID") == 0) {
  1991. if (atts[i + 1]) {
  1992. this->GUID = atts[i + 1];
  1993. if (this->GUID[0] == '{') {
  1994. // remove surrounding curly brackets
  1995. this->GUID = this->GUID.substr(1, this->GUID.size() - 2);
  1996. }
  1997. } else {
  1998. this->GUID.clear();
  1999. }
  2000. return;
  2001. }
  2002. ++i;
  2003. }
  2004. }
  2005. }
  2006. int InitializeParser()
  2007. {
  2008. int ret = cmXMLParser::InitializeParser();
  2009. if (ret == 0) {
  2010. return ret;
  2011. }
  2012. // visual studio projects have a strange encoding, but it is
  2013. // really utf-8
  2014. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  2015. return 1;
  2016. }
  2017. std::string GUID;
  2018. };
  2019. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  2020. const std::string& name, const char* path)
  2021. {
  2022. cmVS7XMLParser parser;
  2023. parser.ParseFile(path);
  2024. // if we can not find a GUID then we will generate one later
  2025. if (parser.GUID.empty()) {
  2026. return;
  2027. }
  2028. std::string guidStoreName = name;
  2029. guidStoreName += "_GUID_CMAKE";
  2030. // save the GUID in the cache
  2031. this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
  2032. guidStoreName.c_str(), parser.GUID.c_str(), "Stored GUID",
  2033. cmStateEnums::INTERNAL);
  2034. }
  2035. std::string cmLocalVisualStudio7Generator::GetTargetDirectory(
  2036. cmGeneratorTarget const* target) const
  2037. {
  2038. std::string dir;
  2039. dir += target->GetName();
  2040. dir += ".dir";
  2041. return dir;
  2042. }
  2043. static bool cmLVS7G_IsFAT(const char* dir)
  2044. {
  2045. if (dir[0] && dir[1] == ':') {
  2046. char volRoot[4] = "_:/";
  2047. volRoot[0] = dir[0];
  2048. char fsName[16];
  2049. if (GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2050. strstr(fsName, "FAT") != 0) {
  2051. return true;
  2052. }
  2053. }
  2054. return false;
  2055. }