cmLocalVisualStudio7Generator.cxx 71 KB

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