cmLocalVisualStudio6Generator.cxx 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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 "cmGlobalGenerator.h"
  14. #include "cmLocalVisualStudio6Generator.h"
  15. #include "cmMakefile.h"
  16. #include "cmSystemTools.h"
  17. #include "cmSourceFile.h"
  18. #include "cmCacheManager.h"
  19. #include "cmake.h"
  20. #include <cmsys/RegularExpression.hxx>
  21. cmLocalVisualStudio6Generator::cmLocalVisualStudio6Generator()
  22. {
  23. }
  24. cmLocalVisualStudio6Generator::~cmLocalVisualStudio6Generator()
  25. {
  26. }
  27. void cmLocalVisualStudio6Generator::Generate()
  28. {
  29. std::set<cmStdString> lang;
  30. lang.insert("C");
  31. lang.insert("CXX");
  32. this->CreateCustomTargetsAndCommands(lang);
  33. this->OutputDSPFile();
  34. }
  35. void cmLocalVisualStudio6Generator::OutputDSPFile()
  36. {
  37. // If not an in source build, then create the output directory
  38. if(strcmp(m_Makefile->GetStartOutputDirectory(),
  39. m_Makefile->GetHomeDirectory()) != 0)
  40. {
  41. if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
  42. {
  43. cmSystemTools::Error("Error creating directory ",
  44. m_Makefile->GetStartOutputDirectory());
  45. }
  46. }
  47. // Setup /I and /LIBPATH options for the resulting DSP file
  48. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  49. std::vector<std::string>::iterator i;
  50. for(i = includes.begin(); i != includes.end(); ++i)
  51. {
  52. m_IncludeOptions += " /I ";
  53. std::string tmp = this->ConvertToOptionallyRelativeOutputPath(i->c_str());
  54. // quote if not already quoted
  55. if (tmp[0] != '"')
  56. {
  57. m_IncludeOptions += "\"";
  58. m_IncludeOptions += tmp;
  59. m_IncludeOptions += "\"";
  60. }
  61. else
  62. {
  63. m_IncludeOptions += tmp;
  64. }
  65. }
  66. // Create the DSP or set of DSP's for libraries and executables
  67. // clear project names
  68. m_CreatedProjectNames.clear();
  69. // build any targets
  70. cmTargets &tgts = m_Makefile->GetTargets();
  71. for(cmTargets::iterator l = tgts.begin();
  72. l != tgts.end(); l++)
  73. {
  74. switch(l->second.GetType())
  75. {
  76. case cmTarget::STATIC_LIBRARY:
  77. this->SetBuildType(STATIC_LIBRARY, l->first.c_str(), l->second);
  78. break;
  79. case cmTarget::SHARED_LIBRARY:
  80. case cmTarget::MODULE_LIBRARY:
  81. this->SetBuildType(DLL, l->first.c_str(), l->second);
  82. break;
  83. case cmTarget::EXECUTABLE:
  84. this->SetBuildType(EXECUTABLE,l->first.c_str(), l->second);
  85. break;
  86. case cmTarget::UTILITY:
  87. this->SetBuildType(UTILITY, l->first.c_str(), l->second);
  88. break;
  89. case cmTarget::INSTALL_FILES:
  90. break;
  91. case cmTarget::INSTALL_PROGRAMS:
  92. break;
  93. default:
  94. cmSystemTools::Error("Bad target type", l->first.c_str());
  95. break;
  96. }
  97. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  98. // so don't build a projectfile for it
  99. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  100. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  101. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  102. {
  103. // check to see if the dsp is going into a sub-directory
  104. std::string::size_type pos = l->first.rfind('/');
  105. if(pos != std::string::npos)
  106. {
  107. std::string dir = m_Makefile->GetStartOutputDirectory();
  108. dir += "/";
  109. dir += l->first.substr(0, pos);
  110. if(!cmSystemTools::MakeDirectory(dir.c_str()))
  111. {
  112. cmSystemTools::Error("Error creating directory ", dir.c_str());
  113. }
  114. }
  115. this->CreateSingleDSP(l->first.c_str(),l->second);
  116. }
  117. }
  118. }
  119. void cmLocalVisualStudio6Generator::CreateSingleDSP(const char *lname, cmTarget &target)
  120. {
  121. // add to the list of projects
  122. std::string pname = lname;
  123. m_CreatedProjectNames.push_back(pname);
  124. // create the dsp.cmake file
  125. std::string fname;
  126. fname = m_Makefile->GetStartOutputDirectory();
  127. fname += "/";
  128. fname += lname;
  129. fname += ".dsp";
  130. // save the name of the real dsp file
  131. std::string realDSP = fname;
  132. fname += ".cmake";
  133. std::ofstream fout(fname.c_str());
  134. if(!fout)
  135. {
  136. cmSystemTools::Error("Error Writing ", fname.c_str());
  137. cmSystemTools::ReportLastSystemError("");
  138. }
  139. this->WriteDSPFile(fout,lname,target);
  140. fout.close();
  141. // if the dsp file has changed, then write it.
  142. cmSystemTools::CopyFileIfDifferent(fname.c_str(), realDSP.c_str());
  143. }
  144. void cmLocalVisualStudio6Generator::AddDSPBuildRule()
  145. {
  146. std::string dspname = *(m_CreatedProjectNames.end()-1);
  147. dspname += ".dsp.cmake";
  148. const char* dsprule = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  149. cmCustomCommandLine commandLine;
  150. commandLine.push_back(dsprule);
  151. std::string makefileIn = m_Makefile->GetStartDirectory();
  152. makefileIn += "/";
  153. makefileIn += "CMakeLists.txt";
  154. std::string args;
  155. args = "-H";
  156. args +=
  157. this->Convert(m_Makefile->GetHomeDirectory(),START_OUTPUT, SHELL, true);
  158. commandLine.push_back(args);
  159. args = "-B";
  160. args +=
  161. this->Convert(m_Makefile->GetHomeOutputDirectory(),
  162. START_OUTPUT, SHELL, true);
  163. commandLine.push_back(args);
  164. std::string configFile =
  165. m_Makefile->GetRequiredDefinition("CMAKE_ROOT");
  166. configFile += "/Templates/CMakeWindowsSystemConfig.cmake";
  167. std::vector<std::string> listFiles = m_Makefile->GetListFiles();
  168. bool found = false;
  169. for(std::vector<std::string>::iterator i = listFiles.begin();
  170. i != listFiles.end(); ++i)
  171. {
  172. if(*i == configFile)
  173. {
  174. found = true;
  175. }
  176. }
  177. if(!found)
  178. {
  179. listFiles.push_back(configFile);
  180. }
  181. cmCustomCommandLines commandLines;
  182. commandLines.push_back(commandLine);
  183. const char* no_comment = 0;
  184. m_Makefile->AddCustomCommandToOutput(dspname.c_str(), listFiles, makefileIn.c_str(),
  185. commandLines, no_comment, true);
  186. }
  187. void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
  188. const char *libName,
  189. cmTarget &target)
  190. {
  191. // if we should add regen rule then...
  192. const char *suppRegenRule =
  193. m_Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  194. if (!cmSystemTools::IsOn(suppRegenRule))
  195. {
  196. this->AddDSPBuildRule();
  197. }
  198. // For utility targets need custom command since pre- and post-
  199. // build does not do anything in Visual Studio 6. In order for the
  200. // rules to run in the correct order as custom commands, we need
  201. // special care for dependencies. The first rule must depend on all
  202. // the dependencies of all the rules. The later rules must each
  203. // depend only on the previous rule.
  204. if (target.GetType() == cmTarget::UTILITY &&
  205. (!target.GetPreBuildCommands().empty() ||
  206. !target.GetPostBuildCommands().empty()))
  207. {
  208. // Accumulate the dependencies of all the commands.
  209. std::vector<std::string> depends;
  210. for (std::vector<cmCustomCommand>::const_iterator cr =
  211. target.GetPreBuildCommands().begin();
  212. cr != target.GetPreBuildCommands().end(); ++cr)
  213. {
  214. depends.insert(depends.end(),
  215. cr->GetDepends().begin(), cr->GetDepends().end());
  216. }
  217. for (std::vector<cmCustomCommand>::const_iterator cr =
  218. target.GetPostBuildCommands().begin();
  219. cr != target.GetPostBuildCommands().end(); ++cr)
  220. {
  221. depends.insert(depends.end(),
  222. cr->GetDepends().begin(), cr->GetDepends().end());
  223. }
  224. // Add the pre- and post-build commands in order.
  225. int count = 1;
  226. for (std::vector<cmCustomCommand>::const_iterator cr =
  227. target.GetPreBuildCommands().begin();
  228. cr != target.GetPreBuildCommands().end(); ++cr)
  229. {
  230. this->AddUtilityCommandHack(target, count++, depends,
  231. cr->GetCommandLines());
  232. }
  233. for (std::vector<cmCustomCommand>::const_iterator cr =
  234. target.GetPostBuildCommands().begin();
  235. cr != target.GetPostBuildCommands().end(); ++cr)
  236. {
  237. this->AddUtilityCommandHack(target, count++, depends,
  238. cr->GetCommandLines());
  239. }
  240. }
  241. // trace the visual studio dependencies
  242. std::string name = libName;
  243. name += ".dsp.cmake";
  244. target.TraceVSDependencies(name, m_Makefile);
  245. // We may be modifying the source groups temporarily, so make a copy.
  246. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  247. // get the classes from the source lists then add them to the groups
  248. std::vector<cmSourceFile*> & classes = target.GetSourceFiles();
  249. // now all of the source files have been properly assigned to the target
  250. // now stick them into source groups using the reg expressions
  251. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  252. i != classes.end(); i++)
  253. {
  254. // Add the file to the list of sources.
  255. std::string source = (*i)->GetFullPath();
  256. cmSourceGroup& sourceGroup = m_Makefile->FindSourceGroup(source.c_str(),
  257. sourceGroups);
  258. sourceGroup.AssignSource(*i);
  259. // while we are at it, if it is a .rule file then for visual studio 6 we
  260. // must generate it
  261. if ((*i)->GetSourceExtension() == "rule")
  262. {
  263. if(!cmSystemTools::FileExists(source.c_str()))
  264. {
  265. cmSystemTools::ReplaceString(source, "$(IntDir)/", "");
  266. #if defined(_WIN32) || defined(__CYGWIN__)
  267. std::ofstream fout(source.c_str(),
  268. std::ios::binary | std::ios::out | std::ios::trunc);
  269. #else
  270. std::ofstream fout(source.c_str(),
  271. std::ios::out | std::ios::trunc);
  272. #endif
  273. if(fout)
  274. {
  275. fout.write("# generated from CMake",22);
  276. fout.flush();
  277. fout.close();
  278. }
  279. }
  280. }
  281. }
  282. // Write the DSP file's header.
  283. this->WriteDSPHeader(fout, libName, target, sourceGroups);
  284. // Loop through every source group.
  285. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  286. sg != sourceGroups.end(); ++sg)
  287. {
  288. this->WriteGroup(&(*sg), target, fout, libName);
  289. }
  290. // Write the DSP file's footer.
  291. this->WriteDSPFooter(fout);
  292. }
  293. void cmLocalVisualStudio6Generator::WriteGroup(const cmSourceGroup *sg, cmTarget target, std::ostream &fout, const char *libName)
  294. {
  295. const std::vector<const cmSourceFile *> &sourceFiles =
  296. sg->GetSourceFiles();
  297. // If the group is empty, don't write it at all.
  298. if(sourceFiles.empty())
  299. {
  300. return;
  301. }
  302. // If the group has a name, write the header.
  303. std::string name = sg->GetName();
  304. if(name != "")
  305. {
  306. this->WriteDSPBeginGroup(fout, name.c_str(), "");
  307. }
  308. // Loop through each source in the source group.
  309. for(std::vector<const cmSourceFile *>::const_iterator sf =
  310. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  311. {
  312. std::string source = (*sf)->GetFullPath();
  313. const cmCustomCommand *command =
  314. (*sf)->GetCustomCommand();
  315. std::string compileFlags;
  316. std::vector<std::string> depends;
  317. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  318. if(cflags)
  319. {
  320. compileFlags = cflags;
  321. }
  322. const char* lang =
  323. m_GlobalGenerator->GetLanguageFromExtension((*sf)->GetSourceExtension().c_str());
  324. if(lang && strcmp(lang, "CXX") == 0)
  325. {
  326. // force a C++ file type
  327. compileFlags += " /TP ";
  328. }
  329. // Check for extra object-file dependencies.
  330. const char* dependsValue = (*sf)->GetProperty("OBJECT_DEPENDS");
  331. if(dependsValue)
  332. {
  333. cmSystemTools::ExpandListArgument(dependsValue, depends);
  334. }
  335. if (source != libName || target.GetType() == cmTarget::UTILITY)
  336. {
  337. fout << "# Begin Source File\n\n";
  338. // Tell MS-Dev what the source is. If the compiler knows how to
  339. // build it, then it will.
  340. fout << "SOURCE=" <<
  341. this->ConvertToOptionallyRelativeOutputPath(source.c_str()) << "\n\n";
  342. if(!depends.empty())
  343. {
  344. // Write out the dependencies for the rule.
  345. fout << "USERDEP__HACK=";
  346. for(std::vector<std::string>::const_iterator d = depends.begin();
  347. d != depends.end(); ++d)
  348. {
  349. fout << "\\\n\t" <<
  350. this->ConvertToOptionallyRelativeOutputPath(d->c_str());
  351. }
  352. fout << "\n";
  353. }
  354. if (command)
  355. {
  356. std::string script =
  357. this->ConstructScript(command->GetCommandLines(), "\\\n\t");
  358. const char* comment = command->GetComment();
  359. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  360. this->WriteCustomRule(fout, source.c_str(), script.c_str(),
  361. (*comment?comment:"Custom Rule"),
  362. command->GetDepends(),
  363. command->GetOutput(), flags);
  364. }
  365. else if(compileFlags.size())
  366. {
  367. for(std::vector<std::string>::iterator i
  368. = m_Configurations.begin(); i != m_Configurations.end(); ++i)
  369. {
  370. if (i == m_Configurations.begin())
  371. {
  372. fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
  373. }
  374. else
  375. {
  376. fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
  377. }
  378. fout << "\n# ADD CPP " << compileFlags << "\n\n";
  379. }
  380. fout << "!ENDIF\n\n";
  381. }
  382. fout << "# End Source File\n";
  383. }
  384. }
  385. std::vector<cmSourceGroup> children = sg->GetGroupChildren();
  386. for(unsigned int i=0;i<children.size();++i)
  387. {
  388. this->WriteGroup(&children[i], target, fout, libName);
  389. }
  390. // If the group has a name, write the footer.
  391. if(name != "")
  392. {
  393. this->WriteDSPEndGroup(fout);
  394. }
  395. }
  396. void
  397. cmLocalVisualStudio6Generator
  398. ::AddUtilityCommandHack(cmTarget& target, int count,
  399. std::vector<std::string>& depends,
  400. const cmCustomCommandLines& commandLines)
  401. {
  402. // Create a fake output that forces the rule to run.
  403. char* output = new char[(strlen(m_Makefile->GetStartOutputDirectory()) +
  404. strlen(target.GetName()) + 30)];
  405. sprintf(output,"%s/%s_force_%i", m_Makefile->GetStartOutputDirectory(),
  406. target.GetName(), count);
  407. // Add the rule with the given dependencies and commands.
  408. const char* no_main_dependency = 0;
  409. const char* no_comment = 0;
  410. m_Makefile->AddCustomCommandToOutput(output,
  411. depends,
  412. no_main_dependency,
  413. commandLines,
  414. no_comment);
  415. // Replace the dependencies with the output of this rule so that the
  416. // next rule added will run after this one.
  417. depends.clear();
  418. depends.push_back(output);
  419. // Add a source file representing this output to the project.
  420. cmSourceFile* outsf = m_Makefile->GetSourceFileWithOutput(output);
  421. target.GetSourceFiles().push_back(outsf);
  422. // Free the fake output name.
  423. delete [] output;
  424. }
  425. void cmLocalVisualStudio6Generator::WriteCustomRule(std::ostream& fout,
  426. const char* source,
  427. const char* command,
  428. const char* comment,
  429. const std::vector<std::string>& depends,
  430. const char *output,
  431. const char* flags
  432. )
  433. {
  434. std::vector<std::string>::iterator i;
  435. for(i = m_Configurations.begin(); i != m_Configurations.end(); ++i)
  436. {
  437. if (i == m_Configurations.begin())
  438. {
  439. fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
  440. }
  441. else
  442. {
  443. fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
  444. }
  445. if(flags)
  446. {
  447. fout << "\n# ADD CPP " << flags << "\n\n";
  448. }
  449. // Write out the dependencies for the rule.
  450. fout << "USERDEP__HACK=";
  451. for(std::vector<std::string>::const_iterator d = depends.begin();
  452. d != depends.end(); ++d)
  453. {
  454. std::string dep = cmSystemTools::GetFilenameName(*d);
  455. if (cmSystemTools::GetFilenameLastExtension(dep) == ".exe")
  456. {
  457. dep = cmSystemTools::GetFilenameWithoutLastExtension(dep);
  458. }
  459. std::string libPath = dep + "_CMAKE_PATH";
  460. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  461. if (cacheValue && *cacheValue)
  462. {
  463. std::string exePath = "";
  464. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  465. {
  466. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  467. }
  468. if(exePath.size())
  469. {
  470. libPath = exePath;
  471. }
  472. else
  473. {
  474. libPath = cacheValue;
  475. }
  476. libPath += "/";
  477. libPath += "$(INTDIR)/";
  478. libPath += dep;
  479. libPath += ".exe";
  480. fout << "\\\n\t" <<
  481. this->ConvertToOptionallyRelativeOutputPath(libPath.c_str());
  482. }
  483. else
  484. {
  485. fout << "\\\n\t" <<
  486. this->ConvertToOptionallyRelativeOutputPath(d->c_str());
  487. }
  488. }
  489. fout << "\n";
  490. fout << "# PROP Ignore_Default_Tool 1\n";
  491. fout << "# Begin Custom Build - Building " << comment
  492. << " $(InputPath)\n\n";
  493. if(output == 0)
  494. {
  495. fout << source << "_force : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
  496. fout << command << "\n\n";
  497. }
  498. // Write a rule for every output generated by this command.
  499. fout << this->ConvertToOptionallyRelativeOutputPath(output)
  500. << " : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
  501. fout << command << "\n\n";
  502. fout << "# End Custom Build\n\n";
  503. }
  504. fout << "!ENDIF\n\n";
  505. }
  506. void cmLocalVisualStudio6Generator::WriteDSPBeginGroup(std::ostream& fout,
  507. const char* group,
  508. const char* filter)
  509. {
  510. fout << "# Begin Group \"" << group << "\"\n"
  511. "# PROP Default_Filter \"" << filter << "\"\n";
  512. }
  513. void cmLocalVisualStudio6Generator::WriteDSPEndGroup(std::ostream& fout)
  514. {
  515. fout << "# End Group\n";
  516. }
  517. void cmLocalVisualStudio6Generator::SetBuildType(BuildType b,
  518. const char* libName,
  519. cmTarget& target)
  520. {
  521. std::string root= m_Makefile->GetRequiredDefinition("CMAKE_ROOT");
  522. const char *def= m_Makefile->GetDefinition( "MSPROJECT_TEMPLATE_DIRECTORY");
  523. if( def)
  524. {
  525. root = def;
  526. }
  527. else
  528. {
  529. root += "/Templates";
  530. }
  531. switch(b)
  532. {
  533. case STATIC_LIBRARY:
  534. m_DSPHeaderTemplate = root;
  535. m_DSPHeaderTemplate += "/staticLibHeader.dsptemplate";
  536. m_DSPFooterTemplate = root;
  537. m_DSPFooterTemplate += "/staticLibFooter.dsptemplate";
  538. break;
  539. case DLL:
  540. m_DSPHeaderTemplate = root;
  541. m_DSPHeaderTemplate += "/DLLHeader.dsptemplate";
  542. m_DSPFooterTemplate = root;
  543. m_DSPFooterTemplate += "/DLLFooter.dsptemplate";
  544. break;
  545. case EXECUTABLE:
  546. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  547. {
  548. m_DSPHeaderTemplate = root;
  549. m_DSPHeaderTemplate += "/EXEWinHeader.dsptemplate";
  550. m_DSPFooterTemplate = root;
  551. m_DSPFooterTemplate += "/EXEFooter.dsptemplate";
  552. }
  553. else
  554. {
  555. m_DSPHeaderTemplate = root;
  556. m_DSPHeaderTemplate += "/EXEHeader.dsptemplate";
  557. m_DSPFooterTemplate = root;
  558. m_DSPFooterTemplate += "/EXEFooter.dsptemplate";
  559. }
  560. break;
  561. case UTILITY:
  562. m_DSPHeaderTemplate = root;
  563. m_DSPHeaderTemplate += "/UtilityHeader.dsptemplate";
  564. m_DSPFooterTemplate = root;
  565. m_DSPFooterTemplate += "/UtilityFooter.dsptemplate";
  566. break;
  567. }
  568. // once the build type is set, determine what configurations are
  569. // possible
  570. std::ifstream fin(m_DSPHeaderTemplate.c_str());
  571. cmsys::RegularExpression reg("# Name ");
  572. if(!fin)
  573. {
  574. cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str());
  575. }
  576. // reset m_Configurations
  577. m_Configurations.erase(m_Configurations.begin(), m_Configurations.end());
  578. // now add all the configurations possible
  579. std::string line;
  580. while(cmSystemTools::GetLineFromStream(fin, line))
  581. {
  582. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName);
  583. if (reg.find(line))
  584. {
  585. m_Configurations.push_back(line.substr(reg.end()));
  586. }
  587. }
  588. }
  589. // look for custom rules on a target and collect them together
  590. std::string
  591. cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target,
  592. const char * /* libName */)
  593. {
  594. std::string customRuleCode = "";
  595. if (target.GetType() >= cmTarget::UTILITY)
  596. {
  597. return customRuleCode;
  598. }
  599. // are there any rules?
  600. if (target.GetPreBuildCommands().size() +
  601. target.GetPreLinkCommands().size() +
  602. target.GetPostBuildCommands().size() == 0)
  603. {
  604. return customRuleCode;
  605. }
  606. customRuleCode = "# Begin Special Build Tool\n";
  607. // Write the pre-build and pre-link together (VS6 does not support
  608. // both). Make sure no continuation character is put on the last
  609. // line.
  610. int prelink_total = (static_cast<int>(target.GetPreBuildCommands().size())+
  611. static_cast<int>(target.GetPreLinkCommands().size()));
  612. int prelink_count = 0;
  613. if(prelink_total > 0)
  614. {
  615. // header stuff
  616. customRuleCode += "PreLink_Cmds=";
  617. }
  618. const char* prelink_newline = "\\\n\t";
  619. for (std::vector<cmCustomCommand>::const_iterator cr =
  620. target.GetPreBuildCommands().begin();
  621. cr != target.GetPreBuildCommands().end(); ++cr)
  622. {
  623. if(++prelink_count == prelink_total)
  624. {
  625. prelink_newline = "";
  626. }
  627. customRuleCode += this->ConstructScript(cr->GetCommandLines(),
  628. prelink_newline);
  629. }
  630. for (std::vector<cmCustomCommand>::const_iterator cr =
  631. target.GetPreLinkCommands().begin();
  632. cr != target.GetPreLinkCommands().end(); ++cr)
  633. {
  634. if(++prelink_count == prelink_total)
  635. {
  636. prelink_newline = "";
  637. }
  638. customRuleCode += this->ConstructScript(cr->GetCommandLines(),
  639. prelink_newline);
  640. }
  641. if(prelink_total > 0)
  642. {
  643. customRuleCode += "\n";
  644. }
  645. // Write the post-build rules. Make sure no continuation character
  646. // is put on the last line.
  647. int postbuild_total = static_cast<int>(target.GetPostBuildCommands().size());
  648. int postbuild_count = 0;
  649. const char* postbuild_newline = "\\\n\t";
  650. if(postbuild_total > 0)
  651. {
  652. customRuleCode += "PostBuild_Cmds=";
  653. }
  654. for (std::vector<cmCustomCommand>::const_iterator cr =
  655. target.GetPostBuildCommands().begin();
  656. cr != target.GetPostBuildCommands().end(); ++cr)
  657. {
  658. if(++postbuild_count == postbuild_total)
  659. {
  660. postbuild_newline = "";
  661. }
  662. customRuleCode += this->ConstructScript(cr->GetCommandLines(),
  663. postbuild_newline);
  664. }
  665. if(postbuild_total > 0)
  666. {
  667. customRuleCode += "\n";
  668. }
  669. customRuleCode += "# End Special Build Tool\n";
  670. return customRuleCode;
  671. }
  672. inline std::string removeQuotes(const std::string& s)
  673. {
  674. if(s[0] == '\"' && s[s.size()-1] == '\"')
  675. {
  676. return s.substr(1, s.size()-2);
  677. }
  678. return s;
  679. }
  680. void cmLocalVisualStudio6Generator
  681. ::WriteDSPHeader(std::ostream& fout,
  682. const char *libName, cmTarget &target,
  683. std::vector<cmSourceGroup> &)
  684. {
  685. std::set<std::string> pathEmitted;
  686. // determine the link directories
  687. std::string libOptions;
  688. std::string libDebugOptions;
  689. std::string libOptimizedOptions;
  690. std::string libMultiLineOptions;
  691. std::string libMultiLineOptionsForDebug;
  692. std::string libMultiLineDebugOptions;
  693. std::string libMultiLineOptimizedOptions;
  694. // suppoirt override in output directory
  695. std::string libPath = "";
  696. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  697. {
  698. libPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  699. }
  700. std::string exePath = "";
  701. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  702. {
  703. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  704. }
  705. if(libPath.size())
  706. {
  707. // make sure there is a trailing slash
  708. if(libPath[libPath.size()-1] != '/')
  709. {
  710. libPath += "/";
  711. }
  712. std::string lpath =
  713. this->ConvertToOptionallyRelativeOutputPath(libPath.c_str());
  714. if(lpath.size() == 0)
  715. {
  716. lpath = ".";
  717. }
  718. std::string lpathIntDir = libPath + "$(INTDIR)";
  719. lpathIntDir = this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  720. if(pathEmitted.insert(lpath).second)
  721. {
  722. libOptions += " /LIBPATH:";
  723. libOptions += lpathIntDir;
  724. libOptions += " ";
  725. libOptions += " /LIBPATH:";
  726. libOptions += lpath;
  727. libOptions += " ";
  728. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  729. libMultiLineOptions += lpathIntDir;
  730. libMultiLineOptions += " ";
  731. libMultiLineOptions += " /LIBPATH:";
  732. libMultiLineOptions += lpath;
  733. libMultiLineOptions += " \n";
  734. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  735. libMultiLineOptionsForDebug += lpathIntDir;
  736. libMultiLineOptionsForDebug += " ";
  737. libMultiLineOptionsForDebug += " /LIBPATH:";
  738. libMultiLineOptionsForDebug += lpath;
  739. libMultiLineOptionsForDebug += " \n";
  740. }
  741. }
  742. if(exePath.size())
  743. {
  744. // make sure there is a trailing slash
  745. if(exePath[exePath.size()-1] != '/')
  746. {
  747. exePath += "/";
  748. }
  749. std::string lpath =
  750. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str());
  751. if(lpath.size() == 0)
  752. {
  753. lpath = ".";
  754. }
  755. std::string lpathIntDir = exePath + "$(INTDIR)";
  756. lpathIntDir = this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  757. if(pathEmitted.insert(lpath).second)
  758. {
  759. libOptions += " /LIBPATH:";
  760. libOptions += lpathIntDir;
  761. libOptions += " ";
  762. libOptions += " /LIBPATH:";
  763. libOptions += lpath;
  764. libOptions += " ";
  765. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  766. libMultiLineOptions += lpathIntDir;
  767. libMultiLineOptions += " ";
  768. libMultiLineOptions += " /LIBPATH:";
  769. libMultiLineOptions += lpath;
  770. libMultiLineOptions += " \n";
  771. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  772. libMultiLineOptionsForDebug += lpathIntDir;
  773. libMultiLineOptionsForDebug += " ";
  774. libMultiLineOptionsForDebug += " /LIBPATH:";
  775. libMultiLineOptionsForDebug += lpath;
  776. libMultiLineOptionsForDebug += " \n";
  777. }
  778. }
  779. std::vector<std::string>::const_iterator i;
  780. const std::vector<std::string>& libdirs = target.GetLinkDirectories();
  781. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  782. {
  783. std::string path = *i;
  784. if(path[path.size()-1] != '/')
  785. {
  786. path += "/";
  787. }
  788. std::string lpath =
  789. this->ConvertToOptionallyRelativeOutputPath(path.c_str());
  790. if(lpath.size() == 0)
  791. {
  792. lpath = ".";
  793. }
  794. std::string lpathIntDir = path + "$(INTDIR)";
  795. lpathIntDir = this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  796. if(pathEmitted.insert(lpath).second)
  797. {
  798. libOptions += " /LIBPATH:";
  799. libOptions += lpathIntDir;
  800. libOptions += " ";
  801. libOptions += " /LIBPATH:";
  802. libOptions += lpath;
  803. libOptions += " ";
  804. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  805. libMultiLineOptions += lpathIntDir;
  806. libMultiLineOptions += " ";
  807. libMultiLineOptions += " /LIBPATH:";
  808. libMultiLineOptions += lpath;
  809. libMultiLineOptions += " \n";
  810. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  811. libMultiLineOptionsForDebug += lpathIntDir;
  812. libMultiLineOptionsForDebug += " ";
  813. libMultiLineOptionsForDebug += " /LIBPATH:";
  814. libMultiLineOptionsForDebug += lpath;
  815. libMultiLineOptionsForDebug += " \n";
  816. }
  817. }
  818. // find link libraries
  819. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  820. cmTarget::LinkLibraries::const_iterator j;
  821. for(j = libs.begin(); j != libs.end(); ++j)
  822. {
  823. // add libraries to executables and dlls (but never include
  824. // a library in a library, bad recursion)
  825. if ((target.GetType() != cmTarget::SHARED_LIBRARY
  826. && target.GetType() != cmTarget::STATIC_LIBRARY
  827. && target.GetType() != cmTarget::MODULE_LIBRARY) ||
  828. (target.GetType()==cmTarget::SHARED_LIBRARY && libName != j->first) ||
  829. (target.GetType()==cmTarget::MODULE_LIBRARY && libName != j->first))
  830. {
  831. std::string lib = j->first;
  832. std::string libDebug = j->first;
  833. std::string libPath = j->first + "_CMAKE_PATH";
  834. const char* cacheValue
  835. = m_GlobalGenerator->GetCMakeInstance()->GetCacheDefinition(
  836. libPath.c_str());
  837. if ( cacheValue && *cacheValue && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX") )
  838. {
  839. libDebug += m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  840. }
  841. if(j->first.find(".lib") == std::string::npos)
  842. {
  843. lib += ".lib";
  844. libDebug += ".lib";
  845. }
  846. lib = this->ConvertToOptionallyRelativeOutputPath(lib.c_str());
  847. libDebug = this->ConvertToOptionallyRelativeOutputPath(libDebug.c_str());
  848. if (j->second == cmTarget::GENERAL)
  849. {
  850. libOptions += " ";
  851. libOptions += lib;
  852. libMultiLineOptions += "# ADD LINK32 ";
  853. libMultiLineOptions += lib;
  854. libMultiLineOptions += "\n";
  855. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  856. libMultiLineOptionsForDebug += libDebug;
  857. libMultiLineOptionsForDebug += "\n";
  858. }
  859. if (j->second == cmTarget::DEBUG)
  860. {
  861. libDebugOptions += " ";
  862. libDebugOptions += lib;
  863. libMultiLineDebugOptions += "# ADD LINK32 ";
  864. libMultiLineDebugOptions += libDebug;
  865. libMultiLineDebugOptions += "\n";
  866. }
  867. if (j->second == cmTarget::OPTIMIZED)
  868. {
  869. libOptimizedOptions += " ";
  870. libOptimizedOptions += lib;
  871. libMultiLineOptimizedOptions += "# ADD LINK32 ";
  872. libMultiLineOptimizedOptions += lib;
  873. libMultiLineOptimizedOptions += "\n";
  874. }
  875. }
  876. }
  877. std::string outputName = "(OUTPUT_NAME is for executables only)";
  878. std::string extraLinkOptions;
  879. if(target.GetType() == cmTarget::EXECUTABLE)
  880. {
  881. extraLinkOptions =
  882. m_Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  883. // Use the OUTPUT_NAME property if it was set. This is supported
  884. // only for executables.
  885. if(const char* outName = target.GetProperty("OUTPUT_NAME"))
  886. {
  887. outputName = outName;
  888. }
  889. else
  890. {
  891. outputName = target.GetName();
  892. }
  893. outputName += ".exe";
  894. }
  895. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  896. {
  897. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  898. }
  899. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  900. {
  901. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  902. }
  903. if(extraLinkOptions.size())
  904. {
  905. libOptions += " ";
  906. libOptions += extraLinkOptions;
  907. libOptions += " ";
  908. libMultiLineOptions += "# ADD LINK32 ";
  909. libMultiLineOptions += extraLinkOptions;
  910. libMultiLineOptions += " \n";
  911. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  912. libMultiLineOptionsForDebug += extraLinkOptions;
  913. libMultiLineOptionsForDebug += " \n";
  914. }
  915. if(const char* stdLibs = m_Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES"))
  916. {
  917. libOptions += " ";
  918. libOptions += stdLibs;
  919. libOptions += " ";
  920. libMultiLineOptions += "# ADD LINK32 ";
  921. libMultiLineOptions += stdLibs;
  922. libMultiLineOptions += " \n";
  923. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  924. libMultiLineOptionsForDebug += stdLibs;
  925. libMultiLineOptionsForDebug += " \n";
  926. }
  927. if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS"))
  928. {
  929. libOptions += " ";
  930. libOptions += targetLinkFlags;
  931. libOptions += " ";
  932. libMultiLineOptions += "# ADD LINK32 ";
  933. libMultiLineOptions += targetLinkFlags;
  934. libMultiLineOptions += " \n";
  935. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  936. libMultiLineOptionsForDebug += targetLinkFlags;
  937. libMultiLineOptionsForDebug += " \n";
  938. }
  939. // are there any custom rules on the target itself
  940. // only if the target is a lib or exe
  941. std::string customRuleCode = this->CreateTargetRules(target, libName);
  942. std::ifstream fin(m_DSPHeaderTemplate.c_str());
  943. if(!fin)
  944. {
  945. cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str());
  946. }
  947. std::string staticLibOptions;
  948. if(target.GetType() == cmTarget::STATIC_LIBRARY )
  949. {
  950. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  951. {
  952. staticLibOptions = libflags;
  953. }
  954. }
  955. std::string exportSymbol;
  956. if (const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  957. {
  958. exportSymbol = custom_export_name;
  959. }
  960. else
  961. {
  962. std::string in = libName;
  963. in += "_EXPORTS";
  964. exportSymbol = cmSystemTools::MakeCindentifier(in.c_str());
  965. }
  966. std::string line;
  967. while(cmSystemTools::GetLineFromStream(fin, line))
  968. {
  969. const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG");
  970. if(!mfcFlag)
  971. {
  972. mfcFlag = "0";
  973. }
  974. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME_EXPORTS",
  975. exportSymbol.c_str());
  976. cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE",
  977. customRuleCode.c_str());
  978. cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG",
  979. mfcFlag);
  980. if(target.GetType() == cmTarget::STATIC_LIBRARY )
  981. {
  982. cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS",
  983. staticLibOptions.c_str());
  984. }
  985. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  986. {
  987. cmSystemTools::ReplaceString(line, "/nologo", "");
  988. }
  989. cmSystemTools::ReplaceString(line, "CM_LIBRARIES",
  990. libOptions.c_str());
  991. cmSystemTools::ReplaceString(line, "CM_DEBUG_LIBRARIES",
  992. libDebugOptions.c_str());
  993. cmSystemTools::ReplaceString(line, "CM_OPTIMIZED_LIBRARIES",
  994. libOptimizedOptions.c_str());
  995. cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES_FOR_DEBUG",
  996. libMultiLineOptionsForDebug.c_str());
  997. cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES",
  998. libMultiLineOptions.c_str());
  999. cmSystemTools::ReplaceString(line, "CM_MULTILINE_DEBUG_LIBRARIES",
  1000. libMultiLineDebugOptions.c_str());
  1001. cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIMIZED_LIBRARIES",
  1002. libMultiLineOptimizedOptions.c_str());
  1003. // Replace the template file text OUTPUT_NAME with the real output
  1004. // name that will be used. Only the executable template should
  1005. // have this text.
  1006. cmSystemTools::ReplaceString(line, "OUTPUT_NAME", outputName.c_str());
  1007. cmSystemTools::ReplaceString(line, "BUILD_INCLUDES",
  1008. m_IncludeOptions.c_str());
  1009. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName);
  1010. // because LIBRARY_OUTPUT_PATH and EXECUTABLE_OUTPUT_PATH
  1011. // are already quoted in the template file,
  1012. // we need to remove the quotes here, we still need
  1013. // to convert to output path for unix to win32 conversion
  1014. cmSystemTools::ReplaceString(line, "LIBRARY_OUTPUT_PATH",
  1015. removeQuotes(
  1016. this->ConvertToOptionallyRelativeOutputPath(libPath.c_str())).c_str());
  1017. cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATH",
  1018. removeQuotes(
  1019. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
  1020. cmSystemTools::ReplaceString(line,
  1021. "EXTRA_DEFINES",
  1022. m_Makefile->GetDefineFlags());
  1023. const char* debugPostfix
  1024. = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  1025. cmSystemTools::ReplaceString(line, "DEBUG_POSTFIX",
  1026. debugPostfix?debugPostfix:"");
  1027. // store flags for each configuration
  1028. std::string flags = " ";
  1029. std::string flagsRelease = " ";
  1030. std::string flagsMinSize = " ";
  1031. std::string flagsDebug = " ";
  1032. std::string flagsDebugRel = " ";
  1033. if(target.GetType() >= cmTarget::EXECUTABLE &&
  1034. target.GetType() <= cmTarget::MODULE_LIBRARY)
  1035. {
  1036. const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator());
  1037. if(!linkLanguage)
  1038. {
  1039. cmSystemTools::Error("CMake can not determine linker language for target:",
  1040. target.GetName());
  1041. return;
  1042. }
  1043. // if CXX is on and the target contains cxx code then add the cxx flags
  1044. std::string baseFlagVar = "CMAKE_";
  1045. baseFlagVar += linkLanguage;
  1046. baseFlagVar += "_FLAGS";
  1047. flags = m_Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  1048. std::string flagVar = baseFlagVar + "_RELEASE";
  1049. flagsRelease = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1050. flagsRelease += " -DCMAKE_INTDIR=\\\"Release\\\" ";
  1051. flagVar = baseFlagVar + "_MINSIZEREL";
  1052. flagsMinSize = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1053. flagsMinSize += " -DCMAKE_INTDIR=\\\"MinSizeRel\\\" ";
  1054. flagVar = baseFlagVar + "_DEBUG";
  1055. flagsDebug = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1056. flagsDebug += " -DCMAKE_INTDIR=\\\"Debug\\\" ";
  1057. flagVar = baseFlagVar + "_RELWITHDEBINFO";
  1058. flagsDebugRel = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1059. flagsDebugRel += " -DCMAKE_INTDIR=\\\"RelWithDebInfo\\\" ";
  1060. }
  1061. // if unicode is not found, then add -D_MBCS
  1062. std::string defs = m_Makefile->GetDefineFlags();
  1063. if(flags.find("D_UNICODE") == flags.npos &&
  1064. defs.find("D_UNICODE") == flags.npos)
  1065. {
  1066. flags += " /D \"_MBCS\"";
  1067. }
  1068. // The template files have CXX FLAGS in them, that need to be replaced.
  1069. // There are not separate CXX and C template files, so we use the same
  1070. // variable names. The previous code sets up flags* variables to contain
  1071. // the correct C or CXX flags
  1072. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_MINSIZEREL", flagsMinSize.c_str());
  1073. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_DEBUG", flagsDebug.c_str());
  1074. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELWITHDEBINFO", flagsDebugRel.c_str());
  1075. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELEASE", flagsRelease.c_str());
  1076. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS", flags.c_str());
  1077. fout << line.c_str() << std::endl;
  1078. }
  1079. }
  1080. void cmLocalVisualStudio6Generator::WriteDSPFooter(std::ostream& fout)
  1081. {
  1082. std::ifstream fin(m_DSPFooterTemplate.c_str());
  1083. if(!fin)
  1084. {
  1085. cmSystemTools::Error("Error Reading ",
  1086. m_DSPFooterTemplate.c_str());
  1087. }
  1088. std::string line;
  1089. while(cmSystemTools::GetLineFromStream(fin, line))
  1090. {
  1091. fout << line << std::endl;
  1092. }
  1093. }