cmLocalVisualStudio6Generator.cxx 69 KB

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