cmLocalVisualStudio6Generator.cxx 69 KB

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