cmLocalVisualStudio7Generator.cxx 79 KB

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