cmLocalVisualStudio6Generator.cxx 68 KB

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