cmLocalVisualStudio7Generator.cxx 76 KB

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