cmLocalVisualStudio6Generator.cxx 67 KB

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