cmLocalVisualStudio6Generator.cxx 65 KB

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