cmLocalVisualStudio7Generator.cxx 75 KB

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