cmFileCommand.cxx 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042
  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 "cmFileCommand.h"
  14. #include "cmake.h"
  15. #include "cmHexFileConverter.h"
  16. #include "cmFileTimeComparison.h"
  17. #if defined(CMAKE_BUILD_WITH_CMAKE)
  18. #include "cm_curl.h"
  19. #endif
  20. #undef GetCurrentDirectory
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. #include <cmsys/Directory.hxx>
  24. #include <cmsys/Glob.hxx>
  25. #include <cmsys/RegularExpression.hxx>
  26. // Table of permissions flags.
  27. #if defined(_WIN32) && !defined(__CYGWIN__)
  28. static mode_t mode_owner_read = S_IREAD;
  29. static mode_t mode_owner_write = S_IWRITE;
  30. static mode_t mode_owner_execute = S_IEXEC;
  31. static mode_t mode_group_read = 0;
  32. static mode_t mode_group_write = 0;
  33. static mode_t mode_group_execute = 0;
  34. static mode_t mode_world_read = 0;
  35. static mode_t mode_world_write = 0;
  36. static mode_t mode_world_execute = 0;
  37. static mode_t mode_setuid = 0;
  38. static mode_t mode_setgid = 0;
  39. #else
  40. static mode_t mode_owner_read = S_IRUSR;
  41. static mode_t mode_owner_write = S_IWUSR;
  42. static mode_t mode_owner_execute = S_IXUSR;
  43. static mode_t mode_group_read = S_IRGRP;
  44. static mode_t mode_group_write = S_IWGRP;
  45. static mode_t mode_group_execute = S_IXGRP;
  46. static mode_t mode_world_read = S_IROTH;
  47. static mode_t mode_world_write = S_IWOTH;
  48. static mode_t mode_world_execute = S_IXOTH;
  49. static mode_t mode_setuid = S_ISUID;
  50. static mode_t mode_setgid = S_ISGID;
  51. #endif
  52. // cmLibraryCommand
  53. bool cmFileCommand
  54. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  55. {
  56. if(args.size() < 2 )
  57. {
  58. this->SetError("must be called with at least two arguments.");
  59. return false;
  60. }
  61. std::string subCommand = args[0];
  62. if ( subCommand == "WRITE" )
  63. {
  64. return this->HandleWriteCommand(args, false);
  65. }
  66. else if ( subCommand == "APPEND" )
  67. {
  68. return this->HandleWriteCommand(args, true);
  69. }
  70. else if ( subCommand == "DOWNLOAD" )
  71. {
  72. return this->HandleDownloadCommand(args);
  73. }
  74. else if ( subCommand == "READ" )
  75. {
  76. return this->HandleReadCommand(args);
  77. }
  78. else if ( subCommand == "STRINGS" )
  79. {
  80. return this->HandleStringsCommand(args);
  81. }
  82. else if ( subCommand == "GLOB" )
  83. {
  84. return this->HandleGlobCommand(args, false);
  85. }
  86. else if ( subCommand == "GLOB_RECURSE" )
  87. {
  88. return this->HandleGlobCommand(args, true);
  89. }
  90. else if ( subCommand == "MAKE_DIRECTORY" )
  91. {
  92. return this->HandleMakeDirectoryCommand(args);
  93. }
  94. else if ( subCommand == "REMOVE" )
  95. {
  96. return this->HandleRemove(args, false);
  97. }
  98. else if ( subCommand == "REMOVE_RECURSE" )
  99. {
  100. return this->HandleRemove(args, true);
  101. }
  102. else if ( subCommand == "INSTALL" )
  103. {
  104. return this->HandleInstallCommand(args);
  105. }
  106. else if ( subCommand == "RELATIVE_PATH" )
  107. {
  108. return this->HandleRelativePathCommand(args);
  109. }
  110. else if ( subCommand == "TO_CMAKE_PATH" )
  111. {
  112. return this->HandleCMakePathCommand(args, false);
  113. }
  114. else if ( subCommand == "TO_NATIVE_PATH" )
  115. {
  116. return this->HandleCMakePathCommand(args, true);
  117. }
  118. std::string e = "does not recognize sub-command "+subCommand;
  119. this->SetError(e.c_str());
  120. return false;
  121. }
  122. //----------------------------------------------------------------------------
  123. bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
  124. bool append)
  125. {
  126. std::string message;
  127. std::vector<std::string>::const_iterator i = args.begin();
  128. i++; // Get rid of subcommand
  129. std::string fileName = *i;
  130. if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
  131. {
  132. fileName = this->Makefile->GetCurrentDirectory();
  133. fileName += "/" + *i;
  134. }
  135. i++;
  136. for(;i != args.end(); ++i)
  137. {
  138. message += *i;
  139. }
  140. if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) )
  141. {
  142. std::string e
  143. = "attempted to write a file: " + fileName +
  144. " into a source directory.";
  145. this->SetError(e.c_str());
  146. cmSystemTools::SetFatalErrorOccured();
  147. return false;
  148. }
  149. std::string dir = cmSystemTools::GetFilenamePath(fileName);
  150. cmSystemTools::MakeDirectory(dir.c_str());
  151. mode_t mode =
  152. #if defined( _MSC_VER ) || defined( __MINGW32__ )
  153. S_IREAD | S_IWRITE
  154. #elif defined( __BORLANDC__ )
  155. S_IRUSR | S_IWUSR
  156. #else
  157. S_IRUSR | S_IWUSR |
  158. S_IRGRP |
  159. S_IROTH
  160. #endif
  161. ;
  162. // Set permissions to writable
  163. if ( cmSystemTools::GetPermissions(fileName.c_str(), mode) )
  164. {
  165. cmSystemTools::SetPermissions(fileName.c_str(),
  166. #if defined( _MSC_VER ) || defined( __MINGW32__ )
  167. S_IREAD | S_IWRITE
  168. #else
  169. S_IRUSR | S_IWUSR
  170. #endif
  171. );
  172. }
  173. // If GetPermissions fails, pretend like it is ok. File open will fail if
  174. // the file is not writable
  175. std::ofstream file(fileName.c_str(), append?std::ios::app: std::ios::out);
  176. if ( !file )
  177. {
  178. std::string error = "Internal CMake error when trying to open file: ";
  179. error += fileName.c_str();
  180. error += " for writing.";
  181. this->SetError(error.c_str());
  182. return false;
  183. }
  184. file << message;
  185. file.close();
  186. cmSystemTools::SetPermissions(fileName.c_str(), mode);
  187. this->Makefile->AddWrittenFile(fileName.c_str());
  188. return true;
  189. }
  190. //----------------------------------------------------------------------------
  191. bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
  192. {
  193. if ( args.size() < 3 )
  194. {
  195. this->SetError("READ must be called with at least two additional "
  196. "arguments");
  197. return false;
  198. }
  199. cmCommandArgumentsHelper argHelper;
  200. cmCommandArgumentGroup group;
  201. cmCAString readArg (&argHelper, "READ");
  202. cmCAString fileNameArg (&argHelper, 0);
  203. cmCAString resultArg (&argHelper, 0);
  204. cmCAString offsetArg (&argHelper, "OFFSET", &group);
  205. cmCAString limitArg (&argHelper, "LIMIT", &group);
  206. cmCAEnabler hexOutputArg (&argHelper, "HEX", &group);
  207. readArg.Follows(0);
  208. fileNameArg.Follows(&readArg);
  209. resultArg.Follows(&fileNameArg);
  210. group.Follows(&resultArg);
  211. argHelper.Parse(&args, 0);
  212. std::string fileName = fileNameArg.GetString();
  213. if ( !cmsys::SystemTools::FileIsFullPath(fileName.c_str()) )
  214. {
  215. fileName = this->Makefile->GetCurrentDirectory();
  216. fileName += "/" + fileNameArg.GetString();
  217. }
  218. std::string variable = resultArg.GetString();
  219. // Open the specified file.
  220. #if defined(_WIN32) || defined(__CYGWIN__)
  221. std::ifstream file(fileName.c_str(), std::ios::in |
  222. (hexOutputArg.IsEnabled() ? std::ios::binary : std::ios::in));
  223. #else
  224. std::ifstream file(fileName.c_str(), std::ios::in);
  225. #endif
  226. if ( !file )
  227. {
  228. std::string error = "Internal CMake error when trying to open file: ";
  229. error += fileName.c_str();
  230. error += " for reading.";
  231. this->SetError(error.c_str());
  232. return false;
  233. }
  234. // is there a limit?
  235. long sizeLimit = -1;
  236. if (limitArg.GetString().size() > 0)
  237. {
  238. sizeLimit = atoi(limitArg.GetCString());
  239. }
  240. // is there an offset?
  241. long offset = 0;
  242. if (offsetArg.GetString().size() > 0)
  243. {
  244. offset = atoi(offsetArg.GetCString());
  245. }
  246. file.seekg(offset);
  247. std::string output;
  248. if (hexOutputArg.IsEnabled())
  249. {
  250. // Convert part of the file into hex code
  251. int c;
  252. while((sizeLimit != 0) && (c = file.get(), file))
  253. {
  254. char hex[4];
  255. sprintf(hex, "%x", c&0xff);
  256. output += hex;
  257. if (sizeLimit > 0)
  258. {
  259. sizeLimit--;
  260. }
  261. }
  262. }
  263. else
  264. {
  265. std::string line;
  266. bool has_newline = false;
  267. while (sizeLimit != 0 &&
  268. cmSystemTools::GetLineFromStream(file, line, &has_newline,
  269. sizeLimit) )
  270. {
  271. if (sizeLimit > 0)
  272. {
  273. sizeLimit = sizeLimit - static_cast<long>(line.size());
  274. if (has_newline)
  275. {
  276. sizeLimit--;
  277. }
  278. if (sizeLimit < 0)
  279. {
  280. sizeLimit = 0;
  281. }
  282. }
  283. output += line;
  284. if ( has_newline )
  285. {
  286. output += "\n";
  287. }
  288. }
  289. }
  290. this->Makefile->AddDefinition(variable.c_str(), output.c_str());
  291. return true;
  292. }
  293. //----------------------------------------------------------------------------
  294. bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
  295. {
  296. if(args.size() < 3)
  297. {
  298. this->SetError("STRINGS requires a file name and output variable");
  299. return false;
  300. }
  301. // Get the file to read.
  302. std::string fileName = args[1];
  303. if(!cmsys::SystemTools::FileIsFullPath(fileName.c_str()))
  304. {
  305. fileName = this->Makefile->GetCurrentDirectory();
  306. fileName += "/" + args[1];
  307. }
  308. // Get the variable in which to store the results.
  309. std::string outVar = args[2];
  310. // Parse the options.
  311. enum { arg_none,
  312. arg_limit_input,
  313. arg_limit_output,
  314. arg_limit_count,
  315. arg_length_minimum,
  316. arg_length_maximum,
  317. arg__maximum,
  318. arg_regex };
  319. unsigned int minlen = 0;
  320. unsigned int maxlen = 0;
  321. int limit_input = -1;
  322. int limit_output = -1;
  323. unsigned int limit_count = 0;
  324. cmsys::RegularExpression regex;
  325. bool have_regex = false;
  326. bool newline_consume = false;
  327. bool hex_conversion_enabled = true;
  328. int arg_mode = arg_none;
  329. for(unsigned int i=3; i < args.size(); ++i)
  330. {
  331. if(args[i] == "LIMIT_INPUT")
  332. {
  333. arg_mode = arg_limit_input;
  334. }
  335. else if(args[i] == "LIMIT_OUTPUT")
  336. {
  337. arg_mode = arg_limit_output;
  338. }
  339. else if(args[i] == "LIMIT_COUNT")
  340. {
  341. arg_mode = arg_limit_count;
  342. }
  343. else if(args[i] == "LENGTH_MINIMUM")
  344. {
  345. arg_mode = arg_length_minimum;
  346. }
  347. else if(args[i] == "LENGTH_MAXIMUM")
  348. {
  349. arg_mode = arg_length_maximum;
  350. }
  351. else if(args[i] == "REGEX")
  352. {
  353. arg_mode = arg_regex;
  354. }
  355. else if(args[i] == "NEWLINE_CONSUME")
  356. {
  357. newline_consume = true;
  358. arg_mode = arg_none;
  359. }
  360. else if(args[i] == "NO_HEX_CONVERSION")
  361. {
  362. hex_conversion_enabled = false;
  363. arg_mode = arg_none;
  364. }
  365. else if(arg_mode == arg_limit_input)
  366. {
  367. if(sscanf(args[i].c_str(), "%d", &limit_input) != 1 ||
  368. limit_input < 0)
  369. {
  370. cmOStringStream e;
  371. e << "STRINGS option LIMIT_INPUT value \""
  372. << args[i] << "\" is not an unsigned integer.";
  373. this->SetError(e.str().c_str());
  374. return false;
  375. }
  376. arg_mode = arg_none;
  377. }
  378. else if(arg_mode == arg_limit_output)
  379. {
  380. if(sscanf(args[i].c_str(), "%d", &limit_output) != 1 ||
  381. limit_output < 0)
  382. {
  383. cmOStringStream e;
  384. e << "STRINGS option LIMIT_OUTPUT value \""
  385. << args[i] << "\" is not an unsigned integer.";
  386. this->SetError(e.str().c_str());
  387. return false;
  388. }
  389. arg_mode = arg_none;
  390. }
  391. else if(arg_mode == arg_limit_count)
  392. {
  393. int count;
  394. if(sscanf(args[i].c_str(), "%d", &count) != 1 || count < 0)
  395. {
  396. cmOStringStream e;
  397. e << "STRINGS option LIMIT_COUNT value \""
  398. << args[i] << "\" is not an unsigned integer.";
  399. this->SetError(e.str().c_str());
  400. return false;
  401. }
  402. limit_count = count;
  403. arg_mode = arg_none;
  404. }
  405. else if(arg_mode == arg_length_minimum)
  406. {
  407. int len;
  408. if(sscanf(args[i].c_str(), "%d", &len) != 1 || len < 0)
  409. {
  410. cmOStringStream e;
  411. e << "STRINGS option LENGTH_MINIMUM value \""
  412. << args[i] << "\" is not an unsigned integer.";
  413. this->SetError(e.str().c_str());
  414. return false;
  415. }
  416. minlen = len;
  417. arg_mode = arg_none;
  418. }
  419. else if(arg_mode == arg_length_maximum)
  420. {
  421. int len;
  422. if(sscanf(args[i].c_str(), "%d", &len) != 1 || len < 0)
  423. {
  424. cmOStringStream e;
  425. e << "STRINGS option LENGTH_MAXIMUM value \""
  426. << args[i] << "\" is not an unsigned integer.";
  427. this->SetError(e.str().c_str());
  428. return false;
  429. }
  430. maxlen = len;
  431. arg_mode = arg_none;
  432. }
  433. else if(arg_mode == arg_regex)
  434. {
  435. if(!regex.compile(args[i].c_str()))
  436. {
  437. cmOStringStream e;
  438. e << "STRINGS option REGEX value \""
  439. << args[i] << "\" could not be compiled.";
  440. this->SetError(e.str().c_str());
  441. return false;
  442. }
  443. have_regex = true;
  444. arg_mode = arg_none;
  445. }
  446. else
  447. {
  448. cmOStringStream e;
  449. e << "STRINGS given unknown argument \""
  450. << args[i] << "\"";
  451. this->SetError(e.str().c_str());
  452. return false;
  453. }
  454. }
  455. if (hex_conversion_enabled)
  456. {
  457. // TODO: should work without temp file, but just on a memory buffer
  458. std::string binaryFileName = this->Makefile->GetCurrentOutputDirectory();
  459. binaryFileName += cmake::GetCMakeFilesDirectory();
  460. binaryFileName += "/FileCommandStringsBinaryFile";
  461. if(cmHexFileConverter::TryConvert(fileName.c_str(),binaryFileName.c_str()))
  462. {
  463. fileName = binaryFileName;
  464. }
  465. }
  466. // Open the specified file.
  467. #if defined(_WIN32) || defined(__CYGWIN__)
  468. std::ifstream fin(fileName.c_str(), std::ios::in | std::ios::binary);
  469. #else
  470. std::ifstream fin(fileName.c_str(), std::ios::in);
  471. #endif
  472. if(!fin)
  473. {
  474. cmOStringStream e;
  475. e << "STRINGS file \"" << fileName << "\" cannot be read.";
  476. this->SetError(e.str().c_str());
  477. return false;
  478. }
  479. // Parse strings out of the file.
  480. int output_size = 0;
  481. std::vector<std::string> strings;
  482. std::string s;
  483. int c;
  484. while((!limit_count || strings.size() < limit_count) &&
  485. (limit_input < 0 || static_cast<int>(fin.tellg()) < limit_input) &&
  486. (c = fin.get(), fin))
  487. {
  488. if(c == '\0')
  489. {
  490. // A terminating null character has been found. Check if the
  491. // current string matches the requirements. Since it was
  492. // terminated by a null character, we require that the length be
  493. // at least one no matter what the user specified.
  494. if(s.length() >= minlen && s.length() >= 1 &&
  495. (!have_regex || regex.find(s.c_str())))
  496. {
  497. output_size += static_cast<int>(s.size()) + 1;
  498. if(limit_output >= 0 && output_size >= limit_output)
  499. {
  500. s = "";
  501. break;
  502. }
  503. strings.push_back(s);
  504. }
  505. // Reset the string to empty.
  506. s = "";
  507. }
  508. else if(c == '\n' && !newline_consume)
  509. {
  510. // The current line has been terminated. Check if the current
  511. // string matches the requirements. The length may now be as
  512. // low as zero since blank lines are allowed.
  513. if(s.length() >= minlen &&
  514. (!have_regex || regex.find(s.c_str())))
  515. {
  516. output_size += static_cast<int>(s.size()) + 1;
  517. if(limit_output >= 0 && output_size >= limit_output)
  518. {
  519. s = "";
  520. break;
  521. }
  522. strings.push_back(s);
  523. }
  524. // Reset the string to empty.
  525. s = "";
  526. }
  527. else if(c == '\r')
  528. {
  529. // Ignore CR character to make output always have UNIX newlines.
  530. }
  531. else if(c >= 0x20 && c < 0x7F || c == '\t' ||
  532. (c == '\n' && newline_consume))
  533. {
  534. // This is an ASCII character that may be part of a string.
  535. s += c;
  536. }
  537. else
  538. {
  539. // This is a non-string character. Reset the string to emtpy.
  540. s = "";
  541. }
  542. // Terminate a string if the maximum length is reached.
  543. if(maxlen > 0 && s.size() == maxlen)
  544. {
  545. if(s.length() >= minlen &&
  546. (!have_regex || regex.find(s.c_str())))
  547. {
  548. output_size += static_cast<int>(s.size()) + 1;
  549. if(limit_output >= 0 && output_size >= limit_output)
  550. {
  551. s = "";
  552. break;
  553. }
  554. strings.push_back(s);
  555. }
  556. s = "";
  557. }
  558. }
  559. // If there is a non-empty current string we have hit the end of the
  560. // input file or the input size limit. Check if the current string
  561. // matches the requirements.
  562. if((!limit_count || strings.size() < limit_count) &&
  563. !s.empty() && s.length() >= minlen &&
  564. (!have_regex || regex.find(s.c_str())))
  565. {
  566. output_size += static_cast<int>(s.size()) + 1;
  567. if(limit_output < 0 || output_size < limit_output)
  568. {
  569. strings.push_back(s);
  570. }
  571. }
  572. // Encode the result in a CMake list.
  573. const char* sep = "";
  574. std::string output;
  575. for(std::vector<std::string>::const_iterator si = strings.begin();
  576. si != strings.end(); ++si)
  577. {
  578. // Separate the strings in the output to make it a list.
  579. output += sep;
  580. sep = ";";
  581. // Store the string in the output, but escape semicolons to
  582. // make sure it is a list.
  583. std::string const& sr = *si;
  584. for(unsigned int i=0; i < sr.size(); ++i)
  585. {
  586. if(sr[i] == ';')
  587. {
  588. output += '\\';
  589. }
  590. output += sr[i];
  591. }
  592. }
  593. // Save the output in a makefile variable.
  594. this->Makefile->AddDefinition(outVar.c_str(), output.c_str());
  595. return true;
  596. }
  597. //----------------------------------------------------------------------------
  598. bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
  599. bool recurse)
  600. {
  601. if ( args.size() < 2 )
  602. {
  603. this->SetError("GLOB requires at least a variable name");
  604. return false;
  605. }
  606. std::vector<std::string>::const_iterator i = args.begin();
  607. i++; // Get rid of subcommand
  608. std::string variable = *i;
  609. i++;
  610. cmsys::Glob g;
  611. g.SetRecurse(recurse);
  612. std::string output = "";
  613. bool first = true;
  614. for ( ; i != args.end(); ++i )
  615. {
  616. if ( *i == "RELATIVE" )
  617. {
  618. ++i; // skip RELATIVE
  619. if ( i == args.end() )
  620. {
  621. this->SetError("GLOB requires a directory after the RELATIVE tag");
  622. return false;
  623. }
  624. g.SetRelative(i->c_str());
  625. ++i;
  626. if(i == args.end())
  627. {
  628. this->SetError("GLOB requires a glob expression after the directory");
  629. return false;
  630. }
  631. }
  632. if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
  633. {
  634. std::string expr = this->Makefile->GetCurrentDirectory();
  635. // Handle script mode
  636. if ( expr.size() > 0 )
  637. {
  638. expr += "/" + *i;
  639. g.FindFiles(expr);
  640. }
  641. else
  642. {
  643. g.FindFiles(*i);
  644. }
  645. }
  646. else
  647. {
  648. g.FindFiles(*i);
  649. }
  650. std::vector<std::string>::size_type cc;
  651. std::vector<std::string>& files = g.GetFiles();
  652. for ( cc = 0; cc < files.size(); cc ++ )
  653. {
  654. if ( !first )
  655. {
  656. output += ";";
  657. }
  658. output += files[cc];
  659. first = false;
  660. }
  661. }
  662. this->Makefile->AddDefinition(variable.c_str(), output.c_str());
  663. return true;
  664. }
  665. //----------------------------------------------------------------------------
  666. bool cmFileCommand::HandleMakeDirectoryCommand(
  667. std::vector<std::string> const& args)
  668. {
  669. if(args.size() < 2 )
  670. {
  671. this->SetError("called with incorrect number of arguments");
  672. return false;
  673. }
  674. std::vector<std::string>::const_iterator i = args.begin();
  675. i++; // Get rid of subcommand
  676. std::string expr;
  677. for ( ; i != args.end(); ++i )
  678. {
  679. const std::string* cdir = &(*i);
  680. if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
  681. {
  682. expr = this->Makefile->GetCurrentDirectory();
  683. expr += "/" + *i;
  684. cdir = &expr;
  685. }
  686. if ( !this->Makefile->CanIWriteThisFile(cdir->c_str()) )
  687. {
  688. std::string e = "attempted to create a directory: " + *cdir
  689. + " into a source directory.";
  690. this->SetError(e.c_str());
  691. cmSystemTools::SetFatalErrorOccured();
  692. return false;
  693. }
  694. if ( !cmSystemTools::MakeDirectory(cdir->c_str()) )
  695. {
  696. std::string error = "problem creating directory: " + *cdir;
  697. this->SetError(error.c_str());
  698. return false;
  699. }
  700. }
  701. return true;
  702. }
  703. //----------------------------------------------------------------------------
  704. // File installation helper class.
  705. struct cmFileInstaller
  706. {
  707. // Methods to actually install files.
  708. bool InstallFile(const char* fromFile, const char* toFile, bool always);
  709. bool InstallDirectory(const char* source, const char* destination,
  710. bool always);
  711. // All instances need the file command and makefile using them.
  712. cmFileInstaller(cmFileCommand* fc, cmMakefile* mf):
  713. FileCommand(fc), Makefile(mf), DestDirLength(0), MatchlessFiles(true)
  714. {
  715. // Get the current manifest.
  716. this->Manifest =
  717. this->Makefile->GetSafeDefinition("CMAKE_INSTALL_MANIFEST_FILES");
  718. }
  719. ~cmFileInstaller()
  720. {
  721. // Save the updated install manifest.
  722. this->Makefile->AddDefinition("CMAKE_INSTALL_MANIFEST_FILES",
  723. this->Manifest.c_str());
  724. }
  725. private:
  726. cmFileCommand* FileCommand;
  727. cmMakefile* Makefile;
  728. cmFileTimeComparison FileTimes;
  729. public:
  730. // The length of the destdir setting.
  731. int DestDirLength;
  732. // Whether to install a file not matching any expression.
  733. bool MatchlessFiles;
  734. // The current file manifest (semicolon separated list).
  735. std::string Manifest;
  736. // Permissions for files and directories installed by this object.
  737. mode_t FilePermissions;
  738. mode_t DirPermissions;
  739. // Properties set by pattern and regex match rules.
  740. struct MatchProperties
  741. {
  742. bool Exclude;
  743. mode_t Permissions;
  744. MatchProperties(): Exclude(false), Permissions(0) {}
  745. };
  746. struct MatchRule
  747. {
  748. cmsys::RegularExpression Regex;
  749. MatchProperties Properties;
  750. std::string RegexString;
  751. MatchRule(std::string const& regex):
  752. Regex(regex.c_str()), RegexString(regex) {}
  753. };
  754. std::vector<MatchRule> MatchRules;
  755. // Get the properties from rules matching this input file.
  756. MatchProperties CollectMatchProperties(const char* file,
  757. bool isDirectory)
  758. {
  759. // Match rules are case-insensitive on some platforms.
  760. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
  761. std::string lower = cmSystemTools::LowerCase(file);
  762. file = lower.c_str();
  763. #endif
  764. // Collect properties from all matching rules.
  765. bool matched = false;
  766. MatchProperties result;
  767. for(std::vector<MatchRule>::iterator mr = this->MatchRules.begin();
  768. mr != this->MatchRules.end(); ++mr)
  769. {
  770. if(mr->Regex.find(file))
  771. {
  772. matched = true;
  773. result.Exclude |= mr->Properties.Exclude;
  774. result.Permissions |= mr->Properties.Permissions;
  775. }
  776. }
  777. if(!matched && !this->MatchlessFiles && !isDirectory)
  778. {
  779. result.Exclude = true;
  780. }
  781. return result;
  782. }
  783. // Append a file to the installation manifest.
  784. void ManifestAppend(std::string const& file)
  785. {
  786. this->Manifest += ";";
  787. this->Manifest += file.substr(this->DestDirLength);
  788. }
  789. // Translate an argument to a permissions bit.
  790. bool CheckPermissions(std::string const& arg, mode_t& permissions)
  791. {
  792. if(arg == "OWNER_READ") { permissions |= mode_owner_read; }
  793. else if(arg == "OWNER_WRITE") { permissions |= mode_owner_write; }
  794. else if(arg == "OWNER_EXECUTE") { permissions |= mode_owner_execute; }
  795. else if(arg == "GROUP_READ") { permissions |= mode_group_read; }
  796. else if(arg == "GROUP_WRITE") { permissions |= mode_group_write; }
  797. else if(arg == "GROUP_EXECUTE") { permissions |= mode_group_execute; }
  798. else if(arg == "WORLD_READ") { permissions |= mode_world_read; }
  799. else if(arg == "WORLD_WRITE") { permissions |= mode_world_write; }
  800. else if(arg == "WORLD_EXECUTE") { permissions |= mode_world_execute; }
  801. else if(arg == "SETUID") { permissions |= mode_setuid; }
  802. else if(arg == "SETGID") { permissions |= mode_setgid; }
  803. else
  804. {
  805. cmOStringStream e;
  806. e << "INSTALL given invalid permission \"" << arg << "\".";
  807. this->FileCommand->SetError(e.str().c_str());
  808. return false;
  809. }
  810. return true;
  811. }
  812. private:
  813. bool InstallSymlink(const char* fromFile, const char* toFile, bool always);
  814. };
  815. //----------------------------------------------------------------------------
  816. bool cmFileInstaller::InstallSymlink(const char* fromFile, const char* toFile,
  817. bool always)
  818. {
  819. // Read the original symlink.
  820. std::string symlinkTarget;
  821. if(!cmSystemTools::ReadSymlink(fromFile, symlinkTarget))
  822. {
  823. cmOStringStream e;
  824. e << "INSTALL cannot read symlink \"" << fromFile
  825. << "\" to duplicate at \"" << toFile << "\".";
  826. this->FileCommand->SetError(e.str().c_str());
  827. return false;
  828. }
  829. // Compare the symlink value to that at the destination if not
  830. // always installing.
  831. bool copy = true;
  832. if(!always)
  833. {
  834. std::string oldSymlinkTarget;
  835. if(cmSystemTools::ReadSymlink(toFile, oldSymlinkTarget))
  836. {
  837. if(symlinkTarget == oldSymlinkTarget)
  838. {
  839. copy = false;
  840. }
  841. }
  842. }
  843. // Inform the user about this file installation.
  844. std::string message = (copy? "Installing: " : "Up-to-date: ");
  845. message += toFile;
  846. this->Makefile->DisplayStatus(message.c_str(), -1);
  847. if(copy)
  848. {
  849. // Remove the destination file so we can always create the symlink.
  850. cmSystemTools::RemoveFile(toFile);
  851. // Create the symlink.
  852. if(!cmSystemTools::CreateSymlink(symlinkTarget.c_str(), toFile))
  853. {
  854. cmOStringStream e;
  855. e << "INSTALL cannot duplicate symlink \"" << fromFile
  856. << "\" at \"" << toFile << "\".";
  857. this->FileCommand->SetError(e.str().c_str());
  858. return false;
  859. }
  860. }
  861. // Add the file to the manifest.
  862. this->ManifestAppend(toFile);
  863. return true;
  864. }
  865. //----------------------------------------------------------------------------
  866. bool cmFileInstaller::InstallFile(const char* fromFile, const char* toFile,
  867. bool always)
  868. {
  869. // Collect any properties matching this file name.
  870. MatchProperties match_properties =
  871. this->CollectMatchProperties(fromFile, false);
  872. // Skip the file if it is excluded.
  873. if(match_properties.Exclude)
  874. {
  875. return true;
  876. }
  877. // Short-circuit for symbolic links.
  878. if(cmSystemTools::FileIsSymlink(fromFile))
  879. {
  880. return this->InstallSymlink(fromFile, toFile, always);
  881. }
  882. // Determine whether we will copy the file.
  883. bool copy = true;
  884. if(!always)
  885. {
  886. // If both files exist with the same time do not copy.
  887. if(!this->FileTimes.FileTimesDiffer(fromFile, toFile))
  888. {
  889. copy = false;
  890. }
  891. }
  892. // Inform the user about this file installation.
  893. std::string message = (copy? "Installing: " : "Up-to-date: ");
  894. message += toFile;
  895. this->Makefile->DisplayStatus(message.c_str(), -1);
  896. // Copy the file.
  897. if(copy && !cmSystemTools::CopyAFile(fromFile, toFile, true))
  898. {
  899. cmOStringStream e;
  900. e << "INSTALL cannot copy file \"" << fromFile
  901. << "\" to \"" << toFile << "\".";
  902. this->FileCommand->SetError(e.str().c_str());
  903. return false;
  904. }
  905. // Add the file to the manifest.
  906. this->ManifestAppend(toFile);
  907. // Set the file modification time of the destination file.
  908. if(copy && !always)
  909. {
  910. cmSystemTools::CopyFileTime(fromFile, toFile);
  911. }
  912. // Set permissions of the destination file.
  913. mode_t permissions = (match_properties.Permissions?
  914. match_properties.Permissions : this->FilePermissions);
  915. if(!permissions)
  916. {
  917. // No permissions were explicitly provided but the user requested
  918. // that the source file permissions be used.
  919. cmSystemTools::GetPermissions(fromFile, permissions);
  920. }
  921. if(permissions && !cmSystemTools::SetPermissions(toFile, permissions))
  922. {
  923. cmOStringStream e;
  924. e << "Problem setting permissions on file \"" << toFile << "\"";
  925. this->FileCommand->SetError(e.str().c_str());
  926. return false;
  927. }
  928. return true;
  929. }
  930. //----------------------------------------------------------------------------
  931. bool cmFileInstaller::InstallDirectory(const char* source,
  932. const char* destination,
  933. bool always)
  934. {
  935. // Collect any properties matching this directory name.
  936. MatchProperties match_properties =
  937. this->CollectMatchProperties(source, true);
  938. // Skip the directory if it is excluded.
  939. if(match_properties.Exclude)
  940. {
  941. return true;
  942. }
  943. // Short-circuit for symbolic links.
  944. if(cmSystemTools::FileIsSymlink(source))
  945. {
  946. return this->InstallSymlink(source, destination, always);
  947. }
  948. // Inform the user about this directory installation.
  949. std::string message = "Installing: ";
  950. message += destination;
  951. this->Makefile->DisplayStatus(message.c_str(), -1);
  952. // Make sure the destination directory exists.
  953. if(!cmSystemTools::MakeDirectory(destination))
  954. {
  955. return false;
  956. }
  957. // Compute the requested permissions for the destination directory.
  958. mode_t permissions = (match_properties.Permissions?
  959. match_properties.Permissions : this->DirPermissions);
  960. if(!permissions)
  961. {
  962. // No permissions were explicitly provided but the user requested
  963. // that the source directory permissions be used.
  964. cmSystemTools::GetPermissions(source, permissions);
  965. }
  966. // Compute the set of permissions required on this directory to
  967. // recursively install files and subdirectories safely.
  968. mode_t required_permissions =
  969. mode_owner_read | mode_owner_write | mode_owner_execute;
  970. // If the required permissions are specified it is safe to set the
  971. // final permissions now. Otherwise we must add the required
  972. // permissions temporarily during file installation.
  973. mode_t permissions_before = 0;
  974. mode_t permissions_after = 0;
  975. if(permissions & required_permissions)
  976. {
  977. permissions_before = permissions;
  978. }
  979. else
  980. {
  981. permissions_before = permissions | required_permissions;
  982. permissions_after = permissions;
  983. }
  984. // Set the required permissions of the destination directory.
  985. if(permissions_before &&
  986. !cmSystemTools::SetPermissions(destination, permissions_before))
  987. {
  988. cmOStringStream e;
  989. e << "Problem setting permissions on directory \""
  990. << destination << "\"";
  991. this->FileCommand->SetError(e.str().c_str());
  992. return false;
  993. }
  994. // Load the directory contents to traverse it recursively.
  995. cmsys::Directory dir;
  996. if(source && *source)
  997. {
  998. dir.Load(source);
  999. }
  1000. unsigned long numFiles = static_cast<unsigned long>(dir.GetNumberOfFiles());
  1001. for(unsigned long fileNum = 0; fileNum < numFiles; ++fileNum)
  1002. {
  1003. if(!(strcmp(dir.GetFile(fileNum), ".") == 0 ||
  1004. strcmp(dir.GetFile(fileNum), "..") == 0))
  1005. {
  1006. cmsys_stl::string fromPath = source;
  1007. fromPath += "/";
  1008. fromPath += dir.GetFile(fileNum);
  1009. if(cmSystemTools::FileIsDirectory(fromPath.c_str()))
  1010. {
  1011. cmsys_stl::string toDir = destination;
  1012. toDir += "/";
  1013. toDir += dir.GetFile(fileNum);
  1014. if(!this->InstallDirectory(fromPath.c_str(), toDir.c_str(), always))
  1015. {
  1016. return false;
  1017. }
  1018. }
  1019. else
  1020. {
  1021. // Install this file.
  1022. std::string toFile = destination;
  1023. toFile += "/";
  1024. toFile += dir.GetFile(fileNum);
  1025. if(!this->InstallFile(fromPath.c_str(), toFile.c_str(), always))
  1026. {
  1027. return false;
  1028. }
  1029. }
  1030. }
  1031. }
  1032. // Set the requested permissions of the destination directory.
  1033. if(permissions_after &&
  1034. !cmSystemTools::SetPermissions(destination, permissions_after))
  1035. {
  1036. cmOStringStream e;
  1037. e << "Problem setting permissions on directory \"" << destination << "\"";
  1038. this->FileCommand->SetError(e.str().c_str());
  1039. return false;
  1040. }
  1041. return true;
  1042. }
  1043. //----------------------------------------------------------------------------
  1044. void cmFileCommand::HandleInstallPermissions(cmFileInstaller& installer,
  1045. mode_t& permissions_file,
  1046. mode_t& permissions_dir,
  1047. int itype,
  1048. bool use_given_permissions_file,
  1049. bool use_given_permissions_dir,
  1050. bool use_source_permissions) const
  1051. {
  1052. // Choose a default for shared library permissions.
  1053. bool install_so_no_exe = this->Makefile->IsOn("CMAKE_INSTALL_SO_NO_EXE");
  1054. // If file permissions were not specified set default permissions
  1055. // for this target type.
  1056. if(!use_given_permissions_file && !use_source_permissions)
  1057. {
  1058. switch(itype)
  1059. {
  1060. case cmTarget::SHARED_LIBRARY:
  1061. case cmTarget::MODULE_LIBRARY:
  1062. if(install_so_no_exe)
  1063. {
  1064. // Use read/write permissions.
  1065. permissions_file = 0;
  1066. permissions_file |= mode_owner_read;
  1067. permissions_file |= mode_owner_write;
  1068. permissions_file |= mode_group_read;
  1069. permissions_file |= mode_world_read;
  1070. break;
  1071. }
  1072. case cmTarget::EXECUTABLE:
  1073. case cmTarget::INSTALL_PROGRAMS:
  1074. // Use read/write/executable permissions.
  1075. permissions_file = 0;
  1076. permissions_file |= mode_owner_read;
  1077. permissions_file |= mode_owner_write;
  1078. permissions_file |= mode_owner_execute;
  1079. permissions_file |= mode_group_read;
  1080. permissions_file |= mode_group_execute;
  1081. permissions_file |= mode_world_read;
  1082. permissions_file |= mode_world_execute;
  1083. break;
  1084. default:
  1085. // Use read/write permissions.
  1086. permissions_file = 0;
  1087. permissions_file |= mode_owner_read;
  1088. permissions_file |= mode_owner_write;
  1089. permissions_file |= mode_group_read;
  1090. permissions_file |= mode_world_read;
  1091. break;
  1092. }
  1093. }
  1094. // If directory permissions were not specified set default permissions.
  1095. if(!use_given_permissions_dir && !use_source_permissions)
  1096. {
  1097. // Use read/write/executable permissions.
  1098. permissions_dir = 0;
  1099. permissions_dir |= mode_owner_read;
  1100. permissions_dir |= mode_owner_write;
  1101. permissions_dir |= mode_owner_execute;
  1102. permissions_dir |= mode_group_read;
  1103. permissions_dir |= mode_group_execute;
  1104. permissions_dir |= mode_world_read;
  1105. permissions_dir |= mode_world_execute;
  1106. }
  1107. // Set the installer permissions.
  1108. installer.FilePermissions = permissions_file;
  1109. installer.DirPermissions = permissions_dir;
  1110. }
  1111. //----------------------------------------------------------------------------
  1112. void cmFileCommand
  1113. ::GetTargetTypeFromString(const std::string& stype, int& itype) const
  1114. {
  1115. if ( stype == "EXECUTABLE" )
  1116. {
  1117. itype = cmTarget::EXECUTABLE;
  1118. }
  1119. else if ( stype == "PROGRAM" )
  1120. {
  1121. itype = cmTarget::INSTALL_PROGRAMS;
  1122. }
  1123. else if ( stype == "STATIC_LIBRARY" )
  1124. {
  1125. itype = cmTarget::STATIC_LIBRARY;
  1126. }
  1127. else if ( stype == "SHARED_LIBRARY" )
  1128. {
  1129. itype = cmTarget::SHARED_LIBRARY;
  1130. }
  1131. else if ( stype == "MODULE" )
  1132. {
  1133. itype = cmTarget::MODULE_LIBRARY;
  1134. }
  1135. else if ( stype == "DIRECTORY" )
  1136. {
  1137. itype = cmTarget::INSTALL_DIRECTORY;
  1138. }
  1139. }
  1140. //----------------------------------------------------------------------------
  1141. bool cmFileCommand::HandleInstallDestination(cmFileInstaller& installer,
  1142. std::string& destination)
  1143. {
  1144. if ( destination.size() < 2 )
  1145. {
  1146. this->SetError("called with inapropriate arguments. "
  1147. "No DESTINATION provided or .");
  1148. return false;
  1149. }
  1150. const char* destdir = cmSystemTools::GetEnv("DESTDIR");
  1151. if ( destdir && *destdir )
  1152. {
  1153. std::string sdestdir = destdir;
  1154. cmSystemTools::ConvertToUnixSlashes(sdestdir);
  1155. char ch1 = destination[0];
  1156. char ch2 = destination[1];
  1157. char ch3 = 0;
  1158. if ( destination.size() > 2 )
  1159. {
  1160. ch3 = destination[2];
  1161. }
  1162. int skip = 0;
  1163. if ( ch1 != '/' )
  1164. {
  1165. int relative = 0;
  1166. if ( ( ch1 >= 'a' && ch1 <= 'z' || ch1 >= 'A' && ch1 <= 'Z' ) &&
  1167. ch2 == ':' )
  1168. {
  1169. // Assume windows
  1170. // let's do some destdir magic:
  1171. skip = 2;
  1172. if ( ch3 != '/' )
  1173. {
  1174. relative = 1;
  1175. }
  1176. }
  1177. else
  1178. {
  1179. relative = 1;
  1180. }
  1181. if ( relative )
  1182. {
  1183. // This is relative path on unix or windows. Since we are doing
  1184. // destdir, this case does not make sense.
  1185. this->SetError("called with relative DESTINATION. This "
  1186. "does not make sense when using DESTDIR. Specify "
  1187. "absolute path or remove DESTDIR environment variable.");
  1188. return false;
  1189. }
  1190. }
  1191. else
  1192. {
  1193. if ( ch2 == '/' )
  1194. {
  1195. // looks like a network path.
  1196. std::string message = "called with network path DESTINATION. This "
  1197. "does not make sense when using DESTDIR. Specify local "
  1198. "absolute path or remove DESTDIR environment variable."
  1199. "\nDESTINATION=\n";
  1200. message += destination;
  1201. this->SetError(message.c_str());
  1202. return false;
  1203. }
  1204. }
  1205. destination = sdestdir + (destination.c_str() + skip);
  1206. installer.DestDirLength = int(sdestdir.size());
  1207. }
  1208. if ( !cmSystemTools::FileExists(destination.c_str()) )
  1209. {
  1210. if ( !cmSystemTools::MakeDirectory(destination.c_str()) )
  1211. {
  1212. std::string errstring = "cannot create directory: " + destination +
  1213. ". Maybe need administrative privileges.";
  1214. this->SetError(errstring.c_str());
  1215. return false;
  1216. }
  1217. }
  1218. if ( !cmSystemTools::FileIsDirectory(destination.c_str()) )
  1219. {
  1220. std::string errstring = "INSTALL destination: " + destination +
  1221. " is not a directory.";
  1222. this->SetError(errstring.c_str());
  1223. return false;
  1224. }
  1225. return true;
  1226. }
  1227. //----------------------------------------------------------------------------
  1228. bool cmFileCommand::HandleInstallCommand(std::vector<std::string> const& args)
  1229. {
  1230. if ( args.size() < 6 )
  1231. {
  1232. this->SetError("called with incorrect number of arguments");
  1233. return false;
  1234. }
  1235. // Construct a file installer object.
  1236. cmFileInstaller installer(this, this->Makefile);
  1237. std::string rename = "";
  1238. std::string destination = "";
  1239. std::vector<std::string> files;
  1240. int itype = cmTarget::INSTALL_FILES;
  1241. std::map<cmStdString, const char*> properties;
  1242. bool optional = false;
  1243. bool result = this->ParseInstallArgs(args, installer, properties,
  1244. itype, rename, destination, files,
  1245. optional);
  1246. if (result == true)
  1247. {
  1248. result = this->DoInstall(installer,
  1249. itype, rename, destination, files, optional);
  1250. }
  1251. return result;
  1252. }
  1253. //----------------------------------------------------------------------------
  1254. bool cmFileCommand::ParseInstallArgs(std::vector<std::string> const& args,
  1255. cmFileInstaller& installer,
  1256. std::map<cmStdString, const char*>& properties,
  1257. int& itype,
  1258. std::string& rename,
  1259. std::string& destination,
  1260. std::vector<std::string>& files,
  1261. bool& optional)
  1262. {
  1263. std::string stype = "FILES";
  1264. bool doing_files = false;
  1265. bool doing_properties = false;
  1266. bool doing_permissions_file = false;
  1267. bool doing_permissions_dir = false;
  1268. bool doing_permissions_match = false;
  1269. bool use_given_permissions_file = false;
  1270. bool use_given_permissions_dir = false;
  1271. bool use_source_permissions = false;
  1272. mode_t permissions_file = 0;
  1273. mode_t permissions_dir = 0;
  1274. cmFileInstaller::MatchRule* current_match_rule = 0;
  1275. std::vector<std::string>::size_type i = 0;
  1276. i++; // Get rid of subcommand
  1277. for ( ; i != args.size(); ++i )
  1278. {
  1279. const std::string* cstr = &args[i];
  1280. if ( *cstr == "DESTINATION" && i < args.size()-1 )
  1281. {
  1282. if(current_match_rule)
  1283. {
  1284. cmOStringStream e;
  1285. e << "INSTALL does not allow \"" << *cstr << "\" after REGEX.";
  1286. this->SetError(e.str().c_str());
  1287. return false;
  1288. }
  1289. i++;
  1290. destination = args[i];
  1291. doing_files = false;
  1292. doing_properties = false;
  1293. doing_permissions_file = false;
  1294. doing_permissions_dir = false;
  1295. }
  1296. else if ( *cstr == "TYPE" && i < args.size()-1 )
  1297. {
  1298. if(current_match_rule)
  1299. {
  1300. cmOStringStream e;
  1301. e << "INSTALL does not allow \"" << *cstr << "\" after REGEX.";
  1302. this->SetError(e.str().c_str());
  1303. return false;
  1304. }
  1305. i++;
  1306. stype = args[i];
  1307. if ( args[i+1] == "OPTIONAL" )
  1308. {
  1309. i++;
  1310. optional = true;
  1311. }
  1312. doing_properties = false;
  1313. doing_files = false;
  1314. doing_permissions_file = false;
  1315. doing_permissions_dir = false;
  1316. }
  1317. else if ( *cstr == "RENAME" && i < args.size()-1 )
  1318. {
  1319. if(current_match_rule)
  1320. {
  1321. cmOStringStream e;
  1322. e << "INSTALL does not allow \"" << *cstr << "\" after REGEX.";
  1323. this->SetError(e.str().c_str());
  1324. return false;
  1325. }
  1326. i++;
  1327. rename = args[i];
  1328. doing_properties = false;
  1329. doing_files = false;
  1330. doing_permissions_file = false;
  1331. doing_permissions_dir = false;
  1332. }
  1333. else if ( *cstr == "REGEX" && i < args.size()-1 )
  1334. {
  1335. i++;
  1336. installer.MatchRules.push_back(cmFileInstaller::MatchRule(args[i]));
  1337. current_match_rule = &*(installer.MatchRules.end()-1);
  1338. if(!current_match_rule->Regex.is_valid())
  1339. {
  1340. cmOStringStream e;
  1341. e << "INSTALL could not compile REGEX \"" << args[i] << "\".";
  1342. this->SetError(e.str().c_str());
  1343. return false;
  1344. }
  1345. doing_properties = false;
  1346. doing_files = false;
  1347. doing_permissions_file = false;
  1348. doing_permissions_dir = false;
  1349. }
  1350. else if ( *cstr == "EXCLUDE" )
  1351. {
  1352. // Add this property to the current match rule.
  1353. if(!current_match_rule)
  1354. {
  1355. cmOStringStream e;
  1356. e << "INSTALL does not allow \""
  1357. << *cstr << "\" before a REGEX is given.";
  1358. this->SetError(e.str().c_str());
  1359. return false;
  1360. }
  1361. current_match_rule->Properties.Exclude = true;
  1362. doing_permissions_match = true;
  1363. }
  1364. else if ( *cstr == "PROPERTIES" )
  1365. {
  1366. if(current_match_rule)
  1367. {
  1368. cmOStringStream e;
  1369. e << "INSTALL does not allow \"" << *cstr << "\" after REGEX.";
  1370. this->SetError(e.str().c_str());
  1371. return false;
  1372. }
  1373. doing_properties = true;
  1374. doing_files = false;
  1375. doing_permissions_file = false;
  1376. doing_permissions_dir = false;
  1377. }
  1378. else if ( *cstr == "PERMISSIONS" )
  1379. {
  1380. if(current_match_rule)
  1381. {
  1382. doing_permissions_match = true;
  1383. doing_permissions_file = false;
  1384. }
  1385. else
  1386. {
  1387. doing_permissions_match = false;
  1388. doing_permissions_file = true;
  1389. use_given_permissions_file = true;
  1390. }
  1391. doing_properties = false;
  1392. doing_files = false;
  1393. doing_permissions_dir = false;
  1394. }
  1395. else if ( *cstr == "DIR_PERMISSIONS" )
  1396. {
  1397. if(current_match_rule)
  1398. {
  1399. cmOStringStream e;
  1400. e << "INSTALL does not allow \"" << *cstr << "\" after REGEX.";
  1401. this->SetError(e.str().c_str());
  1402. return false;
  1403. }
  1404. use_given_permissions_dir = true;
  1405. doing_properties = false;
  1406. doing_files = false;
  1407. doing_permissions_file = false;
  1408. doing_permissions_dir = true;
  1409. }
  1410. else if ( *cstr == "USE_SOURCE_PERMISSIONS" )
  1411. {
  1412. if(current_match_rule)
  1413. {
  1414. cmOStringStream e;
  1415. e << "INSTALL does not allow \"" << *cstr << "\" after REGEX.";
  1416. this->SetError(e.str().c_str());
  1417. return false;
  1418. }
  1419. doing_properties = false;
  1420. doing_files = false;
  1421. doing_permissions_file = false;
  1422. doing_permissions_dir = false;
  1423. use_source_permissions = true;
  1424. }
  1425. else if ( *cstr == "FILES_MATCHING" )
  1426. {
  1427. if(current_match_rule)
  1428. {
  1429. cmOStringStream e;
  1430. e << "INSTALL does not allow \"" << *cstr << "\" after REGEX.";
  1431. this->SetError(e.str().c_str());
  1432. return false;
  1433. }
  1434. doing_properties = false;
  1435. doing_files = false;
  1436. doing_permissions_file = false;
  1437. doing_permissions_dir = false;
  1438. installer.MatchlessFiles = false;
  1439. }
  1440. else if ( *cstr == "COMPONENTS" )
  1441. {
  1442. cmOStringStream e;
  1443. e << "INSTALL called with old-style COMPONENTS argument. "
  1444. << "This script was generated with an older version of CMake. "
  1445. << "Re-run this cmake version on your build tree.";
  1446. this->SetError(e.str().c_str());
  1447. return false;
  1448. }
  1449. else if ( *cstr == "CONFIGURATIONS" )
  1450. {
  1451. cmOStringStream e;
  1452. e << "INSTALL called with old-style CONFIGURATIONS argument. "
  1453. << "This script was generated with an older version of CMake. "
  1454. << "Re-run this cmake version on your build tree.";
  1455. this->SetError(e.str().c_str());
  1456. return false;
  1457. }
  1458. else if ( *cstr == "FILES" && !doing_files)
  1459. {
  1460. if(current_match_rule)
  1461. {
  1462. cmOStringStream e;
  1463. e << "INSTALL does not allow \"" << *cstr << "\" after REGEX.";
  1464. this->SetError(e.str().c_str());
  1465. return false;
  1466. }
  1467. doing_files = true;
  1468. doing_properties = false;
  1469. doing_permissions_file = false;
  1470. doing_permissions_dir = false;
  1471. }
  1472. else if ( doing_properties && i < args.size()-1 )
  1473. {
  1474. properties[args[i]] = args[i+1].c_str();
  1475. i++;
  1476. }
  1477. else if ( doing_files )
  1478. {
  1479. files.push_back(*cstr);
  1480. }
  1481. else if(doing_permissions_file)
  1482. {
  1483. if(!installer.CheckPermissions(args[i], permissions_file))
  1484. {
  1485. return false;
  1486. }
  1487. }
  1488. else if(doing_permissions_dir)
  1489. {
  1490. if(!installer.CheckPermissions(args[i], permissions_dir))
  1491. {
  1492. return false;
  1493. }
  1494. }
  1495. else if(doing_permissions_match)
  1496. {
  1497. if(!installer.CheckPermissions(
  1498. args[i], current_match_rule->Properties.Permissions))
  1499. {
  1500. return false;
  1501. }
  1502. }
  1503. else
  1504. {
  1505. this->SetError("called with inappropriate arguments");
  1506. return false;
  1507. }
  1508. }
  1509. // now check and postprocess what has been parsed
  1510. if ( files.size() == 0 )
  1511. {
  1512. // nothing to do, no files were listed.
  1513. // if this is handled as error, INSTALL_FILES() creates an invalid
  1514. // cmake_install.cmake script with no FILES() arguments if no files were
  1515. // given to INSTALL_FILES(). This was accepted with CMake 2.4.x.
  1516. return true;
  1517. }
  1518. // Check rename form.
  1519. if(!rename.empty())
  1520. {
  1521. if(itype != cmTarget::INSTALL_FILES &&
  1522. itype != cmTarget::INSTALL_PROGRAMS)
  1523. {
  1524. this->SetError("INSTALL option RENAME may be used only with "
  1525. "FILES or PROGRAMS.");
  1526. return false;
  1527. }
  1528. if(files.size() > 1)
  1529. {
  1530. this->SetError("INSTALL option RENAME may be used only with "
  1531. "one file.");
  1532. return false;
  1533. }
  1534. }
  1535. if (this->HandleInstallDestination(installer, destination) == false)
  1536. {
  1537. return false;
  1538. }
  1539. if(properties.find("VERSION") != properties.end())
  1540. {
  1541. cmOStringStream e;
  1542. e << "INSTALL called with old-style VERSION property. "
  1543. << "This script was generated with an older version of CMake. "
  1544. << "Re-run this cmake version on your build tree.";
  1545. this->SetError(e.str().c_str());
  1546. return false;
  1547. }
  1548. if(properties.find("SOVERSION") != properties.end())
  1549. {
  1550. cmOStringStream e;
  1551. e << "INSTALL called with old-style SOVERSION property. "
  1552. << "This script was generated with an older version of CMake. "
  1553. << "Re-run this cmake version on your build tree.";
  1554. this->SetError(e.str().c_str());
  1555. return false;
  1556. }
  1557. this->GetTargetTypeFromString(stype, itype);
  1558. this->HandleInstallPermissions(installer,
  1559. permissions_file,
  1560. permissions_dir,
  1561. itype,
  1562. use_given_permissions_file,
  1563. use_given_permissions_dir,
  1564. use_source_permissions);
  1565. return true;
  1566. }
  1567. //----------------------------------------------------------------------------
  1568. bool cmFileCommand::DoInstall( cmFileInstaller& installer,
  1569. const int itype,
  1570. const std::string& rename,
  1571. const std::string& destination,
  1572. const std::vector<std::string>& files,
  1573. const bool optional)
  1574. {
  1575. typedef std::set<cmStdString>::const_iterator iter_type;
  1576. // Check whether files should be copied always or only if they have
  1577. // changed.
  1578. bool copy_always =
  1579. cmSystemTools::IsOn(cmSystemTools::GetEnv("CMAKE_INSTALL_ALWAYS"));
  1580. // Handle each file listed.
  1581. for (std::vector<std::string>::size_type i = 0; i < files.size(); i ++ )
  1582. {
  1583. // Split the input file into its directory and name components.
  1584. std::vector<std::string> fromPathComponents;
  1585. cmSystemTools::SplitPath(files[i].c_str(), fromPathComponents);
  1586. std::string fromName = *(fromPathComponents.end()-1);
  1587. std::string fromDir = cmSystemTools::JoinPath(fromPathComponents.begin(),
  1588. fromPathComponents.end()-1);
  1589. // Compute the full path to the destination file.
  1590. std::string toFile = destination;
  1591. std::string const& toName = rename.empty()? fromName : rename;
  1592. if(!toName.empty())
  1593. {
  1594. toFile += "/";
  1595. toFile += toName;
  1596. }
  1597. // Construct the full path to the source file. The file name may
  1598. // have been changed above.
  1599. std::string fromFile = fromDir;
  1600. if(!fromName.empty())
  1601. {
  1602. fromFile += "/";
  1603. fromFile += fromName;
  1604. }
  1605. std::string message;
  1606. if(!cmSystemTools::SameFile(fromFile.c_str(), toFile.c_str()))
  1607. {
  1608. if(itype == cmTarget::INSTALL_DIRECTORY &&
  1609. (fromFile.empty() ||
  1610. cmSystemTools::FileIsDirectory(fromFile.c_str())))
  1611. {
  1612. // Try installing this directory.
  1613. if(!installer.InstallDirectory(fromFile.c_str(), toFile.c_str(),
  1614. copy_always))
  1615. {
  1616. return false;
  1617. }
  1618. }
  1619. else if(cmSystemTools::FileExists(fromFile.c_str()))
  1620. {
  1621. // Install this file.
  1622. if(!installer.InstallFile(fromFile.c_str(), toFile.c_str(),
  1623. copy_always))
  1624. {
  1625. return false;
  1626. }
  1627. }
  1628. else if(!optional)
  1629. {
  1630. // The input file does not exist and installation is not optional.
  1631. cmOStringStream e;
  1632. e << "INSTALL cannot find file \"" << fromFile << "\" to install.";
  1633. this->SetError(e.str().c_str());
  1634. return false;
  1635. }
  1636. }
  1637. }
  1638. return true;
  1639. }
  1640. //----------------------------------------------------------------------------
  1641. bool cmFileCommand::HandleRelativePathCommand(
  1642. std::vector<std::string> const& args)
  1643. {
  1644. if(args.size() != 4 )
  1645. {
  1646. this->SetError("called with incorrect number of arguments");
  1647. return false;
  1648. }
  1649. const std::string& outVar = args[1];
  1650. const std::string& directoryName = args[2];
  1651. const std::string& fileName = args[3];
  1652. if(!cmSystemTools::FileIsFullPath(directoryName.c_str()))
  1653. {
  1654. std::string errstring =
  1655. "RelativePath must be passed a full path to the directory: "
  1656. + directoryName;
  1657. this->SetError(errstring.c_str());
  1658. return false;
  1659. }
  1660. if(!cmSystemTools::FileIsFullPath(fileName.c_str()))
  1661. {
  1662. std::string errstring =
  1663. "RelativePath must be passed a full path to the file: "
  1664. + fileName;
  1665. this->SetError(errstring.c_str());
  1666. return false;
  1667. }
  1668. std::string res = cmSystemTools::RelativePath(directoryName.c_str(),
  1669. fileName.c_str());
  1670. this->Makefile->AddDefinition(outVar.c_str(),
  1671. res.c_str());
  1672. return true;
  1673. }
  1674. //----------------------------------------------------------------------------
  1675. bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
  1676. bool recurse)
  1677. {
  1678. std::string message;
  1679. std::vector<std::string>::const_iterator i = args.begin();
  1680. i++; // Get rid of subcommand
  1681. for(;i != args.end(); ++i)
  1682. {
  1683. if(cmSystemTools::FileIsDirectory(i->c_str()) && recurse)
  1684. {
  1685. cmSystemTools::RemoveADirectory(i->c_str());
  1686. }
  1687. else
  1688. {
  1689. cmSystemTools::RemoveFile(i->c_str());
  1690. }
  1691. }
  1692. return true;
  1693. }
  1694. //----------------------------------------------------------------------------
  1695. bool cmFileCommand::HandleCMakePathCommand(std::vector<std::string>
  1696. const& args,
  1697. bool nativePath)
  1698. {
  1699. std::vector<std::string>::const_iterator i = args.begin();
  1700. if(args.size() != 3)
  1701. {
  1702. this->SetError("FILE(SYSTEM_PATH ENV result) must be called with "
  1703. "only three arguments.");
  1704. return false;
  1705. }
  1706. i++; // Get rid of subcommand
  1707. #if defined(_WIN32) && !defined(__CYGWIN__)
  1708. char pathSep = ';';
  1709. #else
  1710. char pathSep = ':';
  1711. #endif
  1712. std::vector<cmsys::String> path = cmSystemTools::SplitString(i->c_str(),
  1713. pathSep);
  1714. i++;
  1715. const char* var = i->c_str();
  1716. std::string value;
  1717. for(std::vector<cmsys::String>::iterator j = path.begin();
  1718. j != path.end(); ++j)
  1719. {
  1720. if(j != path.begin())
  1721. {
  1722. value += ";";
  1723. }
  1724. if(!nativePath)
  1725. {
  1726. cmSystemTools::ConvertToUnixSlashes(*j);
  1727. }
  1728. else
  1729. {
  1730. *j = cmSystemTools::ConvertToOutputPath(j->c_str());
  1731. // remove double quotes in the path
  1732. cmsys::String& s = *j;
  1733. if(s.size() > 1 && s[0] == '\"' && s[s.size()-1] == '\"')
  1734. {
  1735. s = s.substr(1,s.size()-2);
  1736. }
  1737. }
  1738. value += *j;
  1739. }
  1740. this->Makefile->AddDefinition(var, value.c_str());
  1741. return true;
  1742. }
  1743. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1744. // Stuff for curl download
  1745. typedef std::vector<char> cmFileCommandVectorOfChar;
  1746. namespace{
  1747. size_t
  1748. cmFileCommandWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
  1749. void *data)
  1750. {
  1751. register int realsize = (int)(size * nmemb);
  1752. std::ofstream* fout = static_cast<std::ofstream*>(data);
  1753. const char* chPtr = static_cast<char*>(ptr);
  1754. fout->write(chPtr, realsize);
  1755. return realsize;
  1756. }
  1757. static size_t
  1758. cmFileCommandCurlDebugCallback(CURL *, curl_infotype, char *chPtr,
  1759. size_t size, void *data)
  1760. {
  1761. cmFileCommandVectorOfChar *vec
  1762. = static_cast<cmFileCommandVectorOfChar*>(data);
  1763. vec->insert(vec->end(), chPtr, chPtr + size);
  1764. return size;
  1765. }
  1766. }
  1767. #endif
  1768. bool
  1769. cmFileCommand::HandleDownloadCommand(std::vector<std::string>
  1770. const& args)
  1771. {
  1772. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1773. std::vector<std::string>::const_iterator i = args.begin();
  1774. if(args.size() < 3)
  1775. {
  1776. this->SetError("FILE(DOWNLOAD url file) must be called with "
  1777. "at least three arguments.");
  1778. return false;
  1779. }
  1780. i++; // Get rid of subcommand
  1781. std::string url = *i;
  1782. i++;
  1783. std::string file = *i;
  1784. i++;
  1785. double timeout = 0;
  1786. std::string verboseLog;
  1787. std::string statusVar;
  1788. while(i != args.end())
  1789. {
  1790. if(*i == "TIMEOUT")
  1791. {
  1792. i++;
  1793. if(i != args.end())
  1794. {
  1795. timeout = atof(i->c_str());
  1796. }
  1797. else
  1798. {
  1799. this->SetError("FILE(DOWNLOAD url file TIMEOUT time) missing "
  1800. "time for TIMEOUT.");
  1801. return false;
  1802. }
  1803. }
  1804. else if(*i == "LOG")
  1805. {
  1806. i++;
  1807. if( i == args.end())
  1808. {
  1809. this->SetError("FILE(DOWNLOAD url file LOG VAR) missing "
  1810. "VAR for LOG.");
  1811. return false;
  1812. }
  1813. verboseLog = *i;
  1814. }
  1815. else if(*i == "STATUS")
  1816. {
  1817. i++;
  1818. if( i == args.end())
  1819. {
  1820. this->SetError("FILE(DOWNLOAD url file STATUS VAR) missing "
  1821. "VAR for STATUS.");
  1822. return false;
  1823. }
  1824. statusVar = *i;
  1825. }
  1826. i++;
  1827. }
  1828. std::ofstream fout(file.c_str(), std::ios::binary);
  1829. if(!fout)
  1830. {
  1831. this->SetError("FILE(DOWNLOAD url file TIMEOUT time) can not open "
  1832. "file for write.");
  1833. return false;
  1834. }
  1835. CURL *curl;
  1836. curl_global_init(CURL_GLOBAL_DEFAULT);
  1837. curl = curl_easy_init();
  1838. if(!curl)
  1839. {
  1840. this->SetError("FILE(DOWNLOAD ) error "
  1841. "initializing curl.");
  1842. return false;
  1843. }
  1844. curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  1845. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  1846. cmFileCommandWriteMemoryCallback);
  1847. curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  1848. cmFileCommandCurlDebugCallback);
  1849. cmFileCommandVectorOfChar chunkDebug;
  1850. ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&fout);
  1851. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
  1852. if(verboseLog.size())
  1853. {
  1854. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  1855. }
  1856. if(timeout > 0)
  1857. {
  1858. curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout );
  1859. }
  1860. CURLcode res = curl_easy_perform(curl);
  1861. /* always cleanup */
  1862. curl_easy_cleanup(curl);
  1863. if(statusVar.size())
  1864. {
  1865. cmOStringStream result;
  1866. result << (int)res << ";\"" << curl_easy_strerror(res) << "\"";
  1867. this->Makefile->AddDefinition(statusVar.c_str(),
  1868. result.str().c_str());
  1869. }
  1870. curl_global_cleanup();
  1871. if(chunkDebug.size())
  1872. {
  1873. chunkDebug.push_back(0);
  1874. if(CURLE_OPERATION_TIMEOUTED == res)
  1875. {
  1876. std::string output = &*chunkDebug.begin();
  1877. if(verboseLog.size())
  1878. {
  1879. this->Makefile->AddDefinition(verboseLog.c_str(),
  1880. &*chunkDebug.begin());
  1881. }
  1882. }
  1883. this->Makefile->AddDefinition(verboseLog.c_str(),
  1884. &*chunkDebug.begin());
  1885. }
  1886. return true;
  1887. #else
  1888. this->SetError("FILE(DOWNLOAD ) "
  1889. "not supported in bootstrap cmake ");
  1890. return false;
  1891. #endif
  1892. }