cmLocalVisualStudio6Generator.cxx 59 KB

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