cmLocalVisualStudio6Generator.cxx 64 KB

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