cmLocalVisualStudio6Generator.cxx 61 KB

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