1
0

cmLocalVisualStudio7Generator.cxx 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130
  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(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. this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8) {
  851. const char* manifestTool = "VCManifestTool";
  852. if (this->FortranProject) {
  853. manifestTool = "VFManifestTool";
  854. }
  855. /* clang-format off */
  856. fout <<
  857. "\t\t\t<Tool\n"
  858. "\t\t\t\tName=\"" << manifestTool << "\"";
  859. /* clang-format on */
  860. std::vector<cmSourceFile const*> manifest_srcs;
  861. target->GetManifests(manifest_srcs, configName);
  862. if (!manifest_srcs.empty()) {
  863. fout << "\n\t\t\t\tAdditionalManifestFiles=\"";
  864. for (std::vector<cmSourceFile const*>::const_iterator mi =
  865. manifest_srcs.begin();
  866. mi != manifest_srcs.end(); ++mi) {
  867. std::string m = (*mi)->GetFullPath();
  868. fout << this->ConvertToXMLOutputPath(m.c_str()) << ";";
  869. }
  870. fout << "\"";
  871. }
  872. // Check if we need the FAT32 workaround.
  873. // Check the filesystem type where the target will be written.
  874. if (cmLVS7G_IsFAT(target->GetDirectory(configName).c_str())) {
  875. // Add a flag telling the manifest tool to use a workaround
  876. // for FAT32 file systems, which can cause an empty manifest
  877. // to be embedded into the resulting executable. See CMake
  878. // bug #2617.
  879. fout << "\n\t\t\t\tUseFAT32Workaround=\"true\"";
  880. }
  881. fout << "/>\n";
  882. }
  883. this->OutputTargetRules(fout, configName, target, libName);
  884. this->OutputBuildTool(fout, configName, target, targetOptions);
  885. this->OutputDeploymentDebuggerTool(fout, configName, target);
  886. fout << "\t\t</Configuration>\n";
  887. }
  888. std::string cmLocalVisualStudio7Generator::GetBuildTypeLinkerFlags(
  889. std::string rootLinkerFlags, const std::string& configName)
  890. {
  891. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  892. std::string extraLinkOptionsBuildTypeDef =
  893. rootLinkerFlags + "_" + configTypeUpper;
  894. std::string extraLinkOptionsBuildType =
  895. this->Makefile->GetRequiredDefinition(
  896. extraLinkOptionsBuildTypeDef.c_str());
  897. return extraLinkOptionsBuildType;
  898. }
  899. void cmLocalVisualStudio7Generator::OutputBuildTool(
  900. std::ostream& fout, const std::string& configName, cmGeneratorTarget* target,
  901. const Options& targetOptions)
  902. {
  903. cmGlobalVisualStudio7Generator* gg =
  904. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  905. std::string temp;
  906. std::string extraLinkOptions;
  907. if (target->GetType() == cmStateEnums::EXECUTABLE) {
  908. extraLinkOptions =
  909. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS") +
  910. std::string(" ") +
  911. GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  912. }
  913. if (target->GetType() == cmStateEnums::SHARED_LIBRARY) {
  914. extraLinkOptions =
  915. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS") +
  916. std::string(" ") +
  917. GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  918. }
  919. if (target->GetType() == cmStateEnums::MODULE_LIBRARY) {
  920. extraLinkOptions =
  921. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS") +
  922. std::string(" ") +
  923. GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  924. }
  925. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  926. if (targetLinkFlags) {
  927. extraLinkOptions += " ";
  928. extraLinkOptions += targetLinkFlags;
  929. }
  930. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  931. std::string linkFlagsConfig = "LINK_FLAGS_";
  932. linkFlagsConfig += configTypeUpper;
  933. targetLinkFlags = target->GetProperty(linkFlagsConfig.c_str());
  934. if (targetLinkFlags) {
  935. extraLinkOptions += " ";
  936. extraLinkOptions += targetLinkFlags;
  937. }
  938. Options linkOptions(this, Options::Linker);
  939. if (this->FortranProject) {
  940. linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
  941. }
  942. linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
  943. linkOptions.Parse(extraLinkOptions.c_str());
  944. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  945. target->GetModuleDefinitionInfo(configName);
  946. if (mdi && !mdi->DefFile.empty()) {
  947. std::string defFile =
  948. this->ConvertToOutputFormat(mdi->DefFile, cmOutputConverter::SHELL);
  949. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  950. }
  951. switch (target->GetType()) {
  952. case cmStateEnums::UNKNOWN_LIBRARY:
  953. break;
  954. case cmStateEnums::OBJECT_LIBRARY: {
  955. std::string libpath = this->GetTargetDirectory(target);
  956. libpath += "/";
  957. libpath += configName;
  958. libpath += "/";
  959. libpath += target->GetName();
  960. libpath += ".lib";
  961. const char* tool =
  962. this->FortranProject ? "VFLibrarianTool" : "VCLibrarianTool";
  963. fout << "\t\t\t<Tool\n"
  964. << "\t\t\t\tName=\"" << tool << "\"\n";
  965. fout << "\t\t\t\tOutputFile=\""
  966. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  967. break;
  968. }
  969. case cmStateEnums::STATIC_LIBRARY: {
  970. std::string targetNameFull = target->GetFullName(configName);
  971. std::string libpath = target->GetDirectory(configName);
  972. libpath += "/";
  973. libpath += targetNameFull;
  974. const char* tool = "VCLibrarianTool";
  975. if (this->FortranProject) {
  976. tool = "VFLibrarianTool";
  977. }
  978. fout << "\t\t\t<Tool\n"
  979. << "\t\t\t\tName=\"" << tool << "\"\n";
  980. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS8 ||
  981. this->FortranProject) {
  982. std::ostringstream libdeps;
  983. this->Internal->OutputObjects(libdeps, target, configName);
  984. if (!libdeps.str().empty()) {
  985. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str()
  986. << "\"\n";
  987. }
  988. }
  989. std::string libflags;
  990. this->GetStaticLibraryFlags(libflags, configTypeUpper, target);
  991. if (!libflags.empty()) {
  992. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  993. }
  994. fout << "\t\t\t\tOutputFile=\""
  995. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  996. break;
  997. }
  998. case cmStateEnums::SHARED_LIBRARY:
  999. case cmStateEnums::MODULE_LIBRARY: {
  1000. std::string targetName;
  1001. std::string targetNameSO;
  1002. std::string targetNameFull;
  1003. std::string targetNameImport;
  1004. std::string targetNamePDB;
  1005. target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1006. targetNameImport, targetNamePDB, configName);
  1007. // Compute the link library and directory information.
  1008. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
  1009. if (!pcli) {
  1010. return;
  1011. }
  1012. cmComputeLinkInformation& cli = *pcli;
  1013. std::string linkLanguage = cli.GetLinkLanguage();
  1014. // Compute the variable name to lookup standard libraries for this
  1015. // language.
  1016. std::string standardLibsVar = "CMAKE_";
  1017. standardLibsVar += linkLanguage;
  1018. standardLibsVar += "_STANDARD_LIBRARIES";
  1019. const char* tool = "VCLinkerTool";
  1020. if (this->FortranProject) {
  1021. tool = "VFLinkerTool";
  1022. }
  1023. fout << "\t\t\t<Tool\n"
  1024. << "\t\t\t\tName=\"" << tool << "\"\n";
  1025. if (!gg->NeedLinkLibraryDependencies(target)) {
  1026. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1027. }
  1028. // Use the NOINHERIT macro to avoid getting VS project default
  1029. // libraries which may be set by the user to something bad.
  1030. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1031. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1032. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS8 ||
  1033. this->FortranProject) {
  1034. this->Internal->OutputObjects(fout, target, configName, " ");
  1035. }
  1036. fout << " ";
  1037. this->Internal->OutputLibraries(fout, cli.GetItems());
  1038. fout << "\"\n";
  1039. temp = target->GetDirectory(configName);
  1040. temp += "/";
  1041. temp += targetNameFull;
  1042. fout << "\t\t\t\tOutputFile=\""
  1043. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1044. this->WriteTargetVersionAttribute(fout, target);
  1045. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1046. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1047. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1048. fout << "\"\n";
  1049. temp = target->GetPDBDirectory(configName);
  1050. temp += "/";
  1051. temp += targetNamePDB;
  1052. fout << "\t\t\t\tProgramDatabaseFile=\""
  1053. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1054. if (targetOptions.IsDebug()) {
  1055. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1056. }
  1057. if (this->WindowsCEProject) {
  1058. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS9) {
  1059. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1060. } else {
  1061. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1062. }
  1063. }
  1064. std::string stackVar = "CMAKE_";
  1065. stackVar += linkLanguage;
  1066. stackVar += "_STACK_SIZE";
  1067. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1068. if (stackVal) {
  1069. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1070. }
  1071. temp = target->GetDirectory(configName, true);
  1072. temp += "/";
  1073. temp += targetNameImport;
  1074. fout << "\t\t\t\tImportLibrary=\""
  1075. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1076. if (this->FortranProject) {
  1077. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1078. }
  1079. fout << "/>\n";
  1080. } break;
  1081. case cmStateEnums::EXECUTABLE: {
  1082. std::string targetName;
  1083. std::string targetNameFull;
  1084. std::string targetNameImport;
  1085. std::string targetNamePDB;
  1086. target->GetExecutableNames(targetName, targetNameFull, targetNameImport,
  1087. targetNamePDB, configName);
  1088. // Compute the link library and directory information.
  1089. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
  1090. if (!pcli) {
  1091. return;
  1092. }
  1093. cmComputeLinkInformation& cli = *pcli;
  1094. std::string linkLanguage = cli.GetLinkLanguage();
  1095. bool isWin32Executable = target->GetPropertyAsBool("WIN32_EXECUTABLE");
  1096. // Compute the variable name to lookup standard libraries for this
  1097. // language.
  1098. std::string standardLibsVar = "CMAKE_";
  1099. standardLibsVar += linkLanguage;
  1100. standardLibsVar += "_STANDARD_LIBRARIES";
  1101. const char* tool = "VCLinkerTool";
  1102. if (this->FortranProject) {
  1103. tool = "VFLinkerTool";
  1104. }
  1105. fout << "\t\t\t<Tool\n"
  1106. << "\t\t\t\tName=\"" << tool << "\"\n";
  1107. if (!gg->NeedLinkLibraryDependencies(target)) {
  1108. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1109. }
  1110. // Use the NOINHERIT macro to avoid getting VS project default
  1111. // libraries which may be set by the user to something bad.
  1112. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1113. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1114. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS8 ||
  1115. this->FortranProject) {
  1116. this->Internal->OutputObjects(fout, target, configName, " ");
  1117. }
  1118. fout << " ";
  1119. this->Internal->OutputLibraries(fout, cli.GetItems());
  1120. fout << "\"\n";
  1121. temp = target->GetDirectory(configName);
  1122. temp += "/";
  1123. temp += targetNameFull;
  1124. fout << "\t\t\t\tOutputFile=\""
  1125. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1126. this->WriteTargetVersionAttribute(fout, target);
  1127. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1128. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1129. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1130. fout << "\"\n";
  1131. std::string path = this->ConvertToXMLOutputPathSingle(
  1132. target->GetPDBDirectory(configName).c_str());
  1133. fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/" << targetNamePDB
  1134. << "\"\n";
  1135. if (targetOptions.IsDebug()) {
  1136. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1137. }
  1138. if (this->WindowsCEProject) {
  1139. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS9) {
  1140. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1141. } else {
  1142. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1143. }
  1144. if (!linkOptions.GetFlag("EntryPointSymbol")) {
  1145. const char* entryPointSymbol = targetOptions.UsingUnicode()
  1146. ? (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup")
  1147. : (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1148. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1149. }
  1150. } else if (this->FortranProject) {
  1151. fout << "\t\t\t\tSubSystem=\""
  1152. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1153. << "\"\n";
  1154. } else {
  1155. fout << "\t\t\t\tSubSystem=\"" << (isWin32Executable ? "2" : "1")
  1156. << "\"\n";
  1157. }
  1158. std::string stackVar = "CMAKE_";
  1159. stackVar += linkLanguage;
  1160. stackVar += "_STACK_SIZE";
  1161. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1162. if (stackVal) {
  1163. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1164. }
  1165. temp = target->GetDirectory(configName, true);
  1166. temp += "/";
  1167. temp += targetNameImport;
  1168. fout << "\t\t\t\tImportLibrary=\""
  1169. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1170. break;
  1171. }
  1172. case cmStateEnums::UTILITY:
  1173. case cmStateEnums::GLOBAL_TARGET:
  1174. case cmStateEnums::INTERFACE_LIBRARY:
  1175. break;
  1176. }
  1177. }
  1178. void cmLocalVisualStudio7Generator::OutputDeploymentDebuggerTool(
  1179. std::ostream& fout, std::string const& config, cmGeneratorTarget* target)
  1180. {
  1181. if (this->WindowsCEProject) {
  1182. if (const char* dir = target->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY")) {
  1183. /* clang-format off */
  1184. fout <<
  1185. "\t\t\t<DeploymentTool\n"
  1186. "\t\t\t\tForceDirty=\"-1\"\n"
  1187. "\t\t\t\tRemoteDirectory=\"" << this->EscapeForXML(dir) << "\"\n"
  1188. "\t\t\t\tRegisterOutput=\"0\"\n"
  1189. "\t\t\t\tAdditionalFiles=\"\"/>\n"
  1190. ;
  1191. /* clang-format on */
  1192. std::string const exe =
  1193. dir + std::string("\\") + target->GetFullName(config);
  1194. /* clang-format off */
  1195. fout <<
  1196. "\t\t\t<DebuggerTool\n"
  1197. "\t\t\t\tRemoteExecutable=\"" << this->EscapeForXML(exe) << "\"\n"
  1198. "\t\t\t\tArguments=\"\"\n"
  1199. "\t\t\t/>\n"
  1200. ;
  1201. /* clang-format on */
  1202. }
  1203. }
  1204. }
  1205. void cmLocalVisualStudio7Generator::WriteTargetVersionAttribute(
  1206. std::ostream& fout, cmGeneratorTarget* gt)
  1207. {
  1208. int major;
  1209. int minor;
  1210. gt->GetTargetVersion(major, minor);
  1211. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1212. }
  1213. void cmLocalVisualStudio7GeneratorInternals::OutputLibraries(
  1214. std::ostream& fout, ItemVector const& libs)
  1215. {
  1216. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1217. std::string currentBinDir = lg->GetCurrentBinaryDirectory();
  1218. for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
  1219. if (l->IsPath) {
  1220. std::string rel =
  1221. lg->ConvertToRelativePath(currentBinDir, l->Value.c_str());
  1222. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1223. } else if (!l->Target ||
  1224. l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1225. fout << l->Value << " ";
  1226. }
  1227. }
  1228. }
  1229. void cmLocalVisualStudio7GeneratorInternals::OutputObjects(
  1230. std::ostream& fout, cmGeneratorTarget* gt, std::string const& configName,
  1231. const char* isep)
  1232. {
  1233. // VS < 8 does not support per-config source locations so we
  1234. // list object library content on the link line instead.
  1235. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1236. std::string currentBinDir = lg->GetCurrentBinaryDirectory();
  1237. std::vector<cmSourceFile const*> objs;
  1238. gt->GetExternalObjects(objs, configName);
  1239. const char* sep = isep ? isep : "";
  1240. for (std::vector<cmSourceFile const*>::const_iterator i = objs.begin();
  1241. i != objs.end(); ++i) {
  1242. if (!(*i)->GetObjectLibrary().empty()) {
  1243. std::string const& objFile = (*i)->GetFullPath();
  1244. std::string rel = lg->ConvertToRelativePath(currentBinDir, objFile);
  1245. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1246. sep = " ";
  1247. }
  1248. }
  1249. }
  1250. void cmLocalVisualStudio7Generator::OutputLibraryDirectories(
  1251. std::ostream& fout, std::vector<std::string> const& dirs)
  1252. {
  1253. const char* comma = "";
  1254. std::string currentBinDir = this->GetCurrentBinaryDirectory();
  1255. for (std::vector<std::string>::const_iterator d = dirs.begin();
  1256. d != dirs.end(); ++d) {
  1257. // Remove any trailing slash and skip empty paths.
  1258. std::string dir = *d;
  1259. if (dir[dir.size() - 1] == '/') {
  1260. dir = dir.substr(0, dir.size() - 1);
  1261. }
  1262. if (dir.empty()) {
  1263. continue;
  1264. }
  1265. // Switch to a relative path specification if it is shorter.
  1266. if (cmSystemTools::FileIsFullPath(dir.c_str())) {
  1267. std::string rel =
  1268. this->ConvertToRelativePath(currentBinDir, dir.c_str());
  1269. if (rel.size() < dir.size()) {
  1270. dir = rel;
  1271. }
  1272. }
  1273. // First search a configuration-specific subdirectory and then the
  1274. // original directory.
  1275. fout << comma
  1276. << this->ConvertToXMLOutputPath(
  1277. (dir + "/$(ConfigurationName)").c_str())
  1278. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1279. comma = ",";
  1280. }
  1281. }
  1282. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1283. const std::string& libName,
  1284. cmGeneratorTarget* target)
  1285. {
  1286. std::vector<std::string> configs;
  1287. this->Makefile->GetConfigurations(configs);
  1288. // We may be modifying the source groups temporarily, so make a copy.
  1289. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1290. // get the classes from the source lists then add them to the groups
  1291. std::vector<cmSourceFile*> classes;
  1292. if (!target->GetConfigCommonSourceFiles(classes)) {
  1293. return;
  1294. }
  1295. for (std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1296. i != classes.end(); i++) {
  1297. if (!(*i)->GetObjectLibrary().empty()) {
  1298. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS8 ||
  1299. this->FortranProject) {
  1300. // VS < 8 does not support per-config source locations so we
  1301. // list object library content on the link line instead.
  1302. // See OutputObjects.
  1303. continue;
  1304. }
  1305. }
  1306. // Add the file to the list of sources.
  1307. std::string source = (*i)->GetFullPath();
  1308. cmSourceGroup* sourceGroup =
  1309. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1310. sourceGroup->AssignSource(*i);
  1311. }
  1312. // open the project
  1313. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1314. // write the configuration information
  1315. this->WriteConfigurations(fout, configs, libName, target);
  1316. fout << "\t<Files>\n";
  1317. // Loop through every source group.
  1318. for (unsigned int i = 0; i < sourceGroups.size(); ++i) {
  1319. cmSourceGroup sg = sourceGroups[i];
  1320. this->WriteGroup(&sg, target, fout, libName, configs);
  1321. }
  1322. fout << "\t</Files>\n";
  1323. // Write the VCProj file's footer.
  1324. this->WriteVCProjFooter(fout, target);
  1325. }
  1326. struct cmLVS7GFileConfig
  1327. {
  1328. std::string ObjectName;
  1329. std::string CompileFlags;
  1330. std::string CompileDefs;
  1331. std::string CompileDefsConfig;
  1332. std::string AdditionalDeps;
  1333. bool ExcludedFromBuild;
  1334. };
  1335. class cmLocalVisualStudio7GeneratorFCInfo
  1336. {
  1337. public:
  1338. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1339. cmGeneratorTarget* target,
  1340. cmSourceFile const& sf,
  1341. std::vector<std::string> const& configs);
  1342. std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
  1343. };
  1344. cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
  1345. cmLocalVisualStudio7Generator* lg, cmGeneratorTarget* gt,
  1346. cmSourceFile const& sf, std::vector<std::string> const& configs)
  1347. {
  1348. std::string objectName;
  1349. if (gt->HasExplicitObjectName(&sf)) {
  1350. objectName = gt->GetObjectName(&sf);
  1351. }
  1352. // Compute per-source, per-config information.
  1353. for (std::vector<std::string>::const_iterator i = configs.begin();
  1354. i != configs.end(); ++i) {
  1355. std::string configUpper = cmSystemTools::UpperCase(*i);
  1356. cmLVS7GFileConfig fc;
  1357. bool needfc = false;
  1358. if (!objectName.empty()) {
  1359. fc.ObjectName = objectName;
  1360. needfc = true;
  1361. }
  1362. if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
  1363. cmGeneratorExpression ge;
  1364. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(cflags);
  1365. fc.CompileFlags = cge->Evaluate(lg, *i);
  1366. needfc = true;
  1367. }
  1368. if (lg->FortranProject) {
  1369. switch (cmOutputConverter::GetFortranFormat(
  1370. sf.GetProperty("Fortran_FORMAT"))) {
  1371. case cmOutputConverter::FortranFormatFixed:
  1372. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1373. needfc = true;
  1374. break;
  1375. case cmOutputConverter::FortranFormatFree:
  1376. fc.CompileFlags = "-free " + fc.CompileFlags;
  1377. needfc = true;
  1378. break;
  1379. default:
  1380. break;
  1381. }
  1382. }
  1383. if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  1384. fc.CompileDefs = cdefs;
  1385. needfc = true;
  1386. }
  1387. std::string defPropName = "COMPILE_DEFINITIONS_";
  1388. defPropName += configUpper;
  1389. if (const char* ccdefs = sf.GetProperty(defPropName.c_str())) {
  1390. fc.CompileDefsConfig = ccdefs;
  1391. needfc = true;
  1392. }
  1393. // Check for extra object-file dependencies.
  1394. if (const char* deps = sf.GetProperty("OBJECT_DEPENDS")) {
  1395. std::vector<std::string> depends;
  1396. cmSystemTools::ExpandListArgument(deps, depends);
  1397. const char* sep = "";
  1398. for (std::vector<std::string>::iterator j = depends.begin();
  1399. j != depends.end(); ++j) {
  1400. fc.AdditionalDeps += sep;
  1401. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1402. sep = ";";
  1403. needfc = true;
  1404. }
  1405. }
  1406. std::string lang =
  1407. lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  1408. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1409. const std::string& linkLanguage = gt->GetLinkerLanguage(i->c_str());
  1410. bool needForceLang = false;
  1411. // source file does not match its extension language
  1412. if (lang != sourceLang) {
  1413. needForceLang = true;
  1414. lang = sourceLang;
  1415. }
  1416. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1417. // the project file
  1418. fc.ExcludedFromBuild = (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1419. if (fc.ExcludedFromBuild) {
  1420. needfc = true;
  1421. }
  1422. // if the source file does not match the linker language
  1423. // then force c or c++
  1424. if (needForceLang || (linkLanguage != lang)) {
  1425. if (lang == "CXX") {
  1426. // force a C++ file type
  1427. fc.CompileFlags += " /TP ";
  1428. needfc = true;
  1429. } else if (lang == "C") {
  1430. // force to c
  1431. fc.CompileFlags += " /TC ";
  1432. needfc = true;
  1433. }
  1434. }
  1435. if (needfc) {
  1436. this->FileConfigMap[*i] = fc;
  1437. }
  1438. }
  1439. }
  1440. std::string cmLocalVisualStudio7Generator::ComputeLongestObjectDirectory(
  1441. cmGeneratorTarget const* target) const
  1442. {
  1443. std::vector<std::string> configs;
  1444. target->Target->GetMakefile()->GetConfigurations(configs);
  1445. // Compute the maximum length configuration name.
  1446. std::string config_max;
  1447. for (std::vector<std::string>::iterator i = configs.begin();
  1448. i != configs.end(); ++i) {
  1449. if (i->size() > config_max.size()) {
  1450. config_max = *i;
  1451. }
  1452. }
  1453. // Compute the maximum length full path to the intermediate
  1454. // files directory for any configuration. This is used to construct
  1455. // object file names that do not produce paths that are too long.
  1456. std::string dir_max;
  1457. dir_max += this->GetCurrentBinaryDirectory();
  1458. dir_max += "/";
  1459. dir_max += this->GetTargetDirectory(target);
  1460. dir_max += "/";
  1461. dir_max += config_max;
  1462. dir_max += "/";
  1463. return dir_max;
  1464. }
  1465. bool cmLocalVisualStudio7Generator::WriteGroup(
  1466. const cmSourceGroup* sg, cmGeneratorTarget* target, std::ostream& fout,
  1467. const std::string& libName, std::vector<std::string> const& configs)
  1468. {
  1469. cmGlobalVisualStudio7Generator* gg =
  1470. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1471. const std::vector<const cmSourceFile*>& sourceFiles = sg->GetSourceFiles();
  1472. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1473. // Write the children to temporary output.
  1474. bool hasChildrenWithSources = false;
  1475. std::ostringstream tmpOut;
  1476. for (unsigned int i = 0; i < children.size(); ++i) {
  1477. if (this->WriteGroup(&children[i], target, tmpOut, libName, configs)) {
  1478. hasChildrenWithSources = true;
  1479. }
  1480. }
  1481. // If the group is empty, don't write it at all.
  1482. if (sourceFiles.empty() && !hasChildrenWithSources) {
  1483. return false;
  1484. }
  1485. // If the group has a name, write the header.
  1486. std::string name = sg->GetName();
  1487. if (name != "") {
  1488. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1489. }
  1490. // Loop through each source in the source group.
  1491. for (std::vector<const cmSourceFile*>::const_iterator sf =
  1492. sourceFiles.begin();
  1493. sf != sourceFiles.end(); ++sf) {
  1494. std::string source = (*sf)->GetFullPath();
  1495. FCInfo fcinfo(this, target, *(*sf), configs);
  1496. if (source != libName || target->GetType() == cmStateEnums::UTILITY ||
  1497. target->GetType() == cmStateEnums::GLOBAL_TARGET) {
  1498. fout << "\t\t\t<File\n";
  1499. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1500. // Tell MS-Dev what the source is. If the compiler knows how to
  1501. // build it, then it will.
  1502. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1503. if (cmCustomCommand const* command = (*sf)->GetCustomCommand()) {
  1504. this->WriteCustomRule(fout, configs, source.c_str(), *command, fcinfo);
  1505. } else if (!fcinfo.FileConfigMap.empty()) {
  1506. const char* aCompilerTool = "VCCLCompilerTool";
  1507. const char* ppLang = "CXX";
  1508. if (this->FortranProject) {
  1509. aCompilerTool = "VFFortranCompilerTool";
  1510. }
  1511. std::string const& lang = (*sf)->GetLanguage();
  1512. std::string ext = (*sf)->GetExtension();
  1513. ext = cmSystemTools::LowerCase(ext);
  1514. if (ext == "idl") {
  1515. aCompilerTool = "VCMIDLTool";
  1516. if (this->FortranProject) {
  1517. aCompilerTool = "VFMIDLTool";
  1518. }
  1519. }
  1520. if (ext == "rc") {
  1521. aCompilerTool = "VCResourceCompilerTool";
  1522. ppLang = "RC";
  1523. if (this->FortranProject) {
  1524. aCompilerTool = "VFResourceCompilerTool";
  1525. }
  1526. }
  1527. if (ext == "def") {
  1528. aCompilerTool = "VCCustomBuildTool";
  1529. if (this->FortranProject) {
  1530. aCompilerTool = "VFCustomBuildTool";
  1531. }
  1532. }
  1533. if (gg->IsMasmEnabled() && !this->FortranProject &&
  1534. lang == "ASM_MASM") {
  1535. aCompilerTool = "MASM";
  1536. }
  1537. for (std::map<std::string, cmLVS7GFileConfig>::const_iterator fci =
  1538. fcinfo.FileConfigMap.begin();
  1539. fci != fcinfo.FileConfigMap.end(); ++fci) {
  1540. cmLVS7GFileConfig const& fc = fci->second;
  1541. fout << "\t\t\t\t<FileConfiguration\n"
  1542. << "\t\t\t\t\tName=\"" << fci->first << "|"
  1543. << gg->GetPlatformName() << "\"";
  1544. if (fc.ExcludedFromBuild) {
  1545. fout << " ExcludedFromBuild=\"true\"";
  1546. }
  1547. fout << ">\n";
  1548. fout << "\t\t\t\t\t<Tool\n"
  1549. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1550. if (!fc.CompileFlags.empty() || !fc.CompileDefs.empty() ||
  1551. !fc.CompileDefsConfig.empty()) {
  1552. Options::Tool tool = Options::Compiler;
  1553. cmVS7FlagTable const* table =
  1554. cmLocalVisualStudio7GeneratorFlagTable;
  1555. if (this->FortranProject) {
  1556. tool = Options::FortranCompiler;
  1557. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1558. }
  1559. Options fileOptions(this, tool, table, gg->ExtraFlagTable);
  1560. fileOptions.Parse(fc.CompileFlags.c_str());
  1561. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1562. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1563. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1564. fileOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t\t", "\n",
  1565. ppLang);
  1566. }
  1567. if (!fc.AdditionalDeps.empty()) {
  1568. fout << "\t\t\t\t\tAdditionalDependencies=\"" << fc.AdditionalDeps
  1569. << "\"\n";
  1570. }
  1571. if (!fc.ObjectName.empty()) {
  1572. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/" << fc.ObjectName
  1573. << "\"\n";
  1574. }
  1575. fout << "\t\t\t\t\t/>\n"
  1576. << "\t\t\t\t</FileConfiguration>\n";
  1577. }
  1578. }
  1579. fout << "\t\t\t</File>\n";
  1580. }
  1581. }
  1582. // If the group has children with source files, write the children.
  1583. if (hasChildrenWithSources) {
  1584. fout << tmpOut.str();
  1585. }
  1586. // If the group has a name, write the footer.
  1587. if (name != "") {
  1588. this->WriteVCProjEndGroup(fout);
  1589. }
  1590. return true;
  1591. }
  1592. void cmLocalVisualStudio7Generator::WriteCustomRule(
  1593. std::ostream& fout, std::vector<std::string> const& configs,
  1594. const char* source, const cmCustomCommand& command, FCInfo& fcinfo)
  1595. {
  1596. cmGlobalVisualStudio7Generator* gg =
  1597. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1598. // Write the rule for each configuration.
  1599. const char* compileTool = "VCCLCompilerTool";
  1600. if (this->FortranProject) {
  1601. compileTool = "VFCLCompilerTool";
  1602. }
  1603. const char* customTool = "VCCustomBuildTool";
  1604. if (this->FortranProject) {
  1605. customTool = "VFCustomBuildTool";
  1606. }
  1607. for (std::vector<std::string>::const_iterator i = configs.begin();
  1608. i != configs.end(); ++i) {
  1609. cmCustomCommandGenerator ccg(command, *i, this);
  1610. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1611. fout << "\t\t\t\t<FileConfiguration\n";
  1612. fout << "\t\t\t\t\tName=\"" << *i << "|" << gg->GetPlatformName()
  1613. << "\">\n";
  1614. if (!fc.CompileFlags.empty()) {
  1615. fout << "\t\t\t\t\t<Tool\n"
  1616. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1617. << "\t\t\t\t\tAdditionalOptions=\""
  1618. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1619. }
  1620. std::string comment = this->ConstructComment(ccg);
  1621. std::string script = this->ConstructScript(ccg);
  1622. if (this->FortranProject) {
  1623. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1624. }
  1625. /* clang-format off */
  1626. fout << "\t\t\t\t\t<Tool\n"
  1627. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1628. << "\t\t\t\t\tDescription=\""
  1629. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1630. << "\t\t\t\t\tCommandLine=\""
  1631. << this->EscapeForXML(script.c_str()) << "\"\n"
  1632. << "\t\t\t\t\tAdditionalDependencies=\"";
  1633. /* clang-format on */
  1634. if (ccg.GetDepends().empty()) {
  1635. // There are no real dependencies. Produce an artificial one to
  1636. // make sure the rule runs reliably.
  1637. if (!cmSystemTools::FileExists(source)) {
  1638. cmsys::ofstream depout(source);
  1639. depout << "Artificial dependency for a custom command.\n";
  1640. }
  1641. fout << this->ConvertToXMLOutputPath(source);
  1642. } else {
  1643. // Write out the dependencies for the rule.
  1644. for (std::vector<std::string>::const_iterator d =
  1645. ccg.GetDepends().begin();
  1646. d != ccg.GetDepends().end(); ++d) {
  1647. // Get the real name of the dependency in case it is a CMake target.
  1648. std::string dep;
  1649. if (this->GetRealDependency(d->c_str(), i->c_str(), dep)) {
  1650. fout << this->ConvertToXMLOutputPath(dep.c_str()) << ";";
  1651. }
  1652. }
  1653. }
  1654. fout << "\"\n";
  1655. fout << "\t\t\t\t\tOutputs=\"";
  1656. if (ccg.GetOutputs().empty()) {
  1657. fout << source << "_force";
  1658. } else {
  1659. // Write a rule for the output generated by this command.
  1660. const char* sep = "";
  1661. for (std::vector<std::string>::const_iterator o =
  1662. ccg.GetOutputs().begin();
  1663. o != ccg.GetOutputs().end(); ++o) {
  1664. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1665. sep = ";";
  1666. }
  1667. }
  1668. fout << "\"/>\n";
  1669. fout << "\t\t\t\t</FileConfiguration>\n";
  1670. }
  1671. }
  1672. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1673. const char* group,
  1674. const char*)
  1675. {
  1676. /* clang-format off */
  1677. fout << "\t\t<Filter\n"
  1678. << "\t\t\tName=\"" << group << "\"\n"
  1679. << "\t\t\tFilter=\"\">\n";
  1680. /* clang-format on */
  1681. }
  1682. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1683. {
  1684. fout << "\t\t</Filter>\n";
  1685. }
  1686. // look for custom rules on a target and collect them together
  1687. void cmLocalVisualStudio7Generator::OutputTargetRules(
  1688. std::ostream& fout, const std::string& configName, cmGeneratorTarget* target,
  1689. const std::string& /*libName*/)
  1690. {
  1691. if (target->GetType() > cmStateEnums::GLOBAL_TARGET) {
  1692. return;
  1693. }
  1694. EventWriter event(this, configName, fout);
  1695. // Add pre-build event.
  1696. const char* tool =
  1697. this->FortranProject ? "VFPreBuildEventTool" : "VCPreBuildEventTool";
  1698. event.Start(tool);
  1699. event.Write(target->GetPreBuildCommands());
  1700. event.Finish();
  1701. // Add pre-link event.
  1702. tool = this->FortranProject ? "VFPreLinkEventTool" : "VCPreLinkEventTool";
  1703. event.Start(tool);
  1704. bool addedPrelink = false;
  1705. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  1706. target->GetModuleDefinitionInfo(configName);
  1707. if (mdi && mdi->DefFileGenerated) {
  1708. addedPrelink = true;
  1709. std::vector<cmCustomCommand> commands = target->GetPreLinkCommands();
  1710. cmGlobalVisualStudioGenerator* gg =
  1711. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  1712. gg->AddSymbolExportCommand(target, commands, configName);
  1713. event.Write(commands);
  1714. }
  1715. if (!addedPrelink) {
  1716. event.Write(target->GetPreLinkCommands());
  1717. }
  1718. CM_AUTO_PTR<cmCustomCommand> pcc(
  1719. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1720. if (pcc.get()) {
  1721. event.Write(*pcc);
  1722. }
  1723. event.Finish();
  1724. // Add post-build event.
  1725. tool =
  1726. this->FortranProject ? "VFPostBuildEventTool" : "VCPostBuildEventTool";
  1727. event.Start(tool);
  1728. event.Write(target->GetPostBuildCommands());
  1729. event.Finish();
  1730. }
  1731. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1732. cmGeneratorTarget* target)
  1733. {
  1734. // if we have all the required Source code control tags
  1735. // then add that to the project
  1736. const char* vsProjectname = target->GetProperty("VS_SCC_PROJECTNAME");
  1737. const char* vsLocalpath = target->GetProperty("VS_SCC_LOCALPATH");
  1738. const char* vsProvider = target->GetProperty("VS_SCC_PROVIDER");
  1739. if (vsProvider && vsLocalpath && vsProjectname) {
  1740. /* clang-format off */
  1741. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1742. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1743. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1744. /* clang-format on */
  1745. const char* vsAuxPath = target->GetProperty("VS_SCC_AUXPATH");
  1746. if (vsAuxPath) {
  1747. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1748. }
  1749. }
  1750. }
  1751. void cmLocalVisualStudio7Generator::WriteProjectStartFortran(
  1752. std::ostream& fout, const std::string& libName, cmGeneratorTarget* target)
  1753. {
  1754. cmGlobalVisualStudio7Generator* gg =
  1755. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1756. /* clang-format off */
  1757. fout << "<?xml version=\"1.0\" encoding = \""
  1758. << gg->Encoding() << "\"?>\n"
  1759. << "<VisualStudioProject\n"
  1760. << "\tProjectCreator=\"Intel Fortran\"\n"
  1761. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  1762. /* clang-format on */
  1763. const char* keyword = target->GetProperty("VS_KEYWORD");
  1764. if (!keyword) {
  1765. keyword = "Console Application";
  1766. }
  1767. const char* projectType = 0;
  1768. switch (target->GetType()) {
  1769. case cmStateEnums::STATIC_LIBRARY:
  1770. projectType = "typeStaticLibrary";
  1771. if (keyword) {
  1772. keyword = "Static Library";
  1773. }
  1774. break;
  1775. case cmStateEnums::SHARED_LIBRARY:
  1776. case cmStateEnums::MODULE_LIBRARY:
  1777. projectType = "typeDynamicLibrary";
  1778. if (!keyword) {
  1779. keyword = "Dll";
  1780. }
  1781. break;
  1782. case cmStateEnums::EXECUTABLE:
  1783. if (!keyword) {
  1784. keyword = "Console Application";
  1785. }
  1786. projectType = 0;
  1787. break;
  1788. case cmStateEnums::UTILITY:
  1789. case cmStateEnums::GLOBAL_TARGET:
  1790. default:
  1791. break;
  1792. }
  1793. if (projectType) {
  1794. fout << "\tProjectType=\"" << projectType << "\"\n";
  1795. }
  1796. this->WriteProjectSCC(fout, target);
  1797. /* clang-format off */
  1798. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1799. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  1800. << "\t<Platforms>\n"
  1801. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1802. << "\t</Platforms>\n";
  1803. /* clang-format on */
  1804. }
  1805. void cmLocalVisualStudio7Generator::WriteProjectStart(
  1806. std::ostream& fout, const std::string& libName, cmGeneratorTarget* target,
  1807. std::vector<cmSourceGroup>&)
  1808. {
  1809. if (this->FortranProject) {
  1810. this->WriteProjectStartFortran(fout, libName, target);
  1811. return;
  1812. }
  1813. cmGlobalVisualStudio7Generator* gg =
  1814. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1815. /* clang-format off */
  1816. fout << "<?xml version=\"1.0\" encoding = \""
  1817. << gg->Encoding() << "\"?>\n"
  1818. << "<VisualStudioProject\n"
  1819. << "\tProjectType=\"Visual C++\"\n";
  1820. /* clang-format on */
  1821. if (gg->GetVersion() == cmGlobalVisualStudioGenerator::VS71) {
  1822. fout << "\tVersion=\"7.10\"\n";
  1823. } else {
  1824. fout << "\tVersion=\"" << (gg->GetVersion() / 10) << ".00\"\n";
  1825. }
  1826. const char* projLabel = target->GetProperty("PROJECT_LABEL");
  1827. if (!projLabel) {
  1828. projLabel = libName.c_str();
  1829. }
  1830. const char* keyword = target->GetProperty("VS_KEYWORD");
  1831. if (!keyword) {
  1832. keyword = "Win32Proj";
  1833. }
  1834. fout << "\tName=\"" << projLabel << "\"\n";
  1835. if (gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS8) {
  1836. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  1837. }
  1838. this->WriteProjectSCC(fout, target);
  1839. if (const char* targetFrameworkVersion =
  1840. target->GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION")) {
  1841. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  1842. }
  1843. /* clang-format off */
  1844. fout << "\tKeyword=\"" << keyword << "\">\n"
  1845. << "\t<Platforms>\n"
  1846. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1847. << "\t</Platforms>\n";
  1848. /* clang-format on */
  1849. if (gg->IsMasmEnabled()) {
  1850. /* clang-format off */
  1851. fout <<
  1852. "\t<ToolFiles>\n"
  1853. "\t\t<DefaultToolFile\n"
  1854. "\t\t\tFileName=\"masm.rules\"\n"
  1855. "\t\t/>\n"
  1856. "\t</ToolFiles>\n"
  1857. ;
  1858. /* clang-format on */
  1859. }
  1860. }
  1861. void cmLocalVisualStudio7Generator::WriteVCProjFooter(
  1862. std::ostream& fout, cmGeneratorTarget* target)
  1863. {
  1864. fout << "\t<Globals>\n";
  1865. std::vector<std::string> const& props = target->GetPropertyKeys();
  1866. for (std::vector<std::string>::const_iterator i = props.begin();
  1867. i != props.end(); ++i) {
  1868. if (i->find("VS_GLOBAL_") == 0) {
  1869. std::string name = i->substr(10);
  1870. if (name != "") {
  1871. /* clang-format off */
  1872. fout << "\t\t<Global\n"
  1873. << "\t\t\tName=\"" << name << "\"\n"
  1874. << "\t\t\tValue=\"" << target->GetProperty(*i) << "\"\n"
  1875. << "\t\t/>\n";
  1876. /* clang-format on */
  1877. }
  1878. }
  1879. }
  1880. fout << "\t</Globals>\n"
  1881. << "</VisualStudioProject>\n";
  1882. }
  1883. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
  1884. {
  1885. std::string ret = s;
  1886. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1887. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1888. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1889. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1890. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1891. return ret;
  1892. }
  1893. std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
  1894. {
  1895. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1896. }
  1897. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(
  1898. const char* path)
  1899. {
  1900. std::string ret =
  1901. this->ConvertToOutputFormat(path, cmOutputConverter::SHELL);
  1902. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1903. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1904. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1905. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1906. return ret;
  1907. }
  1908. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(
  1909. const char* path)
  1910. {
  1911. std::string ret =
  1912. this->ConvertToOutputFormat(path, cmOutputConverter::SHELL);
  1913. cmSystemTools::ReplaceString(ret, "\"", "");
  1914. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1915. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1916. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1917. return ret;
  1918. }
  1919. // This class is used to parse an existing vs 7 project
  1920. // and extract the GUID
  1921. class cmVS7XMLParser : public cmXMLParser
  1922. {
  1923. public:
  1924. virtual void EndElement(const std::string& /* name */) {}
  1925. virtual void StartElement(const std::string& name, const char** atts)
  1926. {
  1927. // once the GUID is found do nothing
  1928. if (!this->GUID.empty()) {
  1929. return;
  1930. }
  1931. int i = 0;
  1932. if ("VisualStudioProject" == name) {
  1933. while (atts[i]) {
  1934. if (strcmp(atts[i], "ProjectGUID") == 0) {
  1935. if (atts[i + 1]) {
  1936. this->GUID = atts[i + 1];
  1937. this->GUID = this->GUID.substr(1, this->GUID.size() - 2);
  1938. } else {
  1939. this->GUID = "";
  1940. }
  1941. return;
  1942. }
  1943. ++i;
  1944. }
  1945. }
  1946. }
  1947. int InitializeParser()
  1948. {
  1949. int ret = cmXMLParser::InitializeParser();
  1950. if (ret == 0) {
  1951. return ret;
  1952. }
  1953. // visual studio projects have a strange encoding, but it is
  1954. // really utf-8
  1955. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  1956. return 1;
  1957. }
  1958. std::string GUID;
  1959. };
  1960. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  1961. const std::string& name, const char* path)
  1962. {
  1963. cmVS7XMLParser parser;
  1964. parser.ParseFile(path);
  1965. // if we can not find a GUID then we will generate one later
  1966. if (parser.GUID.empty()) {
  1967. return;
  1968. }
  1969. std::string guidStoreName = name;
  1970. guidStoreName += "_GUID_CMAKE";
  1971. // save the GUID in the cache
  1972. this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
  1973. guidStoreName.c_str(), parser.GUID.c_str(), "Stored GUID",
  1974. cmStateEnums::INTERNAL);
  1975. }
  1976. std::string cmLocalVisualStudio7Generator::GetTargetDirectory(
  1977. cmGeneratorTarget const* target) const
  1978. {
  1979. std::string dir;
  1980. dir += target->GetName();
  1981. dir += ".dir";
  1982. return dir;
  1983. }
  1984. static bool cmLVS7G_IsFAT(const char* dir)
  1985. {
  1986. if (dir[0] && dir[1] == ':') {
  1987. char volRoot[4] = "_:/";
  1988. volRoot[0] = dir[0];
  1989. char fsName[16];
  1990. if (GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  1991. strstr(fsName, "FAT") != 0) {
  1992. return true;
  1993. }
  1994. }
  1995. return false;
  1996. }