cmLocalVisualStudio7Generator.cxx 76 KB

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