cmLocalVisualStudio6Generator.cxx 68 KB

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