cmLocalVisualStudio6Generator.cxx 67 KB

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