cmLocalVisualStudio6Generator.cxx 41 KB

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