cmLocalVisualStudio7Generator.cxx 75 KB

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