1
0

cmLocalVisualStudio6Generator.cxx 61 KB

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