cmLocalVisualStudio6Generator.cxx 61 KB

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