cmLocalVisualStudio6Generator.cxx 47 KB

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