cmLocalVisualStudio6Generator.cxx 42 KB

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