cmLocalVisualStudio7Generator.cxx 69 KB

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