cmLocalVisualStudio6Generator.cxx 57 KB

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