cmLocalVisualStudio7Generator.cxx 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954
  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. std::string targetName;
  589. std::string targetNameFull;
  590. std::string targetNamePDB;
  591. target.GetExecutableNames(targetName, targetNameFull,
  592. targetNamePDB, configName);
  593. fout << "\t\t\t\tProgramDataBaseFileName=\""
  594. << this->ExecutableOutputPath
  595. << "$(OutDir)/" << targetNamePDB << "\"\n";
  596. }
  597. else if(target.GetType() == cmTarget::STATIC_LIBRARY ||
  598. target.GetType() == cmTarget::SHARED_LIBRARY ||
  599. target.GetType() == cmTarget::MODULE_LIBRARY)
  600. {
  601. std::string targetName;
  602. std::string targetNameSO;
  603. std::string targetNameFull;
  604. std::string targetNameImport;
  605. std::string targetNamePDB;
  606. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  607. targetNameImport, targetNamePDB, configName);
  608. fout << "\t\t\t\tProgramDataBaseFileName=\""
  609. << this->LibraryOutputPath
  610. << "$(OutDir)/" << targetNamePDB << "\"\n";
  611. }
  612. }
  613. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  614. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  615. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
  616. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  617. for(i = includes.begin();i != includes.end(); ++i)
  618. {
  619. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  620. fout << ipath << ";";
  621. }
  622. // add the -D flags to the RC tool
  623. fout << "\"";
  624. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "");
  625. fout << "/>\n";
  626. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"\n";
  627. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  628. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  629. if( this->PlatformName == "x64" )
  630. {
  631. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  632. }
  633. else if( this->PlatformName == "ia64" )
  634. {
  635. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  636. }
  637. else
  638. {
  639. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  640. }
  641. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  642. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  643. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  644. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  645. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  646. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  647. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  648. // end of <Tool Name=VCMIDLTool
  649. // If we are building a version 8 project file, add a flag telling the
  650. // manifest tool to use a workaround for FAT32 file systems, which can cause
  651. // an empty manifest to be embedded into the resulting executable.
  652. // See CMake bug #2617.
  653. if ( this->Version == 8 )
  654. {
  655. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCManifestTool\"\n"
  656. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  657. << "\t\t\t/>\n";
  658. }
  659. this->OutputTargetRules(fout, target, libName);
  660. this->OutputBuildTool(fout, configName, target);
  661. fout << "\t\t</Configuration>\n";
  662. }
  663. //----------------------------------------------------------------------------
  664. std::string
  665. cmLocalVisualStudio7Generator
  666. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  667. {
  668. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  669. std::string extraLinkOptionsBuildTypeDef =
  670. rootLinkerFlags + "_" + configTypeUpper;
  671. std::string extraLinkOptionsBuildType =
  672. this->Makefile->GetRequiredDefinition
  673. (extraLinkOptionsBuildTypeDef.c_str());
  674. return extraLinkOptionsBuildType;
  675. }
  676. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  677. const char* configName,
  678. cmTarget &target)
  679. {
  680. std::string temp;
  681. std::string extraLinkOptions;
  682. if(target.GetType() == cmTarget::EXECUTABLE)
  683. {
  684. extraLinkOptions =
  685. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  686. + std::string(" ")
  687. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  688. }
  689. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  690. {
  691. extraLinkOptions =
  692. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  693. + std::string(" ")
  694. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  695. }
  696. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  697. {
  698. extraLinkOptions =
  699. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  700. + std::string(" ")
  701. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  702. }
  703. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  704. if(targetLinkFlags)
  705. {
  706. extraLinkOptions += " ";
  707. extraLinkOptions += targetLinkFlags;
  708. }
  709. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  710. std::string linkFlagsConfig = "LINK_FLAGS_";
  711. linkFlagsConfig += configTypeUpper;
  712. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  713. if(targetLinkFlags)
  714. {
  715. extraLinkOptions += " ";
  716. extraLinkOptions += targetLinkFlags;
  717. }
  718. Options linkOptions(Options::Linker);
  719. linkOptions.Parse(extraLinkOptions.c_str());
  720. switch(target.GetType())
  721. {
  722. case cmTarget::STATIC_LIBRARY:
  723. {
  724. std::string targetNameFull = target.GetFullName(configName);
  725. std::string libpath = this->LibraryOutputPath +
  726. "$(OutDir)/" + targetNameFull;
  727. fout << "\t\t\t<Tool\n"
  728. << "\t\t\t\tName=\"VCLibrarianTool\"\n";
  729. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  730. {
  731. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  732. }
  733. fout << "\t\t\t\tOutputFile=\""
  734. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  735. break;
  736. }
  737. case cmTarget::SHARED_LIBRARY:
  738. case cmTarget::MODULE_LIBRARY:
  739. {
  740. std::string targetName;
  741. std::string targetNameSO;
  742. std::string targetNameFull;
  743. std::string targetNameImport;
  744. std::string targetNamePDB;
  745. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  746. targetNameImport, targetNamePDB, configName);
  747. // VS does not distinguish between shared libraries and module
  748. // libraries so it still wants to be given the name of an import
  749. // library for modules.
  750. if(targetNameImport.empty() &&
  751. target.GetType() == cmTarget::MODULE_LIBRARY)
  752. {
  753. targetNameImport =
  754. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  755. targetNameImport += ".lib";
  756. }
  757. // Compute the link library and directory information.
  758. std::vector<cmStdString> linkLibs;
  759. std::vector<cmStdString> linkDirs;
  760. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  761. // Get the language to use for linking.
  762. const char* linkLanguage =
  763. target.GetLinkerLanguage(this->GetGlobalGenerator());
  764. if(!linkLanguage)
  765. {
  766. cmSystemTools::Error
  767. ("CMake can not determine linker language for target:",
  768. target.GetName());
  769. return;
  770. }
  771. // Compute the variable name to lookup standard libraries for this
  772. // language.
  773. std::string standardLibsVar = "CMAKE_";
  774. standardLibsVar += linkLanguage;
  775. standardLibsVar += "_STANDARD_LIBRARIES";
  776. fout << "\t\t\t<Tool\n"
  777. << "\t\t\t\tName=\"VCLinkerTool\"\n";
  778. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  779. // Use the NOINHERIT macro to avoid getting VS project default
  780. // libraries which may be set by the user to something bad.
  781. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  782. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  783. << " ";
  784. this->OutputLibraries(fout, linkLibs);
  785. fout << "\"\n";
  786. temp = this->LibraryOutputPath;
  787. temp += configName;
  788. temp += "/";
  789. temp += targetNameFull;
  790. fout << "\t\t\t\tOutputFile=\""
  791. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  792. this->WriteTargetVersionAttribute(fout, target);
  793. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  794. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  795. this->OutputLibraryDirectories(fout, linkDirs);
  796. fout << "\"\n";
  797. this->OutputModuleDefinitionFile(fout, target);
  798. temp = this->LibraryOutputPath;
  799. temp += "$(OutDir)/";
  800. temp += targetNamePDB;
  801. fout << "\t\t\t\tProgramDataBaseFile=\"" <<
  802. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  803. if(strcmp(configName, "Debug") == 0
  804. || strcmp(configName, "RelWithDebInfo") == 0)
  805. {
  806. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  807. }
  808. std::string stackVar = "CMAKE_";
  809. stackVar += linkLanguage;
  810. stackVar += "_STACK_SIZE";
  811. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  812. if(stackVal)
  813. {
  814. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  815. }
  816. temp = this->LibraryOutputPath;
  817. temp += configName;
  818. temp += "/";
  819. temp += targetNameImport;
  820. fout << "\t\t\t\tImportLibrary=\""
  821. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  822. }
  823. break;
  824. case cmTarget::EXECUTABLE:
  825. {
  826. std::string targetName;
  827. std::string targetNameFull;
  828. std::string targetNamePDB;
  829. target.GetExecutableNames(targetName, targetNameFull,
  830. targetNamePDB, configName);
  831. // Compute the link library and directory information.
  832. std::vector<cmStdString> linkLibs;
  833. std::vector<cmStdString> linkDirs;
  834. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  835. // Get the language to use for linking.
  836. const char* linkLanguage =
  837. target.GetLinkerLanguage(this->GetGlobalGenerator());
  838. if(!linkLanguage)
  839. {
  840. cmSystemTools::Error
  841. ("CMake can not determine linker language for target:",
  842. target.GetName());
  843. return;
  844. }
  845. // Compute the variable name to lookup standard libraries for this
  846. // language.
  847. std::string standardLibsVar = "CMAKE_";
  848. standardLibsVar += linkLanguage;
  849. standardLibsVar += "_STANDARD_LIBRARIES";
  850. fout << "\t\t\t<Tool\n"
  851. << "\t\t\t\tName=\"VCLinkerTool\"\n";
  852. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  853. // Use the NOINHERIT macro to avoid getting VS project default
  854. // libraries which may be set by the user to something bad.
  855. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  856. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  857. << " ";
  858. this->OutputLibraries(fout, linkLibs);
  859. fout << "\"\n";
  860. temp = this->ExecutableOutputPath;
  861. temp += configName;
  862. temp += "/";
  863. temp += targetNameFull;
  864. fout << "\t\t\t\tOutputFile=\""
  865. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  866. this->WriteTargetVersionAttribute(fout, target);
  867. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  868. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  869. this->OutputLibraryDirectories(fout, linkDirs);
  870. fout << "\"\n";
  871. fout << "\t\t\t\tProgramDataBaseFile=\"" << this->ExecutableOutputPath
  872. << "$(OutDir)\\" << targetNamePDB << "\"\n";
  873. if(strcmp(configName, "Debug") == 0
  874. || strcmp(configName, "RelWithDebInfo") == 0)
  875. {
  876. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  877. }
  878. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  879. {
  880. fout << "\t\t\t\tSubSystem=\"2\"\n";
  881. }
  882. else
  883. {
  884. fout << "\t\t\t\tSubSystem=\"1\"\n";
  885. }
  886. std::string stackVar = "CMAKE_";
  887. stackVar += linkLanguage;
  888. stackVar += "_STACK_SIZE";
  889. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  890. if(stackVal)
  891. {
  892. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  893. }
  894. fout << "/>\n";
  895. break;
  896. }
  897. case cmTarget::UTILITY:
  898. case cmTarget::GLOBAL_TARGET:
  899. break;
  900. }
  901. }
  902. //----------------------------------------------------------------------------
  903. void
  904. cmLocalVisualStudio7Generator
  905. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  906. {
  907. int major;
  908. int minor;
  909. target.GetTargetVersion(major, minor);
  910. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  911. }
  912. void cmLocalVisualStudio7Generator
  913. ::OutputModuleDefinitionFile(std::ostream& fout,
  914. cmTarget &target)
  915. {
  916. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  917. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  918. i != classes.end(); i++)
  919. {
  920. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  921. {
  922. fout << "\t\t\t\tModuleDefinitionFile=\""
  923. << this->ConvertToXMLOutputPath((*i)->GetFullPath().c_str())
  924. << "\"\n";
  925. return;
  926. }
  927. }
  928. }
  929. //----------------------------------------------------------------------------
  930. void
  931. cmLocalVisualStudio7Generator
  932. ::OutputLibraries(std::ostream& fout,
  933. std::vector<cmStdString> const& libs)
  934. {
  935. for(std::vector<cmStdString>::const_iterator l = libs.begin();
  936. l != libs.end(); ++l)
  937. {
  938. fout << this->ConvertToXMLOutputPath(l->c_str()) << " ";
  939. }
  940. }
  941. //----------------------------------------------------------------------------
  942. void
  943. cmLocalVisualStudio7Generator
  944. ::OutputLibraryDirectories(std::ostream& fout,
  945. std::vector<cmStdString> const& dirs)
  946. {
  947. const char* comma = "";
  948. for(std::vector<cmStdString>::const_iterator d = dirs.begin();
  949. d != dirs.end(); ++d)
  950. {
  951. // Remove any trailing slash and skip empty paths.
  952. std::string dir = *d;
  953. if(dir[dir.size()-1] == '/')
  954. {
  955. dir = dir.substr(0, dir.size()-1);
  956. }
  957. if(dir.empty())
  958. {
  959. continue;
  960. }
  961. // Switch to a relative path specification if it is shorter.
  962. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  963. {
  964. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  965. if(rel.size() < dir.size())
  966. {
  967. dir = rel;
  968. }
  969. }
  970. // First search a configuration-specific subdirectory and then the
  971. // original directory.
  972. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  973. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  974. comma = ",";
  975. }
  976. }
  977. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  978. const char *libName,
  979. cmTarget &target)
  980. {
  981. // get the configurations
  982. std::vector<std::string> *configs =
  983. static_cast<cmGlobalVisualStudio7Generator *>
  984. (this->GlobalGenerator)->GetConfigurations();
  985. // trace the visual studio dependencies
  986. std::string name = libName;
  987. name += ".vcproj.cmake";
  988. // We may be modifying the source groups temporarily, so make a copy.
  989. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  990. // get the classes from the source lists then add them to the groups
  991. std::vector<cmSourceFile*> & classes = target.GetSourceFiles();
  992. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  993. i != classes.end(); i++)
  994. {
  995. // Add the file to the list of sources.
  996. std::string source = (*i)->GetFullPath();
  997. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  998. {
  999. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1000. }
  1001. cmSourceGroup& sourceGroup =
  1002. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1003. sourceGroup.AssignSource(*i);
  1004. }
  1005. // Compute which sources need unique object computation.
  1006. this->ComputeObjectNameRequirements(sourceGroups);
  1007. // open the project
  1008. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1009. // write the configuration information
  1010. this->WriteConfigurations(fout, libName, target);
  1011. fout << "\t<Files>\n";
  1012. // Loop through every source group.
  1013. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1014. {
  1015. cmSourceGroup sg = sourceGroups[i];
  1016. this->WriteGroup(&sg, target, fout, libName, configs);
  1017. }
  1018. //}
  1019. fout << "\t</Files>\n";
  1020. // Write the VCProj file's footer.
  1021. this->WriteVCProjFooter(fout);
  1022. }
  1023. void cmLocalVisualStudio7Generator
  1024. ::WriteGroup(const cmSourceGroup *sg, cmTarget target,
  1025. std::ostream &fout, const char *libName,
  1026. std::vector<std::string> *configs)
  1027. {
  1028. const std::vector<const cmSourceFile *> &sourceFiles =
  1029. sg->GetSourceFiles();
  1030. // If the group is empty, don't write it at all.
  1031. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  1032. {
  1033. return;
  1034. }
  1035. // If the group has a name, write the header.
  1036. std::string name = sg->GetName();
  1037. if(name != "")
  1038. {
  1039. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1040. }
  1041. // Loop through each source in the source group.
  1042. std::string objectName;
  1043. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1044. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1045. {
  1046. std::string source = (*sf)->GetFullPath();
  1047. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  1048. std::string compileFlags;
  1049. std::string additionalDeps;
  1050. if(this->NeedObjectName.find(*sf) != this->NeedObjectName.end())
  1051. {
  1052. objectName = this->GetObjectFileNameWithoutTarget(*(*sf));
  1053. }
  1054. else
  1055. {
  1056. objectName = "";
  1057. }
  1058. // Add per-source flags.
  1059. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  1060. if(cflags)
  1061. {
  1062. compileFlags += " ";
  1063. compileFlags += cflags;
  1064. }
  1065. const char* lang = this->GlobalGenerator->GetLanguageFromExtension
  1066. ((*sf)->GetSourceExtension().c_str());
  1067. const char* linkLanguage = target.GetLinkerLanguage
  1068. (this->GetGlobalGenerator());
  1069. // If lang is set, the compiler will generate code automatically.
  1070. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1071. // the project file
  1072. bool excludedFromBuild =
  1073. (lang && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY"));
  1074. // if the source file does not match the linker language
  1075. // then force c or c++
  1076. if(linkLanguage && lang && strcmp(lang, linkLanguage) != 0)
  1077. {
  1078. if(strcmp(lang, "CXX") == 0)
  1079. {
  1080. // force a C++ file type
  1081. compileFlags += " /TP ";
  1082. }
  1083. else if(strcmp(lang, "C") == 0)
  1084. {
  1085. // force to c
  1086. compileFlags += " /TC ";
  1087. }
  1088. }
  1089. // Check for extra object-file dependencies.
  1090. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS");
  1091. if(deps)
  1092. {
  1093. std::vector<std::string> depends;
  1094. cmSystemTools::ExpandListArgument(deps, depends);
  1095. if(!depends.empty())
  1096. {
  1097. std::vector<std::string>::iterator i = depends.begin();
  1098. additionalDeps = this->ConvertToXMLOutputPath(i->c_str());
  1099. for(++i;i != depends.end(); ++i)
  1100. {
  1101. additionalDeps += ";";
  1102. additionalDeps += this->ConvertToXMLOutputPath(i->c_str());
  1103. }
  1104. }
  1105. }
  1106. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1107. target.GetType() == cmTarget::GLOBAL_TARGET )
  1108. {
  1109. fout << "\t\t\t<File\n";
  1110. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1111. // Tell MS-Dev what the source is. If the compiler knows how to
  1112. // build it, then it will.
  1113. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1114. if (command)
  1115. {
  1116. // Construct the entire set of commands in one string.
  1117. std::string script =
  1118. this->ConstructScript(command->GetCommandLines(),
  1119. command->GetWorkingDirectory(),
  1120. command->GetEscapeOldStyle(),
  1121. command->GetEscapeAllowMakeVars());
  1122. std::string comment = this->ConstructComment(*command);
  1123. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  1124. this->WriteCustomRule(fout, source.c_str(), script.c_str(),
  1125. comment.c_str(), command->GetDepends(),
  1126. command->GetOutputs(), flags);
  1127. }
  1128. else if(compileFlags.size() || additionalDeps.length()
  1129. || objectName.size() || excludedFromBuild)
  1130. {
  1131. const char* aCompilerTool = "VCCLCompilerTool";
  1132. std::string ext = (*sf)->GetSourceExtension();
  1133. ext = cmSystemTools::LowerCase(ext);
  1134. if(ext == "idl")
  1135. {
  1136. aCompilerTool = "VCMIDLTool";
  1137. }
  1138. if(ext == "rc")
  1139. {
  1140. aCompilerTool = "VCResourceCompilerTool";
  1141. }
  1142. if(ext == "def")
  1143. {
  1144. aCompilerTool = "VCCustomBuildTool";
  1145. }
  1146. for(std::vector<std::string>::iterator i = configs->begin();
  1147. i != configs->end(); ++i)
  1148. {
  1149. fout << "\t\t\t\t<FileConfiguration\n"
  1150. << "\t\t\t\t\tName=\"" << *i
  1151. << "|" << this->PlatformName << "\"";
  1152. if(excludedFromBuild)
  1153. {
  1154. fout << " ExcludedFromBuild=\"true\"";
  1155. }
  1156. fout << ">\n";
  1157. fout << "\t\t\t\t\t<Tool\n"
  1158. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1159. if(!compileFlags.empty())
  1160. {
  1161. Options fileOptions(Options::Compiler);
  1162. fileOptions.Parse(compileFlags.c_str());
  1163. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1164. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1165. fileOptions.OutputPreprocessorDefinitions(fout,
  1166. "\t\t\t\t\t", "\n");
  1167. }
  1168. if(additionalDeps.length())
  1169. {
  1170. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1171. << additionalDeps.c_str() << "\"\n";
  1172. }
  1173. if(objectName.size())
  1174. {
  1175. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1176. << objectName.c_str() << "\"\n";
  1177. }
  1178. fout << "\t\t\t\t\t/>\n"
  1179. << "\t\t\t\t</FileConfiguration>\n";
  1180. }
  1181. }
  1182. fout << "\t\t\t</File>\n";
  1183. }
  1184. }
  1185. std::vector<cmSourceGroup> children = sg->GetGroupChildren();
  1186. for(unsigned int i=0;i<children.size();++i)
  1187. {
  1188. this->WriteGroup(&children[i], target, fout, libName, configs);
  1189. }
  1190. // If the group has a name, write the footer.
  1191. if(name != "")
  1192. {
  1193. this->WriteVCProjEndGroup(fout);
  1194. }
  1195. }
  1196. void cmLocalVisualStudio7Generator::
  1197. WriteCustomRule(std::ostream& fout,
  1198. const char* source,
  1199. const char* command,
  1200. const char* comment,
  1201. const std::vector<std::string>& depends,
  1202. const std::vector<std::string>& outputs,
  1203. const char* compileFlags)
  1204. {
  1205. // Write the rule for each configuration.
  1206. std::vector<std::string>::iterator i;
  1207. std::vector<std::string> *configs =
  1208. static_cast<cmGlobalVisualStudio7Generator *>
  1209. (this->GlobalGenerator)->GetConfigurations();
  1210. for(i = configs->begin(); i != configs->end(); ++i)
  1211. {
  1212. fout << "\t\t\t\t<FileConfiguration\n";
  1213. fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
  1214. if(compileFlags)
  1215. {
  1216. fout << "\t\t\t\t\t<Tool\n"
  1217. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  1218. << "\t\t\t\t\tAdditionalOptions=\""
  1219. << this->EscapeForXML(compileFlags) << "\"/>\n";
  1220. }
  1221. fout << "\t\t\t\t\t<Tool\n"
  1222. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  1223. << "\t\t\t\t\tDescription=\""
  1224. << this->EscapeForXML(comment) << "\"\n"
  1225. << "\t\t\t\t\tCommandLine=\""
  1226. << this->EscapeForXML(command) << "\"\n"
  1227. << "\t\t\t\t\tAdditionalDependencies=\"";
  1228. if(depends.empty())
  1229. {
  1230. // There are no real dependencies. Produce an artificial one to
  1231. // make sure the rule runs reliably.
  1232. if(!cmSystemTools::FileExists(source))
  1233. {
  1234. std::ofstream depout(source);
  1235. depout << "Artificial dependency for a custom command.\n";
  1236. }
  1237. fout << this->ConvertToXMLOutputPath(source);
  1238. }
  1239. else
  1240. {
  1241. // Write out the dependencies for the rule.
  1242. std::string temp;
  1243. for(std::vector<std::string>::const_iterator d = depends.begin();
  1244. d != depends.end(); ++d)
  1245. {
  1246. // Get the real name of the dependency in case it is a CMake target.
  1247. std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
  1248. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1249. << ";";
  1250. }
  1251. }
  1252. fout << "\"\n";
  1253. fout << "\t\t\t\t\tOutputs=\"";
  1254. if(outputs.empty())
  1255. {
  1256. fout << source << "_force";
  1257. }
  1258. else
  1259. {
  1260. // Write a rule for the output generated by this command.
  1261. const char* sep = "";
  1262. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1263. o != outputs.end(); ++o)
  1264. {
  1265. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1266. sep = ";";
  1267. }
  1268. }
  1269. fout << "\"/>\n";
  1270. fout << "\t\t\t\t</FileConfiguration>\n";
  1271. }
  1272. }
  1273. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1274. const char* group,
  1275. const char* )
  1276. {
  1277. fout << "\t\t<Filter\n"
  1278. << "\t\t\tName=\"" << group << "\"\n"
  1279. << "\t\t\tFilter=\"\">\n";
  1280. }
  1281. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1282. {
  1283. fout << "\t\t</Filter>\n";
  1284. }
  1285. // look for custom rules on a target and collect them together
  1286. void cmLocalVisualStudio7Generator
  1287. ::OutputTargetRules(std::ostream& fout,
  1288. cmTarget &target,
  1289. const char * /*libName*/)
  1290. {
  1291. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1292. {
  1293. return;
  1294. }
  1295. // add the pre build rules
  1296. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"";
  1297. bool init = false;
  1298. for (std::vector<cmCustomCommand>::const_iterator cr =
  1299. target.GetPreBuildCommands().begin();
  1300. cr != target.GetPreBuildCommands().end(); ++cr)
  1301. {
  1302. if(!init)
  1303. {
  1304. fout << "\nCommandLine=\"";
  1305. init = true;
  1306. }
  1307. else
  1308. {
  1309. fout << this->EscapeForXML("\n");
  1310. }
  1311. std::string script =
  1312. this->ConstructScript(cr->GetCommandLines(),
  1313. cr->GetWorkingDirectory(),
  1314. cr->GetEscapeOldStyle(),
  1315. cr->GetEscapeAllowMakeVars());
  1316. fout << this->EscapeForXML(script.c_str()).c_str();
  1317. }
  1318. if (init)
  1319. {
  1320. fout << "\"";
  1321. }
  1322. fout << "/>\n";
  1323. // add the pre Link rules
  1324. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"";
  1325. init = false;
  1326. for (std::vector<cmCustomCommand>::const_iterator cr =
  1327. target.GetPreLinkCommands().begin();
  1328. cr != target.GetPreLinkCommands().end(); ++cr)
  1329. {
  1330. if(!init)
  1331. {
  1332. fout << "\nCommandLine=\"";
  1333. init = true;
  1334. }
  1335. else
  1336. {
  1337. fout << this->EscapeForXML("\n");
  1338. }
  1339. std::string script =
  1340. this->ConstructScript(cr->GetCommandLines(),
  1341. cr->GetWorkingDirectory(),
  1342. cr->GetEscapeOldStyle(),
  1343. cr->GetEscapeAllowMakeVars());
  1344. fout << this->EscapeForXML(script.c_str()).c_str();
  1345. }
  1346. if (init)
  1347. {
  1348. fout << "\"";
  1349. }
  1350. fout << "/>\n";
  1351. // add the PostBuild rules
  1352. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
  1353. init = false;
  1354. for (std::vector<cmCustomCommand>::const_iterator cr =
  1355. target.GetPostBuildCommands().begin();
  1356. cr != target.GetPostBuildCommands().end(); ++cr)
  1357. {
  1358. if(!init)
  1359. {
  1360. fout << "\nCommandLine=\"";
  1361. init = true;
  1362. }
  1363. else
  1364. {
  1365. fout << this->EscapeForXML("\n");
  1366. }
  1367. std::string script =
  1368. this->ConstructScript(cr->GetCommandLines(),
  1369. cr->GetWorkingDirectory(),
  1370. cr->GetEscapeOldStyle(),
  1371. cr->GetEscapeAllowMakeVars());
  1372. fout << this->EscapeForXML(script.c_str()).c_str();
  1373. }
  1374. if (init)
  1375. {
  1376. fout << "\"";
  1377. }
  1378. fout << "/>\n";
  1379. }
  1380. void
  1381. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1382. const char *libName,
  1383. cmTarget & target,
  1384. std::vector<cmSourceGroup> &)
  1385. {
  1386. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1387. << "<VisualStudioProject\n"
  1388. << "\tProjectType=\"Visual C++\"\n";
  1389. if(this->Version == 71)
  1390. {
  1391. fout << "\tVersion=\"7.10\"\n";
  1392. }
  1393. else
  1394. {
  1395. if (this->Version == 8)
  1396. {
  1397. fout << "\tVersion=\"8.00\"\n";
  1398. }
  1399. else
  1400. {
  1401. fout << "\tVersion=\"7.00\"\n";
  1402. }
  1403. }
  1404. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  1405. if(!projLabel)
  1406. {
  1407. projLabel = libName;
  1408. }
  1409. const char* keyword = target.GetProperty("VS_KEYWORD");
  1410. if(!keyword)
  1411. {
  1412. keyword = "Win32Proj";
  1413. }
  1414. cmGlobalVisualStudio7Generator* gg =
  1415. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1416. fout << "\tName=\"" << projLabel << "\"\n";
  1417. if(this->Version == 8)
  1418. {
  1419. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n";
  1420. }
  1421. fout << "\tSccProjectName=\"\"\n"
  1422. << "\tSccLocalPath=\"\"\n"
  1423. << "\tKeyword=\"" << keyword << "\">\n"
  1424. << "\t<Platforms>\n"
  1425. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1426. << "\t</Platforms>\n";
  1427. }
  1428. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1429. {
  1430. fout << "\t<Globals>\n"
  1431. << "\t</Globals>\n"
  1432. << "</VisualStudioProject>\n";
  1433. }
  1434. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
  1435. {
  1436. std::string ret = s;
  1437. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1438. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1439. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1440. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1441. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1442. return ret;
  1443. }
  1444. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1445. {
  1446. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1447. }
  1448. std::string cmLocalVisualStudio7Generator
  1449. ::ConvertToXMLOutputPath(const char* path)
  1450. {
  1451. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1452. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1453. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1454. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1455. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1456. return ret;
  1457. }
  1458. std::string cmLocalVisualStudio7Generator
  1459. ::ConvertToXMLOutputPathSingle(const char* path)
  1460. {
  1461. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1462. cmSystemTools::ReplaceString(ret, "\"", "");
  1463. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1464. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1465. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1466. return ret;
  1467. }
  1468. // This class is used to parse an existing vs 7 project
  1469. // and extract the GUID
  1470. class cmVS7XMLParser : public cmXMLParser
  1471. {
  1472. public:
  1473. virtual void EndElement(const char* name)
  1474. {
  1475. }
  1476. virtual void StartElement(const char* name, const char** atts)
  1477. {
  1478. // once the GUID is found do nothing
  1479. if(this->GUID.size())
  1480. {
  1481. return;
  1482. }
  1483. int i =0;
  1484. if(strcmp("VisualStudioProject", name) == 0)
  1485. {
  1486. while(atts[i])
  1487. {
  1488. if(strcmp(atts[i], "ProjectGUID") == 0)
  1489. {
  1490. if(atts[i+1])
  1491. {
  1492. this->GUID = atts[i+1];
  1493. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  1494. }
  1495. else
  1496. {
  1497. this->GUID = "";
  1498. }
  1499. return;
  1500. }
  1501. ++i;
  1502. }
  1503. }
  1504. }
  1505. int InitializeParser()
  1506. {
  1507. int ret = cmXMLParser::InitializeParser();
  1508. if(ret == 0)
  1509. {
  1510. return ret;
  1511. }
  1512. // visual studio projects have a strange encoding, but it is
  1513. // really utf-8
  1514. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  1515. return 1;
  1516. }
  1517. std::string GUID;
  1518. };
  1519. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  1520. const char* name,
  1521. const char* path)
  1522. {
  1523. cmVS7XMLParser parser;
  1524. parser.ParseFile(path);
  1525. // if we can not find a GUID then create one
  1526. if(parser.GUID.size() == 0)
  1527. {
  1528. cmGlobalVisualStudio7Generator* gg =
  1529. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1530. gg->CreateGUID(name);
  1531. return;
  1532. }
  1533. std::string guidStoreName = name;
  1534. guidStoreName += "_GUID_CMAKE";
  1535. // save the GUID in the cache
  1536. this->GlobalGenerator->GetCMakeInstance()->
  1537. AddCacheEntry(guidStoreName.c_str(),
  1538. parser.GUID.c_str(),
  1539. "Stored GUID",
  1540. cmCacheManager::INTERNAL);
  1541. }
  1542. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1543. {
  1544. cmLocalGenerator::ConfigureFinalPass();
  1545. cmTargets &tgts = this->Makefile->GetTargets();
  1546. cmGlobalVisualStudio7Generator* gg =
  1547. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1548. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1549. {
  1550. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  1551. {
  1552. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  1553. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  1554. std::string project_name = cmds[0][0];
  1555. this->ReadAndStoreExternalGUID(project_name.c_str(), cmds[0][1].c_str());
  1556. }
  1557. else
  1558. {
  1559. gg->CreateGUID(l->first.c_str());
  1560. }
  1561. }
  1562. }
  1563. //----------------------------------------------------------------------------
  1564. std::string cmLocalVisualStudio7Generator
  1565. ::GetTargetDirectory(cmTarget& target)
  1566. {
  1567. std::string dir;
  1568. dir += target.GetName();
  1569. dir += ".dir";
  1570. return dir;
  1571. }
  1572. //----------------------------------------------------------------------------
  1573. cmLocalVisualStudio7GeneratorOptions
  1574. ::cmLocalVisualStudio7GeneratorOptions(Tool tool):
  1575. DoingDefine(false), FlagTable(0)
  1576. {
  1577. // Choose the flag table for the requested tool.
  1578. switch(tool)
  1579. {
  1580. case Compiler:
  1581. this->FlagTable = cmLocalVisualStudio7GeneratorFlagTable; break;
  1582. case Linker:
  1583. this->FlagTable = cmLocalVisualStudio7GeneratorLinkFlagTable; break;
  1584. default: break;
  1585. }
  1586. // Exception handling is on by default because the platform file has
  1587. // "/EHsc" in the flags. Normally, that will override this
  1588. // initialization to off, but the user has the option of removing
  1589. // the flag to disable exception handling. When the user does
  1590. // remove the flag we need to override the IDE default of on.
  1591. this->FlagMap["ExceptionHandling"] = "FALSE";
  1592. }
  1593. //----------------------------------------------------------------------------
  1594. void cmLocalVisualStudio7GeneratorOptions::SetVerboseMakefile(bool verbose)
  1595. {
  1596. // If verbose makefiles have been requested and the /nologo option
  1597. // was not given explicitly in the flags we want to add an attribute
  1598. // to the generated project to disable logo suppression. Otherwise
  1599. // the GUI default is to enable suppression.
  1600. if(verbose &&
  1601. this->FlagMap.find("SuppressStartupBanner") == this->FlagMap.end())
  1602. {
  1603. this->FlagMap["SuppressStartupBanner"] = "FALSE";
  1604. }
  1605. }
  1606. //----------------------------------------------------------------------------
  1607. void cmLocalVisualStudio7GeneratorOptions::AddDefine(const std::string& def)
  1608. {
  1609. this->Defines.push_back(def);
  1610. }
  1611. //----------------------------------------------------------------------------
  1612. void cmLocalVisualStudio7GeneratorOptions::AddFlag(const char* flag,
  1613. const char* value)
  1614. {
  1615. this->FlagMap[flag] = value;
  1616. }
  1617. //----------------------------------------------------------------------------
  1618. bool cmLocalVisualStudio7GeneratorOptions::UsingUnicode()
  1619. {
  1620. // Look for the a _UNICODE definition.
  1621. for(std::vector<cmStdString>::const_iterator di = this->Defines.begin();
  1622. di != this->Defines.end(); ++di)
  1623. {
  1624. if(*di == "_UNICODE")
  1625. {
  1626. return true;
  1627. }
  1628. }
  1629. return false;
  1630. }
  1631. //----------------------------------------------------------------------------
  1632. bool cmLocalVisualStudio7GeneratorOptions::UsingDebugPDB()
  1633. {
  1634. std::map<cmStdString, cmStdString>::iterator mi =
  1635. this->FlagMap.find("DebugInformationFormat");
  1636. if(mi != this->FlagMap.end() && mi->second != "1")
  1637. {
  1638. return true;
  1639. }
  1640. else
  1641. {
  1642. return false;
  1643. }
  1644. }
  1645. //----------------------------------------------------------------------------
  1646. void cmLocalVisualStudio7GeneratorOptions::Parse(const char* flags)
  1647. {
  1648. // Parse the input string as a windows command line since the string
  1649. // is intended for writing directly into the build files.
  1650. std::vector<std::string> args;
  1651. cmSystemTools::ParseWindowsCommandLine(flags, args);
  1652. // Process flags that need to be represented specially in the IDE
  1653. // project file.
  1654. for(std::vector<std::string>::iterator ai = args.begin();
  1655. ai != args.end(); ++ai)
  1656. {
  1657. this->HandleFlag(ai->c_str());
  1658. }
  1659. }
  1660. //----------------------------------------------------------------------------
  1661. void cmLocalVisualStudio7GeneratorOptions::HandleFlag(const char* flag)
  1662. {
  1663. // If the last option was -D then this option is the definition.
  1664. if(this->DoingDefine)
  1665. {
  1666. this->DoingDefine = false;
  1667. this->Defines.push_back(flag);
  1668. return;
  1669. }
  1670. // Look for known arguments.
  1671. if(flag[0] == '-' || flag[0] == '/')
  1672. {
  1673. if(flag[1] == 'D')
  1674. {
  1675. if(flag[2] == '\0')
  1676. {
  1677. // The next argument will have the definition.
  1678. this->DoingDefine = true;
  1679. }
  1680. else
  1681. {
  1682. // Store this definition.
  1683. this->Defines.push_back(flag+2);
  1684. }
  1685. return;
  1686. }
  1687. else if(this->FlagTable)
  1688. {
  1689. // Look for an entry in the flag table matching this flag.
  1690. bool flag_handled = false;
  1691. for(cmVS7FlagTable const* entry = this->FlagTable;
  1692. entry->IDEName; ++entry)
  1693. {
  1694. bool entry_found = false;
  1695. if(entry->special & cmVS7FlagTable::UserValue)
  1696. {
  1697. // This flag table entry accepts a user-specified value. If
  1698. // the entry specifies UserRequired we must match only if a
  1699. // non-empty value is given.
  1700. int n = static_cast<int>(strlen(entry->commandFlag));
  1701. if(strncmp(flag+1, entry->commandFlag, n) == 0 &&
  1702. (!(entry->special & cmVS7FlagTable::UserRequired) ||
  1703. static_cast<int>(strlen(flag+1)) > n))
  1704. {
  1705. if(entry->special & cmVS7FlagTable::UserIgnored)
  1706. {
  1707. // Ignore the user-specified value.
  1708. this->FlagMap[entry->IDEName] = entry->value;
  1709. }
  1710. else
  1711. {
  1712. // Use the user-specified value.
  1713. this->FlagMap[entry->IDEName] = flag+1+n;
  1714. }
  1715. entry_found = true;
  1716. }
  1717. }
  1718. else if(strcmp(flag+1, entry->commandFlag) == 0)
  1719. {
  1720. // This flag table entry provides a fixed value.
  1721. this->FlagMap[entry->IDEName] = entry->value;
  1722. entry_found = true;
  1723. }
  1724. // If the flag has been handled by an entry not requesting a
  1725. // search continuation we are done.
  1726. if(entry_found && !(entry->special & cmVS7FlagTable::Continue))
  1727. {
  1728. return;
  1729. }
  1730. // If the entry was found the flag has been handled.
  1731. flag_handled |= entry_found;
  1732. }
  1733. // If any map entry handled the flag we are done.
  1734. if(flag_handled)
  1735. {
  1736. return;
  1737. }
  1738. }
  1739. }
  1740. // This option is not known. Store it in the output flags.
  1741. this->FlagString += " ";
  1742. this->FlagString +=
  1743. cmSystemTools::EscapeWindowsShellArgument(flag,
  1744. cmsysSystem_Shell_Flag_VSIDE);
  1745. }
  1746. //----------------------------------------------------------------------------
  1747. void
  1748. cmLocalVisualStudio7GeneratorOptions
  1749. ::OutputPreprocessorDefinitions(std::ostream& fout,
  1750. const char* prefix,
  1751. const char* suffix)
  1752. {
  1753. if(this->Defines.empty())
  1754. {
  1755. return;
  1756. }
  1757. fout << prefix << "PreprocessorDefinitions=\"";
  1758. const char* comma = "";
  1759. for(std::vector<cmStdString>::const_iterator di = this->Defines.begin();
  1760. di != this->Defines.end(); ++di)
  1761. {
  1762. // Escape this flag for the IDE.
  1763. std::string define =
  1764. cmLocalVisualStudio7GeneratorEscapeForXML(di->c_str());
  1765. // Old comment:
  1766. // Double-quotes in the value of the definition must be escaped
  1767. // with a backslash. The entire definition should be quoted in
  1768. // the generated xml attribute to avoid confusing the VS parser.
  1769. // Write this flag. Quote it if the definition is not
  1770. // alphanumeric.
  1771. if(define.find_first_not_of(
  1772. "-_abcdefghigklmnopqrstuvwxyz1234567890ABCDEFGHIGKLMNOPQRSTUVWXYZ")
  1773. != define.npos)
  1774. {
  1775. fout << comma << "&quot;" << define << "&quot;";
  1776. }
  1777. else
  1778. {
  1779. fout << comma << define;
  1780. }
  1781. comma = ",";
  1782. }
  1783. fout << "\"" << suffix;
  1784. }
  1785. //----------------------------------------------------------------------------
  1786. void
  1787. cmLocalVisualStudio7GeneratorOptions
  1788. ::OutputFlagMap(std::ostream& fout, const char* indent)
  1789. {
  1790. for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
  1791. m != this->FlagMap.end(); ++m)
  1792. {
  1793. fout << indent << m->first << "=\"" << m->second << "\"\n";
  1794. }
  1795. }
  1796. //----------------------------------------------------------------------------
  1797. void
  1798. cmLocalVisualStudio7GeneratorOptions
  1799. ::OutputAdditionalOptions(std::ostream& fout,
  1800. const char* prefix,
  1801. const char* suffix)
  1802. {
  1803. if(!this->FlagString.empty())
  1804. {
  1805. fout << prefix << "AdditionalOptions=\"";
  1806. fout <<
  1807. cmLocalVisualStudio7GeneratorEscapeForXML(this->FlagString.c_str());
  1808. fout << "\"" << suffix;
  1809. }
  1810. }