cmLocalVisualStudio6Generator.cxx 42 KB

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