cmLocalVisualStudio6Generator.cxx 42 KB

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