cmLocalVisualStudio6Generator.cxx 58 KB

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