cmLocalVisualStudio7Generator.cxx 75 KB

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