cmLocalVisualStudio7Generator.cxx 77 KB

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