cmLocalVisualStudio6Generator.cxx 63 KB

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