cmLocalVisualStudio6Generator.cxx 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGlobalGenerator.h"
  11. #include "cmLocalVisualStudio6Generator.h"
  12. #include "cmMakefile.h"
  13. #include "cmSystemTools.h"
  14. #include "cmSourceFile.h"
  15. #include "cmCacheManager.h"
  16. #include "cmake.h"
  17. #include "cmComputeLinkInformation.h"
  18. #include <cmsys/RegularExpression.hxx>
  19. cmLocalVisualStudio6Generator::cmLocalVisualStudio6Generator()
  20. {
  21. }
  22. cmLocalVisualStudio6Generator::~cmLocalVisualStudio6Generator()
  23. {
  24. }
  25. //----------------------------------------------------------------------------
  26. // Helper class to write build events.
  27. class cmLocalVisualStudio6Generator::EventWriter
  28. {
  29. public:
  30. EventWriter(cmLocalVisualStudio6Generator* lg,
  31. const char* config, std::string& code):
  32. LG(lg), Config(config), Code(code), First(true) {}
  33. void Start(const char* event)
  34. {
  35. this->First = true;
  36. this->Event = event;
  37. }
  38. void Finish()
  39. {
  40. this->Code += (this->First? "" : "\n");
  41. }
  42. void Write(std::vector<cmCustomCommand> const& ccs)
  43. {
  44. for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  45. ci != ccs.end(); ++ci)
  46. {
  47. this->Write(*ci);
  48. }
  49. }
  50. void Write(cmCustomCommand const& cc)
  51. {
  52. if(this->First)
  53. {
  54. this->Code += this->Event + "_Cmds=";
  55. this->First = false;
  56. }
  57. else
  58. {
  59. this->Code += "\\\n\t";
  60. }
  61. this->Code +=
  62. this->LG->ConstructScript(cc.GetCommandLines(),
  63. cc.GetWorkingDirectory(),
  64. this->Config,
  65. cc.GetEscapeOldStyle(),
  66. cc.GetEscapeAllowMakeVars(),
  67. "\\\n\t");
  68. }
  69. private:
  70. cmLocalVisualStudio6Generator* LG;
  71. const char* Config;
  72. std::string& Code;
  73. bool First;
  74. std::string Event;
  75. };
  76. void cmLocalVisualStudio6Generator::AddHelperCommands()
  77. {
  78. std::set<cmStdString> lang;
  79. lang.insert("C");
  80. lang.insert("CXX");
  81. this->CreateCustomTargetsAndCommands(lang);
  82. }
  83. void cmLocalVisualStudio6Generator::Generate()
  84. {
  85. this->OutputDSPFile();
  86. }
  87. void cmLocalVisualStudio6Generator::OutputDSPFile()
  88. {
  89. // If not an in source build, then create the output directory
  90. if(strcmp(this->Makefile->GetStartOutputDirectory(),
  91. this->Makefile->GetHomeDirectory()) != 0)
  92. {
  93. if(!cmSystemTools::MakeDirectory
  94. (this->Makefile->GetStartOutputDirectory()))
  95. {
  96. cmSystemTools::Error("Error creating directory ",
  97. this->Makefile->GetStartOutputDirectory());
  98. }
  99. }
  100. // Setup /I and /LIBPATH options for the resulting DSP file. VS 6
  101. // truncates long include paths so make it as short as possible if
  102. // the length threatens this problem.
  103. unsigned int maxIncludeLength = 3000;
  104. bool useShortPath = false;
  105. for(int j=0; j < 2; ++j)
  106. {
  107. std::vector<std::string> includes;
  108. this->GetIncludeDirectories(includes);
  109. std::vector<std::string>::iterator i;
  110. for(i = includes.begin(); i != includes.end(); ++i)
  111. {
  112. std::string tmp =
  113. this->ConvertToOptionallyRelativeOutputPath(i->c_str());
  114. if(useShortPath)
  115. {
  116. cmSystemTools::GetShortPath(tmp.c_str(), tmp);
  117. }
  118. this->IncludeOptions += " /I ";
  119. // quote if not already quoted
  120. if (tmp[0] != '"')
  121. {
  122. this->IncludeOptions += "\"";
  123. this->IncludeOptions += tmp;
  124. this->IncludeOptions += "\"";
  125. }
  126. else
  127. {
  128. this->IncludeOptions += tmp;
  129. }
  130. }
  131. if(j == 0 && this->IncludeOptions.size() > maxIncludeLength)
  132. {
  133. this->IncludeOptions = "";
  134. useShortPath = true;
  135. }
  136. else
  137. {
  138. break;
  139. }
  140. }
  141. // Create the DSP or set of DSP's for libraries and executables
  142. cmTargets &tgts = this->Makefile->GetTargets();
  143. for(cmTargets::iterator l = tgts.begin();
  144. l != tgts.end(); l++)
  145. {
  146. // Add a rule to regenerate the build system when the target
  147. // specification source changes.
  148. const char* suppRegenRule =
  149. this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  150. if (!cmSystemTools::IsOn(suppRegenRule))
  151. {
  152. this->AddDSPBuildRule(l->second);
  153. }
  154. }
  155. // build any targets
  156. for(cmTargets::iterator l = tgts.begin();
  157. l != tgts.end(); l++)
  158. {
  159. switch(l->second.GetType())
  160. {
  161. case cmTarget::STATIC_LIBRARY:
  162. this->SetBuildType(STATIC_LIBRARY, l->first.c_str(), l->second);
  163. break;
  164. case cmTarget::SHARED_LIBRARY:
  165. case cmTarget::MODULE_LIBRARY:
  166. this->SetBuildType(DLL, l->first.c_str(), l->second);
  167. break;
  168. case cmTarget::EXECUTABLE:
  169. this->SetBuildType(EXECUTABLE,l->first.c_str(), l->second);
  170. break;
  171. case cmTarget::UTILITY:
  172. case cmTarget::GLOBAL_TARGET:
  173. this->SetBuildType(UTILITY, l->first.c_str(), l->second);
  174. break;
  175. default:
  176. cmSystemTools::Error("Bad target type", l->first.c_str());
  177. break;
  178. }
  179. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  180. // so don't build a projectfile for it
  181. const char* path =
  182. l->second.GetProperty("EXTERNAL_MSPROJECT");
  183. if(!path)
  184. {
  185. // check to see if the dsp is going into a sub-directory
  186. std::string::size_type pos = l->first.rfind('/');
  187. if(pos != std::string::npos)
  188. {
  189. std::string dir = this->Makefile->GetStartOutputDirectory();
  190. dir += "/";
  191. dir += l->first.substr(0, pos);
  192. if(!cmSystemTools::MakeDirectory(dir.c_str()))
  193. {
  194. cmSystemTools::Error("Error creating directory ", dir.c_str());
  195. }
  196. }
  197. this->CreateSingleDSP(l->first.c_str(),l->second);
  198. }
  199. }
  200. }
  201. // Utility function to make a valid VS6 *.dsp filename out
  202. // of a CMake target name:
  203. //
  204. extern std::string GetVS6TargetName(const std::string& targetName);
  205. void cmLocalVisualStudio6Generator::CreateSingleDSP(const char *lname,
  206. cmTarget &target)
  207. {
  208. // add to the list of projects
  209. std::string pname = GetVS6TargetName(lname);
  210. // create the dsp.cmake file
  211. std::string fname;
  212. fname = this->Makefile->GetStartOutputDirectory();
  213. fname += "/";
  214. fname += pname;
  215. fname += ".dsp";
  216. // save the name of the real dsp file
  217. std::string realDSP = fname;
  218. fname += ".cmake";
  219. std::ofstream fout(fname.c_str());
  220. if(!fout)
  221. {
  222. cmSystemTools::Error("Error Writing ", fname.c_str());
  223. cmSystemTools::ReportLastSystemError("");
  224. }
  225. this->WriteDSPFile(fout,pname.c_str(),target);
  226. fout.close();
  227. // if the dsp file has changed, then write it.
  228. cmSystemTools::CopyFileIfDifferent(fname.c_str(), realDSP.c_str());
  229. }
  230. void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmTarget& tgt)
  231. {
  232. std::string dspname = GetVS6TargetName(tgt.GetName());
  233. dspname += ".dsp.cmake";
  234. const char* dsprule =
  235. this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  236. cmCustomCommandLine commandLine;
  237. commandLine.push_back(dsprule);
  238. std::string makefileIn = this->Makefile->GetStartDirectory();
  239. makefileIn += "/";
  240. makefileIn += "CMakeLists.txt";
  241. if(!cmSystemTools::FileExists(makefileIn.c_str()))
  242. {
  243. return;
  244. }
  245. std::string comment = "Building Custom Rule ";
  246. comment += makefileIn;
  247. std::string args;
  248. args = "-H";
  249. args += this->Convert(this->Makefile->GetHomeDirectory(),
  250. START_OUTPUT, UNCHANGED, true);
  251. commandLine.push_back(args);
  252. args = "-B";
  253. args +=
  254. this->Convert(this->Makefile->GetHomeOutputDirectory(),
  255. START_OUTPUT, UNCHANGED, true);
  256. commandLine.push_back(args);
  257. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  258. cmCustomCommandLines commandLines;
  259. commandLines.push_back(commandLine);
  260. const char* no_working_directory = 0;
  261. this->Makefile->AddCustomCommandToOutput(dspname.c_str(), listFiles,
  262. makefileIn.c_str(), commandLines,
  263. comment.c_str(),
  264. no_working_directory, true);
  265. if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
  266. {
  267. tgt.AddSourceFile(file);
  268. }
  269. else
  270. {
  271. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  272. }
  273. }
  274. void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
  275. const char *libName,
  276. cmTarget &target)
  277. {
  278. // For utility targets need custom command since pre- and post-
  279. // build does not do anything in Visual Studio 6. In order for the
  280. // rules to run in the correct order as custom commands, we need
  281. // special care for dependencies. The first rule must depend on all
  282. // the dependencies of all the rules. The later rules must each
  283. // depend only on the previous rule.
  284. if ((target.GetType() == cmTarget::UTILITY ||
  285. target.GetType() == cmTarget::GLOBAL_TARGET) &&
  286. (!target.GetPreBuildCommands().empty() ||
  287. !target.GetPostBuildCommands().empty()))
  288. {
  289. // Accumulate the dependencies of all the commands.
  290. std::vector<std::string> depends;
  291. for (std::vector<cmCustomCommand>::const_iterator cr =
  292. target.GetPreBuildCommands().begin();
  293. cr != target.GetPreBuildCommands().end(); ++cr)
  294. {
  295. depends.insert(depends.end(),
  296. cr->GetDepends().begin(), cr->GetDepends().end());
  297. }
  298. for (std::vector<cmCustomCommand>::const_iterator cr =
  299. target.GetPostBuildCommands().begin();
  300. cr != target.GetPostBuildCommands().end(); ++cr)
  301. {
  302. depends.insert(depends.end(),
  303. cr->GetDepends().begin(), cr->GetDepends().end());
  304. }
  305. // Add the pre- and post-build commands in order.
  306. int count = 1;
  307. for (std::vector<cmCustomCommand>::const_iterator cr =
  308. target.GetPreBuildCommands().begin();
  309. cr != target.GetPreBuildCommands().end(); ++cr)
  310. {
  311. this->AddUtilityCommandHack(target, count++, depends, *cr);
  312. }
  313. for (std::vector<cmCustomCommand>::const_iterator cr =
  314. target.GetPostBuildCommands().begin();
  315. cr != target.GetPostBuildCommands().end(); ++cr)
  316. {
  317. this->AddUtilityCommandHack(target, count++, depends, *cr);
  318. }
  319. }
  320. // We may be modifying the source groups temporarily, so make a copy.
  321. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  322. // get the classes from the source lists then add them to the groups
  323. std::vector<cmSourceFile*> const & classes = target.GetSourceFiles();
  324. // now all of the source files have been properly assigned to the target
  325. // now stick them into source groups using the reg expressions
  326. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  327. i != classes.end(); i++)
  328. {
  329. // Add the file to the list of sources.
  330. std::string source = (*i)->GetFullPath();
  331. cmSourceGroup& sourceGroup =
  332. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  333. sourceGroup.AssignSource(*i);
  334. // while we are at it, if it is a .rule file then for visual studio 6 we
  335. // must generate it
  336. if ((*i)->GetExtension() == "rule")
  337. {
  338. if(!cmSystemTools::FileExists(source.c_str()))
  339. {
  340. cmSystemTools::ReplaceString(source, "$(IntDir)/", "");
  341. #if defined(_WIN32) || defined(__CYGWIN__)
  342. std::ofstream fout(source.c_str(),
  343. std::ios::binary | std::ios::out
  344. | std::ios::trunc);
  345. #else
  346. std::ofstream fout(source.c_str(),
  347. std::ios::out | std::ios::trunc);
  348. #endif
  349. if(fout)
  350. {
  351. fout.write("# generated from CMake",22);
  352. fout.flush();
  353. fout.close();
  354. }
  355. }
  356. }
  357. }
  358. // Compute which sources need unique object computation.
  359. this->ComputeObjectNameRequirements(sourceGroups);
  360. // Write the DSP file's header.
  361. this->WriteDSPHeader(fout, libName, target, sourceGroups);
  362. // Loop through every source group.
  363. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  364. sg != sourceGroups.end(); ++sg)
  365. {
  366. this->WriteGroup(&(*sg), target, fout, libName);
  367. }
  368. // Write the DSP file's footer.
  369. this->WriteDSPFooter(fout);
  370. }
  371. void cmLocalVisualStudio6Generator
  372. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  373. std::ostream &fout, const char *libName)
  374. {
  375. const std::vector<const cmSourceFile *> &sourceFiles =
  376. sg->GetSourceFiles();
  377. // If the group is empty, don't write it at all.
  378. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  379. {
  380. return;
  381. }
  382. // If the group has a name, write the header.
  383. std::string name = sg->GetName();
  384. if(name != "")
  385. {
  386. this->WriteDSPBeginGroup(fout, name.c_str(), "");
  387. }
  388. // Compute the maximum length configuration name.
  389. std::string config_max;
  390. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  391. i != this->Configurations.end(); ++i)
  392. {
  393. // Strip the subdirectory name out of the configuration name.
  394. std::string config = this->GetConfigName(*i);
  395. if(config.size() > config_max.size())
  396. {
  397. config_max = config;
  398. }
  399. }
  400. // Compute the maximum length full path to the intermediate
  401. // files directory for any configuration. This is used to construct
  402. // object file names that do not produce paths that are too long.
  403. std::string dir_max;
  404. dir_max += this->Makefile->GetCurrentOutputDirectory();
  405. dir_max += "/";
  406. dir_max += config_max;
  407. dir_max += "/";
  408. // Loop through each source in the source group.
  409. for(std::vector<const cmSourceFile *>::const_iterator sf =
  410. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  411. {
  412. std::string source = (*sf)->GetFullPath();
  413. const cmCustomCommand *command =
  414. (*sf)->GetCustomCommand();
  415. std::string compileFlags;
  416. std::vector<std::string> depends;
  417. std::string objectNameDir;
  418. if(this->NeedObjectName.find(*sf) != this->NeedObjectName.end())
  419. {
  420. objectNameDir =
  421. cmSystemTools::GetFilenamePath(
  422. this->GetObjectFileNameWithoutTarget(*(*sf), dir_max));
  423. }
  424. // Add per-source file flags.
  425. if(const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS"))
  426. {
  427. compileFlags += cflags;
  428. }
  429. const char* lang = this->GetSourceFileLanguage(*(*sf));
  430. if(lang)
  431. {
  432. if(strcmp(lang, "CXX") == 0)
  433. {
  434. // force a C++ file type
  435. compileFlags += " /TP ";
  436. }
  437. else if(strcmp(lang, "C") == 0)
  438. {
  439. // force to c file type
  440. compileFlags += " /TC ";
  441. }
  442. }
  443. // Add per-source and per-configuration preprocessor definitions.
  444. std::map<cmStdString, cmStdString> cdmap;
  445. this->AppendDefines(compileFlags,
  446. (*sf)->GetProperty("COMPILE_DEFINITIONS"), lang);
  447. if(const char* cdefs = (*sf)->GetProperty("COMPILE_DEFINITIONS_DEBUG"))
  448. {
  449. this->AppendDefines(cdmap["DEBUG"], cdefs, lang);
  450. }
  451. if(const char* cdefs = (*sf)->GetProperty("COMPILE_DEFINITIONS_RELEASE"))
  452. {
  453. this->AppendDefines(cdmap["RELEASE"], cdefs, lang);
  454. }
  455. if(const char* cdefs =
  456. (*sf)->GetProperty("COMPILE_DEFINITIONS_MINSIZEREL"))
  457. {
  458. this->AppendDefines(cdmap["MINSIZEREL"], cdefs, lang);
  459. }
  460. if(const char* cdefs =
  461. (*sf)->GetProperty("COMPILE_DEFINITIONS_RELWITHDEBINFO"))
  462. {
  463. this->AppendDefines(cdmap["RELWITHDEBINFO"], cdefs, lang);
  464. }
  465. bool excludedFromBuild =
  466. (lang && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY"));
  467. // Check for extra object-file dependencies.
  468. const char* dependsValue = (*sf)->GetProperty("OBJECT_DEPENDS");
  469. if(dependsValue)
  470. {
  471. cmSystemTools::ExpandListArgument(dependsValue, depends);
  472. }
  473. if (GetVS6TargetName(source) != libName ||
  474. target.GetType() == cmTarget::UTILITY ||
  475. target.GetType() == cmTarget::GLOBAL_TARGET)
  476. {
  477. fout << "# Begin Source File\n\n";
  478. // Tell MS-Dev what the source is. If the compiler knows how to
  479. // build it, then it will.
  480. fout << "SOURCE=" <<
  481. this->ConvertToOptionallyRelativeOutputPath(source.c_str()) << "\n\n";
  482. if(!depends.empty())
  483. {
  484. // Write out the dependencies for the rule.
  485. fout << "USERDEP__HACK=";
  486. for(std::vector<std::string>::const_iterator d = depends.begin();
  487. d != depends.end(); ++d)
  488. {
  489. fout << "\\\n\t" <<
  490. this->ConvertToOptionallyRelativeOutputPath(d->c_str());
  491. }
  492. fout << "\n";
  493. }
  494. if (command)
  495. {
  496. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  497. this->WriteCustomRule(fout, source.c_str(), *command, flags);
  498. }
  499. else if(!compileFlags.empty() || !objectNameDir.empty() ||
  500. excludedFromBuild || !cdmap.empty())
  501. {
  502. for(std::vector<std::string>::iterator i
  503. = this->Configurations.begin();
  504. i != this->Configurations.end(); ++i)
  505. {
  506. // Strip the subdirectory name out of the configuration name.
  507. std::string config = this->GetConfigName(*i);
  508. if (i == this->Configurations.begin())
  509. {
  510. fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
  511. }
  512. else
  513. {
  514. fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
  515. }
  516. if(excludedFromBuild)
  517. {
  518. fout << "# PROP Exclude_From_Build 1\n";
  519. }
  520. if(!compileFlags.empty())
  521. {
  522. fout << "\n# ADD CPP " << compileFlags << "\n\n";
  523. }
  524. std::map<cmStdString, cmStdString>::iterator cdi =
  525. cdmap.find(cmSystemTools::UpperCase(config));
  526. if(cdi != cdmap.end() && !cdi->second.empty())
  527. {
  528. fout << "\n# ADD CPP " << cdi->second << "\n\n";
  529. }
  530. if(!objectNameDir.empty())
  531. {
  532. // Setup an alternate object file directory.
  533. fout << "\n# PROP Intermediate_Dir \""
  534. << config << "/" << objectNameDir << "\"\n\n";
  535. }
  536. }
  537. fout << "!ENDIF\n\n";
  538. }
  539. fout << "# End Source File\n";
  540. }
  541. }
  542. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  543. for(unsigned int i=0;i<children.size();++i)
  544. {
  545. this->WriteGroup(&children[i], target, fout, libName);
  546. }
  547. // If the group has a name, write the footer.
  548. if(name != "")
  549. {
  550. this->WriteDSPEndGroup(fout);
  551. }
  552. }
  553. void
  554. cmLocalVisualStudio6Generator
  555. ::AddUtilityCommandHack(cmTarget& target, int count,
  556. std::vector<std::string>& depends,
  557. const cmCustomCommand& origCommand)
  558. {
  559. // Create a fake output that forces the rule to run.
  560. char* output = new char[(strlen(this->Makefile->GetStartOutputDirectory()) +
  561. strlen(target.GetName()) + 30)];
  562. sprintf(output,"%s/%s_force_%i", this->Makefile->GetStartOutputDirectory(),
  563. target.GetName(), count);
  564. std::string comment = this->ConstructComment(origCommand, "<hack>");
  565. // Add the rule with the given dependencies and commands.
  566. const char* no_main_dependency = 0;
  567. this->Makefile->AddCustomCommandToOutput(output,
  568. depends,
  569. no_main_dependency,
  570. origCommand.GetCommandLines(),
  571. comment.c_str(),
  572. origCommand.GetWorkingDirectory());
  573. // Replace the dependencies with the output of this rule so that the
  574. // next rule added will run after this one.
  575. depends.clear();
  576. depends.push_back(output);
  577. // Add a source file representing this output to the project.
  578. cmSourceFile* outsf = this->Makefile->GetSourceFileWithOutput(output);
  579. target.AddSourceFile(outsf);
  580. // Free the fake output name.
  581. delete [] output;
  582. }
  583. void
  584. cmLocalVisualStudio6Generator
  585. ::WriteCustomRule(std::ostream& fout,
  586. const char* source,
  587. const cmCustomCommand& command,
  588. const char* flags)
  589. {
  590. std::string comment =
  591. this->ConstructComment(command, "Building Custom Rule $(InputPath)");
  592. if(comment == "<hack>")
  593. {
  594. comment = "";
  595. }
  596. // Write the rule for each configuration.
  597. std::vector<std::string>::iterator i;
  598. for(i = this->Configurations.begin(); i != this->Configurations.end(); ++i)
  599. {
  600. std::string config = this->GetConfigName(*i);
  601. std::string script =
  602. this->ConstructScript(command.GetCommandLines(),
  603. command.GetWorkingDirectory(),
  604. config.c_str(),
  605. command.GetEscapeOldStyle(),
  606. command.GetEscapeAllowMakeVars(),
  607. "\\\n\t");
  608. if (i == this->Configurations.begin())
  609. {
  610. fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
  611. }
  612. else
  613. {
  614. fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
  615. }
  616. if(flags)
  617. {
  618. fout << "\n# ADD CPP " << flags << "\n\n";
  619. }
  620. // Write out the dependencies for the rule.
  621. fout << "USERDEP__HACK=";
  622. for(std::vector<std::string>::const_iterator d =
  623. command.GetDepends().begin();
  624. d != command.GetDepends().end();
  625. ++d)
  626. {
  627. // Lookup the real name of the dependency in case it is a CMake target.
  628. std::string dep = this->GetRealDependency(d->c_str(),
  629. config.c_str());
  630. fout << "\\\n\t" <<
  631. this->ConvertToOptionallyRelativeOutputPath(dep.c_str());
  632. }
  633. fout << "\n";
  634. fout << "# PROP Ignore_Default_Tool 1\n";
  635. fout << "# Begin Custom Build -";
  636. if(!comment.empty())
  637. {
  638. fout << " " << comment.c_str();
  639. }
  640. fout << "\n\n";
  641. if(command.GetOutputs().empty())
  642. {
  643. fout << source
  644. << "_force : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
  645. fout << script.c_str() << "\n\n";
  646. }
  647. else
  648. {
  649. for(std::vector<std::string>::const_iterator o =
  650. command.GetOutputs().begin();
  651. o != command.GetOutputs().end();
  652. ++o)
  653. {
  654. // Write a rule for every output generated by this command.
  655. fout << this->ConvertToOptionallyRelativeOutputPath(o->c_str())
  656. << " : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
  657. fout << script.c_str() << "\n\n";
  658. }
  659. }
  660. fout << "# End Custom Build\n\n";
  661. }
  662. fout << "!ENDIF\n\n";
  663. }
  664. void cmLocalVisualStudio6Generator::WriteDSPBeginGroup(std::ostream& fout,
  665. const char* group,
  666. const char* filter)
  667. {
  668. fout << "# Begin Group \"" << group << "\"\n"
  669. "# PROP Default_Filter \"" << filter << "\"\n";
  670. }
  671. void cmLocalVisualStudio6Generator::WriteDSPEndGroup(std::ostream& fout)
  672. {
  673. fout << "# End Group\n";
  674. }
  675. void cmLocalVisualStudio6Generator::SetBuildType(BuildType b,
  676. const char* libName,
  677. cmTarget& target)
  678. {
  679. std::string root= this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
  680. const char *def=
  681. this->Makefile->GetDefinition( "MSPROJECT_TEMPLATE_DIRECTORY");
  682. if( def)
  683. {
  684. root = def;
  685. }
  686. else
  687. {
  688. root += "/Templates";
  689. }
  690. switch(b)
  691. {
  692. case STATIC_LIBRARY:
  693. this->DSPHeaderTemplate = root;
  694. this->DSPHeaderTemplate += "/staticLibHeader.dsptemplate";
  695. this->DSPFooterTemplate = root;
  696. this->DSPFooterTemplate += "/staticLibFooter.dsptemplate";
  697. break;
  698. case DLL:
  699. this->DSPHeaderTemplate = root;
  700. this->DSPHeaderTemplate += "/DLLHeader.dsptemplate";
  701. this->DSPFooterTemplate = root;
  702. this->DSPFooterTemplate += "/DLLFooter.dsptemplate";
  703. break;
  704. case EXECUTABLE:
  705. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  706. {
  707. this->DSPHeaderTemplate = root;
  708. this->DSPHeaderTemplate += "/EXEWinHeader.dsptemplate";
  709. this->DSPFooterTemplate = root;
  710. this->DSPFooterTemplate += "/EXEFooter.dsptemplate";
  711. }
  712. else
  713. {
  714. this->DSPHeaderTemplate = root;
  715. this->DSPHeaderTemplate += "/EXEHeader.dsptemplate";
  716. this->DSPFooterTemplate = root;
  717. this->DSPFooterTemplate += "/EXEFooter.dsptemplate";
  718. }
  719. break;
  720. case UTILITY:
  721. this->DSPHeaderTemplate = root;
  722. this->DSPHeaderTemplate += "/UtilityHeader.dsptemplate";
  723. this->DSPFooterTemplate = root;
  724. this->DSPFooterTemplate += "/UtilityFooter.dsptemplate";
  725. break;
  726. }
  727. // once the build type is set, determine what configurations are
  728. // possible
  729. std::ifstream fin(this->DSPHeaderTemplate.c_str());
  730. cmsys::RegularExpression reg("# Name ");
  731. if(!fin)
  732. {
  733. cmSystemTools::Error("Error Reading ", this->DSPHeaderTemplate.c_str());
  734. }
  735. // reset this->Configurations
  736. this->Configurations.erase(this->Configurations.begin(),
  737. this->Configurations.end());
  738. // now add all the configurations possible
  739. std::string vs6name = GetVS6TargetName(libName);
  740. std::string line;
  741. while(cmSystemTools::GetLineFromStream(fin, line))
  742. {
  743. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME", vs6name.c_str());
  744. if (reg.find(line))
  745. {
  746. this->Configurations.push_back(line.substr(reg.end()));
  747. }
  748. }
  749. }
  750. //----------------------------------------------------------------------------
  751. cmsys::auto_ptr<cmCustomCommand>
  752. cmLocalVisualStudio6Generator::MaybeCreateOutputDir(cmTarget& target,
  753. const char* config)
  754. {
  755. cmsys::auto_ptr<cmCustomCommand> pcc;
  756. // VS6 forgets to create the output directory for archives if it
  757. // differs from the intermediate directory.
  758. if(target.GetType() != cmTarget::STATIC_LIBRARY) { return pcc; }
  759. std::string outDir = target.GetDirectory(config, false);
  760. // Add a pre-link event to create the directory.
  761. cmCustomCommandLine command;
  762. command.push_back(this->Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
  763. command.push_back("-E");
  764. command.push_back("make_directory");
  765. command.push_back(outDir);
  766. std::vector<std::string> no_output;
  767. std::vector<std::string> no_depends;
  768. cmCustomCommandLines commands;
  769. commands.push_back(command);
  770. pcc.reset(new cmCustomCommand(no_output, no_depends, commands, 0, 0));
  771. pcc->SetEscapeOldStyle(false);
  772. pcc->SetEscapeAllowMakeVars(true);
  773. return pcc;
  774. }
  775. // look for custom rules on a target and collect them together
  776. std::string
  777. cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target,
  778. const char* configName,
  779. const char * /* libName */)
  780. {
  781. if (target.GetType() >= cmTarget::UTILITY )
  782. {
  783. return "";
  784. }
  785. std::string customRuleCode = "# Begin Special Build Tool\n";
  786. EventWriter event(this, configName, customRuleCode);
  787. // Write the pre-build and pre-link together (VS6 does not support both).
  788. event.Start("PreLink");
  789. event.Write(target.GetPreBuildCommands());
  790. event.Write(target.GetPreLinkCommands());
  791. cmsys::auto_ptr<cmCustomCommand> pcc(
  792. this->MaybeCreateImplibDir(target, configName));
  793. if(pcc.get())
  794. {
  795. event.Write(*pcc);
  796. }
  797. pcc = this->MaybeCreateOutputDir(target, configName);
  798. if(pcc.get())
  799. {
  800. event.Write(*pcc);
  801. }
  802. event.Finish();
  803. // Write the post-build rules.
  804. event.Start("PostBuild");
  805. event.Write(target.GetPostBuildCommands());
  806. event.Finish();
  807. customRuleCode += "# End Special Build Tool\n";
  808. return customRuleCode;
  809. }
  810. inline std::string removeQuotes(const std::string& s)
  811. {
  812. if(s[0] == '\"' && s[s.size()-1] == '\"')
  813. {
  814. return s.substr(1, s.size()-2);
  815. }
  816. return s;
  817. }
  818. // Code in blocks surrounded by a test for this definition is needed
  819. // only for compatibility with user project's replacement DSP
  820. // templates. The CMake templates no longer use them.
  821. #define CM_USE_OLD_VS6
  822. void cmLocalVisualStudio6Generator
  823. ::WriteDSPHeader(std::ostream& fout,
  824. const char *libName, cmTarget &target,
  825. std::vector<cmSourceGroup> &)
  826. {
  827. bool targetBuilds = (target.GetType() >= cmTarget::EXECUTABLE &&
  828. target.GetType() <= cmTarget::MODULE_LIBRARY);
  829. #ifdef CM_USE_OLD_VS6
  830. // Lookup the library and executable output directories.
  831. std::string libPath;
  832. if(this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  833. {
  834. libPath = this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  835. }
  836. std::string exePath;
  837. if(this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  838. {
  839. exePath = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  840. }
  841. // Make sure there are trailing slashes.
  842. if(!libPath.empty())
  843. {
  844. if(libPath[libPath.size()-1] != '/')
  845. {
  846. libPath += "/";
  847. }
  848. }
  849. if(!exePath.empty())
  850. {
  851. if(exePath[exePath.size()-1] != '/')
  852. {
  853. exePath += "/";
  854. }
  855. }
  856. std::set<std::string> pathEmitted;
  857. // determine the link directories
  858. std::string libOptions;
  859. std::string libDebugOptions;
  860. std::string libOptimizedOptions;
  861. std::string libMultiLineOptions;
  862. std::string libMultiLineOptionsForDebug;
  863. std::string libMultiLineDebugOptions;
  864. std::string libMultiLineOptimizedOptions;
  865. if(libPath.size())
  866. {
  867. std::string lpath =
  868. this->ConvertToOptionallyRelativeOutputPath(libPath.c_str());
  869. if(lpath.size() == 0)
  870. {
  871. lpath = ".";
  872. }
  873. std::string lpathIntDir = libPath + "$(INTDIR)";
  874. lpathIntDir =
  875. this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  876. if(pathEmitted.insert(lpath).second)
  877. {
  878. libOptions += " /LIBPATH:";
  879. libOptions += lpathIntDir;
  880. libOptions += " ";
  881. libOptions += " /LIBPATH:";
  882. libOptions += lpath;
  883. libOptions += " ";
  884. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  885. libMultiLineOptions += lpathIntDir;
  886. libMultiLineOptions += " ";
  887. libMultiLineOptions += " /LIBPATH:";
  888. libMultiLineOptions += lpath;
  889. libMultiLineOptions += " \n";
  890. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  891. libMultiLineOptionsForDebug += lpathIntDir;
  892. libMultiLineOptionsForDebug += " ";
  893. libMultiLineOptionsForDebug += " /LIBPATH:";
  894. libMultiLineOptionsForDebug += lpath;
  895. libMultiLineOptionsForDebug += " \n";
  896. }
  897. }
  898. if(exePath.size())
  899. {
  900. std::string lpath =
  901. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str());
  902. if(lpath.size() == 0)
  903. {
  904. lpath = ".";
  905. }
  906. std::string lpathIntDir = exePath + "$(INTDIR)";
  907. lpathIntDir =
  908. this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  909. if(pathEmitted.insert(lpath).second)
  910. {
  911. libOptions += " /LIBPATH:";
  912. libOptions += lpathIntDir;
  913. libOptions += " ";
  914. libOptions += " /LIBPATH:";
  915. libOptions += lpath;
  916. libOptions += " ";
  917. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  918. libMultiLineOptions += lpathIntDir;
  919. libMultiLineOptions += " ";
  920. libMultiLineOptions += " /LIBPATH:";
  921. libMultiLineOptions += lpath;
  922. libMultiLineOptions += " \n";
  923. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  924. libMultiLineOptionsForDebug += lpathIntDir;
  925. libMultiLineOptionsForDebug += " ";
  926. libMultiLineOptionsForDebug += " /LIBPATH:";
  927. libMultiLineOptionsForDebug += lpath;
  928. libMultiLineOptionsForDebug += " \n";
  929. }
  930. }
  931. std::vector<std::string>::const_iterator i;
  932. const std::vector<std::string>& libdirs = target.GetLinkDirectories();
  933. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  934. {
  935. std::string path = *i;
  936. if(path[path.size()-1] != '/')
  937. {
  938. path += "/";
  939. }
  940. std::string lpath =
  941. this->ConvertToOptionallyRelativeOutputPath(path.c_str());
  942. if(lpath.size() == 0)
  943. {
  944. lpath = ".";
  945. }
  946. std::string lpathIntDir = path + "$(INTDIR)";
  947. lpathIntDir =
  948. this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  949. if(pathEmitted.insert(lpath).second)
  950. {
  951. libOptions += " /LIBPATH:";
  952. libOptions += lpathIntDir;
  953. libOptions += " ";
  954. libOptions += " /LIBPATH:";
  955. libOptions += lpath;
  956. libOptions += " ";
  957. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  958. libMultiLineOptions += lpathIntDir;
  959. libMultiLineOptions += " ";
  960. libMultiLineOptions += " /LIBPATH:";
  961. libMultiLineOptions += lpath;
  962. libMultiLineOptions += " \n";
  963. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  964. libMultiLineOptionsForDebug += lpathIntDir;
  965. libMultiLineOptionsForDebug += " ";
  966. libMultiLineOptionsForDebug += " /LIBPATH:";
  967. libMultiLineOptionsForDebug += lpath;
  968. libMultiLineOptionsForDebug += " \n";
  969. }
  970. }
  971. // find link libraries
  972. const cmTarget::LinkLibraryVectorType& libs = target.GetLinkLibraries();
  973. cmTarget::LinkLibraryVectorType::const_iterator j;
  974. for(j = libs.begin(); j != libs.end(); ++j)
  975. {
  976. // add libraries to executables and dlls (but never include
  977. // a library in a library, bad recursion)
  978. // NEVER LINK STATIC LIBRARIES TO OTHER STATIC LIBRARIES
  979. if ((target.GetType() != cmTarget::SHARED_LIBRARY
  980. && target.GetType() != cmTarget::STATIC_LIBRARY
  981. && target.GetType() != cmTarget::MODULE_LIBRARY) ||
  982. (target.GetType()==cmTarget::SHARED_LIBRARY
  983. && libName != GetVS6TargetName(j->first)) ||
  984. (target.GetType()==cmTarget::MODULE_LIBRARY
  985. && libName != GetVS6TargetName(j->first)))
  986. {
  987. // Compute the proper name to use to link this library.
  988. std::string lib;
  989. std::string libDebug;
  990. cmTarget* tgt = this->GlobalGenerator->FindTarget(0, j->first.c_str());
  991. if(tgt)
  992. {
  993. lib = cmSystemTools::GetFilenameWithoutExtension
  994. (tgt->GetFullName().c_str());
  995. libDebug = cmSystemTools::GetFilenameWithoutExtension
  996. (tgt->GetFullName("Debug").c_str());
  997. lib += ".lib";
  998. libDebug += ".lib";
  999. }
  1000. else
  1001. {
  1002. lib = j->first.c_str();
  1003. libDebug = j->first.c_str();
  1004. if(j->first.find(".lib") == std::string::npos)
  1005. {
  1006. lib += ".lib";
  1007. libDebug += ".lib";
  1008. }
  1009. }
  1010. lib = this->ConvertToOptionallyRelativeOutputPath(lib.c_str());
  1011. libDebug =
  1012. this->ConvertToOptionallyRelativeOutputPath(libDebug.c_str());
  1013. if (j->second == cmTarget::GENERAL)
  1014. {
  1015. libOptions += " ";
  1016. libOptions += lib;
  1017. libMultiLineOptions += "# ADD LINK32 ";
  1018. libMultiLineOptions += lib;
  1019. libMultiLineOptions += "\n";
  1020. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  1021. libMultiLineOptionsForDebug += libDebug;
  1022. libMultiLineOptionsForDebug += "\n";
  1023. }
  1024. if (j->second == cmTarget::DEBUG)
  1025. {
  1026. libDebugOptions += " ";
  1027. libDebugOptions += lib;
  1028. libMultiLineDebugOptions += "# ADD LINK32 ";
  1029. libMultiLineDebugOptions += libDebug;
  1030. libMultiLineDebugOptions += "\n";
  1031. }
  1032. if (j->second == cmTarget::OPTIMIZED)
  1033. {
  1034. libOptimizedOptions += " ";
  1035. libOptimizedOptions += lib;
  1036. libMultiLineOptimizedOptions += "# ADD LINK32 ";
  1037. libMultiLineOptimizedOptions += lib;
  1038. libMultiLineOptimizedOptions += "\n";
  1039. }
  1040. }
  1041. }
  1042. #endif
  1043. // Get extra linker options for this target type.
  1044. std::string extraLinkOptions;
  1045. std::string extraLinkOptionsDebug;
  1046. std::string extraLinkOptionsRelease;
  1047. std::string extraLinkOptionsMinSizeRel;
  1048. std::string extraLinkOptionsRelWithDebInfo;
  1049. if(target.GetType() == cmTarget::EXECUTABLE)
  1050. {
  1051. extraLinkOptions =
  1052. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  1053. }
  1054. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  1055. {
  1056. extraLinkOptions =
  1057. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  1058. }
  1059. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  1060. {
  1061. extraLinkOptions =
  1062. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  1063. }
  1064. // Get extra linker options for this target.
  1065. if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS"))
  1066. {
  1067. extraLinkOptions += " ";
  1068. extraLinkOptions += targetLinkFlags;
  1069. }
  1070. if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_DEBUG"))
  1071. {
  1072. extraLinkOptionsDebug += " ";
  1073. extraLinkOptionsDebug += targetLinkFlags;
  1074. }
  1075. if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_RELEASE"))
  1076. {
  1077. extraLinkOptionsRelease += " ";
  1078. extraLinkOptionsRelease += targetLinkFlags;
  1079. }
  1080. if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_MINSIZEREL"))
  1081. {
  1082. extraLinkOptionsMinSizeRel += " ";
  1083. extraLinkOptionsMinSizeRel += targetLinkFlags;
  1084. }
  1085. if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_RELWITHDEBINFO"))
  1086. {
  1087. extraLinkOptionsRelWithDebInfo += " ";
  1088. extraLinkOptionsRelWithDebInfo += targetLinkFlags;
  1089. }
  1090. // Get standard libraries for this language.
  1091. if(targetBuilds)
  1092. {
  1093. // Get the language to use for linking.
  1094. const char* linkLanguage = target.GetLinkerLanguage();
  1095. if(!linkLanguage)
  1096. {
  1097. cmSystemTools::Error
  1098. ("CMake can not determine linker language for target:",
  1099. target.GetName());
  1100. return;
  1101. }
  1102. // Compute the variable name to lookup standard libraries for this
  1103. // language.
  1104. std::string standardLibsVar = "CMAKE_";
  1105. standardLibsVar += linkLanguage;
  1106. standardLibsVar += "_STANDARD_LIBRARIES";
  1107. // Add standard libraries.
  1108. if(const char* stdLibs =
  1109. this->Makefile->GetDefinition(standardLibsVar.c_str()))
  1110. {
  1111. extraLinkOptions += " ";
  1112. extraLinkOptions += stdLibs;
  1113. }
  1114. }
  1115. // Compute version number information.
  1116. std::string targetVersionFlag;
  1117. if(target.GetType() == cmTarget::EXECUTABLE ||
  1118. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1119. target.GetType() == cmTarget::MODULE_LIBRARY)
  1120. {
  1121. int major;
  1122. int minor;
  1123. target.GetTargetVersion(major, minor);
  1124. cmOStringStream targetVersionStream;
  1125. targetVersionStream << "/version:" << major << "." << minor;
  1126. targetVersionFlag = targetVersionStream.str();
  1127. }
  1128. // Compute the real name of the target.
  1129. std::string outputName =
  1130. "(OUTPUT_NAME is for libraries and executables only)";
  1131. std::string outputNameDebug = outputName;
  1132. std::string outputNameRelease = outputName;
  1133. std::string outputNameMinSizeRel = outputName;
  1134. std::string outputNameRelWithDebInfo = outputName;
  1135. if(target.GetType() == cmTarget::EXECUTABLE ||
  1136. target.GetType() == cmTarget::STATIC_LIBRARY ||
  1137. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1138. target.GetType() == cmTarget::MODULE_LIBRARY)
  1139. {
  1140. outputName = target.GetFullName();
  1141. outputNameDebug = target.GetFullName("Debug");
  1142. outputNameRelease = target.GetFullName("Release");
  1143. outputNameMinSizeRel = target.GetFullName("MinSizeRel");
  1144. outputNameRelWithDebInfo = target.GetFullName("RelWithDebInfo");
  1145. }
  1146. // Compute the output directory for the target.
  1147. std::string outputDirDebug;
  1148. std::string outputDirRelease;
  1149. std::string outputDirMinSizeRel;
  1150. std::string outputDirRelWithDebInfo;
  1151. if(target.GetType() == cmTarget::EXECUTABLE ||
  1152. target.GetType() == cmTarget::STATIC_LIBRARY ||
  1153. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1154. target.GetType() == cmTarget::MODULE_LIBRARY)
  1155. {
  1156. outputDirDebug =
  1157. removeQuotes(this->ConvertToOptionallyRelativeOutputPath(
  1158. target.GetDirectory("Debug").c_str()));
  1159. outputDirRelease =
  1160. removeQuotes(this->ConvertToOptionallyRelativeOutputPath(
  1161. target.GetDirectory("Release").c_str()));
  1162. outputDirMinSizeRel =
  1163. removeQuotes(this->ConvertToOptionallyRelativeOutputPath(
  1164. target.GetDirectory("MinSizeRel").c_str()));
  1165. outputDirRelWithDebInfo =
  1166. removeQuotes(this->ConvertToOptionallyRelativeOutputPath(
  1167. target.GetDirectory("RelWithDebInfo").c_str()));
  1168. }
  1169. // Compute the proper link information for the target.
  1170. std::string optionsDebug;
  1171. std::string optionsRelease;
  1172. std::string optionsMinSizeRel;
  1173. std::string optionsRelWithDebInfo;
  1174. if(target.GetType() == cmTarget::EXECUTABLE ||
  1175. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1176. target.GetType() == cmTarget::MODULE_LIBRARY)
  1177. {
  1178. extraLinkOptionsDebug =
  1179. extraLinkOptions + " " + extraLinkOptionsDebug;
  1180. extraLinkOptionsRelease =
  1181. extraLinkOptions + " " + extraLinkOptionsRelease;
  1182. extraLinkOptionsMinSizeRel =
  1183. extraLinkOptions + " " + extraLinkOptionsMinSizeRel;
  1184. extraLinkOptionsRelWithDebInfo =
  1185. extraLinkOptions + " " + extraLinkOptionsRelWithDebInfo;
  1186. this->ComputeLinkOptions(target, "Debug", extraLinkOptionsDebug,
  1187. optionsDebug);
  1188. this->ComputeLinkOptions(target, "Release", extraLinkOptionsRelease,
  1189. optionsRelease);
  1190. this->ComputeLinkOptions(target, "MinSizeRel", extraLinkOptionsMinSizeRel,
  1191. optionsMinSizeRel);
  1192. this->ComputeLinkOptions(target, "RelWithDebInfo", extraLinkOptionsRelWithDebInfo,
  1193. optionsRelWithDebInfo);
  1194. }
  1195. // Compute the path of the import library.
  1196. std::string targetImplibFlagDebug;
  1197. std::string targetImplibFlagRelease;
  1198. std::string targetImplibFlagMinSizeRel;
  1199. std::string targetImplibFlagRelWithDebInfo;
  1200. if(target.GetType() == cmTarget::SHARED_LIBRARY ||
  1201. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1202. target.GetType() == cmTarget::EXECUTABLE)
  1203. {
  1204. std::string fullPathImpDebug = target.GetDirectory("Debug", true);
  1205. std::string fullPathImpRelease = target.GetDirectory("Release", true);
  1206. std::string fullPathImpMinSizeRel =
  1207. target.GetDirectory("MinSizeRel", true);
  1208. std::string fullPathImpRelWithDebInfo =
  1209. target.GetDirectory("RelWithDebInfo", true);
  1210. fullPathImpDebug += "/";
  1211. fullPathImpRelease += "/";
  1212. fullPathImpMinSizeRel += "/";
  1213. fullPathImpRelWithDebInfo += "/";
  1214. fullPathImpDebug += target.GetFullName("Debug", true);
  1215. fullPathImpRelease += target.GetFullName("Release", true);
  1216. fullPathImpMinSizeRel += target.GetFullName("MinSizeRel", true);
  1217. fullPathImpRelWithDebInfo += target.GetFullName("RelWithDebInfo", true);
  1218. targetImplibFlagDebug = "/implib:";
  1219. targetImplibFlagRelease = "/implib:";
  1220. targetImplibFlagMinSizeRel = "/implib:";
  1221. targetImplibFlagRelWithDebInfo = "/implib:";
  1222. targetImplibFlagDebug +=
  1223. this->ConvertToOptionallyRelativeOutputPath(fullPathImpDebug.c_str());
  1224. targetImplibFlagRelease +=
  1225. this->ConvertToOptionallyRelativeOutputPath(fullPathImpRelease.c_str());
  1226. targetImplibFlagMinSizeRel +=
  1227. this->ConvertToOptionallyRelativeOutputPath(
  1228. fullPathImpMinSizeRel.c_str());
  1229. targetImplibFlagRelWithDebInfo +=
  1230. this->ConvertToOptionallyRelativeOutputPath(
  1231. fullPathImpRelWithDebInfo.c_str());
  1232. }
  1233. #ifdef CM_USE_OLD_VS6
  1234. // Compute link information for the target.
  1235. if(extraLinkOptions.size())
  1236. {
  1237. libOptions += " ";
  1238. libOptions += extraLinkOptions;
  1239. libOptions += " ";
  1240. libMultiLineOptions += "# ADD LINK32 ";
  1241. libMultiLineOptions += extraLinkOptions;
  1242. libMultiLineOptions += " \n";
  1243. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  1244. libMultiLineOptionsForDebug += extraLinkOptions;
  1245. libMultiLineOptionsForDebug += " \n";
  1246. }
  1247. #endif
  1248. // are there any custom rules on the target itself
  1249. // only if the target is a lib or exe
  1250. std::string customRuleCodeRelease
  1251. = this->CreateTargetRules(target, "RELEASE", libName);
  1252. std::string customRuleCodeDebug
  1253. = this->CreateTargetRules(target, "DEBUG", libName);
  1254. std::string customRuleCodeMinSizeRel
  1255. = this->CreateTargetRules(target, "MINSIZEREL", libName);
  1256. std::string customRuleCodeRelWithDebInfo
  1257. = this->CreateTargetRules(target, "RELWITHDEBINFO", libName);
  1258. std::ifstream fin(this->DSPHeaderTemplate.c_str());
  1259. if(!fin)
  1260. {
  1261. cmSystemTools::Error("Error Reading ", this->DSPHeaderTemplate.c_str());
  1262. }
  1263. std::string staticLibOptions;
  1264. if(target.GetType() == cmTarget::STATIC_LIBRARY )
  1265. {
  1266. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  1267. {
  1268. staticLibOptions = libflags;
  1269. }
  1270. }
  1271. // Add the export symbol definition for shared library objects.
  1272. std::string exportSymbol;
  1273. if(const char* exportMacro = target.GetExportMacro())
  1274. {
  1275. exportSymbol = exportMacro;
  1276. }
  1277. std::string line;
  1278. std::string libnameExports;
  1279. if(exportSymbol.size())
  1280. {
  1281. libnameExports = "/D \"";
  1282. libnameExports += exportSymbol;
  1283. libnameExports += "\"";
  1284. }
  1285. while(cmSystemTools::GetLineFromStream(fin, line))
  1286. {
  1287. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  1288. if(!mfcFlag)
  1289. {
  1290. mfcFlag = "0";
  1291. }
  1292. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME_EXPORTS",
  1293. libnameExports.c_str());
  1294. cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG",
  1295. mfcFlag);
  1296. if(target.GetType() == cmTarget::STATIC_LIBRARY )
  1297. {
  1298. cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS",
  1299. staticLibOptions.c_str());
  1300. }
  1301. if(this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  1302. {
  1303. cmSystemTools::ReplaceString(line, "/nologo", "");
  1304. }
  1305. #ifdef CM_USE_OLD_VS6
  1306. cmSystemTools::ReplaceString(line, "CM_LIBRARIES",
  1307. libOptions.c_str());
  1308. cmSystemTools::ReplaceString(line, "CM_DEBUG_LIBRARIES",
  1309. libDebugOptions.c_str());
  1310. cmSystemTools::ReplaceString(line, "CM_OPTIMIZED_LIBRARIES",
  1311. libOptimizedOptions.c_str());
  1312. cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES_FOR_DEBUG",
  1313. libMultiLineOptionsForDebug.c_str());
  1314. cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES",
  1315. libMultiLineOptions.c_str());
  1316. cmSystemTools::ReplaceString(line, "CM_MULTILINE_DEBUG_LIBRARIES",
  1317. libMultiLineDebugOptions.c_str());
  1318. cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIMIZED_LIBRARIES",
  1319. libMultiLineOptimizedOptions.c_str());
  1320. #endif
  1321. // Substitute the rules for custom command. When specifying just the
  1322. // target name for the command the command can be different for
  1323. // different configs
  1324. cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE_RELEASE",
  1325. customRuleCodeRelease.c_str());
  1326. cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE_DEBUG",
  1327. customRuleCodeDebug.c_str());
  1328. cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE_MINSIZEREL",
  1329. customRuleCodeMinSizeRel.c_str());
  1330. cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE_RELWITHDEBINFO",
  1331. customRuleCodeRelWithDebInfo.c_str());
  1332. // Substitute the real output name into the template.
  1333. cmSystemTools::ReplaceString(line, "OUTPUT_NAME_DEBUG",
  1334. outputNameDebug.c_str());
  1335. cmSystemTools::ReplaceString(line, "OUTPUT_NAME_RELEASE",
  1336. outputNameRelease.c_str());
  1337. cmSystemTools::ReplaceString(line, "OUTPUT_NAME_MINSIZEREL",
  1338. outputNameMinSizeRel.c_str());
  1339. cmSystemTools::ReplaceString(line, "OUTPUT_NAME_RELWITHDEBINFO",
  1340. outputNameRelWithDebInfo.c_str());
  1341. cmSystemTools::ReplaceString(line, "OUTPUT_NAME", outputName.c_str());
  1342. // Substitute the proper link information into the template.
  1343. cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIONS_DEBUG",
  1344. optionsDebug.c_str());
  1345. cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIONS_RELEASE",
  1346. optionsRelease.c_str());
  1347. cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIONS_MINSIZEREL",
  1348. optionsMinSizeRel.c_str());
  1349. cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIONS_RELWITHDEBINFO",
  1350. optionsRelWithDebInfo.c_str());
  1351. cmSystemTools::ReplaceString(line, "BUILD_INCLUDES",
  1352. this->IncludeOptions.c_str());
  1353. cmSystemTools::ReplaceString(line, "TARGET_VERSION_FLAG",
  1354. targetVersionFlag.c_str());
  1355. cmSystemTools::ReplaceString(line, "TARGET_IMPLIB_FLAG_DEBUG",
  1356. targetImplibFlagDebug.c_str());
  1357. cmSystemTools::ReplaceString(line, "TARGET_IMPLIB_FLAG_RELEASE",
  1358. targetImplibFlagRelease.c_str());
  1359. cmSystemTools::ReplaceString(line, "TARGET_IMPLIB_FLAG_MINSIZEREL",
  1360. targetImplibFlagMinSizeRel.c_str());
  1361. cmSystemTools::ReplaceString(line, "TARGET_IMPLIB_FLAG_RELWITHDEBINFO",
  1362. targetImplibFlagRelWithDebInfo.c_str());
  1363. std::string vs6name = GetVS6TargetName(libName);
  1364. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME", vs6name.c_str());
  1365. #ifdef CM_USE_OLD_VS6
  1366. // because LIBRARY_OUTPUT_PATH and EXECUTABLE_OUTPUT_PATH
  1367. // are already quoted in the template file,
  1368. // we need to remove the quotes here, we still need
  1369. // to convert to output path for unix to win32 conversion
  1370. cmSystemTools::ReplaceString
  1371. (line, "LIBRARY_OUTPUT_PATH",
  1372. removeQuotes(this->ConvertToOptionallyRelativeOutputPath
  1373. (libPath.c_str())).c_str());
  1374. cmSystemTools::ReplaceString
  1375. (line, "EXECUTABLE_OUTPUT_PATH",
  1376. removeQuotes(this->ConvertToOptionallyRelativeOutputPath
  1377. (exePath.c_str())).c_str());
  1378. #endif
  1379. if(targetBuilds)
  1380. {
  1381. cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_DEBUG",
  1382. outputDirDebug.c_str());
  1383. cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_RELEASE",
  1384. outputDirRelease.c_str());
  1385. cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_MINSIZEREL",
  1386. outputDirMinSizeRel.c_str());
  1387. cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_RELWITHDEBINFO",
  1388. outputDirRelWithDebInfo.c_str());
  1389. #ifdef CM_USE_OLD_VS6
  1390. std::string outPath = target.GetDirectory();
  1391. cmSystemTools::ReplaceString
  1392. (line, "OUTPUT_DIRECTORY",
  1393. removeQuotes(this->ConvertToOptionallyRelativeOutputPath
  1394. (outPath.c_str())).c_str());
  1395. #endif
  1396. }
  1397. cmSystemTools::ReplaceString(line,
  1398. "EXTRA_DEFINES",
  1399. this->Makefile->GetDefineFlags());
  1400. const char* debugPostfix
  1401. = this->Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  1402. cmSystemTools::ReplaceString(line, "DEBUG_POSTFIX",
  1403. debugPostfix?debugPostfix:"");
  1404. // store flags for each configuration
  1405. std::string flags = " ";
  1406. std::string flagsRelease = " ";
  1407. std::string flagsMinSize = " ";
  1408. std::string flagsDebug = " ";
  1409. std::string flagsDebugRel = " ";
  1410. if(target.GetType() >= cmTarget::EXECUTABLE &&
  1411. target.GetType() <= cmTarget::MODULE_LIBRARY)
  1412. {
  1413. const char* linkLanguage = target.GetLinkerLanguage();
  1414. if(!linkLanguage)
  1415. {
  1416. cmSystemTools::Error
  1417. ("CMake can not determine linker language for target:",
  1418. target.GetName());
  1419. return;
  1420. }
  1421. // if CXX is on and the target contains cxx code then add the cxx flags
  1422. std::string baseFlagVar = "CMAKE_";
  1423. baseFlagVar += linkLanguage;
  1424. baseFlagVar += "_FLAGS";
  1425. flags = this->Makefile->GetSafeDefinition(baseFlagVar.c_str());
  1426. std::string flagVar = baseFlagVar + "_RELEASE";
  1427. flagsRelease = this->Makefile->GetSafeDefinition(flagVar.c_str());
  1428. flagsRelease += " -DCMAKE_INTDIR=\\\"Release\\\" ";
  1429. flagVar = baseFlagVar + "_MINSIZEREL";
  1430. flagsMinSize = this->Makefile->GetSafeDefinition(flagVar.c_str());
  1431. flagsMinSize += " -DCMAKE_INTDIR=\\\"MinSizeRel\\\" ";
  1432. flagVar = baseFlagVar + "_DEBUG";
  1433. flagsDebug = this->Makefile->GetSafeDefinition(flagVar.c_str());
  1434. flagsDebug += " -DCMAKE_INTDIR=\\\"Debug\\\" ";
  1435. flagVar = baseFlagVar + "_RELWITHDEBINFO";
  1436. flagsDebugRel = this->Makefile->GetSafeDefinition(flagVar.c_str());
  1437. flagsDebugRel += " -DCMAKE_INTDIR=\\\"RelWithDebInfo\\\" ";
  1438. }
  1439. // if unicode is not found, then add -D_MBCS
  1440. std::string defs = this->Makefile->GetDefineFlags();
  1441. if(flags.find("D_UNICODE") == flags.npos &&
  1442. defs.find("D_UNICODE") == flags.npos)
  1443. {
  1444. flags += " /D \"_MBCS\"";
  1445. }
  1446. // Add per-target flags.
  1447. if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
  1448. {
  1449. flags += " ";
  1450. flags += targetFlags;
  1451. }
  1452. // Add per-target and per-configuration preprocessor definitions.
  1453. std::string defines = " ";
  1454. std::string debugDefines = " ";
  1455. std::string releaseDefines = " ";
  1456. std::string minsizeDefines = " ";
  1457. std::string debugrelDefines = " ";
  1458. this->AppendDefines(
  1459. defines,
  1460. this->Makefile->GetProperty("COMPILE_DEFINITIONS"), 0);
  1461. this->AppendDefines(
  1462. debugDefines,
  1463. this->Makefile->GetProperty("COMPILE_DEFINITIONS_DEBUG"),0);
  1464. this->AppendDefines(
  1465. releaseDefines,
  1466. this->Makefile->GetProperty("COMPILE_DEFINITIONS_RELEASE"), 0);
  1467. this->AppendDefines(
  1468. minsizeDefines,
  1469. this->Makefile->GetProperty("COMPILE_DEFINITIONS_MINSIZEREL"), 0);
  1470. this->AppendDefines(
  1471. debugrelDefines,
  1472. this->Makefile->GetProperty("COMPILE_DEFINITIONS_RELWITHDEBINFO"), 0);
  1473. this->AppendDefines(
  1474. defines,
  1475. target.GetProperty("COMPILE_DEFINITIONS"), 0);
  1476. this->AppendDefines(
  1477. debugDefines,
  1478. target.GetProperty("COMPILE_DEFINITIONS_DEBUG"), 0);
  1479. this->AppendDefines(
  1480. releaseDefines,
  1481. target.GetProperty("COMPILE_DEFINITIONS_RELEASE"), 0);
  1482. this->AppendDefines(
  1483. minsizeDefines,
  1484. target.GetProperty("COMPILE_DEFINITIONS_MINSIZEREL"), 0);
  1485. this->AppendDefines(
  1486. debugrelDefines,
  1487. target.GetProperty("COMPILE_DEFINITIONS_RELWITHDEBINFO"), 0);
  1488. flags += defines;
  1489. flagsDebug += debugDefines;
  1490. flagsRelease += releaseDefines;
  1491. flagsMinSize += minsizeDefines;
  1492. flagsDebugRel += debugrelDefines;
  1493. // The template files have CXX FLAGS in them, that need to be replaced.
  1494. // There are not separate CXX and C template files, so we use the same
  1495. // variable names. The previous code sets up flags* variables to contain
  1496. // the correct C or CXX flags
  1497. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_MINSIZEREL",
  1498. flagsMinSize.c_str());
  1499. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_DEBUG",
  1500. flagsDebug.c_str());
  1501. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELWITHDEBINFO",
  1502. flagsDebugRel.c_str());
  1503. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELEASE",
  1504. flagsRelease.c_str());
  1505. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS", flags.c_str());
  1506. cmSystemTools::ReplaceString(line, "COMPILE_DEFINITIONS_MINSIZEREL",
  1507. minsizeDefines.c_str());
  1508. cmSystemTools::ReplaceString(line, "COMPILE_DEFINITIONS_DEBUG",
  1509. debugDefines.c_str());
  1510. cmSystemTools::ReplaceString(line, "COMPILE_DEFINITIONS_RELWITHDEBINFO",
  1511. debugrelDefines.c_str());
  1512. cmSystemTools::ReplaceString(line, "COMPILE_DEFINITIONS_RELEASE",
  1513. releaseDefines.c_str());
  1514. cmSystemTools::ReplaceString(line, "COMPILE_DEFINITIONS", defines.c_str());
  1515. fout << line.c_str() << std::endl;
  1516. }
  1517. }
  1518. void cmLocalVisualStudio6Generator::WriteDSPFooter(std::ostream& fout)
  1519. {
  1520. std::ifstream fin(this->DSPFooterTemplate.c_str());
  1521. if(!fin)
  1522. {
  1523. cmSystemTools::Error("Error Reading ",
  1524. this->DSPFooterTemplate.c_str());
  1525. }
  1526. std::string line;
  1527. while(cmSystemTools::GetLineFromStream(fin, line))
  1528. {
  1529. fout << line << std::endl;
  1530. }
  1531. }
  1532. //----------------------------------------------------------------------------
  1533. void cmLocalVisualStudio6Generator
  1534. ::ComputeLinkOptions(cmTarget& target,
  1535. const char* configName,
  1536. const std::string extraOptions,
  1537. std::string& options)
  1538. {
  1539. // Compute the link information for this configuration.
  1540. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1541. if(!pcli)
  1542. {
  1543. return;
  1544. }
  1545. cmComputeLinkInformation& cli = *pcli;
  1546. typedef cmComputeLinkInformation::ItemVector ItemVector;
  1547. ItemVector const& linkLibs = cli.GetItems();
  1548. std::vector<std::string> const& linkDirs = cli.GetDirectories();
  1549. // Build the link options code.
  1550. for(std::vector<std::string>::const_iterator d = linkDirs.begin();
  1551. d != linkDirs.end(); ++d)
  1552. {
  1553. std::string dir = *d;
  1554. if(!dir.empty())
  1555. {
  1556. if(dir[dir.size()-1] != '/')
  1557. {
  1558. dir += "/";
  1559. }
  1560. dir += "$(IntDir)";
  1561. options += "# ADD LINK32 /LIBPATH:";
  1562. options += this->ConvertToOptionallyRelativeOutputPath(dir.c_str());
  1563. options += " /LIBPATH:";
  1564. options += this->ConvertToOptionallyRelativeOutputPath(d->c_str());
  1565. options += "\n";
  1566. }
  1567. }
  1568. for(ItemVector::const_iterator l = linkLibs.begin();
  1569. l != linkLibs.end(); ++l)
  1570. {
  1571. options += "# ADD LINK32 ";
  1572. if(l->IsPath)
  1573. {
  1574. options +=
  1575. this->ConvertToOptionallyRelativeOutputPath(l->Value.c_str());
  1576. }
  1577. else
  1578. {
  1579. options += l->Value;
  1580. }
  1581. options += "\n";
  1582. }
  1583. // Add extra options if any.
  1584. if(!extraOptions.empty())
  1585. {
  1586. options += "# ADD LINK32 ";
  1587. options += extraOptions;
  1588. options += "\n";
  1589. }
  1590. }
  1591. std::string
  1592. cmLocalVisualStudio6Generator
  1593. ::GetTargetDirectory(cmTarget const&) const
  1594. {
  1595. // No per-target directory for this generator (yet).
  1596. return "";
  1597. }
  1598. void cmLocalVisualStudio6Generator
  1599. ::GetTargetObjectFileDirectories(cmTarget* ,
  1600. std::vector<std::string>&
  1601. dirs)
  1602. {
  1603. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  1604. dir += "/";
  1605. dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
  1606. dirs.push_back(dir);
  1607. }
  1608. std::string
  1609. cmLocalVisualStudio6Generator
  1610. ::GetConfigName(std::string const& configuration) const
  1611. {
  1612. // Strip the subdirectory name out of the configuration name.
  1613. std::string config = configuration;
  1614. std::string::size_type pos = config.find_last_of(" ");
  1615. config = config.substr(pos+1, std::string::npos);
  1616. config = config.substr(0, config.size()-1);
  1617. return config;
  1618. }
  1619. //----------------------------------------------------------------------------
  1620. bool
  1621. cmLocalVisualStudio6Generator
  1622. ::CheckDefinition(std::string const& define) const
  1623. {
  1624. // Perform the standard check first.
  1625. if(!this->cmLocalGenerator::CheckDefinition(define))
  1626. {
  1627. return false;
  1628. }
  1629. // Now do the VS6-specific check.
  1630. if(define.find_first_of(" ") != define.npos &&
  1631. define.find_first_of("\"$;") != define.npos)
  1632. {
  1633. cmOStringStream e;
  1634. e << "WARNING: The VS6 IDE does not support preprocessor definition "
  1635. << "values with spaces and '\"', '$', or ';'.\n"
  1636. << "CMake is dropping a preprocessor definition: " << define << "\n"
  1637. << "Consider defining the macro in a (configured) header file.\n";
  1638. cmSystemTools::Message(e.str().c_str());
  1639. return false;
  1640. }
  1641. // Assume it is supported.
  1642. return true;
  1643. }