cmLocalVisualStudio7Generator.cxx 78 KB

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