cmLocalVisualStudio6Generator.cxx 69 KB

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