cmLocalVisualStudio7Generator.cxx 63 KB

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