cmLocalVisualStudio7Generator.cxx 75 KB

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