cmLocalVisualStudio7Generator.cxx 64 KB

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