cmLocalVisualStudio7Generator.cxx 79 KB

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