cmLocalVisualStudio6Generator.cxx 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  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. std::string exePathDebug = "";
  702. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  703. {
  704. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  705. }
  706. if(libPath.size())
  707. {
  708. // make sure there is a trailing slash
  709. if(libPath[libPath.size()-1] != '/')
  710. {
  711. libPath += "/";
  712. }
  713. std::string lpath =
  714. this->ConvertToOptionallyRelativeOutputPath(libPath.c_str());
  715. if(lpath.size() == 0)
  716. {
  717. lpath = ".";
  718. }
  719. std::string lpathIntDir = libPath + "$(INTDIR)";
  720. lpathIntDir = this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  721. if(pathEmitted.insert(lpath).second)
  722. {
  723. libOptions += " /LIBPATH:";
  724. libOptions += lpathIntDir;
  725. libOptions += " ";
  726. libOptions += " /LIBPATH:";
  727. libOptions += lpath;
  728. libOptions += " ";
  729. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  730. libMultiLineOptions += lpathIntDir;
  731. libMultiLineOptions += " ";
  732. libMultiLineOptions += " /LIBPATH:";
  733. libMultiLineOptions += lpath;
  734. libMultiLineOptions += " \n";
  735. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  736. libMultiLineOptionsForDebug += lpathIntDir;
  737. libMultiLineOptionsForDebug += " ";
  738. libMultiLineOptionsForDebug += " /LIBPATH:";
  739. libMultiLineOptionsForDebug += lpath;
  740. libMultiLineOptionsForDebug += " \n";
  741. }
  742. }
  743. if(exePath.size())
  744. {
  745. // make sure there is a trailing slash
  746. if(exePath[exePath.size()-1] != '/')
  747. {
  748. exePath += "/";
  749. }
  750. std::string lpath =
  751. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str());
  752. if(lpath.size() == 0)
  753. {
  754. lpath = ".";
  755. }
  756. std::string lpathIntDir = exePath + "$(INTDIR)";
  757. lpathIntDir = this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  758. if(pathEmitted.insert(lpath).second)
  759. {
  760. libOptions += " /LIBPATH:";
  761. libOptions += lpathIntDir;
  762. libOptions += " ";
  763. libOptions += " /LIBPATH:";
  764. libOptions += lpath;
  765. libOptions += " ";
  766. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  767. libMultiLineOptions += lpathIntDir;
  768. libMultiLineOptions += " ";
  769. libMultiLineOptions += " /LIBPATH:";
  770. libMultiLineOptions += lpath;
  771. libMultiLineOptions += " \n";
  772. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  773. libMultiLineOptionsForDebug += lpathIntDir;
  774. libMultiLineOptionsForDebug += " ";
  775. libMultiLineOptionsForDebug += " /LIBPATH:";
  776. libMultiLineOptionsForDebug += lpath;
  777. libMultiLineOptionsForDebug += " \n";
  778. }
  779. }
  780. std::vector<std::string>::const_iterator i;
  781. const std::vector<std::string>& libdirs = target.GetLinkDirectories();
  782. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  783. {
  784. std::string path = *i;
  785. if(path[path.size()-1] != '/')
  786. {
  787. path += "/";
  788. }
  789. std::string lpath =
  790. this->ConvertToOptionallyRelativeOutputPath(path.c_str());
  791. if(lpath.size() == 0)
  792. {
  793. lpath = ".";
  794. }
  795. std::string lpathIntDir = path + "$(INTDIR)";
  796. lpathIntDir = this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  797. if(pathEmitted.insert(lpath).second)
  798. {
  799. libOptions += " /LIBPATH:";
  800. libOptions += lpathIntDir;
  801. libOptions += " ";
  802. libOptions += " /LIBPATH:";
  803. libOptions += lpath;
  804. libOptions += " ";
  805. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  806. libMultiLineOptions += lpathIntDir;
  807. libMultiLineOptions += " ";
  808. libMultiLineOptions += " /LIBPATH:";
  809. libMultiLineOptions += lpath;
  810. libMultiLineOptions += " \n";
  811. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  812. libMultiLineOptionsForDebug += lpathIntDir;
  813. libMultiLineOptionsForDebug += " ";
  814. libMultiLineOptionsForDebug += " /LIBPATH:";
  815. libMultiLineOptionsForDebug += lpath;
  816. libMultiLineOptionsForDebug += " \n";
  817. }
  818. }
  819. // find link libraries
  820. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  821. cmTarget::LinkLibraries::const_iterator j;
  822. for(j = libs.begin(); j != libs.end(); ++j)
  823. {
  824. // add libraries to executables and dlls (but never include
  825. // a library in a library, bad recursion)
  826. if ((target.GetType() != cmTarget::SHARED_LIBRARY
  827. && target.GetType() != cmTarget::STATIC_LIBRARY
  828. && target.GetType() != cmTarget::MODULE_LIBRARY) ||
  829. (target.GetType()==cmTarget::SHARED_LIBRARY && libName != j->first) ||
  830. (target.GetType()==cmTarget::MODULE_LIBRARY && libName != j->first))
  831. {
  832. std::string lib = j->first;
  833. std::string libDebug = j->first;
  834. std::string libPath = j->first + "_CMAKE_PATH";
  835. const char* cacheValue
  836. = m_GlobalGenerator->GetCMakeInstance()->GetCacheDefinition(
  837. libPath.c_str());
  838. if ( cacheValue && *cacheValue && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX") )
  839. {
  840. libDebug += m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  841. }
  842. if(j->first.find(".lib") == std::string::npos)
  843. {
  844. lib += ".lib";
  845. libDebug += ".lib";
  846. }
  847. lib = this->ConvertToOptionallyRelativeOutputPath(lib.c_str());
  848. libDebug = this->ConvertToOptionallyRelativeOutputPath(libDebug.c_str());
  849. if (j->second == cmTarget::GENERAL)
  850. {
  851. libOptions += " ";
  852. libOptions += lib;
  853. libMultiLineOptions += "# ADD LINK32 ";
  854. libMultiLineOptions += lib;
  855. libMultiLineOptions += "\n";
  856. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  857. libMultiLineOptionsForDebug += libDebug;
  858. libMultiLineOptionsForDebug += "\n";
  859. }
  860. if (j->second == cmTarget::DEBUG)
  861. {
  862. libDebugOptions += " ";
  863. libDebugOptions += lib;
  864. libMultiLineDebugOptions += "# ADD LINK32 ";
  865. libMultiLineDebugOptions += libDebug;
  866. libMultiLineDebugOptions += "\n";
  867. }
  868. if (j->second == cmTarget::OPTIMIZED)
  869. {
  870. libOptimizedOptions += " ";
  871. libOptimizedOptions += lib;
  872. libMultiLineOptimizedOptions += "# ADD LINK32 ";
  873. libMultiLineOptimizedOptions += lib;
  874. libMultiLineOptimizedOptions += "\n";
  875. }
  876. }
  877. }
  878. std::string extraLinkOptions;
  879. if(target.GetType() == cmTarget::EXECUTABLE)
  880. {
  881. extraLinkOptions =
  882. m_Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  883. // if the executable has an output name then add the appropriate flag
  884. if (target.GetProperty("OUTPUT_NAME"))
  885. {
  886. std::string outputname = target.GetProperty("OUTPUT_NAME");
  887. libMultiLineOptions += "# ADD LINK32 /out:";
  888. libMultiLineOptions += outputname;
  889. libMultiLineOptions += " \n";
  890. }
  891. else
  892. {
  893. libMultiLineOptions += "# ADD LINK32 /out:\"";
  894. if(exePath != "")
  895. {
  896. libMultiLineOptions += exePath + "/" + libName + ".exe";
  897. }
  898. else
  899. {
  900. libMultiLineOptions += std::string(libName) + ".exe";
  901. }
  902. libMultiLineOptions += "\"\n";
  903. libMultiLineOptionsForDebug += "# ADD LINK32 /out:\"";
  904. if(exePath != "")
  905. {
  906. libMultiLineOptionsForDebug += exePath + "$(INTDIR)/" + libName + "D.exe";
  907. }
  908. else
  909. {
  910. libMultiLineOptionsForDebug += std::string("$(INTDIR)/")
  911. + std::string(libName) + "D.exe";
  912. }
  913. libMultiLineOptionsForDebug += "\"\n";
  914. }
  915. }
  916. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  917. {
  918. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  919. }
  920. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  921. {
  922. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  923. }
  924. if(extraLinkOptions.size())
  925. {
  926. libOptions += " ";
  927. libOptions += extraLinkOptions;
  928. libOptions += " ";
  929. libMultiLineOptions += "# ADD LINK32 ";
  930. libMultiLineOptions += extraLinkOptions;
  931. libMultiLineOptions += " \n";
  932. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  933. libMultiLineOptionsForDebug += extraLinkOptions;
  934. libMultiLineOptionsForDebug += " \n";
  935. }
  936. if(const char* stdLibs = m_Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES"))
  937. {
  938. libOptions += " ";
  939. libOptions += stdLibs;
  940. libOptions += " ";
  941. libMultiLineOptions += "# ADD LINK32 ";
  942. libMultiLineOptions += stdLibs;
  943. libMultiLineOptions += " \n";
  944. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  945. libMultiLineOptionsForDebug += stdLibs;
  946. libMultiLineOptionsForDebug += " \n";
  947. }
  948. if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS"))
  949. {
  950. libOptions += " ";
  951. libOptions += targetLinkFlags;
  952. libOptions += " ";
  953. libMultiLineOptions += "# ADD LINK32 ";
  954. libMultiLineOptions += targetLinkFlags;
  955. libMultiLineOptions += " \n";
  956. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  957. libMultiLineOptionsForDebug += targetLinkFlags;
  958. libMultiLineOptionsForDebug += " \n";
  959. }
  960. // are there any custom rules on the target itself
  961. // only if the target is a lib or exe
  962. std::string customRuleCode = this->CreateTargetRules(target, libName);
  963. std::ifstream fin(m_DSPHeaderTemplate.c_str());
  964. if(!fin)
  965. {
  966. cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str());
  967. }
  968. std::string staticLibOptions;
  969. if(target.GetType() == cmTarget::STATIC_LIBRARY )
  970. {
  971. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  972. {
  973. staticLibOptions = libflags;
  974. }
  975. }
  976. std::string exportSymbol;
  977. if (const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  978. {
  979. exportSymbol = custom_export_name;
  980. }
  981. else
  982. {
  983. std::string in = libName;
  984. in += "_EXPORTS";
  985. exportSymbol = cmSystemTools::MakeCindentifier(in.c_str());
  986. }
  987. std::string line;
  988. while(cmSystemTools::GetLineFromStream(fin, line))
  989. {
  990. const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG");
  991. if(!mfcFlag)
  992. {
  993. mfcFlag = "0";
  994. }
  995. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME_EXPORTS",
  996. exportSymbol.c_str());
  997. cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE",
  998. customRuleCode.c_str());
  999. cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG",
  1000. mfcFlag);
  1001. if(target.GetType() == cmTarget::STATIC_LIBRARY )
  1002. {
  1003. cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS",
  1004. staticLibOptions.c_str());
  1005. }
  1006. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  1007. {
  1008. cmSystemTools::ReplaceString(line, "/nologo", "");
  1009. }
  1010. cmSystemTools::ReplaceString(line, "CM_LIBRARIES",
  1011. libOptions.c_str());
  1012. cmSystemTools::ReplaceString(line, "CM_DEBUG_LIBRARIES",
  1013. libDebugOptions.c_str());
  1014. cmSystemTools::ReplaceString(line, "CM_OPTIMIZED_LIBRARIES",
  1015. libOptimizedOptions.c_str());
  1016. cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES_FOR_DEBUG",
  1017. libMultiLineOptionsForDebug.c_str());
  1018. cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES",
  1019. libMultiLineOptions.c_str());
  1020. cmSystemTools::ReplaceString(line, "CM_MULTILINE_DEBUG_LIBRARIES",
  1021. libMultiLineDebugOptions.c_str());
  1022. cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIMIZED_LIBRARIES",
  1023. libMultiLineOptimizedOptions.c_str());
  1024. cmSystemTools::ReplaceString(line, "BUILD_INCLUDES",
  1025. m_IncludeOptions.c_str());
  1026. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName);
  1027. // because LIBRARY_OUTPUT_PATH and EXECUTABLE_OUTPUT_PATH
  1028. // are already quoted in the template file,
  1029. // we need to remove the quotes here, we still need
  1030. // to convert to output path for unix to win32 conversion
  1031. cmSystemTools::ReplaceString(line, "LIBRARY_OUTPUT_PATH",
  1032. removeQuotes(
  1033. this->ConvertToOptionallyRelativeOutputPath(libPath.c_str())).c_str());
  1034. if (!m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH_OVERRIDE") || exePath == "")
  1035. {
  1036. cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATH",
  1037. removeQuotes(
  1038. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
  1039. } else
  1040. {
  1041. cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATHRelease",
  1042. removeQuotes(
  1043. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
  1044. cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATHDebug",
  1045. removeQuotes(
  1046. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
  1047. cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATHMinSizeRel",
  1048. removeQuotes(
  1049. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
  1050. cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATHRelWithDebInfo",
  1051. removeQuotes(
  1052. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
  1053. }
  1054. cmSystemTools::ReplaceString(line,
  1055. "EXTRA_DEFINES",
  1056. m_Makefile->GetDefineFlags());
  1057. const char* debugPostfix
  1058. = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  1059. cmSystemTools::ReplaceString(line, "DEBUG_POSTFIX",
  1060. debugPostfix?debugPostfix:"");
  1061. // store flags for each configuration
  1062. std::string flags = " ";
  1063. std::string flagsRelease = " ";
  1064. std::string flagsMinSize = " ";
  1065. std::string flagsDebug = " ";
  1066. std::string flagsDebugRel = " ";
  1067. if(target.GetType() >= cmTarget::EXECUTABLE &&
  1068. target.GetType() <= cmTarget::MODULE_LIBRARY)
  1069. {
  1070. const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator());
  1071. if(!linkLanguage)
  1072. {
  1073. cmSystemTools::Error("CMake can not determine linker language for target:",
  1074. target.GetName());
  1075. return;
  1076. }
  1077. // if CXX is on and the target contains cxx code then add the cxx flags
  1078. std::string baseFlagVar = "CMAKE_";
  1079. baseFlagVar += linkLanguage;
  1080. baseFlagVar += "_FLAGS";
  1081. flags = m_Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  1082. std::string flagVar = baseFlagVar + "_RELEASE";
  1083. flagsRelease = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1084. flagsRelease += " -DCMAKE_INTDIR=\\\"Release\\\" ";
  1085. flagVar = baseFlagVar + "_MINSIZEREL";
  1086. flagsMinSize = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1087. flagsMinSize += " -DCMAKE_INTDIR=\\\"MinSizeRel\\\" ";
  1088. flagVar = baseFlagVar + "_DEBUG";
  1089. flagsDebug = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1090. flagsDebug += " -DCMAKE_INTDIR=\\\"Debug\\\" ";
  1091. flagVar = baseFlagVar + "_RELWITHDEBINFO";
  1092. flagsDebugRel = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1093. flagsDebugRel += " -DCMAKE_INTDIR=\\\"RelWithDebInfo\\\" ";
  1094. }
  1095. // if unicode is not found, then add -D_MBCS
  1096. std::string defs = m_Makefile->GetDefineFlags();
  1097. if(flags.find("D_UNICODE") == flags.npos &&
  1098. defs.find("D_UNICODE") == flags.npos)
  1099. {
  1100. flags += " /D \"_MBCS\"";
  1101. }
  1102. // The template files have CXX FLAGS in them, that need to be replaced.
  1103. // There are not separate CXX and C template files, so we use the same
  1104. // variable names. The previous code sets up flags* variables to contain
  1105. // the correct C or CXX flags
  1106. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_MINSIZEREL", flagsMinSize.c_str());
  1107. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_DEBUG", flagsDebug.c_str());
  1108. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELWITHDEBINFO", flagsDebugRel.c_str());
  1109. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELEASE", flagsRelease.c_str());
  1110. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS", flags.c_str());
  1111. fout << line.c_str() << std::endl;
  1112. }
  1113. }
  1114. void cmLocalVisualStudio6Generator::WriteDSPFooter(std::ostream& fout)
  1115. {
  1116. std::ifstream fin(m_DSPFooterTemplate.c_str());
  1117. if(!fin)
  1118. {
  1119. cmSystemTools::Error("Error Reading ",
  1120. m_DSPFooterTemplate.c_str());
  1121. }
  1122. std::string line;
  1123. while(cmSystemTools::GetLineFromStream(fin, line))
  1124. {
  1125. fout << line << std::endl;
  1126. }
  1127. }