cmLocalVisualStudio7Generator.cxx 68 KB

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