cmLocalVisualStudio6Generator.cxx 61 KB

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