cmLocalVisualStudio6Generator.cxx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. cmLocalVisualStudio6Generator::cmLocalVisualStudio6Generator()
  20. {
  21. }
  22. cmLocalVisualStudio6Generator::~cmLocalVisualStudio6Generator()
  23. {
  24. }
  25. void cmLocalVisualStudio6Generator::Generate(bool /* fromTheTop */)
  26. {
  27. // this is misnammed right now, it doesn't really generate the makefile but
  28. // instead sets up the Makefile for generation
  29. this->m_Makefile->GenerateMakefile();
  30. this->OutputDSPFile();
  31. }
  32. void cmLocalVisualStudio6Generator::OutputDSPFile()
  33. {
  34. // If not an in source build, then create the output directory
  35. if(strcmp(m_Makefile->GetStartOutputDirectory(),
  36. m_Makefile->GetHomeDirectory()) != 0)
  37. {
  38. if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
  39. {
  40. cmSystemTools::Error("Error creating directory ",
  41. m_Makefile->GetStartOutputDirectory());
  42. }
  43. }
  44. // Setup /I and /LIBPATH options for the resulting DSP file
  45. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  46. std::vector<std::string>::iterator i;
  47. for(i = includes.begin(); i != includes.end(); ++i)
  48. {
  49. m_IncludeOptions += " /I ";
  50. std::string tmp = cmSystemTools::ConvertToOutputPath(i->c_str());
  51. // quote if not already quoted
  52. if (tmp[0] != '"')
  53. {
  54. m_IncludeOptions += "\"";
  55. m_IncludeOptions += tmp;
  56. m_IncludeOptions += "\"";
  57. }
  58. else
  59. {
  60. m_IncludeOptions += tmp;
  61. }
  62. }
  63. // Create the DSP or set of DSP's for libraries and executables
  64. // clear project names
  65. m_CreatedProjectNames.clear();
  66. // build any targets
  67. cmTargets &tgts = m_Makefile->GetTargets();
  68. for(cmTargets::iterator l = tgts.begin();
  69. l != tgts.end(); l++)
  70. {
  71. switch(l->second.GetType())
  72. {
  73. case cmTarget::STATIC_LIBRARY:
  74. this->SetBuildType(STATIC_LIBRARY, l->first.c_str());
  75. break;
  76. case cmTarget::SHARED_LIBRARY:
  77. this->SetBuildType(DLL, l->first.c_str());
  78. break;
  79. case cmTarget::EXECUTABLE:
  80. this->SetBuildType(EXECUTABLE,l->first.c_str());
  81. break;
  82. case cmTarget::WIN32_EXECUTABLE:
  83. this->SetBuildType(WIN32_EXECUTABLE,l->first.c_str());
  84. break;
  85. case cmTarget::UTILITY:
  86. this->SetBuildType(UTILITY, l->first.c_str());
  87. break;
  88. case cmTarget::INSTALL_FILES:
  89. break;
  90. case cmTarget::INSTALL_PROGRAMS:
  91. break;
  92. default:
  93. cmSystemTools::Error("Bad target type", l->first.c_str());
  94. break;
  95. }
  96. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  97. // so don't build a projectfile for it
  98. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  99. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  100. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  101. {
  102. // check to see if the dsp is going into a sub-directory
  103. std::string::size_type pos = l->first.rfind('/');
  104. if(pos != std::string::npos)
  105. {
  106. std::string dir = m_Makefile->GetStartOutputDirectory();
  107. dir += "/";
  108. dir += l->first.substr(0, pos);
  109. if(!cmSystemTools::MakeDirectory(dir.c_str()))
  110. {
  111. cmSystemTools::Error("Error creating directory ", dir.c_str());
  112. }
  113. }
  114. this->CreateSingleDSP(l->first.c_str(),l->second);
  115. }
  116. }
  117. }
  118. void cmLocalVisualStudio6Generator::CreateSingleDSP(const char *lname, cmTarget &target)
  119. {
  120. // add to the list of projects
  121. std::string pname = lname;
  122. m_CreatedProjectNames.push_back(pname);
  123. // create the dsp.cmake file
  124. std::string fname;
  125. fname = m_Makefile->GetStartOutputDirectory();
  126. fname += "/";
  127. fname += lname;
  128. fname += ".dsp";
  129. // save the name of the real dsp file
  130. std::string realDSP = fname;
  131. fname += ".cmake";
  132. std::ofstream fout(fname.c_str());
  133. if(!fout)
  134. {
  135. cmSystemTools::Error("Error Writing ", fname.c_str());
  136. }
  137. this->WriteDSPFile(fout,lname,target);
  138. fout.close();
  139. // if the dsp file has changed, then write it.
  140. cmSystemTools::CopyFileIfDifferent(fname.c_str(), realDSP.c_str());
  141. }
  142. void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmSourceGroup& sourceGroup)
  143. {
  144. std::string dspname = *(m_CreatedProjectNames.end()-1);
  145. if(dspname == "ALL_BUILD")
  146. {
  147. return;
  148. }
  149. dspname += ".dsp.cmake";
  150. std::string makefileIn = m_Makefile->GetStartDirectory();
  151. makefileIn += "/";
  152. makefileIn += "CMakeLists.txt";
  153. makefileIn = cmSystemTools::ConvertToOutputPath(makefileIn.c_str());
  154. std::string dsprule = "${CMAKE_COMMAND}";
  155. m_Makefile->ExpandVariablesInString(dsprule);
  156. dsprule = cmSystemTools::ConvertToOutputPath(dsprule.c_str());
  157. std::string args = makefileIn;
  158. args += " -H";
  159. args +=
  160. cmSystemTools::ConvertToOutputPath(m_Makefile->GetHomeDirectory());
  161. args += " -S";
  162. args +=
  163. cmSystemTools::ConvertToOutputPath(m_Makefile->GetStartDirectory());
  164. args += " -O";
  165. args +=
  166. cmSystemTools::ConvertToOutputPath(m_Makefile->GetStartOutputDirectory());
  167. args += " -B";
  168. args +=
  169. cmSystemTools::ConvertToOutputPath(m_Makefile->GetHomeOutputDirectory());
  170. m_Makefile->ExpandVariablesInString(args);
  171. std::string configFile =
  172. m_Makefile->GetDefinition("CMAKE_ROOT");
  173. configFile += "/Templates/CMakeWindowsSystemConfig.cmake";
  174. std::vector<std::string> listFiles = m_Makefile->GetListFiles();
  175. bool found = false;
  176. for(std::vector<std::string>::iterator i = listFiles.begin();
  177. i != listFiles.end(); ++i)
  178. {
  179. if(*i == configFile)
  180. {
  181. found = true;
  182. }
  183. }
  184. if(!found)
  185. {
  186. listFiles.push_back(configFile);
  187. }
  188. std::vector<std::string> outputs;
  189. outputs.push_back(dspname);
  190. cmCustomCommand cc(makefileIn.c_str(), dsprule.c_str(),
  191. args.c_str(),
  192. listFiles,
  193. outputs);
  194. sourceGroup.AddCustomCommand(cc);
  195. }
  196. void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
  197. const char *libName,
  198. cmTarget &target)
  199. {
  200. // We may be modifying the source groups temporarily, so make a copy.
  201. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  202. // get the classes from the source lists then add them to the groups
  203. std::vector<cmSourceFile*> classes = target.GetSourceFiles();
  204. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  205. i != classes.end(); i++)
  206. {
  207. // Add the file to the list of sources.
  208. std::string source = (*i)->GetFullPath();
  209. cmSourceGroup& sourceGroup = m_Makefile->FindSourceGroup(source.c_str(),
  210. sourceGroups);
  211. sourceGroup.AddSource(source.c_str(), *i);
  212. }
  213. // add any custom rules to the source groups
  214. for (std::vector<cmCustomCommand>::const_iterator cr =
  215. target.GetCustomCommands().begin();
  216. cr != target.GetCustomCommands().end(); ++cr)
  217. {
  218. cmSourceGroup& sourceGroup =
  219. m_Makefile->FindSourceGroup(cr->GetSourceName().c_str(),
  220. sourceGroups);
  221. cmCustomCommand cc(*cr);
  222. cc.ExpandVariables(*m_Makefile);
  223. sourceGroup.AddCustomCommand(cc);
  224. }
  225. // Write the DSP file's header.
  226. this->WriteDSPHeader(fout, libName, target, sourceGroups);
  227. // Find the group in which the CMakeLists.txt source belongs, and add
  228. // the rule to generate this DSP file.
  229. for(std::vector<cmSourceGroup>::reverse_iterator sg = sourceGroups.rbegin();
  230. sg != sourceGroups.rend(); ++sg)
  231. {
  232. if(sg->Matches("CMakeLists.txt"))
  233. {
  234. this->AddDSPBuildRule(*sg);
  235. break;
  236. }
  237. }
  238. // Loop through every source group.
  239. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  240. sg != sourceGroups.end(); ++sg)
  241. {
  242. const cmSourceGroup::BuildRules& buildRules = sg->GetBuildRules();
  243. // If the group is empty, don't write it at all.
  244. if(buildRules.empty())
  245. { continue; }
  246. // If the group has a name, write the header.
  247. std::string name = sg->GetName();
  248. if(name != "")
  249. {
  250. this->WriteDSPBeginGroup(fout, name.c_str(), "");
  251. }
  252. // Loop through each build rule in the source group.
  253. for(cmSourceGroup::BuildRules::const_iterator cc =
  254. buildRules.begin(); cc != buildRules.end(); ++ cc)
  255. {
  256. std::string source = cc->first;
  257. const cmSourceGroup::Commands& commands = cc->second.m_Commands;
  258. const char* compileFlags = 0;
  259. if(cc->second.m_SourceFile)
  260. {
  261. compileFlags = cc->second.m_SourceFile->GetProperty("COMPILE_FLAGS");
  262. }
  263. if (source != libName || target.GetType() == cmTarget::UTILITY)
  264. {
  265. fout << "# Begin Source File\n\n";
  266. // Tell MS-Dev what the source is. If the compiler knows how to
  267. // build it, then it will.
  268. fout << "SOURCE=" <<
  269. cmSystemTools::ConvertToOutputPath(source.c_str()) << "\n\n";
  270. if (!commands.empty())
  271. {
  272. cmSourceGroup::CommandFiles totalCommand;
  273. std::string totalCommandStr;
  274. totalCommandStr = this->CombineCommands(commands, totalCommand,
  275. source.c_str());
  276. this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(),
  277. totalCommand.m_Depends,
  278. totalCommand.m_Outputs, compileFlags);
  279. }
  280. else if(compileFlags)
  281. {
  282. for(std::vector<std::string>::iterator i
  283. = m_Configurations.begin(); i != m_Configurations.end(); ++i)
  284. {
  285. if (i == m_Configurations.begin())
  286. {
  287. fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
  288. }
  289. else
  290. {
  291. fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
  292. }
  293. fout << "\n# ADD CPP " << compileFlags << "\n\n";
  294. }
  295. fout << "!ENDIF\n\n";
  296. }
  297. fout << "# End Source File\n";
  298. }
  299. }
  300. // If the group has a name, write the footer.
  301. if(name != "")
  302. {
  303. this->WriteDSPEndGroup(fout);
  304. }
  305. }
  306. // Write the DSP file's footer.
  307. this->WriteDSPFooter(fout);
  308. }
  309. void cmLocalVisualStudio6Generator::WriteCustomRule(std::ostream& fout,
  310. const char* source,
  311. const char* command,
  312. const std::set<std::string>& depends,
  313. const std::set<std::string>& outputs,
  314. const char* flags
  315. )
  316. {
  317. std::vector<std::string>::iterator i;
  318. for(i = m_Configurations.begin(); i != m_Configurations.end(); ++i)
  319. {
  320. if (i == m_Configurations.begin())
  321. {
  322. fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
  323. }
  324. else
  325. {
  326. fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
  327. }
  328. if(flags)
  329. {
  330. fout << "\n# ADD CPP " << flags << "\n\n";
  331. }
  332. // Write out the dependencies for the rule.
  333. fout << "USERDEP__HACK=";
  334. for(std::set<std::string>::const_iterator d = depends.begin();
  335. d != depends.end(); ++d)
  336. {
  337. fout << "\\\n\t" <<
  338. cmSystemTools::ConvertToOutputPath(d->c_str());
  339. }
  340. fout << "\n";
  341. fout << "# PROP Ignore_Default_Tool 1\n";
  342. fout << "# Begin Custom Build\n\n";
  343. if(outputs.size() == 0)
  344. {
  345. fout << source << "_force : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"";
  346. fout << command << "\n\n";
  347. }
  348. // Write a rule for every output generated by this command.
  349. for(std::set<std::string>::const_iterator output = outputs.begin();
  350. output != outputs.end(); ++output)
  351. {
  352. fout << "\"" << output->c_str()
  353. << "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"";
  354. fout << command << "\n\n";
  355. }
  356. fout << "# End Custom Build\n\n";
  357. }
  358. fout << "!ENDIF\n\n";
  359. }
  360. void cmLocalVisualStudio6Generator::WriteDSPBeginGroup(std::ostream& fout,
  361. const char* group,
  362. const char* filter)
  363. {
  364. fout << "# Begin Group \"" << group << "\"\n"
  365. "# PROP Default_Filter \"" << filter << "\"\n";
  366. }
  367. void cmLocalVisualStudio6Generator::WriteDSPEndGroup(std::ostream& fout)
  368. {
  369. fout << "# End Group\n";
  370. }
  371. void cmLocalVisualStudio6Generator::SetBuildType(BuildType b, const char *libName)
  372. {
  373. std::string root= m_Makefile->GetDefinition("CMAKE_ROOT");
  374. const char *def= m_Makefile->GetDefinition( "MSPROJECT_TEMPLATE_DIRECTORY");
  375. if( def)
  376. {
  377. root = def;
  378. }
  379. else
  380. {
  381. root += "/Templates";
  382. }
  383. switch(b)
  384. {
  385. case STATIC_LIBRARY:
  386. m_DSPHeaderTemplate = root;
  387. m_DSPHeaderTemplate += "/staticLibHeader.dsptemplate";
  388. m_DSPFooterTemplate = root;
  389. m_DSPFooterTemplate += "/staticLibFooter.dsptemplate";
  390. break;
  391. case DLL:
  392. m_DSPHeaderTemplate = root;
  393. m_DSPHeaderTemplate += "/DLLHeader.dsptemplate";
  394. m_DSPFooterTemplate = root;
  395. m_DSPFooterTemplate += "/DLLFooter.dsptemplate";
  396. break;
  397. case EXECUTABLE:
  398. m_DSPHeaderTemplate = root;
  399. m_DSPHeaderTemplate += "/EXEHeader.dsptemplate";
  400. m_DSPFooterTemplate = root;
  401. m_DSPFooterTemplate += "/EXEFooter.dsptemplate";
  402. break;
  403. case WIN32_EXECUTABLE:
  404. m_DSPHeaderTemplate = root;
  405. m_DSPHeaderTemplate += "/EXEWinHeader.dsptemplate";
  406. m_DSPFooterTemplate = root;
  407. m_DSPFooterTemplate += "/EXEFooter.dsptemplate";
  408. break;
  409. case UTILITY:
  410. m_DSPHeaderTemplate = root;
  411. m_DSPHeaderTemplate += "/UtilityHeader.dsptemplate";
  412. m_DSPFooterTemplate = root;
  413. m_DSPFooterTemplate += "/UtilityFooter.dsptemplate";
  414. break;
  415. }
  416. // once the build type is set, determine what configurations are
  417. // possible
  418. std::ifstream fin(m_DSPHeaderTemplate.c_str());
  419. cmRegularExpression reg("# Name ");
  420. if(!fin)
  421. {
  422. cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str());
  423. }
  424. // reset m_Configurations
  425. m_Configurations.erase(m_Configurations.begin(), m_Configurations.end());
  426. // now add all the configurations possible
  427. char buffer[2048];
  428. while(fin)
  429. {
  430. fin.getline(buffer, 2048);
  431. std::string line = buffer;
  432. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName);
  433. if (reg.find(line))
  434. {
  435. m_Configurations.push_back(line.substr(reg.end()));
  436. }
  437. }
  438. }
  439. std::string
  440. cmLocalVisualStudio6Generator::CombineCommands(const cmSourceGroup::Commands &commands,
  441. cmSourceGroup::CommandFiles &totalCommand,
  442. const char *source)
  443. {
  444. // Loop through every custom command generating code from the
  445. // current source.
  446. // build up the depends and outputs and commands
  447. std::string totalCommandStr = "";
  448. std::string temp;
  449. for(cmSourceGroup::Commands::const_iterator c = commands.begin();
  450. c != commands.end(); ++c)
  451. {
  452. totalCommandStr += "\n\t";
  453. temp= c->second.m_Command;
  454. temp = cmSystemTools::ConvertToOutputPath(temp.c_str());
  455. totalCommandStr += temp;
  456. totalCommandStr += " ";
  457. totalCommandStr += c->second.m_Arguments;
  458. totalCommand.Merge(c->second);
  459. }
  460. // Create a dummy file with the name of the source if it does
  461. // not exist
  462. if(totalCommand.m_Outputs.empty())
  463. {
  464. std::string dummyFile = m_Makefile->GetStartOutputDirectory();
  465. dummyFile += "/";
  466. dummyFile += source;
  467. if(!cmSystemTools::FileExists(dummyFile.c_str()))
  468. {
  469. std::ofstream fout(dummyFile.c_str());
  470. fout << "Dummy file created by cmake as unused source for utility command.\n";
  471. }
  472. }
  473. return totalCommandStr;
  474. }
  475. // look for custom rules on a target and collect them together
  476. std::string
  477. cmLocalVisualStudio6Generator::CreateTargetRules(const cmTarget &target,
  478. const char *libName)
  479. {
  480. std::string customRuleCode = "";
  481. if (target.GetType() >= cmTarget::UTILITY)
  482. {
  483. return customRuleCode;
  484. }
  485. // Find the group in which the lix exe custom rules belong
  486. bool init = false;
  487. for (std::vector<cmCustomCommand>::const_iterator cr =
  488. target.GetCustomCommands().begin();
  489. cr != target.GetCustomCommands().end(); ++cr)
  490. {
  491. cmCustomCommand cc(*cr);
  492. cc.ExpandVariables(*m_Makefile);
  493. if (cc.GetSourceName() == libName)
  494. {
  495. if (!init)
  496. {
  497. // header stuff
  498. customRuleCode = "# Begin Special Build Tool\nPostBuild_Cmds=";
  499. init = true;
  500. }
  501. else
  502. {
  503. customRuleCode += "\t";
  504. }
  505. customRuleCode += cc.GetCommand() + " " + cc.GetArguments();
  506. }
  507. }
  508. if (init)
  509. {
  510. customRuleCode += "\n# End Special Build Tool\n";
  511. }
  512. return customRuleCode;
  513. }
  514. inline std::string removeQuotes(const std::string& s)
  515. {
  516. if(s[0] == '\"' && s[s.size()-1] == '\"')
  517. {
  518. return s.substr(1, s.size()-2);
  519. }
  520. return s;
  521. }
  522. void cmLocalVisualStudio6Generator::WriteDSPHeader(std::ostream& fout, const char *libName,
  523. const cmTarget &target,
  524. std::vector<cmSourceGroup> &)
  525. {
  526. std::set<std::string> pathEmitted;
  527. // determine the link directories
  528. std::string libOptions;
  529. std::string libDebugOptions;
  530. std::string libOptimizedOptions;
  531. std::string libMultiLineOptions;
  532. std::string libMultiLineDebugOptions;
  533. std::string libMultiLineOptimizedOptions;
  534. // suppoirt override in output directory
  535. std::string libPath = "";
  536. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  537. {
  538. libPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  539. }
  540. std::string exePath = "";
  541. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  542. {
  543. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  544. }
  545. if(libPath.size())
  546. {
  547. // make sure there is a trailing slash
  548. if(libPath[libPath.size()-1] != '/')
  549. {
  550. libPath += "/";
  551. }
  552. std::string lpath =
  553. cmSystemTools::ConvertToOutputPath(libPath.c_str());
  554. std::string lpathIntDir = libPath + "$(INTDIR)";
  555. lpathIntDir = cmSystemTools::ConvertToOutputPath(lpathIntDir.c_str());
  556. if(pathEmitted.insert(lpath).second)
  557. {
  558. libOptions += " /LIBPATH:";
  559. libOptions += lpathIntDir;
  560. libOptions += " ";
  561. libOptions += " /LIBPATH:";
  562. libOptions += lpath;
  563. libOptions += " ";
  564. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  565. libMultiLineOptions += lpathIntDir;
  566. libMultiLineOptions += " ";
  567. libMultiLineOptions += " /LIBPATH:";
  568. libMultiLineOptions += lpath;
  569. libMultiLineOptions += " \n";
  570. }
  571. }
  572. if(exePath.size())
  573. {
  574. // make sure there is a trailing slash
  575. if(exePath[exePath.size()-1] != '/')
  576. {
  577. exePath += "/";
  578. }
  579. std::string lpath =
  580. cmSystemTools::ConvertToOutputPath(exePath.c_str());
  581. std::string lpathIntDir = exePath + "$(INTDIR)";
  582. lpathIntDir = cmSystemTools::ConvertToOutputPath(lpathIntDir.c_str());
  583. if(pathEmitted.insert(lpath).second)
  584. {
  585. libOptions += " /LIBPATH:";
  586. libOptions += lpathIntDir;
  587. libOptions += " ";
  588. libOptions += " /LIBPATH:";
  589. libOptions += lpath;
  590. libOptions += " ";
  591. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  592. libMultiLineOptions += lpathIntDir;
  593. libMultiLineOptions += " ";
  594. libMultiLineOptions += " /LIBPATH:";
  595. libMultiLineOptions += lpath;
  596. libMultiLineOptions += " \n";
  597. }
  598. }
  599. std::vector<std::string>::const_iterator i;
  600. const std::vector<std::string>& libdirs = target.GetLinkDirectories();
  601. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  602. {
  603. std::string path = *i;
  604. if(path[path.size()-1] != '/')
  605. {
  606. path += "/";
  607. }
  608. std::string lpath =
  609. cmSystemTools::ConvertToOutputPath(path.c_str());
  610. std::string lpathIntDir = path + "$(INTDIR)";
  611. lpathIntDir = cmSystemTools::ConvertToOutputPath(lpathIntDir.c_str());
  612. if(pathEmitted.insert(lpath).second)
  613. {
  614. libOptions += " /LIBPATH:";
  615. libOptions += lpathIntDir;
  616. libOptions += " ";
  617. libOptions += " /LIBPATH:";
  618. libOptions += lpath;
  619. libOptions += " ";
  620. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  621. libMultiLineOptions += lpathIntDir;
  622. libMultiLineOptions += " ";
  623. libMultiLineOptions += " /LIBPATH:";
  624. libMultiLineOptions += lpath;
  625. libMultiLineOptions += " \n";
  626. }
  627. }
  628. // find link libraries
  629. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  630. cmTarget::LinkLibraries::const_iterator j;
  631. for(j = libs.begin(); j != libs.end(); ++j)
  632. {
  633. // add libraries to executables and dlls (but never include
  634. // a library in a library, bad recursion)
  635. if ((target.GetType() != cmTarget::SHARED_LIBRARY
  636. && target.GetType() != cmTarget::STATIC_LIBRARY) ||
  637. (target.GetType() == cmTarget::SHARED_LIBRARY && libName != j->first))
  638. {
  639. std::string lib = j->first;
  640. if(j->first.find(".lib") == std::string::npos)
  641. {
  642. lib += ".lib";
  643. }
  644. lib = cmSystemTools::ConvertToOutputPath(lib.c_str());
  645. if (j->second == cmTarget::GENERAL)
  646. {
  647. libOptions += " ";
  648. libOptions += lib;
  649. libMultiLineOptions += "# ADD LINK32 ";
  650. libMultiLineOptions += lib;
  651. libMultiLineOptions += "\n";
  652. }
  653. if (j->second == cmTarget::DEBUG)
  654. {
  655. libDebugOptions += " ";
  656. libDebugOptions += lib;
  657. libMultiLineDebugOptions += "# ADD LINK32 ";
  658. libMultiLineDebugOptions += lib;
  659. libMultiLineDebugOptions += "\n";
  660. }
  661. if (j->second == cmTarget::OPTIMIZED)
  662. {
  663. libOptimizedOptions += " ";
  664. libOptimizedOptions += lib;
  665. libMultiLineOptimizedOptions += "# ADD LINK32 ";
  666. libMultiLineOptimizedOptions += lib;
  667. libMultiLineOptimizedOptions += "\n";
  668. }
  669. }
  670. }
  671. std::string extraLinkOptions =
  672. m_Makefile->GetDefinition("CMAKE_EXTRA_LINK_FLAGS");
  673. if(extraLinkOptions.size())
  674. {
  675. libOptions += " ";
  676. libOptions += extraLinkOptions;
  677. libOptions += " ";
  678. libMultiLineOptions += "# ADD LINK32 ";
  679. libMultiLineOptions += extraLinkOptions;
  680. libMultiLineOptions += " \n";
  681. }
  682. // are there any custom rules on the target itself
  683. // only if the target is a lib or exe
  684. std::string customRuleCode = this->CreateTargetRules(target, libName);
  685. std::ifstream fin(m_DSPHeaderTemplate.c_str());
  686. if(!fin)
  687. {
  688. cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str());
  689. }
  690. char buffer[2048];
  691. while(fin)
  692. {
  693. fin.getline(buffer, 2048);
  694. std::string line = buffer;
  695. const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG");
  696. if(!mfcFlag)
  697. {
  698. mfcFlag = "0";
  699. }
  700. cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE",
  701. customRuleCode.c_str());
  702. cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG",
  703. mfcFlag);
  704. cmSystemTools::ReplaceString(line, "CM_LIBRARIES",
  705. libOptions.c_str());
  706. cmSystemTools::ReplaceString(line, "CM_DEBUG_LIBRARIES",
  707. libDebugOptions.c_str());
  708. cmSystemTools::ReplaceString(line, "CM_OPTIMIZED_LIBRARIES",
  709. libOptimizedOptions.c_str());
  710. cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES",
  711. libMultiLineOptions.c_str());
  712. cmSystemTools::ReplaceString(line, "CM_MULTILINE_DEBUG_LIBRARIES",
  713. libMultiLineDebugOptions.c_str());
  714. cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIMIZED_LIBRARIES",
  715. libMultiLineOptimizedOptions.c_str());
  716. cmSystemTools::ReplaceString(line, "BUILD_INCLUDES",
  717. m_IncludeOptions.c_str());
  718. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName);
  719. // because LIBRARY_OUTPUT_PATH and EXECUTABLE_OUTPUT_PATH
  720. // are already quoted in the template file,
  721. // we need to remove the quotes here, we still need
  722. // to convert to output path for unix to win32 conversion
  723. cmSystemTools::ReplaceString(line, "LIBRARY_OUTPUT_PATH",
  724. removeQuotes(
  725. cmSystemTools::ConvertToOutputPath(libPath.c_str())).c_str());
  726. cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATH",
  727. removeQuotes(
  728. cmSystemTools::ConvertToOutputPath(exePath.c_str())).c_str());
  729. cmSystemTools::ReplaceString(line,
  730. "EXTRA_DEFINES",
  731. m_Makefile->GetDefineFlags());
  732. std::string flags = m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_RELEASE");
  733. flags += " -DCMAKE_INTDIR=\\\"Release\\\"";
  734. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELEASE", flags.c_str());
  735. flags = m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_MINSIZEREL");
  736. flags += " -DCMAKE_INTDIR=\\\"MinSizeRel\\\"";
  737. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_MINSIZEREL", flags.c_str());
  738. flags = m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_DEBUG");
  739. flags += " -DCMAKE_INTDIR=\\\"Debug\\\"";
  740. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_DEBUG", flags.c_str());
  741. flags = m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_RELWITHDEBINFO");
  742. flags += " -DCMAKE_INTDIR=\\\"RelWithDebInfo\\\"";
  743. cmSystemTools::ReplaceString(line,"CMAKE_CXX_FLAGS_RELWITHDEBINFO", flags.c_str());
  744. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS",
  745. m_Makefile->
  746. GetDefinition("CMAKE_CXX_FLAGS"));
  747. fout << line.c_str() << std::endl;
  748. }
  749. }
  750. void cmLocalVisualStudio6Generator::WriteDSPFooter(std::ostream& fout)
  751. {
  752. std::ifstream fin(m_DSPFooterTemplate.c_str());
  753. if(!fin)
  754. {
  755. cmSystemTools::Error("Error Reading ",
  756. m_DSPFooterTemplate.c_str());
  757. }
  758. char buffer[2048];
  759. while(fin)
  760. {
  761. fin.getline(buffer, 2048);
  762. fout << buffer << std::endl;
  763. }
  764. }