cmLocalVisualStudio6Generator.cxx 61 KB

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