cmLocalVisualStudio7Generator.cxx 79 KB

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