cmLocalVisualStudio7Generator.cxx 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238
  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. // boolean flags
  444. {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE", 0},
  445. {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "FALSE", 0},
  446. {"Detect64BitPortabilityProblems", "Wp64",
  447. "Detect 64-bit Portability Problems", "TRUE", 0},
  448. {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
  449. "TRUE", 0},
  450. {"EnableFunctionLevelLinking", "Gy",
  451. "EnableFunctionLevelLinking", "TRUE", 0},
  452. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE", 0},
  453. {"GlobalOptimizations", "Og", "Global Optimize", "TRUE", 0},
  454. {"ImproveFloatingPointConsistency", "Op",
  455. "ImproveFloatingPointConsistency", "TRUE", 0},
  456. {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE", 0},
  457. {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE", 0},
  458. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE", 0},
  459. {"RuntimeTypeInfo", "GR",
  460. "Turn on Run time type information for c++", "TRUE", 0},
  461. {"RuntimeTypeInfo", "GR-",
  462. "Turn off Run time type information for c++", "FALSE", 0},
  463. {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE", 0},
  464. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "TRUE", 0},
  465. {"WholeProgramOptimization", "GL",
  466. "Enables whole program optimization", "TRUE", 0},
  467. {"WholeProgramOptimization", "GL-",
  468. "Disables whole program optimization", "FALSE", 0},
  469. {"WarnAsError", "WX", "Treat warnings as errors", "TRUE", 0},
  470. {"BrowseInformation", "FR", "Generate browse information", "1", 0},
  471. {"StringPooling", "GF", "Enable StringPooling", "TRUE", 0},
  472. {0,0,0,0,0}
  473. };
  474. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  475. {
  476. // option flags (some flags map to the same option)
  477. {"GenerateManifest", "MANIFEST:NO",
  478. "disable manifest generation", "FALSE", 0},
  479. {"GenerateManifest", "MANIFEST", "enable manifest generation", "TRUE", 0},
  480. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
  481. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
  482. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
  483. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
  484. {"DataExecutionPrevention", "NXCOMPAT:NO",
  485. "Not known to work with Windows Data Execution Prevention", "1", 0},
  486. {"DataExecutionPrevention", "NXCOMPAT",
  487. "Known to work with Windows Data Execution Prevention", "2", 0},
  488. {"DelaySign", "DELAYSIGN:NO", "", "false", 0},
  489. {"DelaySign", "DELAYSIGN", "", "true", 0},
  490. {"EntryPointSymbol", "ENTRY:", "sets the starting address", "",
  491. cmVS7FlagTable::UserValue},
  492. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  493. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  494. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  495. "TRUE", 0},
  496. {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
  497. {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
  498. "2", 0},
  499. {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
  500. "1", 0},
  501. {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
  502. {"ResourceOnlyDLL", "NOENTRY", "Create DLL with no entry point", "true", 0},
  503. {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
  504. {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
  505. {"Profile", "PROFILE", "", "true", 0},
  506. {"RandomizedBaseAddress", "DYNAMICBASE:NO",
  507. "Image may not be rebased at load-time", "1", 0},
  508. {"RandomizedBaseAddress", "DYNAMICBASE",
  509. "Image may be rebased at load-time", "2", 0},
  510. {"SetChecksum", "RELEASE", "Enable setting checksum in header", "true", 0},
  511. {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
  512. {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
  513. {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
  514. {"TargetMachine", "MACHINE:AM33", "Machine AM33", "2", 0},
  515. {"TargetMachine", "MACHINE:ARM", "Machine ARM", "3", 0},
  516. {"TargetMachine", "MACHINE:EBC", "Machine EBC", "4", 0},
  517. {"TargetMachine", "MACHINE:IA64", "Machine IA64", "5", 0},
  518. {"TargetMachine", "MACHINE:M32R", "Machine M32R", "6", 0},
  519. {"TargetMachine", "MACHINE:MIPS", "Machine MIPS", "7", 0},
  520. {"TargetMachine", "MACHINE:MIPS16", "Machine MIPS16", "8", 0},
  521. {"TargetMachine", "MACHINE:MIPSFPU)", "Machine MIPSFPU", "9", 0},
  522. {"TargetMachine", "MACHINE:MIPSFPU16", "Machine MIPSFPU16", "10", 0},
  523. {"TargetMachine", "MACHINE:MIPSR41XX", "Machine MIPSR41XX", "11", 0},
  524. {"TargetMachine", "MACHINE:SH3", "Machine SH3", "12", 0},
  525. {"TargetMachine", "MACHINE:SH3DSP", "Machine SH3DSP", "13", 0},
  526. {"TargetMachine", "MACHINE:SH4", "Machine SH4", "14", 0},
  527. {"TargetMachine", "MACHINE:SH5", "Machine SH5", "15", 0},
  528. {"TargetMachine", "MACHINE:THUMB", "Machine THUMB", "16", 0},
  529. {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
  530. {"TurnOffAssemblyGeneration", "NOASSEMBLY",
  531. "No assembly even if CLR information is present in objects.", "true", 0},
  532. {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
  533. cmVS7FlagTable::UserValue},
  534. {"GenerateMapFile", "MAP", "enable generation of map file", "TRUE", 0},
  535. {0,0,0,0,0}
  536. };
  537. //----------------------------------------------------------------------------
  538. // Helper class to write build event <Tool .../> elements.
  539. class cmLocalVisualStudio7Generator::EventWriter
  540. {
  541. public:
  542. EventWriter(cmLocalVisualStudio7Generator* lg,
  543. const char* config, std::ostream& os):
  544. LG(lg), Config(config), Stream(os), First(true) {}
  545. void Start(const char* tool)
  546. {
  547. this->First = true;
  548. this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
  549. }
  550. void Finish()
  551. {
  552. this->Stream << (this->First? "" : "\"") << "/>\n";
  553. }
  554. void Write(std::vector<cmCustomCommand> const& ccs)
  555. {
  556. for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  557. ci != ccs.end(); ++ci)
  558. {
  559. this->Write(*ci);
  560. }
  561. }
  562. void Write(cmCustomCommand const& cc)
  563. {
  564. if(this->First)
  565. {
  566. const char* comment = cc.GetComment();
  567. if(comment && *comment)
  568. {
  569. this->Stream << "\nDescription=\""
  570. << this->LG->EscapeForXML(comment) << "\"";
  571. }
  572. this->Stream << "\nCommandLine=\"";
  573. this->First = false;
  574. }
  575. else
  576. {
  577. this->Stream << this->LG->EscapeForXML("\n");
  578. }
  579. std::string script = this->LG->ConstructScript(cc, this->Config);
  580. this->Stream << this->LG->EscapeForXML(script.c_str());
  581. }
  582. private:
  583. cmLocalVisualStudio7Generator* LG;
  584. const char* Config;
  585. std::ostream& Stream;
  586. bool First;
  587. };
  588. //----------------------------------------------------------------------------
  589. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  590. const char* configName,
  591. const char *libName,
  592. cmTarget &target)
  593. {
  594. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  595. if(!mfcFlag)
  596. {
  597. mfcFlag = "0";
  598. }
  599. fout << "\t\t<Configuration\n"
  600. << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n"
  601. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  602. // This is an internal type to Visual Studio, it seems that:
  603. // 4 == static library
  604. // 2 == dll
  605. // 1 == executable
  606. // 10 == utility
  607. const char* configType = "10";
  608. const char* projectType = 0;
  609. bool targetBuilds = true;
  610. switch(target.GetType())
  611. {
  612. case cmTarget::OBJECT_LIBRARY:
  613. targetBuilds = false; // TODO: PDB for object library?
  614. case cmTarget::STATIC_LIBRARY:
  615. projectType = "typeStaticLibrary";
  616. configType = "4";
  617. break;
  618. case cmTarget::SHARED_LIBRARY:
  619. case cmTarget::MODULE_LIBRARY:
  620. projectType = "typeDynamicLibrary";
  621. configType = "2";
  622. break;
  623. case cmTarget::EXECUTABLE:
  624. configType = "1";
  625. break;
  626. case cmTarget::UTILITY:
  627. case cmTarget::GLOBAL_TARGET:
  628. configType = "10";
  629. default:
  630. targetBuilds = false;
  631. break;
  632. }
  633. if(this->FortranProject && projectType)
  634. {
  635. configType = projectType;
  636. }
  637. std::string flags;
  638. if(strcmp(configType, "10") != 0)
  639. {
  640. const char* linkLanguage = (this->FortranProject? "Fortran":
  641. target.GetLinkerLanguage(configName));
  642. if(!linkLanguage)
  643. {
  644. cmSystemTools::Error
  645. ("CMake can not determine linker language for target: ",
  646. target.GetName());
  647. return;
  648. }
  649. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0
  650. || strcmp(linkLanguage, "Fortran") == 0)
  651. {
  652. std::string baseFlagVar = "CMAKE_";
  653. baseFlagVar += linkLanguage;
  654. baseFlagVar += "_FLAGS";
  655. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  656. std::string flagVar = baseFlagVar + std::string("_") +
  657. cmSystemTools::UpperCase(configName);
  658. flags += " ";
  659. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  660. }
  661. // set the correct language
  662. if(strcmp(linkLanguage, "C") == 0)
  663. {
  664. flags += " /TC ";
  665. }
  666. if(strcmp(linkLanguage, "CXX") == 0)
  667. {
  668. flags += " /TP ";
  669. }
  670. // Add the target-specific flags.
  671. this->AddCompileOptions(flags, &target, linkLanguage, configName);
  672. }
  673. if(this->FortranProject)
  674. {
  675. switch(this->GetFortranFormat(target.GetProperty("Fortran_FORMAT")))
  676. {
  677. case FortranFormatFixed: flags += " -fixed"; break;
  678. case FortranFormatFree: flags += " -free"; break;
  679. default: break;
  680. }
  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. std::string asmLocation = std::string(configName) + "/";
  696. targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  697. targetOptions.Parse(flags.c_str());
  698. targetOptions.Parse(defineFlags.c_str());
  699. targetOptions.ParseFinish();
  700. cmGeneratorTarget* gt =
  701. this->GlobalGenerator->GetGeneratorTarget(&target);
  702. std::vector<std::string> targetDefines;
  703. target.GetCompileDefinitions(targetDefines, configName);
  704. targetOptions.AddDefines(targetDefines);
  705. targetOptions.SetVerboseMakefile(
  706. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  707. // Add a definition for the configuration name.
  708. std::string configDefine = "CMAKE_INTDIR=\"";
  709. configDefine += configName;
  710. configDefine += "\"";
  711. targetOptions.AddDefine(configDefine);
  712. // Add the export symbol definition for shared library objects.
  713. if(const char* exportMacro = target.GetExportMacro())
  714. {
  715. targetOptions.AddDefine(exportMacro);
  716. }
  717. // The intermediate directory name consists of a directory for the
  718. // target and a subdirectory for the configuration name.
  719. std::string intermediateDir = this->GetTargetDirectory(target);
  720. intermediateDir += "/";
  721. intermediateDir += configName;
  722. fout << "\t\t\tIntermediateDirectory=\""
  723. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  724. << "\"\n"
  725. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  726. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  727. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  728. // If unicode is enabled change the character set to unicode, if not
  729. // then default to MBCS.
  730. if(targetOptions.UsingUnicode())
  731. {
  732. fout << "\t\t\tCharacterSet=\"1\">\n";
  733. }
  734. else if(targetOptions.UsingSBCS())
  735. {
  736. fout << "\t\t\tCharacterSet=\"0\">\n";
  737. }
  738. else
  739. {
  740. fout << "\t\t\tCharacterSet=\"2\">\n";
  741. }
  742. const char* tool = "VCCLCompilerTool";
  743. if(this->FortranProject)
  744. {
  745. tool = "VFFortranCompilerTool";
  746. }
  747. fout << "\t\t\t<Tool\n"
  748. << "\t\t\t\tName=\"" << tool << "\"\n";
  749. if(this->FortranProject)
  750. {
  751. const char* target_mod_dir =
  752. target.GetProperty("Fortran_MODULE_DIRECTORY");
  753. std::string modDir;
  754. if(target_mod_dir)
  755. {
  756. modDir = this->Convert(target_mod_dir,
  757. cmLocalGenerator::START_OUTPUT,
  758. cmLocalGenerator::UNCHANGED);
  759. }
  760. else
  761. {
  762. modDir = ".";
  763. }
  764. fout << "\t\t\t\tModulePath=\""
  765. << this->ConvertToXMLOutputPath(modDir.c_str())
  766. << "\\$(ConfigurationName)\"\n";
  767. }
  768. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  769. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  770. std::vector<std::string> includes;
  771. this->GetIncludeDirectories(includes, gt, "C", configName);
  772. std::vector<std::string>::iterator i = includes.begin();
  773. for(;i != includes.end(); ++i)
  774. {
  775. // output the include path
  776. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  777. fout << ipath << ";";
  778. // if this is fortran then output the include with
  779. // a ConfigurationName on the end of it.
  780. if(this->FortranProject)
  781. {
  782. ipath = i->c_str();
  783. ipath += "/$(ConfigurationName)";
  784. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  785. fout << ipath << ";";
  786. }
  787. }
  788. fout << "\"\n";
  789. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  790. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  791. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  792. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  793. tool = "VCCustomBuildTool";
  794. if(this->FortranProject)
  795. {
  796. tool = "VFCustomBuildTool";
  797. }
  798. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  799. tool = "VCResourceCompilerTool";
  800. if(this->FortranProject)
  801. {
  802. tool = "VFResourceCompilerTool";
  803. }
  804. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  805. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  806. for(i = includes.begin();i != includes.end(); ++i)
  807. {
  808. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  809. fout << ipath << ";";
  810. }
  811. // add the -D flags to the RC tool
  812. fout << "\"";
  813. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  814. fout << "/>\n";
  815. tool = "VCMIDLTool";
  816. if(this->FortranProject)
  817. {
  818. tool = "VFMIDLTool";
  819. }
  820. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  821. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  822. for(i = includes.begin(); i != includes.end(); ++i)
  823. {
  824. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  825. fout << ipath << ";";
  826. }
  827. fout << "\"\n";
  828. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  829. if( this->PlatformName == "x64" )
  830. {
  831. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  832. }
  833. else if( this->PlatformName == "ia64" )
  834. {
  835. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  836. }
  837. else
  838. {
  839. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  840. }
  841. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  842. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  843. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  844. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  845. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  846. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  847. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  848. // end of <Tool Name=VCMIDLTool
  849. // Check if we need the FAT32 workaround.
  850. if(targetBuilds && this->Version >= VS8)
  851. {
  852. // Check the filesystem type where the target will be written.
  853. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  854. {
  855. // Add a flag telling the manifest tool to use a workaround
  856. // for FAT32 file systems, which can cause an empty manifest
  857. // to be embedded into the resulting executable. See CMake
  858. // bug #2617.
  859. const char* manifestTool = "VCManifestTool";
  860. if(this->FortranProject)
  861. {
  862. manifestTool = "VFManifestTool";
  863. }
  864. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << manifestTool << "\"\n"
  865. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  866. << "\t\t\t/>\n";
  867. }
  868. }
  869. this->OutputTargetRules(fout, configName, target, libName);
  870. this->OutputBuildTool(fout, configName, target, targetOptions.IsDebug());
  871. fout << "\t\t</Configuration>\n";
  872. }
  873. //----------------------------------------------------------------------------
  874. std::string
  875. cmLocalVisualStudio7Generator
  876. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  877. {
  878. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  879. std::string extraLinkOptionsBuildTypeDef =
  880. rootLinkerFlags + "_" + configTypeUpper;
  881. std::string extraLinkOptionsBuildType =
  882. this->Makefile->GetRequiredDefinition
  883. (extraLinkOptionsBuildTypeDef.c_str());
  884. return extraLinkOptionsBuildType;
  885. }
  886. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  887. const char* configName,
  888. cmTarget &target,
  889. bool isDebug)
  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(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(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. fout << "\t\t\t\tEntryPointSymbol=\""
  1163. << (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup")
  1164. << "\"\n";
  1165. }
  1166. else if ( this->FortranProject )
  1167. {
  1168. fout << "\t\t\t\tSubSystem=\""
  1169. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1170. << "\"\n";
  1171. }
  1172. else
  1173. {
  1174. fout << "\t\t\t\tSubSystem=\""
  1175. << (isWin32Executable ? "2" : "1")
  1176. << "\"\n";
  1177. }
  1178. std::string stackVar = "CMAKE_";
  1179. stackVar += linkLanguage;
  1180. stackVar += "_STACK_SIZE";
  1181. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1182. if(stackVal)
  1183. {
  1184. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1185. }
  1186. temp = target.GetDirectory(configName, true);
  1187. temp += "/";
  1188. temp += targetNameImport;
  1189. fout << "\t\t\t\tImportLibrary=\""
  1190. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1191. break;
  1192. }
  1193. case cmTarget::UTILITY:
  1194. case cmTarget::GLOBAL_TARGET:
  1195. break;
  1196. }
  1197. }
  1198. //----------------------------------------------------------------------------
  1199. void
  1200. cmLocalVisualStudio7Generator
  1201. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1202. {
  1203. int major;
  1204. int minor;
  1205. target.GetTargetVersion(major, minor);
  1206. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1207. }
  1208. //----------------------------------------------------------------------------
  1209. void
  1210. cmLocalVisualStudio7GeneratorInternals
  1211. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1212. {
  1213. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1214. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1215. {
  1216. if(l->IsPath)
  1217. {
  1218. std::string rel = lg->Convert(l->Value.c_str(),
  1219. cmLocalGenerator::START_OUTPUT,
  1220. cmLocalGenerator::UNCHANGED);
  1221. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1222. }
  1223. else
  1224. {
  1225. fout << l->Value << " ";
  1226. }
  1227. }
  1228. }
  1229. //----------------------------------------------------------------------------
  1230. void
  1231. cmLocalVisualStudio7GeneratorInternals
  1232. ::OutputObjects(std::ostream& fout, cmTarget* t, const char* isep)
  1233. {
  1234. // VS < 8 does not support per-config source locations so we
  1235. // list object library content on the link line instead.
  1236. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1237. cmGeneratorTarget* gt =
  1238. lg->GetGlobalGenerator()->GetGeneratorTarget(t);
  1239. std::vector<std::string> objs;
  1240. gt->UseObjectLibraries(objs);
  1241. const char* sep = isep? isep : "";
  1242. for(std::vector<std::string>::const_iterator
  1243. oi = objs.begin(); oi != objs.end(); ++oi)
  1244. {
  1245. std::string rel = lg->Convert(oi->c_str(),
  1246. cmLocalGenerator::START_OUTPUT,
  1247. cmLocalGenerator::UNCHANGED);
  1248. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1249. sep = " ";
  1250. }
  1251. }
  1252. //----------------------------------------------------------------------------
  1253. void
  1254. cmLocalVisualStudio7Generator
  1255. ::OutputLibraryDirectories(std::ostream& fout,
  1256. std::vector<std::string> const& dirs)
  1257. {
  1258. const char* comma = "";
  1259. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1260. d != dirs.end(); ++d)
  1261. {
  1262. // Remove any trailing slash and skip empty paths.
  1263. std::string dir = *d;
  1264. if(dir[dir.size()-1] == '/')
  1265. {
  1266. dir = dir.substr(0, dir.size()-1);
  1267. }
  1268. if(dir.empty())
  1269. {
  1270. continue;
  1271. }
  1272. // Switch to a relative path specification if it is shorter.
  1273. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1274. {
  1275. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1276. if(rel.size() < dir.size())
  1277. {
  1278. dir = rel;
  1279. }
  1280. }
  1281. // First search a configuration-specific subdirectory and then the
  1282. // original directory.
  1283. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  1284. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1285. comma = ",";
  1286. }
  1287. }
  1288. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1289. const char *libName,
  1290. cmTarget &target)
  1291. {
  1292. // get the configurations
  1293. std::vector<std::string> *configs =
  1294. static_cast<cmGlobalVisualStudio7Generator *>
  1295. (this->GlobalGenerator)->GetConfigurations();
  1296. // We may be modifying the source groups temporarily, so make a copy.
  1297. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1298. // get the classes from the source lists then add them to the groups
  1299. this->ModuleDefinitionFile = "";
  1300. std::vector<cmSourceFile*>const & classes = target.GetSourceFiles();
  1301. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1302. i != classes.end(); i++)
  1303. {
  1304. // Add the file to the list of sources.
  1305. std::string source = (*i)->GetFullPath();
  1306. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1307. {
  1308. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1309. }
  1310. cmSourceGroup& sourceGroup =
  1311. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1312. sourceGroup.AssignSource(*i);
  1313. }
  1314. // open the project
  1315. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1316. // write the configuration information
  1317. this->WriteConfigurations(fout, libName, target);
  1318. fout << "\t<Files>\n";
  1319. // Loop through every source group.
  1320. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1321. {
  1322. cmSourceGroup sg = sourceGroups[i];
  1323. this->WriteGroup(&sg, target, fout, libName, configs);
  1324. }
  1325. if(this->GetVersion() >= VS8)
  1326. {
  1327. // VS >= 8 support per-config source locations so we
  1328. // list object library content as external objects.
  1329. cmGeneratorTarget* gt =
  1330. this->GlobalGenerator->GetGeneratorTarget(&target);
  1331. std::vector<std::string> objs;
  1332. gt->UseObjectLibraries(objs);
  1333. if(!objs.empty())
  1334. {
  1335. // TODO: Separate sub-filter for each object library used?
  1336. fout << "\t\t<Filter Name=\"Object Libraries\">\n";
  1337. for(std::vector<std::string>::const_iterator
  1338. oi = objs.begin(); oi != objs.end(); ++oi)
  1339. {
  1340. std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str());
  1341. fout << "\t\t\t<File RelativePath=\"" << o << "\" />\n";
  1342. }
  1343. fout << "\t\t</Filter>\n";
  1344. }
  1345. }
  1346. fout << "\t</Files>\n";
  1347. // Write the VCProj file's footer.
  1348. this->WriteVCProjFooter(fout, target);
  1349. }
  1350. struct cmLVS7GFileConfig
  1351. {
  1352. std::string ObjectName;
  1353. std::string CompileFlags;
  1354. std::string CompileDefs;
  1355. std::string CompileDefsConfig;
  1356. std::string AdditionalDeps;
  1357. bool ExcludedFromBuild;
  1358. };
  1359. class cmLocalVisualStudio7GeneratorFCInfo
  1360. {
  1361. public:
  1362. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1363. cmTarget& target,
  1364. cmSourceFile const& sf,
  1365. std::vector<std::string>* configs);
  1366. std::map<cmStdString, cmLVS7GFileConfig> FileConfigMap;
  1367. };
  1368. cmLocalVisualStudio7GeneratorFCInfo
  1369. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1370. cmTarget& target,
  1371. cmSourceFile const& sf,
  1372. std::vector<std::string>* configs)
  1373. {
  1374. cmGeneratorTarget* gt =
  1375. lg->GetGlobalGenerator()->GetGeneratorTarget(&target);
  1376. std::string objectName;
  1377. if(gt->ExplicitObjectName.find(&sf) != gt->ExplicitObjectName.end())
  1378. {
  1379. objectName = gt->Objects[&sf];
  1380. }
  1381. // Compute per-source, per-config information.
  1382. for(std::vector<std::string>::iterator i = configs->begin();
  1383. i != configs->end(); ++i)
  1384. {
  1385. std::string configUpper = cmSystemTools::UpperCase(*i);
  1386. cmLVS7GFileConfig fc;
  1387. bool needfc = false;
  1388. if(!objectName.empty())
  1389. {
  1390. fc.ObjectName = objectName;
  1391. needfc = true;
  1392. }
  1393. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1394. {
  1395. fc.CompileFlags = cflags;
  1396. needfc = true;
  1397. }
  1398. if(lg->FortranProject)
  1399. {
  1400. switch(lg->GetFortranFormat(sf.GetProperty("Fortran_FORMAT")))
  1401. {
  1402. case cmLocalGenerator::FortranFormatFixed:
  1403. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1404. needfc = true;
  1405. break;
  1406. case cmLocalGenerator::FortranFormatFree:
  1407. fc.CompileFlags = "-free " + fc.CompileFlags;
  1408. needfc = true;
  1409. break;
  1410. default: break;
  1411. }
  1412. }
  1413. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1414. {
  1415. fc.CompileDefs = cdefs;
  1416. needfc = true;
  1417. }
  1418. std::string defPropName = "COMPILE_DEFINITIONS_";
  1419. defPropName += configUpper;
  1420. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1421. {
  1422. fc.CompileDefsConfig = ccdefs;
  1423. needfc = true;
  1424. }
  1425. // Check for extra object-file dependencies.
  1426. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1427. {
  1428. std::vector<std::string> depends;
  1429. cmSystemTools::ExpandListArgument(deps, depends);
  1430. const char* sep = "";
  1431. for(std::vector<std::string>::iterator j = depends.begin();
  1432. j != depends.end(); ++j)
  1433. {
  1434. fc.AdditionalDeps += sep;
  1435. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1436. sep = ";";
  1437. needfc = true;
  1438. }
  1439. }
  1440. const char* lang =
  1441. lg->GlobalGenerator->GetLanguageFromExtension
  1442. (sf.GetExtension().c_str());
  1443. const char* sourceLang = lg->GetSourceFileLanguage(sf);
  1444. const char* linkLanguage = target.GetLinkerLanguage(i->c_str());
  1445. bool needForceLang = false;
  1446. // source file does not match its extension language
  1447. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  1448. {
  1449. needForceLang = true;
  1450. lang = sourceLang;
  1451. }
  1452. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1453. // the project file
  1454. fc.ExcludedFromBuild =
  1455. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1456. if(fc.ExcludedFromBuild)
  1457. {
  1458. needfc = true;
  1459. }
  1460. // if the source file does not match the linker language
  1461. // then force c or c++
  1462. if(needForceLang || (linkLanguage && lang
  1463. && strcmp(lang, linkLanguage) != 0))
  1464. {
  1465. if(strcmp(lang, "CXX") == 0)
  1466. {
  1467. // force a C++ file type
  1468. fc.CompileFlags += " /TP ";
  1469. needfc = true;
  1470. }
  1471. else if(strcmp(lang, "C") == 0)
  1472. {
  1473. // force to c
  1474. fc.CompileFlags += " /TC ";
  1475. needfc = true;
  1476. }
  1477. }
  1478. if(needfc)
  1479. {
  1480. this->FileConfigMap[*i] = fc;
  1481. }
  1482. }
  1483. }
  1484. //----------------------------------------------------------------------------
  1485. std::string
  1486. cmLocalVisualStudio7Generator
  1487. ::ComputeLongestObjectDirectory(cmTarget& target) const
  1488. {
  1489. std::vector<std::string> *configs =
  1490. static_cast<cmGlobalVisualStudio7Generator *>
  1491. (this->GlobalGenerator)->GetConfigurations();
  1492. // Compute the maximum length configuration name.
  1493. std::string config_max;
  1494. for(std::vector<std::string>::iterator i = configs->begin();
  1495. i != configs->end(); ++i)
  1496. {
  1497. if(i->size() > config_max.size())
  1498. {
  1499. config_max = *i;
  1500. }
  1501. }
  1502. // Compute the maximum length full path to the intermediate
  1503. // files directory for any configuration. This is used to construct
  1504. // object file names that do not produce paths that are too long.
  1505. std::string dir_max;
  1506. dir_max += this->Makefile->GetCurrentOutputDirectory();
  1507. dir_max += "/";
  1508. dir_max += this->GetTargetDirectory(target);
  1509. dir_max += "/";
  1510. dir_max += config_max;
  1511. dir_max += "/";
  1512. return dir_max;
  1513. }
  1514. bool cmLocalVisualStudio7Generator
  1515. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  1516. std::ostream &fout, const char *libName,
  1517. std::vector<std::string> *configs)
  1518. {
  1519. const std::vector<const cmSourceFile *> &sourceFiles =
  1520. sg->GetSourceFiles();
  1521. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1522. // Write the children to temporary output.
  1523. bool hasChildrenWithSources = false;
  1524. cmOStringStream tmpOut;
  1525. for(unsigned int i=0;i<children.size();++i)
  1526. {
  1527. if(this->WriteGroup(&children[i], target, tmpOut, libName, configs))
  1528. {
  1529. hasChildrenWithSources = true;
  1530. }
  1531. }
  1532. // If the group is empty, don't write it at all.
  1533. if(sourceFiles.empty() && !hasChildrenWithSources)
  1534. {
  1535. return false;
  1536. }
  1537. // If the group has a name, write the header.
  1538. std::string name = sg->GetName();
  1539. if(name != "")
  1540. {
  1541. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1542. }
  1543. // Loop through each source in the source group.
  1544. std::string objectName;
  1545. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1546. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1547. {
  1548. std::string source = (*sf)->GetFullPath();
  1549. FCInfo fcinfo(this, target, *(*sf), configs);
  1550. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1551. target.GetType() == cmTarget::GLOBAL_TARGET )
  1552. {
  1553. fout << "\t\t\t<File\n";
  1554. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1555. // Tell MS-Dev what the source is. If the compiler knows how to
  1556. // build it, then it will.
  1557. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1558. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1559. {
  1560. this->WriteCustomRule(fout, source.c_str(), *command, fcinfo);
  1561. }
  1562. else if(!fcinfo.FileConfigMap.empty())
  1563. {
  1564. const char* aCompilerTool = "VCCLCompilerTool";
  1565. const char* lang = "CXX";
  1566. if(this->FortranProject)
  1567. {
  1568. aCompilerTool = "VFFortranCompilerTool";
  1569. }
  1570. std::string ext = (*sf)->GetExtension();
  1571. ext = cmSystemTools::LowerCase(ext);
  1572. if(ext == "idl")
  1573. {
  1574. aCompilerTool = "VCMIDLTool";
  1575. if(this->FortranProject)
  1576. {
  1577. aCompilerTool = "VFMIDLTool";
  1578. }
  1579. }
  1580. if(ext == "rc")
  1581. {
  1582. aCompilerTool = "VCResourceCompilerTool";
  1583. lang = "RC";
  1584. if(this->FortranProject)
  1585. {
  1586. aCompilerTool = "VFResourceCompilerTool";
  1587. }
  1588. }
  1589. if(ext == "def")
  1590. {
  1591. aCompilerTool = "VCCustomBuildTool";
  1592. if(this->FortranProject)
  1593. {
  1594. aCompilerTool = "VFCustomBuildTool";
  1595. }
  1596. }
  1597. for(std::map<cmStdString, cmLVS7GFileConfig>::const_iterator
  1598. fci = fcinfo.FileConfigMap.begin();
  1599. fci != fcinfo.FileConfigMap.end(); ++fci)
  1600. {
  1601. cmLVS7GFileConfig const& fc = fci->second;
  1602. fout << "\t\t\t\t<FileConfiguration\n"
  1603. << "\t\t\t\t\tName=\"" << fci->first
  1604. << "|" << this->PlatformName << "\"";
  1605. if(fc.ExcludedFromBuild)
  1606. {
  1607. fout << " ExcludedFromBuild=\"true\"";
  1608. }
  1609. fout << ">\n";
  1610. fout << "\t\t\t\t\t<Tool\n"
  1611. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1612. if(!fc.CompileFlags.empty() ||
  1613. !fc.CompileDefs.empty() ||
  1614. !fc.CompileDefsConfig.empty())
  1615. {
  1616. Options::Tool tool = Options::Compiler;
  1617. cmVS7FlagTable const* table =
  1618. cmLocalVisualStudio7GeneratorFlagTable;
  1619. if(this->FortranProject)
  1620. {
  1621. tool = Options::FortranCompiler;
  1622. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1623. }
  1624. Options fileOptions(this, tool, table,
  1625. this->ExtraFlagTable);
  1626. fileOptions.Parse(fc.CompileFlags.c_str());
  1627. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1628. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1629. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1630. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1631. fileOptions.OutputPreprocessorDefinitions(fout,
  1632. "\t\t\t\t\t", "\n",
  1633. lang);
  1634. }
  1635. if(!fc.AdditionalDeps.empty())
  1636. {
  1637. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1638. << fc.AdditionalDeps.c_str() << "\"\n";
  1639. }
  1640. if(!fc.ObjectName.empty())
  1641. {
  1642. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1643. << fc.ObjectName.c_str() << "\"\n";
  1644. }
  1645. fout << "\t\t\t\t\t/>\n"
  1646. << "\t\t\t\t</FileConfiguration>\n";
  1647. }
  1648. }
  1649. fout << "\t\t\t</File>\n";
  1650. }
  1651. }
  1652. // If the group has children with source files, write the children.
  1653. if(hasChildrenWithSources)
  1654. {
  1655. fout << tmpOut.str();
  1656. }
  1657. // If the group has a name, write the footer.
  1658. if(name != "")
  1659. {
  1660. this->WriteVCProjEndGroup(fout);
  1661. }
  1662. return true;
  1663. }
  1664. void cmLocalVisualStudio7Generator::
  1665. WriteCustomRule(std::ostream& fout,
  1666. const char* source,
  1667. const cmCustomCommand& command,
  1668. FCInfo& fcinfo)
  1669. {
  1670. std::string comment = this->ConstructComment(command);
  1671. // Write the rule for each configuration.
  1672. std::vector<std::string>::iterator i;
  1673. std::vector<std::string> *configs =
  1674. static_cast<cmGlobalVisualStudio7Generator *>
  1675. (this->GlobalGenerator)->GetConfigurations();
  1676. const char* compileTool = "VCCLCompilerTool";
  1677. if(this->FortranProject)
  1678. {
  1679. compileTool = "VFCLCompilerTool";
  1680. }
  1681. const char* customTool = "VCCustomBuildTool";
  1682. if(this->FortranProject)
  1683. {
  1684. customTool = "VFCustomBuildTool";
  1685. }
  1686. for(i = configs->begin(); i != configs->end(); ++i)
  1687. {
  1688. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1689. fout << "\t\t\t\t<FileConfiguration\n";
  1690. fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
  1691. if(!fc.CompileFlags.empty())
  1692. {
  1693. fout << "\t\t\t\t\t<Tool\n"
  1694. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1695. << "\t\t\t\t\tAdditionalOptions=\""
  1696. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1697. }
  1698. std::string script = this->ConstructScript(command, i->c_str());
  1699. if(this->FortranProject)
  1700. {
  1701. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1702. }
  1703. fout << "\t\t\t\t\t<Tool\n"
  1704. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1705. << "\t\t\t\t\tDescription=\""
  1706. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1707. << "\t\t\t\t\tCommandLine=\""
  1708. << this->EscapeForXML(script.c_str()) << "\"\n"
  1709. << "\t\t\t\t\tAdditionalDependencies=\"";
  1710. if(command.GetDepends().empty())
  1711. {
  1712. // There are no real dependencies. Produce an artificial one to
  1713. // make sure the rule runs reliably.
  1714. if(!cmSystemTools::FileExists(source))
  1715. {
  1716. std::ofstream depout(source);
  1717. depout << "Artificial dependency for a custom command.\n";
  1718. }
  1719. fout << this->ConvertToXMLOutputPath(source);
  1720. }
  1721. else
  1722. {
  1723. // Write out the dependencies for the rule.
  1724. for(std::vector<std::string>::const_iterator d =
  1725. command.GetDepends().begin();
  1726. d != command.GetDepends().end();
  1727. ++d)
  1728. {
  1729. // Get the real name of the dependency in case it is a CMake target.
  1730. std::string dep;
  1731. if(this->GetRealDependency(d->c_str(), i->c_str(), dep))
  1732. {
  1733. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1734. << ";";
  1735. }
  1736. }
  1737. }
  1738. fout << "\"\n";
  1739. fout << "\t\t\t\t\tOutputs=\"";
  1740. if(command.GetOutputs().empty())
  1741. {
  1742. fout << source << "_force";
  1743. }
  1744. else
  1745. {
  1746. // Write a rule for the output generated by this command.
  1747. const char* sep = "";
  1748. for(std::vector<std::string>::const_iterator o =
  1749. command.GetOutputs().begin();
  1750. o != command.GetOutputs().end();
  1751. ++o)
  1752. {
  1753. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1754. sep = ";";
  1755. }
  1756. }
  1757. fout << "\"/>\n";
  1758. fout << "\t\t\t\t</FileConfiguration>\n";
  1759. }
  1760. }
  1761. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1762. const char* group,
  1763. const char* )
  1764. {
  1765. fout << "\t\t<Filter\n"
  1766. << "\t\t\tName=\"" << group << "\"\n"
  1767. << "\t\t\tFilter=\"\">\n";
  1768. }
  1769. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1770. {
  1771. fout << "\t\t</Filter>\n";
  1772. }
  1773. // look for custom rules on a target and collect them together
  1774. void cmLocalVisualStudio7Generator
  1775. ::OutputTargetRules(std::ostream& fout,
  1776. const char* configName,
  1777. cmTarget &target,
  1778. const char * /*libName*/)
  1779. {
  1780. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1781. {
  1782. return;
  1783. }
  1784. EventWriter event(this, configName, fout);
  1785. // Add pre-build event.
  1786. const char* tool =
  1787. this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
  1788. event.Start(tool);
  1789. event.Write(target.GetPreBuildCommands());
  1790. event.Finish();
  1791. // Add pre-link event.
  1792. tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
  1793. event.Start(tool);
  1794. event.Write(target.GetPreLinkCommands());
  1795. cmsys::auto_ptr<cmCustomCommand> pcc(
  1796. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1797. if(pcc.get())
  1798. {
  1799. event.Write(*pcc);
  1800. }
  1801. event.Finish();
  1802. // Add post-build event.
  1803. tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
  1804. event.Start(tool);
  1805. event.Write(target.GetPostBuildCommands());
  1806. event.Finish();
  1807. }
  1808. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1809. cmTarget& target)
  1810. {
  1811. // if we have all the required Source code control tags
  1812. // then add that to the project
  1813. const char* vsProjectname = target.GetProperty("VS_SCC_PROJECTNAME");
  1814. const char* vsLocalpath = target.GetProperty("VS_SCC_LOCALPATH");
  1815. const char* vsProvider = target.GetProperty("VS_SCC_PROVIDER");
  1816. if(vsProvider && vsLocalpath && vsProjectname)
  1817. {
  1818. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1819. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1820. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1821. const char* vsAuxPath = target.GetProperty("VS_SCC_AUXPATH");
  1822. if(vsAuxPath)
  1823. {
  1824. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1825. }
  1826. }
  1827. }
  1828. void
  1829. cmLocalVisualStudio7Generator
  1830. ::WriteProjectStartFortran(std::ostream& fout,
  1831. const char *libName,
  1832. cmTarget & target)
  1833. {
  1834. cmGlobalVisualStudio7Generator* gg =
  1835. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1836. // Compute the version of the Intel plugin to the VS IDE.
  1837. // If the key does not exist then use a default guess.
  1838. std::string intelVersion = "9.10";
  1839. std::string vskey = gg->GetRegistryBase();
  1840. vskey += "\\Packages\\" CM_INTEL_PLUGIN_GUID ";ProductVersion";
  1841. cmSystemTools::ReadRegistryValue(vskey.c_str(), intelVersion,
  1842. cmSystemTools::KeyWOW64_32);
  1843. if (intelVersion.find("13") == 0 ||
  1844. intelVersion.find("12") == 0 ||
  1845. intelVersion.find("11") == 0)
  1846. {
  1847. // Version 11.x, 12.x, and 13.x actually use 11.0 in project files!
  1848. intelVersion = "11.0" ;
  1849. }
  1850. else if(intelVersion.find("10") == 0)
  1851. {
  1852. // Version 10.x actually uses 9.10 in project files!
  1853. intelVersion = "9.10";
  1854. }
  1855. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1856. << "<VisualStudioProject\n"
  1857. << "\tProjectCreator=\"Intel Fortran\"\n"
  1858. << "\tVersion=\"" << intelVersion << "\"\n";
  1859. const char* keyword = target.GetProperty("VS_KEYWORD");
  1860. if(!keyword)
  1861. {
  1862. keyword = "Console Application";
  1863. }
  1864. const char* projectType = 0;
  1865. switch(target.GetType())
  1866. {
  1867. case cmTarget::STATIC_LIBRARY:
  1868. projectType = "typeStaticLibrary";
  1869. if(keyword)
  1870. {
  1871. keyword = "Static Library";
  1872. }
  1873. break;
  1874. case cmTarget::SHARED_LIBRARY:
  1875. case cmTarget::MODULE_LIBRARY:
  1876. projectType = "typeDynamicLibrary";
  1877. if(!keyword)
  1878. {
  1879. keyword = "Dll";
  1880. }
  1881. break;
  1882. case cmTarget::EXECUTABLE:
  1883. if(!keyword)
  1884. {
  1885. keyword = "Console Application";
  1886. }
  1887. projectType = 0;
  1888. break;
  1889. case cmTarget::UTILITY:
  1890. case cmTarget::GLOBAL_TARGET:
  1891. default:
  1892. break;
  1893. }
  1894. if(projectType)
  1895. {
  1896. fout << "\tProjectType=\"" << projectType << "\"\n";
  1897. }
  1898. this->WriteProjectSCC(fout, target);
  1899. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1900. << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\">\n"
  1901. << "\t<Platforms>\n"
  1902. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1903. << "\t</Platforms>\n";
  1904. }
  1905. void
  1906. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1907. const char *libName,
  1908. cmTarget & target,
  1909. std::vector<cmSourceGroup> &)
  1910. {
  1911. if(this->FortranProject)
  1912. {
  1913. this->WriteProjectStartFortran(fout, libName, target);
  1914. return;
  1915. }
  1916. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1917. << "<VisualStudioProject\n"
  1918. << "\tProjectType=\"Visual C++\"\n";
  1919. if(this->Version == VS71)
  1920. {
  1921. fout << "\tVersion=\"7.10\"\n";
  1922. }
  1923. else
  1924. {
  1925. fout << "\tVersion=\"" << (this->Version/10) << ".00\"\n";
  1926. }
  1927. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  1928. if(!projLabel)
  1929. {
  1930. projLabel = libName;
  1931. }
  1932. const char* keyword = target.GetProperty("VS_KEYWORD");
  1933. if(!keyword)
  1934. {
  1935. keyword = "Win32Proj";
  1936. }
  1937. cmGlobalVisualStudio7Generator* gg =
  1938. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1939. fout << "\tName=\"" << projLabel << "\"\n";
  1940. if(this->Version >= VS8)
  1941. {
  1942. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n";
  1943. }
  1944. this->WriteProjectSCC(fout, target);
  1945. fout << "\tKeyword=\"" << keyword << "\">\n"
  1946. << "\t<Platforms>\n"
  1947. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1948. << "\t</Platforms>\n";
  1949. }
  1950. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout,
  1951. cmTarget &target)
  1952. {
  1953. fout << "\t<Globals>\n";
  1954. cmPropertyMap const& props = target.GetProperties();
  1955. for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
  1956. {
  1957. if(i->first.find("VS_GLOBAL_") == 0)
  1958. {
  1959. std::string name = i->first.substr(10);
  1960. if(name != "")
  1961. {
  1962. fout << "\t\t<Global\n"
  1963. << "\t\t\tName=\"" << name << "\"\n"
  1964. << "\t\t\tValue=\"" << i->second.GetValue() << "\"\n"
  1965. << "\t\t/>\n";
  1966. }
  1967. }
  1968. }
  1969. fout << "\t</Globals>\n"
  1970. << "</VisualStudioProject>\n";
  1971. }
  1972. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
  1973. {
  1974. std::string ret = s;
  1975. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1976. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1977. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1978. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1979. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1980. return ret;
  1981. }
  1982. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1983. {
  1984. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1985. }
  1986. std::string cmLocalVisualStudio7Generator
  1987. ::ConvertToXMLOutputPath(const char* path)
  1988. {
  1989. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1990. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1991. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1992. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1993. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1994. return ret;
  1995. }
  1996. std::string cmLocalVisualStudio7Generator
  1997. ::ConvertToXMLOutputPathSingle(const char* path)
  1998. {
  1999. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  2000. cmSystemTools::ReplaceString(ret, "\"", "");
  2001. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2002. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2003. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2004. return ret;
  2005. }
  2006. // This class is used to parse an existing vs 7 project
  2007. // and extract the GUID
  2008. class cmVS7XMLParser : public cmXMLParser
  2009. {
  2010. public:
  2011. virtual void EndElement(const char* /* name */)
  2012. {
  2013. }
  2014. virtual void StartElement(const char* name, const char** atts)
  2015. {
  2016. // once the GUID is found do nothing
  2017. if(this->GUID.size())
  2018. {
  2019. return;
  2020. }
  2021. int i =0;
  2022. if(strcmp("VisualStudioProject", name) == 0)
  2023. {
  2024. while(atts[i])
  2025. {
  2026. if(strcmp(atts[i], "ProjectGUID") == 0)
  2027. {
  2028. if(atts[i+1])
  2029. {
  2030. this->GUID = atts[i+1];
  2031. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  2032. }
  2033. else
  2034. {
  2035. this->GUID = "";
  2036. }
  2037. return;
  2038. }
  2039. ++i;
  2040. }
  2041. }
  2042. }
  2043. int InitializeParser()
  2044. {
  2045. int ret = cmXMLParser::InitializeParser();
  2046. if(ret == 0)
  2047. {
  2048. return ret;
  2049. }
  2050. // visual studio projects have a strange encoding, but it is
  2051. // really utf-8
  2052. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  2053. return 1;
  2054. }
  2055. std::string GUID;
  2056. };
  2057. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  2058. const char* name,
  2059. const char* path)
  2060. {
  2061. cmVS7XMLParser parser;
  2062. parser.ParseFile(path);
  2063. // if we can not find a GUID then create one
  2064. if(parser.GUID.size() == 0)
  2065. {
  2066. cmGlobalVisualStudio7Generator* gg =
  2067. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  2068. gg->CreateGUID(name);
  2069. return;
  2070. }
  2071. std::string guidStoreName = name;
  2072. guidStoreName += "_GUID_CMAKE";
  2073. // save the GUID in the cache
  2074. this->GlobalGenerator->GetCMakeInstance()->
  2075. AddCacheEntry(guidStoreName.c_str(),
  2076. parser.GUID.c_str(),
  2077. "Stored GUID",
  2078. cmCacheManager::INTERNAL);
  2079. }
  2080. //----------------------------------------------------------------------------
  2081. std::string cmLocalVisualStudio7Generator
  2082. ::GetTargetDirectory(cmTarget const& target) const
  2083. {
  2084. std::string dir;
  2085. dir += target.GetName();
  2086. dir += ".dir";
  2087. return dir;
  2088. }
  2089. //----------------------------------------------------------------------------
  2090. #include <windows.h>
  2091. static bool cmLVS6G_IsFAT(const char* dir)
  2092. {
  2093. if(dir[0] && dir[1] == ':')
  2094. {
  2095. char volRoot[4] = "_:/";
  2096. volRoot[0] = dir[0];
  2097. char fsName[16];
  2098. if(GetVolumeInformation(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2099. strstr(fsName, "FAT") != 0)
  2100. {
  2101. return true;
  2102. }
  2103. }
  2104. return false;
  2105. }