cmLocalVisualStudio7Generator.cxx 63 KB

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