cmLocalVisualStudio7Generator.cxx 63 KB

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