cmLocalVisualStudio6Generator.cxx 65 KB

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