cmLocalVisualStudio7Generator.cxx 67 KB

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