cmLocalVisualStudio7Generator.cxx 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987
  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. // Fix the ExceptionHandling option to default to off.
  398. void FixExceptionHandlingDefault();
  399. // Store options for verbose builds.
  400. void SetVerboseMakefile(bool verbose);
  401. // Store definitions and flags.
  402. void AddDefine(const std::string& define);
  403. void AddFlag(const char* flag, const char* value);
  404. // Check for specific options.
  405. bool UsingUnicode();
  406. bool UsingDebugPDB();
  407. // Write options to output.
  408. void OutputPreprocessorDefinitions(std::ostream& fout,
  409. const char* prefix,
  410. const char* suffix);
  411. void OutputFlagMap(std::ostream& fout, const char* indent);
  412. void OutputAdditionalOptions(std::ostream& fout,
  413. const char* prefix,
  414. const char* suffix);
  415. private:
  416. // create a map of xml tags to the values they should have in the output
  417. // for example, "BufferSecurityCheck" = "TRUE"
  418. // first fill this table with the values for the configuration
  419. // Debug, Release, etc,
  420. // Then parse the command line flags specified in CMAKE_CXX_FLAGS
  421. // and CMAKE_C_FLAGS
  422. // and overwrite or add new values to this map
  423. std::map<cmStdString, cmStdString> FlagMap;
  424. // Preprocessor definitions.
  425. std::vector<cmStdString> Defines;
  426. // Unrecognized flags that get no special handling.
  427. cmStdString FlagString;
  428. bool DoingDefine;
  429. cmVS7FlagTable const* FlagTable;
  430. void HandleFlag(const char* flag);
  431. };
  432. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  433. const char* configName,
  434. const char *libName,
  435. cmTarget &target)
  436. {
  437. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  438. if(!mfcFlag)
  439. {
  440. mfcFlag = "0";
  441. }
  442. fout << "\t\t<Configuration\n"
  443. << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n"
  444. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  445. // This is an internal type to Visual Studio, it seems that:
  446. // 4 == static library
  447. // 2 == dll
  448. // 1 == executable
  449. // 10 == utility
  450. const char* configType = "10";
  451. switch(target.GetType())
  452. {
  453. case cmTarget::STATIC_LIBRARY:
  454. configType = "4";
  455. break;
  456. case cmTarget::SHARED_LIBRARY:
  457. case cmTarget::MODULE_LIBRARY:
  458. configType = "2";
  459. break;
  460. case cmTarget::EXECUTABLE:
  461. configType = "1";
  462. break;
  463. case cmTarget::UTILITY:
  464. case cmTarget::GLOBAL_TARGET:
  465. configType = "10";
  466. default:
  467. break;
  468. }
  469. std::string flags;
  470. if(strcmp(configType, "10") != 0)
  471. {
  472. const char* linkLanguage =
  473. target.GetLinkerLanguage(this->GetGlobalGenerator());
  474. if(!linkLanguage)
  475. {
  476. cmSystemTools::Error
  477. ("CMake can not determine linker language for target:",
  478. target.GetName());
  479. return;
  480. }
  481. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0)
  482. {
  483. std::string baseFlagVar = "CMAKE_";
  484. baseFlagVar += linkLanguage;
  485. baseFlagVar += "_FLAGS";
  486. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  487. std::string flagVar = baseFlagVar + std::string("_") +
  488. cmSystemTools::UpperCase(configName);
  489. flags += " ";
  490. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  491. }
  492. // set the correct language
  493. if(strcmp(linkLanguage, "C") == 0)
  494. {
  495. flags += " /TC ";
  496. }
  497. if(strcmp(linkLanguage, "CXX") == 0)
  498. {
  499. flags += " /TP ";
  500. }
  501. }
  502. // Add the target-specific flags.
  503. if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
  504. {
  505. flags += " ";
  506. flags += targetFlags;
  507. }
  508. // Get preprocessor definitions for this directory.
  509. std::string defineFlags = this->Makefile->GetDefineFlags();
  510. // Construct a set of build options for this target.
  511. Options targetOptions(Options::Compiler);
  512. targetOptions.FixExceptionHandlingDefault();
  513. targetOptions.Parse(flags.c_str());
  514. targetOptions.Parse(defineFlags.c_str());
  515. targetOptions.SetVerboseMakefile(
  516. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  517. // Add a definition for the configuration name.
  518. std::string configDefine = "CMAKE_INTDIR=\\\"";
  519. configDefine += configName;
  520. configDefine += "\\\"";
  521. targetOptions.AddDefine(configDefine);
  522. // Add a definition for the export macro.
  523. if(target.GetType() == cmTarget::SHARED_LIBRARY ||
  524. target.GetType() == cmTarget::MODULE_LIBRARY)
  525. {
  526. std::string exportSymbol;
  527. if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  528. {
  529. exportSymbol = custom_export_name;
  530. }
  531. else
  532. {
  533. std::string id = libName;
  534. id += "_EXPORTS";
  535. exportSymbol = cmSystemTools::MakeCindentifier(id.c_str());
  536. }
  537. targetOptions.AddDefine(exportSymbol);
  538. }
  539. // Override the flag map with cmake-specific settings.
  540. if(this->Makefile->IsOn("CMAKE_CXX_USE_RTTI"))
  541. {
  542. targetOptions.AddFlag("RuntimeTypeInfo", "TRUE");
  543. }
  544. if(const char* warningLevel =
  545. this->Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL"))
  546. {
  547. targetOptions.AddFlag("WarningLevel", warningLevel);
  548. }
  549. // The intermediate directory name consists of a directory for the
  550. // target and a subdirectory for the configuration name.
  551. std::string intermediateDir = this->GetTargetDirectory(target);
  552. intermediateDir += "/";
  553. intermediateDir += configName;
  554. fout << "\t\t\tIntermediateDirectory=\""
  555. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  556. << "\"\n"
  557. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  558. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  559. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  560. // If unicode is enabled change the character set to unicode, if not
  561. // then default to MBCS.
  562. if(targetOptions.UsingUnicode())
  563. {
  564. fout << "\t\t\tCharacterSet=\"1\">\n";
  565. }
  566. else
  567. {
  568. fout << "\t\t\tCharacterSet=\"2\">\n";
  569. }
  570. fout << "\t\t\t<Tool\n"
  571. << "\t\t\t\tName=\"VCCLCompilerTool\"\n";
  572. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  573. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  574. std::vector<std::string> includes;
  575. this->GetIncludeDirectories(includes);
  576. std::vector<std::string>::iterator i = includes.begin();
  577. for(;i != includes.end(); ++i)
  578. {
  579. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  580. fout << ipath << ";";
  581. }
  582. fout << "\"\n";
  583. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  584. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  585. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  586. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  587. if(targetOptions.UsingDebugPDB())
  588. {
  589. if(target.GetType() == cmTarget::EXECUTABLE)
  590. {
  591. fout << "\t\t\t\tProgramDataBaseFileName=\""
  592. << this->ExecutableOutputPath
  593. << "$(OutDir)/" << target.GetPDBName(configName) << "\"\n";
  594. }
  595. else if(target.GetType() == cmTarget::STATIC_LIBRARY ||
  596. target.GetType() == cmTarget::SHARED_LIBRARY ||
  597. target.GetType() == cmTarget::MODULE_LIBRARY)
  598. {
  599. fout << "\t\t\t\tProgramDataBaseFileName=\""
  600. << this->LibraryOutputPath
  601. << "$(OutDir)/" << target.GetPDBName(configName) << "\"\n";
  602. }
  603. }
  604. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  605. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  606. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
  607. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  608. for(i = includes.begin();i != includes.end(); ++i)
  609. {
  610. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  611. fout << ipath << ";";
  612. }
  613. // add the -D flags to the RC tool
  614. fout << "\"";
  615. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "");
  616. fout << "/>\n";
  617. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"\n";
  618. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  619. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  620. if( this->PlatformName == "x64" )
  621. {
  622. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  623. }
  624. else if( this->PlatformName == "ia64" )
  625. {
  626. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  627. }
  628. else
  629. {
  630. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  631. }
  632. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  633. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  634. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  635. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  636. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  637. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  638. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  639. // end of <Tool Name=VCMIDLTool
  640. // If we are building a version 8 project file, add a flag telling the
  641. // manifest tool to use a workaround for FAT32 file systems, which can cause
  642. // an empty manifest to be embedded into the resulting executable.
  643. // See CMake bug #2617.
  644. if ( this->Version == 8 )
  645. {
  646. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCManifestTool\"\n"
  647. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  648. << "\t\t\t/>\n";
  649. }
  650. this->OutputTargetRules(fout, target, libName);
  651. this->OutputBuildTool(fout, configName, target);
  652. fout << "\t\t</Configuration>\n";
  653. }
  654. //----------------------------------------------------------------------------
  655. std::string
  656. cmLocalVisualStudio7Generator
  657. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  658. {
  659. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  660. std::string extraLinkOptionsBuildTypeDef =
  661. rootLinkerFlags + "_" + configTypeUpper;
  662. std::string extraLinkOptionsBuildType =
  663. this->Makefile->GetRequiredDefinition
  664. (extraLinkOptionsBuildTypeDef.c_str());
  665. return extraLinkOptionsBuildType;
  666. }
  667. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  668. const char* configName,
  669. cmTarget &target)
  670. {
  671. std::string temp;
  672. std::string extraLinkOptions;
  673. if(target.GetType() == cmTarget::EXECUTABLE)
  674. {
  675. extraLinkOptions =
  676. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  677. + std::string(" ")
  678. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  679. }
  680. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  681. {
  682. extraLinkOptions =
  683. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  684. + std::string(" ")
  685. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  686. }
  687. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  688. {
  689. extraLinkOptions =
  690. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  691. + std::string(" ")
  692. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  693. }
  694. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  695. if(targetLinkFlags)
  696. {
  697. extraLinkOptions += " ";
  698. extraLinkOptions += targetLinkFlags;
  699. }
  700. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  701. std::string linkFlagsConfig = "LINK_FLAGS_";
  702. linkFlagsConfig += configTypeUpper;
  703. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  704. if(targetLinkFlags)
  705. {
  706. extraLinkOptions += " ";
  707. extraLinkOptions += targetLinkFlags;
  708. }
  709. Options linkOptions(Options::Linker);
  710. linkOptions.Parse(extraLinkOptions.c_str());
  711. switch(target.GetType())
  712. {
  713. case cmTarget::STATIC_LIBRARY:
  714. {
  715. std::string targetNameFull = target.GetFullName(configName);
  716. std::string libpath = this->LibraryOutputPath +
  717. "$(OutDir)/" + targetNameFull;
  718. fout << "\t\t\t<Tool\n"
  719. << "\t\t\t\tName=\"VCLibrarianTool\"\n";
  720. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  721. {
  722. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  723. }
  724. fout << "\t\t\t\tOutputFile=\""
  725. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  726. break;
  727. }
  728. case cmTarget::SHARED_LIBRARY:
  729. case cmTarget::MODULE_LIBRARY:
  730. {
  731. std::string targetName;
  732. std::string targetNameSO;
  733. std::string targetNameFull;
  734. std::string targetNameImport;
  735. std::string targetNamePDB;
  736. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  737. targetNameImport, targetNamePDB, configName);
  738. // VS does not distinguish between shared libraries and module
  739. // libraries so it still wants to be given the name of an import
  740. // library for modules.
  741. if(targetNameImport.empty() &&
  742. target.GetType() == cmTarget::MODULE_LIBRARY)
  743. {
  744. targetNameImport =
  745. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  746. targetNameImport += ".lib";
  747. }
  748. // Compute the link library and directory information.
  749. std::vector<cmStdString> linkLibs;
  750. std::vector<cmStdString> linkDirs;
  751. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  752. // Get the language to use for linking.
  753. const char* linkLanguage =
  754. target.GetLinkerLanguage(this->GetGlobalGenerator());
  755. if(!linkLanguage)
  756. {
  757. cmSystemTools::Error
  758. ("CMake can not determine linker language for target:",
  759. target.GetName());
  760. return;
  761. }
  762. // Compute the variable name to lookup standard libraries for this
  763. // language.
  764. std::string standardLibsVar = "CMAKE_";
  765. standardLibsVar += linkLanguage;
  766. standardLibsVar += "_STANDARD_LIBRARIES";
  767. fout << "\t\t\t<Tool\n"
  768. << "\t\t\t\tName=\"VCLinkerTool\"\n";
  769. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  770. // Use the NOINHERIT macro to avoid getting VS project default
  771. // libraries which may be set by the user to something bad.
  772. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  773. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  774. << " ";
  775. this->OutputLibraries(fout, linkLibs);
  776. fout << "\"\n";
  777. temp = this->LibraryOutputPath;
  778. temp += configName;
  779. temp += "/";
  780. temp += targetNameFull;
  781. fout << "\t\t\t\tOutputFile=\""
  782. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  783. this->WriteTargetVersionAttribute(fout, target);
  784. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  785. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  786. this->OutputLibraryDirectories(fout, linkDirs);
  787. fout << "\"\n";
  788. this->OutputModuleDefinitionFile(fout, target);
  789. temp = this->LibraryOutputPath;
  790. temp += "$(OutDir)/";
  791. temp += targetNamePDB;
  792. fout << "\t\t\t\tProgramDataBaseFile=\"" <<
  793. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  794. if(strcmp(configName, "Debug") == 0
  795. || strcmp(configName, "RelWithDebInfo") == 0)
  796. {
  797. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  798. }
  799. std::string stackVar = "CMAKE_";
  800. stackVar += linkLanguage;
  801. stackVar += "_STACK_SIZE";
  802. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  803. if(stackVal)
  804. {
  805. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  806. }
  807. temp = this->LibraryOutputPath;
  808. temp += configName;
  809. temp += "/";
  810. temp += targetNameImport;
  811. fout << "\t\t\t\tImportLibrary=\""
  812. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  813. }
  814. break;
  815. case cmTarget::EXECUTABLE:
  816. {
  817. std::string targetName;
  818. std::string targetNameFull;
  819. std::string targetNamePDB;
  820. target.GetExecutableNames(targetName, targetNameFull,
  821. targetNamePDB, configName);
  822. // Compute the link library and directory information.
  823. std::vector<cmStdString> linkLibs;
  824. std::vector<cmStdString> linkDirs;
  825. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  826. // Get the language to use for linking.
  827. const char* linkLanguage =
  828. target.GetLinkerLanguage(this->GetGlobalGenerator());
  829. if(!linkLanguage)
  830. {
  831. cmSystemTools::Error
  832. ("CMake can not determine linker language for target:",
  833. target.GetName());
  834. return;
  835. }
  836. // Compute the variable name to lookup standard libraries for this
  837. // language.
  838. std::string standardLibsVar = "CMAKE_";
  839. standardLibsVar += linkLanguage;
  840. standardLibsVar += "_STANDARD_LIBRARIES";
  841. fout << "\t\t\t<Tool\n"
  842. << "\t\t\t\tName=\"VCLinkerTool\"\n";
  843. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  844. // Use the NOINHERIT macro to avoid getting VS project default
  845. // libraries which may be set by the user to something bad.
  846. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  847. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  848. << " ";
  849. this->OutputLibraries(fout, linkLibs);
  850. fout << "\"\n";
  851. temp = this->ExecutableOutputPath;
  852. temp += configName;
  853. temp += "/";
  854. temp += targetNameFull;
  855. fout << "\t\t\t\tOutputFile=\""
  856. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  857. this->WriteTargetVersionAttribute(fout, target);
  858. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  859. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  860. this->OutputLibraryDirectories(fout, linkDirs);
  861. fout << "\"\n";
  862. fout << "\t\t\t\tProgramDataBaseFile=\"" << this->ExecutableOutputPath
  863. << "$(OutDir)\\" << targetNamePDB << "\"\n";
  864. if(strcmp(configName, "Debug") == 0
  865. || strcmp(configName, "RelWithDebInfo") == 0)
  866. {
  867. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  868. }
  869. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  870. {
  871. fout << "\t\t\t\tSubSystem=\"2\"\n";
  872. }
  873. else
  874. {
  875. fout << "\t\t\t\tSubSystem=\"1\"\n";
  876. }
  877. std::string stackVar = "CMAKE_";
  878. stackVar += linkLanguage;
  879. stackVar += "_STACK_SIZE";
  880. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  881. if(stackVal)
  882. {
  883. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  884. }
  885. fout << "/>\n";
  886. break;
  887. }
  888. case cmTarget::UTILITY:
  889. case cmTarget::GLOBAL_TARGET:
  890. break;
  891. }
  892. }
  893. //----------------------------------------------------------------------------
  894. void
  895. cmLocalVisualStudio7Generator
  896. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  897. {
  898. int major;
  899. int minor;
  900. target.GetTargetVersion(major, minor);
  901. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  902. }
  903. void cmLocalVisualStudio7Generator
  904. ::OutputModuleDefinitionFile(std::ostream& fout,
  905. cmTarget &target)
  906. {
  907. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  908. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  909. i != classes.end(); i++)
  910. {
  911. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  912. {
  913. fout << "\t\t\t\tModuleDefinitionFile=\""
  914. << this->ConvertToXMLOutputPath((*i)->GetFullPath().c_str())
  915. << "\"\n";
  916. return;
  917. }
  918. }
  919. }
  920. //----------------------------------------------------------------------------
  921. void
  922. cmLocalVisualStudio7Generator
  923. ::OutputLibraries(std::ostream& fout,
  924. std::vector<cmStdString> const& libs)
  925. {
  926. for(std::vector<cmStdString>::const_iterator l = libs.begin();
  927. l != libs.end(); ++l)
  928. {
  929. fout << this->ConvertToXMLOutputPath(l->c_str()) << " ";
  930. }
  931. }
  932. //----------------------------------------------------------------------------
  933. void
  934. cmLocalVisualStudio7Generator
  935. ::OutputLibraryDirectories(std::ostream& fout,
  936. std::vector<cmStdString> const& dirs)
  937. {
  938. const char* comma = "";
  939. for(std::vector<cmStdString>::const_iterator d = dirs.begin();
  940. d != dirs.end(); ++d)
  941. {
  942. // Remove any trailing slash and skip empty paths.
  943. std::string dir = *d;
  944. if(dir[dir.size()-1] == '/')
  945. {
  946. dir = dir.substr(0, dir.size()-1);
  947. }
  948. if(dir.empty())
  949. {
  950. continue;
  951. }
  952. // Switch to a relative path specification if it is shorter.
  953. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  954. {
  955. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  956. if(rel.size() < dir.size())
  957. {
  958. dir = rel;
  959. }
  960. }
  961. // First search a configuration-specific subdirectory and then the
  962. // original directory.
  963. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  964. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  965. comma = ",";
  966. }
  967. }
  968. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  969. const char *libName,
  970. cmTarget &target)
  971. {
  972. // get the configurations
  973. std::vector<std::string> *configs =
  974. static_cast<cmGlobalVisualStudio7Generator *>
  975. (this->GlobalGenerator)->GetConfigurations();
  976. // trace the visual studio dependencies
  977. std::string name = libName;
  978. name += ".vcproj.cmake";
  979. // We may be modifying the source groups temporarily, so make a copy.
  980. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  981. // get the classes from the source lists then add them to the groups
  982. std::vector<cmSourceFile*> & classes = target.GetSourceFiles();
  983. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  984. i != classes.end(); i++)
  985. {
  986. // Add the file to the list of sources.
  987. std::string source = (*i)->GetFullPath();
  988. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  989. {
  990. this->ModuleDefinitionFile = (*i)->GetFullPath();
  991. }
  992. cmSourceGroup& sourceGroup =
  993. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  994. sourceGroup.AssignSource(*i);
  995. }
  996. // Compute which sources need unique object computation.
  997. this->ComputeObjectNameRequirements(sourceGroups);
  998. // open the project
  999. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1000. // write the configuration information
  1001. this->WriteConfigurations(fout, libName, target);
  1002. fout << "\t<Files>\n";
  1003. // Loop through every source group.
  1004. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1005. {
  1006. cmSourceGroup sg = sourceGroups[i];
  1007. this->WriteGroup(&sg, target, fout, libName, configs);
  1008. }
  1009. //}
  1010. fout << "\t</Files>\n";
  1011. // Write the VCProj file's footer.
  1012. this->WriteVCProjFooter(fout);
  1013. }
  1014. void cmLocalVisualStudio7Generator
  1015. ::WriteGroup(const cmSourceGroup *sg, cmTarget target,
  1016. std::ostream &fout, const char *libName,
  1017. std::vector<std::string> *configs)
  1018. {
  1019. const std::vector<const cmSourceFile *> &sourceFiles =
  1020. sg->GetSourceFiles();
  1021. // If the group is empty, don't write it at all.
  1022. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  1023. {
  1024. return;
  1025. }
  1026. // If the group has a name, write the header.
  1027. std::string name = sg->GetName();
  1028. if(name != "")
  1029. {
  1030. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1031. }
  1032. // Loop through each source in the source group.
  1033. std::string objectName;
  1034. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1035. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1036. {
  1037. std::string source = (*sf)->GetFullPath();
  1038. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  1039. std::string compileFlags;
  1040. std::string additionalDeps;
  1041. if(this->NeedObjectName.find(*sf) != this->NeedObjectName.end())
  1042. {
  1043. objectName = this->GetObjectFileNameWithoutTarget(*(*sf));
  1044. }
  1045. else
  1046. {
  1047. objectName = "";
  1048. }
  1049. // Add per-source flags.
  1050. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  1051. if(cflags)
  1052. {
  1053. compileFlags += " ";
  1054. compileFlags += cflags;
  1055. }
  1056. const char* lang = this->GlobalGenerator->GetLanguageFromExtension
  1057. ((*sf)->GetSourceExtension().c_str());
  1058. const char* sourceLang = this->GetSourceFileLanguage(*(*sf));
  1059. const char* linkLanguage = target.GetLinkerLanguage
  1060. (this->GetGlobalGenerator());
  1061. bool needForceLang = false;
  1062. // source file does not match its extension language
  1063. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  1064. {
  1065. needForceLang = true;
  1066. lang = sourceLang;
  1067. }
  1068. // If lang is set, the compiler will generate code automatically.
  1069. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1070. // the project file
  1071. bool excludedFromBuild =
  1072. (lang && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY"));
  1073. // if the source file does not match the linker language
  1074. // then force c or c++
  1075. if(needForceLang || (linkLanguage && lang
  1076. && 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(),
  1556. cmds[0][1].c_str());
  1557. }
  1558. else
  1559. {
  1560. gg->CreateGUID(l->first.c_str());
  1561. }
  1562. }
  1563. }
  1564. //----------------------------------------------------------------------------
  1565. std::string cmLocalVisualStudio7Generator
  1566. ::GetTargetDirectory(cmTarget& target)
  1567. {
  1568. std::string dir;
  1569. dir += target.GetName();
  1570. dir += ".dir";
  1571. return dir;
  1572. }
  1573. //----------------------------------------------------------------------------
  1574. cmLocalVisualStudio7GeneratorOptions
  1575. ::cmLocalVisualStudio7GeneratorOptions(Tool tool):
  1576. DoingDefine(false), FlagTable(0)
  1577. {
  1578. // Choose the flag table for the requested tool.
  1579. switch(tool)
  1580. {
  1581. case Compiler:
  1582. this->FlagTable = cmLocalVisualStudio7GeneratorFlagTable; break;
  1583. case Linker:
  1584. this->FlagTable = cmLocalVisualStudio7GeneratorLinkFlagTable; break;
  1585. default: break;
  1586. }
  1587. }
  1588. //----------------------------------------------------------------------------
  1589. void cmLocalVisualStudio7GeneratorOptions::FixExceptionHandlingDefault()
  1590. {
  1591. // Exception handling is on by default because the platform file has
  1592. // "/EHsc" in the flags. Normally, that will override this
  1593. // initialization to off, but the user has the option of removing
  1594. // the flag to disable exception handling. When the user does
  1595. // remove the flag we need to override the IDE default of on.
  1596. this->FlagMap["ExceptionHandling"] = "FALSE";
  1597. }
  1598. //----------------------------------------------------------------------------
  1599. void cmLocalVisualStudio7GeneratorOptions::SetVerboseMakefile(bool verbose)
  1600. {
  1601. // If verbose makefiles have been requested and the /nologo option
  1602. // was not given explicitly in the flags we want to add an attribute
  1603. // to the generated project to disable logo suppression. Otherwise
  1604. // the GUI default is to enable suppression.
  1605. if(verbose &&
  1606. this->FlagMap.find("SuppressStartupBanner") == this->FlagMap.end())
  1607. {
  1608. this->FlagMap["SuppressStartupBanner"] = "FALSE";
  1609. }
  1610. }
  1611. //----------------------------------------------------------------------------
  1612. void cmLocalVisualStudio7GeneratorOptions::AddDefine(const std::string& def)
  1613. {
  1614. this->Defines.push_back(def);
  1615. }
  1616. //----------------------------------------------------------------------------
  1617. void cmLocalVisualStudio7GeneratorOptions::AddFlag(const char* flag,
  1618. const char* value)
  1619. {
  1620. this->FlagMap[flag] = value;
  1621. }
  1622. //----------------------------------------------------------------------------
  1623. bool cmLocalVisualStudio7GeneratorOptions::UsingUnicode()
  1624. {
  1625. // Look for the a _UNICODE definition.
  1626. for(std::vector<cmStdString>::const_iterator di = this->Defines.begin();
  1627. di != this->Defines.end(); ++di)
  1628. {
  1629. if(*di == "_UNICODE")
  1630. {
  1631. return true;
  1632. }
  1633. }
  1634. return false;
  1635. }
  1636. //----------------------------------------------------------------------------
  1637. bool cmLocalVisualStudio7GeneratorOptions::UsingDebugPDB()
  1638. {
  1639. std::map<cmStdString, cmStdString>::iterator mi =
  1640. this->FlagMap.find("DebugInformationFormat");
  1641. if(mi != this->FlagMap.end() && mi->second != "1")
  1642. {
  1643. return true;
  1644. }
  1645. else
  1646. {
  1647. return false;
  1648. }
  1649. }
  1650. //----------------------------------------------------------------------------
  1651. void cmLocalVisualStudio7GeneratorOptions::Parse(const char* flags)
  1652. {
  1653. // Parse the input string as a windows command line since the string
  1654. // is intended for writing directly into the build files.
  1655. std::vector<std::string> args;
  1656. cmSystemTools::ParseWindowsCommandLine(flags, args);
  1657. // Process flags that need to be represented specially in the IDE
  1658. // project file.
  1659. for(std::vector<std::string>::iterator ai = args.begin();
  1660. ai != args.end(); ++ai)
  1661. {
  1662. this->HandleFlag(ai->c_str());
  1663. }
  1664. }
  1665. //----------------------------------------------------------------------------
  1666. void cmLocalVisualStudio7GeneratorOptions::HandleFlag(const char* flag)
  1667. {
  1668. // If the last option was -D then this option is the definition.
  1669. if(this->DoingDefine)
  1670. {
  1671. this->DoingDefine = false;
  1672. this->Defines.push_back(flag);
  1673. return;
  1674. }
  1675. // Look for known arguments.
  1676. if(flag[0] == '-' || flag[0] == '/')
  1677. {
  1678. if(flag[1] == 'D')
  1679. {
  1680. if(flag[2] == '\0')
  1681. {
  1682. // The next argument will have the definition.
  1683. this->DoingDefine = true;
  1684. }
  1685. else
  1686. {
  1687. // Store this definition.
  1688. this->Defines.push_back(flag+2);
  1689. }
  1690. return;
  1691. }
  1692. else if(this->FlagTable)
  1693. {
  1694. // Look for an entry in the flag table matching this flag.
  1695. bool flag_handled = false;
  1696. for(cmVS7FlagTable const* entry = this->FlagTable;
  1697. entry->IDEName; ++entry)
  1698. {
  1699. bool entry_found = false;
  1700. if(entry->special & cmVS7FlagTable::UserValue)
  1701. {
  1702. // This flag table entry accepts a user-specified value. If
  1703. // the entry specifies UserRequired we must match only if a
  1704. // non-empty value is given.
  1705. int n = static_cast<int>(strlen(entry->commandFlag));
  1706. if(strncmp(flag+1, entry->commandFlag, n) == 0 &&
  1707. (!(entry->special & cmVS7FlagTable::UserRequired) ||
  1708. static_cast<int>(strlen(flag+1)) > n))
  1709. {
  1710. if(entry->special & cmVS7FlagTable::UserIgnored)
  1711. {
  1712. // Ignore the user-specified value.
  1713. this->FlagMap[entry->IDEName] = entry->value;
  1714. }
  1715. else
  1716. {
  1717. // Use the user-specified value.
  1718. this->FlagMap[entry->IDEName] = flag+1+n;
  1719. }
  1720. entry_found = true;
  1721. }
  1722. }
  1723. else if(strcmp(flag+1, entry->commandFlag) == 0)
  1724. {
  1725. // This flag table entry provides a fixed value.
  1726. this->FlagMap[entry->IDEName] = entry->value;
  1727. entry_found = true;
  1728. }
  1729. // If the flag has been handled by an entry not requesting a
  1730. // search continuation we are done.
  1731. if(entry_found && !(entry->special & cmVS7FlagTable::Continue))
  1732. {
  1733. return;
  1734. }
  1735. // If the entry was found the flag has been handled.
  1736. flag_handled = flag_handled || entry_found;
  1737. }
  1738. // If any map entry handled the flag we are done.
  1739. if(flag_handled)
  1740. {
  1741. return;
  1742. }
  1743. }
  1744. }
  1745. // This option is not known. Store it in the output flags.
  1746. this->FlagString += " ";
  1747. this->FlagString +=
  1748. cmSystemTools::EscapeWindowsShellArgument(flag,
  1749. cmsysSystem_Shell_Flag_VSIDE);
  1750. }
  1751. //----------------------------------------------------------------------------
  1752. void
  1753. cmLocalVisualStudio7GeneratorOptions
  1754. ::OutputPreprocessorDefinitions(std::ostream& fout,
  1755. const char* prefix,
  1756. const char* suffix)
  1757. {
  1758. if(this->Defines.empty())
  1759. {
  1760. return;
  1761. }
  1762. fout << prefix << "PreprocessorDefinitions=\"";
  1763. const char* comma = "";
  1764. for(std::vector<cmStdString>::const_iterator di = this->Defines.begin();
  1765. di != this->Defines.end(); ++di)
  1766. {
  1767. // Escape this flag for the IDE.
  1768. std::string define =
  1769. cmLocalVisualStudio7GeneratorEscapeForXML(di->c_str());
  1770. // Old comment:
  1771. // Double-quotes in the value of the definition must be escaped
  1772. // with a backslash. The entire definition should be quoted in
  1773. // the generated xml attribute to avoid confusing the VS parser.
  1774. // Write this flag. Quote it if the definition is not
  1775. // alphanumeric.
  1776. if(define.find_first_not_of(
  1777. "-_abcdefghigklmnopqrstuvwxyz1234567890ABCDEFGHIGKLMNOPQRSTUVWXYZ")
  1778. != define.npos)
  1779. {
  1780. fout << comma << "&quot;" << define << "&quot;";
  1781. }
  1782. else
  1783. {
  1784. fout << comma << define;
  1785. }
  1786. comma = ",";
  1787. }
  1788. fout << "\"" << suffix;
  1789. }
  1790. //----------------------------------------------------------------------------
  1791. void
  1792. cmLocalVisualStudio7GeneratorOptions
  1793. ::OutputFlagMap(std::ostream& fout, const char* indent)
  1794. {
  1795. for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
  1796. m != this->FlagMap.end(); ++m)
  1797. {
  1798. fout << indent << m->first << "=\"" << m->second << "\"\n";
  1799. }
  1800. }
  1801. //----------------------------------------------------------------------------
  1802. void
  1803. cmLocalVisualStudio7GeneratorOptions
  1804. ::OutputAdditionalOptions(std::ostream& fout,
  1805. const char* prefix,
  1806. const char* suffix)
  1807. {
  1808. if(!this->FlagString.empty())
  1809. {
  1810. fout << prefix << "AdditionalOptions=\"";
  1811. fout <<
  1812. cmLocalVisualStudio7GeneratorEscapeForXML(this->FlagString.c_str());
  1813. fout << "\"" << suffix;
  1814. }
  1815. }
  1816. void cmLocalVisualStudio7Generator::
  1817. GetTargetObjectFileDirectories(cmTarget* target,
  1818. std::vector<std::string>&
  1819. dirs)
  1820. {
  1821. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  1822. dir += "/";
  1823. dir += this->GetTargetDirectory(*target);
  1824. dir += "/";
  1825. dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
  1826. std::cerr << dir << "\n";
  1827. dirs.push_back(dir);
  1828. }
  1829. // return the source name for the object file
  1830. std::string
  1831. cmLocalVisualStudio7Generator::GetSourceObjectName(cmSourceFile& sf )
  1832. {
  1833. std::string ret = sf.GetSourceName();
  1834. std::string::size_type pos = ret.find("/");
  1835. if(pos == ret.npos)
  1836. {
  1837. return ret;
  1838. }
  1839. return ret.substr(pos+1);
  1840. }