cmDSPWriter.cxx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2001 Insight Consortium
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. * The name of the Insight Consortium, nor the names of any consortium members,
  17. nor of any contributors, may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. * Modified source versions must be plainly marked as such, and must not be
  20. misrepresented as being the original software.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  25. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. =========================================================================*/
  32. #include "cmDSPWriter.h"
  33. #include "cmStandardIncludes.h"
  34. #include "cmSystemTools.h"
  35. #include "cmRegularExpression.h"
  36. #include "cmCacheManager.h"
  37. cmDSPWriter::~cmDSPWriter()
  38. {
  39. }
  40. cmDSPWriter::cmDSPWriter(cmMakefile*mf)
  41. {
  42. m_Makefile = mf;
  43. }
  44. void cmDSPWriter::OutputDSPFile()
  45. {
  46. // If not an in source build, then create the output directory
  47. if(strcmp(m_Makefile->GetStartOutputDirectory(),
  48. m_Makefile->GetHomeDirectory()) != 0)
  49. {
  50. if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
  51. {
  52. cmSystemTools::Error("Error creating directory ",
  53. m_Makefile->GetStartOutputDirectory());
  54. }
  55. }
  56. // Setup /I and /LIBPATH options for the resulting DSP file
  57. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  58. std::vector<std::string>::iterator i;
  59. for(i = includes.begin(); i != includes.end(); ++i)
  60. {
  61. m_IncludeOptions += " /I ";
  62. m_IncludeOptions += cmSystemTools::EscapeSpaces(i->c_str());
  63. }
  64. // Create the DSP or set of DSP's for libraries and executables
  65. // clear project names
  66. m_CreatedProjectNames.clear();
  67. // build any targets
  68. cmTargets &tgts = m_Makefile->GetTargets();
  69. for(cmTargets::iterator l = tgts.begin();
  70. l != tgts.end(); l++)
  71. {
  72. switch(l->second.GetType())
  73. {
  74. case cmTarget::STATIC_LIBRARY:
  75. this->SetBuildType(STATIC_LIBRARY, l->first.c_str());
  76. break;
  77. case cmTarget::SHARED_LIBRARY:
  78. this->SetBuildType(DLL, l->first.c_str());
  79. break;
  80. case cmTarget::EXECUTABLE:
  81. this->SetBuildType(EXECUTABLE,l->first.c_str());
  82. break;
  83. case cmTarget::WIN32_EXECUTABLE:
  84. this->SetBuildType(WIN32_EXECUTABLE,l->first.c_str());
  85. break;
  86. case cmTarget::UTILITY:
  87. this->SetBuildType(UTILITY, l->first.c_str());
  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. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  98. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  99. {
  100. this->CreateSingleDSP(l->first.c_str(),l->second);
  101. }
  102. }
  103. }
  104. void cmDSPWriter::CreateSingleDSP(const char *lname, cmTarget &target)
  105. {
  106. std::string fname;
  107. fname = m_Makefile->GetStartOutputDirectory();
  108. fname += "/";
  109. fname += lname;
  110. fname += ".dsp";
  111. std::string pname = lname;
  112. m_CreatedProjectNames.push_back(pname);
  113. std::ofstream fout(fname.c_str());
  114. if(!fout)
  115. {
  116. cmSystemTools::Error("Error Writing ", fname.c_str());
  117. }
  118. this->WriteDSPFile(fout,lname,target);
  119. }
  120. void cmDSPWriter::AddDSPBuildRule(cmSourceGroup& sourceGroup)
  121. {
  122. std::string dspname = *(m_CreatedProjectNames.end()-1);
  123. if(dspname == "ALL_BUILD")
  124. {
  125. return;
  126. }
  127. dspname += ".dsp";
  128. std::string makefileIn = m_Makefile->GetStartDirectory();
  129. makefileIn += "/";
  130. makefileIn += "CMakeLists.txt";
  131. makefileIn = cmSystemTools::HandleNetworkPaths(makefileIn.c_str());
  132. std::string dsprule = "${CMAKE_COMMAND} ";
  133. m_Makefile->ExpandVariablesInString(dsprule);
  134. dsprule = cmSystemTools::HandleNetworkPaths(dsprule.c_str());
  135. std::string args = makefileIn;
  136. args += " -DSP -H\"";
  137. args += cmSystemTools::HandleNetworkPaths(m_Makefile->GetHomeDirectory());
  138. args += "\" -S\"";
  139. args += cmSystemTools::HandleNetworkPaths(m_Makefile->GetStartDirectory());
  140. args += "\" -O\"";
  141. args += cmSystemTools::HandleNetworkPaths(m_Makefile->GetStartOutputDirectory());
  142. args += "\" -B\"";
  143. args += cmSystemTools::HandleNetworkPaths(m_Makefile->GetHomeOutputDirectory());
  144. args += "\"";
  145. m_Makefile->ExpandVariablesInString(args);
  146. std::vector<std::string> outputs;
  147. outputs.push_back(dspname);
  148. cmCustomCommand cc(makefileIn.c_str(), dsprule.c_str(),
  149. args.c_str(),
  150. m_Makefile->GetListFiles(),
  151. outputs);
  152. sourceGroup.AddCustomCommand(cc);
  153. }
  154. void cmDSPWriter::WriteDSPFile(std::ostream& fout,
  155. const char *libName,
  156. cmTarget &target)
  157. {
  158. // Write the DSP file's header.
  159. this->WriteDSPHeader(fout, libName, target);
  160. // We may be modifying the source groups temporarily, so make a copy.
  161. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  162. // get the classes from the source lists then add them to the groups
  163. std::vector<cmSourceFile> classes = target.GetSourceFiles();
  164. for(std::vector<cmSourceFile>::iterator i = classes.begin();
  165. i != classes.end(); i++)
  166. {
  167. if(!i->IsAHeaderFileOnly())
  168. {
  169. // Add the file to the list of sources.
  170. std::string source = i->GetFullPath();
  171. cmSourceGroup& sourceGroup = m_Makefile->FindSourceGroup(source.c_str(),
  172. sourceGroups);
  173. sourceGroup.AddSource(source.c_str());
  174. }
  175. }
  176. // add any custom rules to the source groups
  177. for (std::vector<cmCustomCommand>::const_iterator cr =
  178. target.GetCustomCommands().begin();
  179. cr != target.GetCustomCommands().end(); ++cr)
  180. {
  181. cmSourceGroup& sourceGroup =
  182. m_Makefile->FindSourceGroup(cr->GetSourceName().c_str(),
  183. sourceGroups);
  184. cmCustomCommand cc(*cr);
  185. cc.ExpandVariables(*m_Makefile);
  186. sourceGroup.AddCustomCommand(cc);
  187. }
  188. // Find the group in which the CMakeLists.txt source belongs, and add
  189. // the rule to generate this DSP file.
  190. for(std::vector<cmSourceGroup>::reverse_iterator sg = sourceGroups.rbegin();
  191. sg != sourceGroups.rend(); ++sg)
  192. {
  193. if(sg->Matches("CMakeLists.txt"))
  194. {
  195. this->AddDSPBuildRule(*sg);
  196. break;
  197. }
  198. }
  199. // Loop through every source group.
  200. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  201. sg != sourceGroups.end(); ++sg)
  202. {
  203. const cmSourceGroup::BuildRules& buildRules = sg->GetBuildRules();
  204. // If the group is empty, don't write it at all.
  205. if(buildRules.empty())
  206. { continue; }
  207. // If the group has a name, write the header.
  208. std::string name = sg->GetName();
  209. if(name != "")
  210. {
  211. this->WriteDSPBeginGroup(fout, name.c_str(), "");
  212. }
  213. // Loop through each build rule in the source group.
  214. for(cmSourceGroup::BuildRules::const_iterator cc =
  215. buildRules.begin(); cc != buildRules.end(); ++ cc)
  216. {
  217. std::string source = cc->first;
  218. const cmSourceGroup::Commands& commands = cc->second;
  219. fout << "# Begin Source File\n\n";\
  220. // Tell MS-Dev what the source is. If the compiler knows how to
  221. // build it, then it will.
  222. fout << "SOURCE=" << cmSystemTools::EscapeSpaces(source.c_str()) << "\n\n";
  223. if (!commands.empty())
  224. {
  225. // Loop through every custom command generating code from the
  226. // current source.
  227. // build up the depends and outputs and commands
  228. cmSourceGroup::CommandFiles totalCommand;
  229. std::string totalCommandStr;
  230. std::string temp;
  231. for(cmSourceGroup::Commands::const_iterator c = commands.begin();
  232. c != commands.end(); ++c)
  233. {
  234. totalCommandStr += "\n\t";
  235. temp= c->second.m_Command;
  236. cmSystemTools::ConvertToWindowsSlashes(temp);
  237. temp = cmSystemTools::EscapeSpaces(temp.c_str());
  238. totalCommandStr += temp;
  239. totalCommandStr += " ";
  240. totalCommandStr += c->second.m_Arguments;
  241. totalCommand.Merge(c->second);
  242. }
  243. // Create a dummy file with the name of the source if it does
  244. // not exist
  245. if(totalCommand.m_Outputs.empty())
  246. {
  247. std::string dummyFile = m_Makefile->GetStartOutputDirectory();
  248. dummyFile += "/";
  249. dummyFile += source;
  250. if(!cmSystemTools::FileExists(dummyFile.c_str()))
  251. {
  252. std::ofstream fout(dummyFile.c_str());
  253. fout << "Dummy file created by cmake as unused source for utility command.\n";
  254. }
  255. }
  256. this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(),
  257. totalCommand.m_Depends,
  258. totalCommand.m_Outputs);
  259. }
  260. fout << "# End Source File\n";
  261. }
  262. // If the group has a name, write the footer.
  263. if(name != "")
  264. {
  265. this->WriteDSPEndGroup(fout);
  266. }
  267. }
  268. // Write the DSP file's footer.
  269. this->WriteDSPFooter(fout);
  270. }
  271. void cmDSPWriter::WriteCustomRule(std::ostream& fout,
  272. const char* source,
  273. const char* command,
  274. const std::set<std::string>& depends,
  275. const std::set<std::string>& outputs)
  276. {
  277. std::vector<std::string>::iterator i;
  278. for(i = m_Configurations.begin(); i != m_Configurations.end(); ++i)
  279. {
  280. if (i == m_Configurations.begin())
  281. {
  282. fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
  283. }
  284. else
  285. {
  286. fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
  287. }
  288. // Write out the dependencies for the rule.
  289. fout << "USERDEP__HACK=";
  290. std::string temp;
  291. for(std::set<std::string>::const_iterator d = depends.begin();
  292. d != depends.end(); ++d)
  293. {
  294. temp = *d;
  295. fout << "\\\n\t" << cmSystemTools::EscapeSpaces(cmSystemTools::ConvertToWindowsSlashes(temp));
  296. }
  297. fout << "\n";
  298. fout << "# Begin Custom Build\n\n";
  299. if(outputs.size() == 0)
  300. {
  301. fout << source << "_force : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"";
  302. fout << command << "\n\n";
  303. }
  304. // Write a rule for every output generated by this command.
  305. for(std::set<std::string>::const_iterator output = outputs.begin();
  306. output != outputs.end(); ++output)
  307. {
  308. fout << "\"" << output->c_str()
  309. << "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"";
  310. fout << command << "\n\n";
  311. }
  312. fout << "# End Custom Build\n\n";
  313. }
  314. fout << "!ENDIF\n\n";
  315. }
  316. void cmDSPWriter::WriteDSPBeginGroup(std::ostream& fout,
  317. const char* group,
  318. const char* filter)
  319. {
  320. fout << "# Begin Group \"" << group << "\"\n"
  321. "# PROP Default_Filter \"" << filter << "\"\n";
  322. }
  323. void cmDSPWriter::WriteDSPEndGroup(std::ostream& fout)
  324. {
  325. fout << "# End Group\n";
  326. }
  327. void cmDSPWriter::SetBuildType(BuildType b, const char *libName)
  328. {
  329. std::string root= m_Makefile->GetDefinition("CMAKE_ROOT");
  330. const char *def= m_Makefile->GetDefinition( "MSPROJECT_TEMPLATE_DIRECTORY");
  331. if( def)
  332. {
  333. root = def;
  334. }
  335. else
  336. {
  337. root += "/Templates";
  338. }
  339. switch(b)
  340. {
  341. case STATIC_LIBRARY:
  342. m_DSPHeaderTemplate = root;
  343. m_DSPHeaderTemplate += "/staticLibHeader.dsptemplate";
  344. m_DSPFooterTemplate = root;
  345. m_DSPFooterTemplate += "/staticLibFooter.dsptemplate";
  346. break;
  347. case DLL:
  348. m_DSPHeaderTemplate = root;
  349. m_DSPHeaderTemplate += "/DLLHeader.dsptemplate";
  350. m_DSPFooterTemplate = root;
  351. m_DSPFooterTemplate += "/DLLFooter.dsptemplate";
  352. break;
  353. case EXECUTABLE:
  354. m_DSPHeaderTemplate = root;
  355. m_DSPHeaderTemplate += "/EXEHeader.dsptemplate";
  356. m_DSPFooterTemplate = root;
  357. m_DSPFooterTemplate += "/EXEFooter.dsptemplate";
  358. break;
  359. case WIN32_EXECUTABLE:
  360. m_DSPHeaderTemplate = root;
  361. m_DSPHeaderTemplate += "/EXEWinHeader.dsptemplate";
  362. m_DSPFooterTemplate = root;
  363. m_DSPFooterTemplate += "/EXEFooter.dsptemplate";
  364. break;
  365. case UTILITY:
  366. m_DSPHeaderTemplate = root;
  367. m_DSPHeaderTemplate += "/UtilityHeader.dsptemplate";
  368. m_DSPFooterTemplate = root;
  369. m_DSPFooterTemplate += "/UtilityFooter.dsptemplate";
  370. break;
  371. }
  372. // once the build type is set, determine what configurations are
  373. // possible
  374. std::ifstream fin(m_DSPHeaderTemplate.c_str());
  375. cmRegularExpression reg("# Name ");
  376. if(!fin)
  377. {
  378. cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str());
  379. }
  380. // reset m_Configurations
  381. m_Configurations.erase(m_Configurations.begin(), m_Configurations.end());
  382. // now add all the configurations possible
  383. char buffer[2048];
  384. while(fin)
  385. {
  386. fin.getline(buffer, 2048);
  387. std::string line = buffer;
  388. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName);
  389. if (reg.find(line))
  390. {
  391. m_Configurations.push_back(line.substr(reg.end()));
  392. }
  393. }
  394. }
  395. void cmDSPWriter::WriteDSPHeader(std::ostream& fout, const char *libName,
  396. const cmTarget &target)
  397. {
  398. // determine the link directories
  399. std::string libOptions;
  400. std::string libDebugOptions;
  401. std::string libOptimizedOptions;
  402. std::string libMultiLineOptions;
  403. std::string libMultiLineDebugOptions;
  404. std::string libMultiLineOptimizedOptions;
  405. // suppoirt override in output directory
  406. std::string libPath = "";
  407. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  408. {
  409. libPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  410. }
  411. std::string exePath = "";
  412. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  413. {
  414. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  415. }
  416. if(libPath.size())
  417. {
  418. // make sure there is a trailing slash
  419. if(libPath[libPath.size()-1] != '/')
  420. {
  421. libPath += "/";
  422. }
  423. libOptions += " /LIBPATH:\"";
  424. libOptions += cmSystemTools::HandleNetworkPaths(libPath.c_str());
  425. libOptions += "$(IntDir)\" ";
  426. libOptions += " /LIBPATH:\"";
  427. libOptions += cmSystemTools::HandleNetworkPaths(libPath.c_str());
  428. libOptions += "\" ";
  429. libMultiLineOptions += "# ADD LINK32 /LIBPATH:\"";
  430. libMultiLineOptions += cmSystemTools::HandleNetworkPaths(libPath.c_str());
  431. libMultiLineOptions += "$(IntDir)\" ";
  432. libMultiLineOptions += " /LIBPATH:\"";
  433. libMultiLineOptions += cmSystemTools::HandleNetworkPaths(libPath.c_str());
  434. libMultiLineOptions += "\" \n";
  435. }
  436. if(exePath.size())
  437. {
  438. // make sure there is a trailing slash
  439. if(exePath[exePath.size()-1] != '/')
  440. {
  441. exePath += "/";
  442. }
  443. libOptions += " /LIBPATH:\"";
  444. libOptions += cmSystemTools::HandleNetworkPaths(exePath.c_str());
  445. libOptions += "$(IntDir)\" ";
  446. libOptions += " /LIBPATH:\"";
  447. libOptions += cmSystemTools::HandleNetworkPaths(exePath.c_str());
  448. libOptions += "\" ";
  449. libMultiLineOptions += "# ADD LINK32 /LIBPATH:\"";
  450. libMultiLineOptions += cmSystemTools::HandleNetworkPaths(exePath.c_str());
  451. libMultiLineOptions += "$(IntDir)\" ";
  452. libMultiLineOptions += " /LIBPATH:\"";
  453. libMultiLineOptions += cmSystemTools::HandleNetworkPaths(exePath.c_str());
  454. libMultiLineOptions += "\" \n";
  455. }
  456. std::vector<std::string>::iterator i;
  457. std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
  458. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  459. {
  460. libOptions += " /LIBPATH:\"";
  461. libOptions += cmSystemTools::HandleNetworkPaths(i->c_str());
  462. libOptions += "/$(IntDir)\" ";
  463. libOptions += " /LIBPATH:\"";
  464. libOptions += cmSystemTools::HandleNetworkPaths(i->c_str());
  465. libOptions += "\" ";
  466. libMultiLineOptions += "# ADD LINK32 /LIBPATH:\"";
  467. libMultiLineOptions += cmSystemTools::HandleNetworkPaths(i->c_str());
  468. libMultiLineOptions += "/$(IntDir)\" ";
  469. libMultiLineOptions += " /LIBPATH:\"";
  470. libMultiLineOptions += cmSystemTools::HandleNetworkPaths(i->c_str());
  471. libMultiLineOptions += "\" \n";
  472. }
  473. // find link libraries
  474. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  475. cmTarget::LinkLibraries::const_iterator j;
  476. for(j = libs.begin(); j != libs.end(); ++j)
  477. {
  478. // add libraries to executables and dlls (but never include
  479. // a library in a library, bad recursion)
  480. if ((target.GetType() != cmTarget::SHARED_LIBRARY
  481. && target.GetType() != cmTarget::STATIC_LIBRARY) ||
  482. (target.GetType() == cmTarget::SHARED_LIBRARY && libName != j->first))
  483. {
  484. std::string lib = j->first;
  485. if(j->first.find(".lib") == std::string::npos)
  486. {
  487. lib += ".lib";
  488. }
  489. lib = cmSystemTools::EscapeSpaces(lib.c_str());
  490. if (j->second == cmTarget::GENERAL)
  491. {
  492. libOptions += " ";
  493. libOptions += lib;
  494. libMultiLineOptions += "# ADD LINK32 ";
  495. libMultiLineOptions += lib;
  496. libMultiLineOptions += "\n";
  497. }
  498. if (j->second == cmTarget::DEBUG)
  499. {
  500. libDebugOptions += " ";
  501. libDebugOptions += lib;
  502. libMultiLineDebugOptions += "# ADD LINK32 ";
  503. libMultiLineDebugOptions += lib;
  504. libMultiLineDebugOptions += "\n";
  505. }
  506. if (j->second == cmTarget::OPTIMIZED)
  507. {
  508. libOptimizedOptions += " ";
  509. libOptimizedOptions += lib;
  510. libMultiLineOptimizedOptions += "# ADD LINK32 ";
  511. libMultiLineOptimizedOptions += lib;
  512. libMultiLineOptimizedOptions += "\n";
  513. }
  514. }
  515. }
  516. libOptions += " /STACK:10000000 ";
  517. libMultiLineOptions += "# ADD LINK32 /STACK:10000000 \n";
  518. std::ifstream fin(m_DSPHeaderTemplate.c_str());
  519. if(!fin)
  520. {
  521. cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str());
  522. }
  523. char buffer[2048];
  524. while(fin)
  525. {
  526. fin.getline(buffer, 2048);
  527. std::string line = buffer;
  528. const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG");
  529. if(!mfcFlag)
  530. {
  531. mfcFlag = "0";
  532. }
  533. cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG",
  534. mfcFlag);
  535. cmSystemTools::ReplaceString(line, "CM_LIBRARIES",
  536. libOptions.c_str());
  537. cmSystemTools::ReplaceString(line, "CM_DEBUG_LIBRARIES",
  538. libDebugOptions.c_str());
  539. cmSystemTools::ReplaceString(line, "CM_OPTIMIZED_LIBRARIES",
  540. libOptimizedOptions.c_str());
  541. cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES",
  542. libMultiLineOptions.c_str());
  543. cmSystemTools::ReplaceString(line, "CM_MULTILINE_DEBUG_LIBRARIES",
  544. libMultiLineDebugOptions.c_str());
  545. cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIMIZED_LIBRARIES",
  546. libMultiLineOptimizedOptions.c_str());
  547. cmSystemTools::ReplaceString(line, "BUILD_INCLUDES",
  548. m_IncludeOptions.c_str());
  549. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName);
  550. cmSystemTools::ReplaceString(line, "LIBRARY_OUTPUT_PATH",
  551. cmSystemTools::HandleNetworkPaths(libPath.c_str()).c_str());
  552. cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATH",
  553. cmSystemTools::HandleNetworkPaths(exePath.c_str()).c_str());
  554. cmSystemTools::ReplaceString(line,
  555. "EXTRA_DEFINES",
  556. m_Makefile->GetDefineFlags());
  557. cmSystemTools::ReplaceString(line,
  558. "CMAKE_CXX_FLAGS_RELEASE",
  559. m_Makefile->
  560. GetDefinition("CMAKE_CXX_FLAGS_RELEASE"));
  561. cmSystemTools::ReplaceString(line,
  562. "CMAKE_CXX_FLAGS_MINSIZEREL",
  563. m_Makefile->
  564. GetDefinition("CMAKE_CXX_FLAGS_MINSIZEREL")
  565. );
  566. cmSystemTools::ReplaceString(line,
  567. "CMAKE_CXX_FLAGS_DEBUG",
  568. m_Makefile->
  569. GetDefinition("CMAKE_CXX_FLAGS_DEBUG"));
  570. cmSystemTools::ReplaceString(line,
  571. "CMAKE_CXX_FLAGS_RELWITHDEBINFO",
  572. m_Makefile->
  573. GetDefinition("CMAKE_CXX_FLAGS_RELWITHDEBINFO"));
  574. cmSystemTools::ReplaceString(line,
  575. "CMAKE_CXX_FLAGS",
  576. m_Makefile->
  577. GetDefinition("CMAKE_CXX_FLAGS"));
  578. fout << line.c_str() << std::endl;
  579. }
  580. }
  581. void cmDSPWriter::WriteDSPFooter(std::ostream& fout)
  582. {
  583. std::ifstream fin(m_DSPFooterTemplate.c_str());
  584. if(!fin)
  585. {
  586. cmSystemTools::Error("Error Reading ",
  587. m_DSPFooterTemplate.c_str());
  588. }
  589. char buffer[2048];
  590. while(fin)
  591. {
  592. fin.getline(buffer, 2048);
  593. fout << buffer << std::endl;
  594. }
  595. }