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