cmLocalVisualStudio7Generator.cxx 63 KB

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