cmLocalVisualStudio7Generator.cxx 69 KB

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