cmFileCommand.cxx 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382
  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 "cmFileCommand.h"
  11. #include "cmCryptoHash.h"
  12. #include "cmake.h"
  13. #include "cmHexFileConverter.h"
  14. #include "cmInstallType.h"
  15. #include "cmFileTimeComparison.h"
  16. #include "cmCryptoHash.h"
  17. #include "cmTimestamp.h"
  18. #if defined(CMAKE_BUILD_WITH_CMAKE)
  19. #include "cm_curl.h"
  20. #endif
  21. #undef GetCurrentDirectory
  22. #include <assert.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <cmsys/auto_ptr.hxx>
  26. #include <cmsys/Directory.hxx>
  27. #include <cmsys/Glob.hxx>
  28. #include <cmsys/RegularExpression.hxx>
  29. #include <cmsys/FStream.hxx>
  30. // Table of permissions flags.
  31. #if defined(_WIN32) && !defined(__CYGWIN__)
  32. static mode_t mode_owner_read = S_IREAD;
  33. static mode_t mode_owner_write = S_IWRITE;
  34. static mode_t mode_owner_execute = S_IEXEC;
  35. static mode_t mode_group_read = 0;
  36. static mode_t mode_group_write = 0;
  37. static mode_t mode_group_execute = 0;
  38. static mode_t mode_world_read = 0;
  39. static mode_t mode_world_write = 0;
  40. static mode_t mode_world_execute = 0;
  41. static mode_t mode_setuid = 0;
  42. static mode_t mode_setgid = 0;
  43. #else
  44. static mode_t mode_owner_read = S_IRUSR;
  45. static mode_t mode_owner_write = S_IWUSR;
  46. static mode_t mode_owner_execute = S_IXUSR;
  47. static mode_t mode_group_read = S_IRGRP;
  48. static mode_t mode_group_write = S_IWGRP;
  49. static mode_t mode_group_execute = S_IXGRP;
  50. static mode_t mode_world_read = S_IROTH;
  51. static mode_t mode_world_write = S_IWOTH;
  52. static mode_t mode_world_execute = S_IXOTH;
  53. static mode_t mode_setuid = S_ISUID;
  54. static mode_t mode_setgid = S_ISGID;
  55. #endif
  56. // cmLibraryCommand
  57. bool cmFileCommand
  58. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  59. {
  60. if(args.size() < 2 )
  61. {
  62. this->SetError("must be called with at least two arguments.");
  63. return false;
  64. }
  65. std::string subCommand = args[0];
  66. if ( subCommand == "WRITE" )
  67. {
  68. return this->HandleWriteCommand(args, false);
  69. }
  70. else if ( subCommand == "APPEND" )
  71. {
  72. return this->HandleWriteCommand(args, true);
  73. }
  74. else if ( subCommand == "DOWNLOAD" )
  75. {
  76. return this->HandleDownloadCommand(args);
  77. }
  78. else if ( subCommand == "UPLOAD" )
  79. {
  80. return this->HandleUploadCommand(args);
  81. }
  82. else if ( subCommand == "READ" )
  83. {
  84. return this->HandleReadCommand(args);
  85. }
  86. else if ( subCommand == "MD5" ||
  87. subCommand == "SHA1" ||
  88. subCommand == "SHA224" ||
  89. subCommand == "SHA256" ||
  90. subCommand == "SHA384" ||
  91. subCommand == "SHA512" )
  92. {
  93. return this->HandleHashCommand(args);
  94. }
  95. else if ( subCommand == "STRINGS" )
  96. {
  97. return this->HandleStringsCommand(args);
  98. }
  99. else if ( subCommand == "GLOB" )
  100. {
  101. return this->HandleGlobCommand(args, false);
  102. }
  103. else if ( subCommand == "GLOB_RECURSE" )
  104. {
  105. return this->HandleGlobCommand(args, true);
  106. }
  107. else if ( subCommand == "MAKE_DIRECTORY" )
  108. {
  109. return this->HandleMakeDirectoryCommand(args);
  110. }
  111. else if ( subCommand == "RENAME" )
  112. {
  113. return this->HandleRename(args);
  114. }
  115. else if ( subCommand == "REMOVE" )
  116. {
  117. return this->HandleRemove(args, false);
  118. }
  119. else if ( subCommand == "REMOVE_RECURSE" )
  120. {
  121. return this->HandleRemove(args, true);
  122. }
  123. else if ( subCommand == "COPY" )
  124. {
  125. return this->HandleCopyCommand(args);
  126. }
  127. else if ( subCommand == "INSTALL" )
  128. {
  129. return this->HandleInstallCommand(args);
  130. }
  131. else if ( subCommand == "DIFFERENT" )
  132. {
  133. return this->HandleDifferentCommand(args);
  134. }
  135. else if ( subCommand == "RPATH_CHANGE" || subCommand == "CHRPATH" )
  136. {
  137. return this->HandleRPathChangeCommand(args);
  138. }
  139. else if ( subCommand == "RPATH_CHECK" )
  140. {
  141. return this->HandleRPathCheckCommand(args);
  142. }
  143. else if ( subCommand == "RPATH_REMOVE" )
  144. {
  145. return this->HandleRPathRemoveCommand(args);
  146. }
  147. else if ( subCommand == "RELATIVE_PATH" )
  148. {
  149. return this->HandleRelativePathCommand(args);
  150. }
  151. else if ( subCommand == "TO_CMAKE_PATH" )
  152. {
  153. return this->HandleCMakePathCommand(args, false);
  154. }
  155. else if ( subCommand == "TO_NATIVE_PATH" )
  156. {
  157. return this->HandleCMakePathCommand(args, true);
  158. }
  159. else if ( subCommand == "TIMESTAMP" )
  160. {
  161. return this->HandleTimestampCommand(args);
  162. }
  163. else if ( subCommand == "GENERATE" )
  164. {
  165. return this->HandleGenerateCommand(args);
  166. }
  167. std::string e = "does not recognize sub-command "+subCommand;
  168. this->SetError(e);
  169. return false;
  170. }
  171. //----------------------------------------------------------------------------
  172. bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
  173. bool append)
  174. {
  175. std::string message;
  176. std::vector<std::string>::const_iterator i = args.begin();
  177. i++; // Get rid of subcommand
  178. std::string fileName = *i;
  179. if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
  180. {
  181. fileName = this->Makefile->GetCurrentDirectory();
  182. fileName += "/" + *i;
  183. }
  184. i++;
  185. for(;i != args.end(); ++i)
  186. {
  187. message += *i;
  188. }
  189. if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) )
  190. {
  191. std::string e
  192. = "attempted to write a file: " + fileName +
  193. " into a source directory.";
  194. this->SetError(e);
  195. cmSystemTools::SetFatalErrorOccured();
  196. return false;
  197. }
  198. std::string dir = cmSystemTools::GetFilenamePath(fileName);
  199. cmSystemTools::MakeDirectory(dir.c_str());
  200. mode_t mode = 0;
  201. // Set permissions to writable
  202. if ( cmSystemTools::GetPermissions(fileName.c_str(), mode) )
  203. {
  204. cmSystemTools::SetPermissions(fileName.c_str(),
  205. #if defined( _MSC_VER ) || defined( __MINGW32__ )
  206. mode | S_IWRITE
  207. #elif defined( __BORLANDC__ )
  208. mode | S_IWUSR
  209. #else
  210. mode | S_IWUSR | S_IWGRP
  211. #endif
  212. );
  213. }
  214. // If GetPermissions fails, pretend like it is ok. File open will fail if
  215. // the file is not writable
  216. cmsys::ofstream file(fileName.c_str(), append?std::ios::app: std::ios::out);
  217. if ( !file )
  218. {
  219. std::string error = "Internal CMake error when trying to open file: ";
  220. error += fileName.c_str();
  221. error += " for writing.";
  222. this->SetError(error);
  223. return false;
  224. }
  225. file << message;
  226. file.close();
  227. if(mode)
  228. {
  229. cmSystemTools::SetPermissions(fileName.c_str(), mode);
  230. }
  231. return true;
  232. }
  233. //----------------------------------------------------------------------------
  234. bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
  235. {
  236. if ( args.size() < 3 )
  237. {
  238. this->SetError("READ must be called with at least two additional "
  239. "arguments");
  240. return false;
  241. }
  242. cmCommandArgumentsHelper argHelper;
  243. cmCommandArgumentGroup group;
  244. cmCAString readArg (&argHelper, "READ");
  245. cmCAString fileNameArg (&argHelper, 0);
  246. cmCAString resultArg (&argHelper, 0);
  247. cmCAString offsetArg (&argHelper, "OFFSET", &group);
  248. cmCAString limitArg (&argHelper, "LIMIT", &group);
  249. cmCAEnabler hexOutputArg (&argHelper, "HEX", &group);
  250. readArg.Follows(0);
  251. fileNameArg.Follows(&readArg);
  252. resultArg.Follows(&fileNameArg);
  253. group.Follows(&resultArg);
  254. argHelper.Parse(&args, 0);
  255. std::string fileName = fileNameArg.GetString();
  256. if ( !cmsys::SystemTools::FileIsFullPath(fileName.c_str()) )
  257. {
  258. fileName = this->Makefile->GetCurrentDirectory();
  259. fileName += "/" + fileNameArg.GetString();
  260. }
  261. std::string variable = resultArg.GetString();
  262. // Open the specified file.
  263. #if defined(_WIN32) || defined(__CYGWIN__)
  264. cmsys::ifstream file(fileName.c_str(), std::ios::in |
  265. (hexOutputArg.IsEnabled() ? std::ios::binary : std::ios::in));
  266. #else
  267. cmsys::ifstream file(fileName.c_str(), std::ios::in);
  268. #endif
  269. if ( !file )
  270. {
  271. std::string error = "Internal CMake error when trying to open file: ";
  272. error += fileName.c_str();
  273. error += " for reading.";
  274. this->SetError(error);
  275. return false;
  276. }
  277. // is there a limit?
  278. long sizeLimit = -1;
  279. if (limitArg.GetString().size() > 0)
  280. {
  281. sizeLimit = atoi(limitArg.GetCString());
  282. }
  283. // is there an offset?
  284. long offset = 0;
  285. if (offsetArg.GetString().size() > 0)
  286. {
  287. offset = atoi(offsetArg.GetCString());
  288. }
  289. file.seekg(offset, std::ios::beg); // explicit ios::beg for IBM VisualAge 6
  290. std::string output;
  291. if (hexOutputArg.IsEnabled())
  292. {
  293. // Convert part of the file into hex code
  294. char c;
  295. while((sizeLimit != 0) && (file.get(c)))
  296. {
  297. char hex[4];
  298. sprintf(hex, "%.2x", c&0xff);
  299. output += hex;
  300. if (sizeLimit > 0)
  301. {
  302. sizeLimit--;
  303. }
  304. }
  305. }
  306. else
  307. {
  308. std::string line;
  309. bool has_newline = false;
  310. while (sizeLimit != 0 &&
  311. cmSystemTools::GetLineFromStream(file, line, &has_newline,
  312. sizeLimit) )
  313. {
  314. if (sizeLimit > 0)
  315. {
  316. sizeLimit = sizeLimit - static_cast<long>(line.size());
  317. if (has_newline)
  318. {
  319. sizeLimit--;
  320. }
  321. if (sizeLimit < 0)
  322. {
  323. sizeLimit = 0;
  324. }
  325. }
  326. output += line;
  327. if ( has_newline )
  328. {
  329. output += "\n";
  330. }
  331. }
  332. }
  333. this->Makefile->AddDefinition(variable, output.c_str());
  334. return true;
  335. }
  336. //----------------------------------------------------------------------------
  337. bool cmFileCommand::HandleHashCommand(std::vector<std::string> const& args)
  338. {
  339. #if defined(CMAKE_BUILD_WITH_CMAKE)
  340. if(args.size() != 3)
  341. {
  342. cmOStringStream e;
  343. e << args[0] << " requires a file name and output variable";
  344. this->SetError(e.str());
  345. return false;
  346. }
  347. cmsys::auto_ptr<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str()));
  348. if(hash.get())
  349. {
  350. std::string out = hash->HashFile(args[1]);
  351. if(!out.empty())
  352. {
  353. this->Makefile->AddDefinition(args[2], out.c_str());
  354. return true;
  355. }
  356. cmOStringStream e;
  357. e << args[0] << " failed to read file \"" << args[1] << "\": "
  358. << cmSystemTools::GetLastSystemError();
  359. this->SetError(e.str());
  360. }
  361. return false;
  362. #else
  363. cmOStringStream e;
  364. e << args[0] << " not available during bootstrap";
  365. this->SetError(e.str().c_str());
  366. return false;
  367. #endif
  368. }
  369. //----------------------------------------------------------------------------
  370. bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
  371. {
  372. if(args.size() < 3)
  373. {
  374. this->SetError("STRINGS requires a file name and output variable");
  375. return false;
  376. }
  377. // Get the file to read.
  378. std::string fileName = args[1];
  379. if(!cmsys::SystemTools::FileIsFullPath(fileName.c_str()))
  380. {
  381. fileName = this->Makefile->GetCurrentDirectory();
  382. fileName += "/" + args[1];
  383. }
  384. // Get the variable in which to store the results.
  385. std::string outVar = args[2];
  386. // Parse the options.
  387. enum { arg_none,
  388. arg_limit_input,
  389. arg_limit_output,
  390. arg_limit_count,
  391. arg_length_minimum,
  392. arg_length_maximum,
  393. arg__maximum,
  394. arg_regex };
  395. unsigned int minlen = 0;
  396. unsigned int maxlen = 0;
  397. int limit_input = -1;
  398. int limit_output = -1;
  399. unsigned int limit_count = 0;
  400. cmsys::RegularExpression regex;
  401. bool have_regex = false;
  402. bool newline_consume = false;
  403. bool hex_conversion_enabled = true;
  404. int arg_mode = arg_none;
  405. for(unsigned int i=3; i < args.size(); ++i)
  406. {
  407. if(args[i] == "LIMIT_INPUT")
  408. {
  409. arg_mode = arg_limit_input;
  410. }
  411. else if(args[i] == "LIMIT_OUTPUT")
  412. {
  413. arg_mode = arg_limit_output;
  414. }
  415. else if(args[i] == "LIMIT_COUNT")
  416. {
  417. arg_mode = arg_limit_count;
  418. }
  419. else if(args[i] == "LENGTH_MINIMUM")
  420. {
  421. arg_mode = arg_length_minimum;
  422. }
  423. else if(args[i] == "LENGTH_MAXIMUM")
  424. {
  425. arg_mode = arg_length_maximum;
  426. }
  427. else if(args[i] == "REGEX")
  428. {
  429. arg_mode = arg_regex;
  430. }
  431. else if(args[i] == "NEWLINE_CONSUME")
  432. {
  433. newline_consume = true;
  434. arg_mode = arg_none;
  435. }
  436. else if(args[i] == "NO_HEX_CONVERSION")
  437. {
  438. hex_conversion_enabled = false;
  439. arg_mode = arg_none;
  440. }
  441. else if(arg_mode == arg_limit_input)
  442. {
  443. if(sscanf(args[i].c_str(), "%d", &limit_input) != 1 ||
  444. limit_input < 0)
  445. {
  446. cmOStringStream e;
  447. e << "STRINGS option LIMIT_INPUT value \""
  448. << args[i] << "\" is not an unsigned integer.";
  449. this->SetError(e.str());
  450. return false;
  451. }
  452. arg_mode = arg_none;
  453. }
  454. else if(arg_mode == arg_limit_output)
  455. {
  456. if(sscanf(args[i].c_str(), "%d", &limit_output) != 1 ||
  457. limit_output < 0)
  458. {
  459. cmOStringStream e;
  460. e << "STRINGS option LIMIT_OUTPUT value \""
  461. << args[i] << "\" is not an unsigned integer.";
  462. this->SetError(e.str());
  463. return false;
  464. }
  465. arg_mode = arg_none;
  466. }
  467. else if(arg_mode == arg_limit_count)
  468. {
  469. int count;
  470. if(sscanf(args[i].c_str(), "%d", &count) != 1 || count < 0)
  471. {
  472. cmOStringStream e;
  473. e << "STRINGS option LIMIT_COUNT value \""
  474. << args[i] << "\" is not an unsigned integer.";
  475. this->SetError(e.str());
  476. return false;
  477. }
  478. limit_count = count;
  479. arg_mode = arg_none;
  480. }
  481. else if(arg_mode == arg_length_minimum)
  482. {
  483. int len;
  484. if(sscanf(args[i].c_str(), "%d", &len) != 1 || len < 0)
  485. {
  486. cmOStringStream e;
  487. e << "STRINGS option LENGTH_MINIMUM value \""
  488. << args[i] << "\" is not an unsigned integer.";
  489. this->SetError(e.str());
  490. return false;
  491. }
  492. minlen = len;
  493. arg_mode = arg_none;
  494. }
  495. else if(arg_mode == arg_length_maximum)
  496. {
  497. int len;
  498. if(sscanf(args[i].c_str(), "%d", &len) != 1 || len < 0)
  499. {
  500. cmOStringStream e;
  501. e << "STRINGS option LENGTH_MAXIMUM value \""
  502. << args[i] << "\" is not an unsigned integer.";
  503. this->SetError(e.str());
  504. return false;
  505. }
  506. maxlen = len;
  507. arg_mode = arg_none;
  508. }
  509. else if(arg_mode == arg_regex)
  510. {
  511. if(!regex.compile(args[i].c_str()))
  512. {
  513. cmOStringStream e;
  514. e << "STRINGS option REGEX value \""
  515. << args[i] << "\" could not be compiled.";
  516. this->SetError(e.str());
  517. return false;
  518. }
  519. have_regex = true;
  520. arg_mode = arg_none;
  521. }
  522. else
  523. {
  524. cmOStringStream e;
  525. e << "STRINGS given unknown argument \""
  526. << args[i] << "\"";
  527. this->SetError(e.str());
  528. return false;
  529. }
  530. }
  531. if (hex_conversion_enabled)
  532. {
  533. // TODO: should work without temp file, but just on a memory buffer
  534. std::string binaryFileName = this->Makefile->GetCurrentOutputDirectory();
  535. binaryFileName += cmake::GetCMakeFilesDirectory();
  536. binaryFileName += "/FileCommandStringsBinaryFile";
  537. if(cmHexFileConverter::TryConvert(fileName.c_str(),binaryFileName.c_str()))
  538. {
  539. fileName = binaryFileName;
  540. }
  541. }
  542. // Open the specified file.
  543. #if defined(_WIN32) || defined(__CYGWIN__)
  544. cmsys::ifstream fin(fileName.c_str(), std::ios::in | std::ios::binary);
  545. #else
  546. cmsys::ifstream fin(fileName.c_str(), std::ios::in);
  547. #endif
  548. if(!fin)
  549. {
  550. cmOStringStream e;
  551. e << "STRINGS file \"" << fileName << "\" cannot be read.";
  552. this->SetError(e.str());
  553. return false;
  554. }
  555. // Parse strings out of the file.
  556. int output_size = 0;
  557. std::vector<std::string> strings;
  558. std::string s;
  559. int c;
  560. while((!limit_count || strings.size() < limit_count) &&
  561. (limit_input < 0 || static_cast<int>(fin.tellg()) < limit_input) &&
  562. (c = fin.get(), fin))
  563. {
  564. if(c == '\n' && !newline_consume)
  565. {
  566. // The current line has been terminated. Check if the current
  567. // string matches the requirements. The length may now be as
  568. // low as zero since blank lines are allowed.
  569. if(s.length() >= minlen &&
  570. (!have_regex || regex.find(s.c_str())))
  571. {
  572. output_size += static_cast<int>(s.size()) + 1;
  573. if(limit_output >= 0 && output_size >= limit_output)
  574. {
  575. s = "";
  576. break;
  577. }
  578. strings.push_back(s);
  579. }
  580. // Reset the string to empty.
  581. s = "";
  582. }
  583. else if(c == '\r')
  584. {
  585. // Ignore CR character to make output always have UNIX newlines.
  586. }
  587. else if((c >= 0x20 && c < 0x7F) || c == '\t' ||
  588. (c == '\n' && newline_consume))
  589. {
  590. // This is an ASCII character that may be part of a string.
  591. // Cast added to avoid compiler warning. Cast is ok because
  592. // c is guaranteed to fit in char by the above if...
  593. s += static_cast<char>(c);
  594. }
  595. else
  596. {
  597. // TODO: Support ENCODING option. See issue #10519.
  598. // A non-string character has been found. Check if the current
  599. // string matches the requirements. We require that the length
  600. // be at least one no matter what the user specified.
  601. if(s.length() >= minlen && s.length() >= 1 &&
  602. (!have_regex || regex.find(s.c_str())))
  603. {
  604. output_size += static_cast<int>(s.size()) + 1;
  605. if(limit_output >= 0 && output_size >= limit_output)
  606. {
  607. s = "";
  608. break;
  609. }
  610. strings.push_back(s);
  611. }
  612. // Reset the string to empty.
  613. s = "";
  614. }
  615. // Terminate a string if the maximum length is reached.
  616. if(maxlen > 0 && s.size() == maxlen)
  617. {
  618. if(s.length() >= minlen &&
  619. (!have_regex || regex.find(s.c_str())))
  620. {
  621. output_size += static_cast<int>(s.size()) + 1;
  622. if(limit_output >= 0 && output_size >= limit_output)
  623. {
  624. s = "";
  625. break;
  626. }
  627. strings.push_back(s);
  628. }
  629. s = "";
  630. }
  631. }
  632. // If there is a non-empty current string we have hit the end of the
  633. // input file or the input size limit. Check if the current string
  634. // matches the requirements.
  635. if((!limit_count || strings.size() < limit_count) &&
  636. !s.empty() && s.length() >= minlen &&
  637. (!have_regex || regex.find(s.c_str())))
  638. {
  639. output_size += static_cast<int>(s.size()) + 1;
  640. if(limit_output < 0 || output_size < limit_output)
  641. {
  642. strings.push_back(s);
  643. }
  644. }
  645. // Encode the result in a CMake list.
  646. const char* sep = "";
  647. std::string output;
  648. for(std::vector<std::string>::const_iterator si = strings.begin();
  649. si != strings.end(); ++si)
  650. {
  651. // Separate the strings in the output to make it a list.
  652. output += sep;
  653. sep = ";";
  654. // Store the string in the output, but escape semicolons to
  655. // make sure it is a list.
  656. std::string const& sr = *si;
  657. for(unsigned int i=0; i < sr.size(); ++i)
  658. {
  659. if(sr[i] == ';')
  660. {
  661. output += '\\';
  662. }
  663. output += sr[i];
  664. }
  665. }
  666. // Save the output in a makefile variable.
  667. this->Makefile->AddDefinition(outVar, output.c_str());
  668. return true;
  669. }
  670. //----------------------------------------------------------------------------
  671. bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
  672. bool recurse)
  673. {
  674. // File commands has at least one argument
  675. assert(args.size() > 1);
  676. std::vector<std::string>::const_iterator i = args.begin();
  677. i++; // Get rid of subcommand
  678. std::string variable = *i;
  679. i++;
  680. cmsys::Glob g;
  681. g.SetRecurse(recurse);
  682. bool explicitFollowSymlinks = false;
  683. cmPolicies::PolicyStatus status =
  684. this->Makefile->GetPolicyStatus(cmPolicies::CMP0009);
  685. if(recurse)
  686. {
  687. switch(status)
  688. {
  689. case cmPolicies::NEW:
  690. g.RecurseThroughSymlinksOff();
  691. break;
  692. case cmPolicies::OLD:
  693. case cmPolicies::WARN:
  694. case cmPolicies::REQUIRED_IF_USED:
  695. case cmPolicies::REQUIRED_ALWAYS:
  696. g.RecurseThroughSymlinksOn();
  697. break;
  698. }
  699. }
  700. std::string output = "";
  701. bool first = true;
  702. for ( ; i != args.end(); ++i )
  703. {
  704. if ( recurse && (*i == "FOLLOW_SYMLINKS") )
  705. {
  706. explicitFollowSymlinks = true;
  707. g.RecurseThroughSymlinksOn();
  708. ++i;
  709. if ( i == args.end() )
  710. {
  711. this->SetError(
  712. "GLOB_RECURSE requires a glob expression after FOLLOW_SYMLINKS");
  713. return false;
  714. }
  715. }
  716. if ( *i == "RELATIVE" )
  717. {
  718. ++i; // skip RELATIVE
  719. if ( i == args.end() )
  720. {
  721. this->SetError("GLOB requires a directory after the RELATIVE tag");
  722. return false;
  723. }
  724. g.SetRelative(i->c_str());
  725. ++i;
  726. if(i == args.end())
  727. {
  728. this->SetError("GLOB requires a glob expression after the directory");
  729. return false;
  730. }
  731. }
  732. if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
  733. {
  734. std::string expr = this->Makefile->GetCurrentDirectory();
  735. // Handle script mode
  736. if ( expr.size() > 0 )
  737. {
  738. expr += "/" + *i;
  739. g.FindFiles(expr);
  740. }
  741. else
  742. {
  743. g.FindFiles(*i);
  744. }
  745. }
  746. else
  747. {
  748. g.FindFiles(*i);
  749. }
  750. std::vector<std::string>::size_type cc;
  751. std::vector<std::string>& files = g.GetFiles();
  752. for ( cc = 0; cc < files.size(); cc ++ )
  753. {
  754. if ( !first )
  755. {
  756. output += ";";
  757. }
  758. output += files[cc];
  759. first = false;
  760. }
  761. }
  762. if(recurse && !explicitFollowSymlinks)
  763. {
  764. switch (status)
  765. {
  766. case cmPolicies::NEW:
  767. // Correct behavior, yay!
  768. break;
  769. case cmPolicies::OLD:
  770. // Probably not really the expected behavior, but the author explicitly
  771. // asked for the old behavior... no warning.
  772. case cmPolicies::WARN:
  773. // Possibly unexpected old behavior *and* we actually traversed
  774. // symlinks without being explicitly asked to: warn the author.
  775. if(g.GetFollowedSymlinkCount() != 0)
  776. {
  777. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
  778. this->Makefile->GetPolicies()->
  779. GetPolicyWarning(cmPolicies::CMP0009));
  780. }
  781. break;
  782. case cmPolicies::REQUIRED_IF_USED:
  783. case cmPolicies::REQUIRED_ALWAYS:
  784. this->SetError("policy CMP0009 error");
  785. this->Makefile->IssueMessage(cmake::FATAL_ERROR,
  786. this->Makefile->GetPolicies()->
  787. GetRequiredPolicyError(cmPolicies::CMP0009));
  788. return false;
  789. }
  790. }
  791. this->Makefile->AddDefinition(variable, output.c_str());
  792. return true;
  793. }
  794. //----------------------------------------------------------------------------
  795. bool cmFileCommand::HandleMakeDirectoryCommand(
  796. std::vector<std::string> const& args)
  797. {
  798. // File command has at least one argument
  799. assert(args.size() > 1);
  800. std::vector<std::string>::const_iterator i = args.begin();
  801. i++; // Get rid of subcommand
  802. std::string expr;
  803. for ( ; i != args.end(); ++i )
  804. {
  805. const std::string* cdir = &(*i);
  806. if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
  807. {
  808. expr = this->Makefile->GetCurrentDirectory();
  809. expr += "/" + *i;
  810. cdir = &expr;
  811. }
  812. if ( !this->Makefile->CanIWriteThisFile(cdir->c_str()) )
  813. {
  814. std::string e = "attempted to create a directory: " + *cdir
  815. + " into a source directory.";
  816. this->SetError(e);
  817. cmSystemTools::SetFatalErrorOccured();
  818. return false;
  819. }
  820. if ( !cmSystemTools::MakeDirectory(cdir->c_str()) )
  821. {
  822. std::string error = "problem creating directory: " + *cdir;
  823. this->SetError(error);
  824. return false;
  825. }
  826. }
  827. return true;
  828. }
  829. //----------------------------------------------------------------------------
  830. bool
  831. cmFileCommand::HandleDifferentCommand(std::vector<std::string> const& args)
  832. {
  833. /*
  834. FILE(DIFFERENT <variable> FILES <lhs> <rhs>)
  835. */
  836. // Evaluate arguments.
  837. const char* file_lhs = 0;
  838. const char* file_rhs = 0;
  839. const char* var = 0;
  840. enum Doing { DoingNone, DoingVar, DoingFileLHS, DoingFileRHS };
  841. Doing doing = DoingVar;
  842. for(unsigned int i=1; i < args.size(); ++i)
  843. {
  844. if(args[i] == "FILES")
  845. {
  846. doing = DoingFileLHS;
  847. }
  848. else if(doing == DoingVar)
  849. {
  850. var = args[i].c_str();
  851. doing = DoingNone;
  852. }
  853. else if(doing == DoingFileLHS)
  854. {
  855. file_lhs = args[i].c_str();
  856. doing = DoingFileRHS;
  857. }
  858. else if(doing == DoingFileRHS)
  859. {
  860. file_rhs = args[i].c_str();
  861. doing = DoingNone;
  862. }
  863. else
  864. {
  865. cmOStringStream e;
  866. e << "DIFFERENT given unknown argument " << args[i];
  867. this->SetError(e.str());
  868. return false;
  869. }
  870. }
  871. if(!var)
  872. {
  873. this->SetError("DIFFERENT not given result variable name.");
  874. return false;
  875. }
  876. if(!file_lhs || !file_rhs)
  877. {
  878. this->SetError("DIFFERENT not given FILES option with two file names.");
  879. return false;
  880. }
  881. // Compare the files.
  882. const char* result =
  883. cmSystemTools::FilesDiffer(file_lhs, file_rhs)? "1" : "0";
  884. this->Makefile->AddDefinition(var, result);
  885. return true;
  886. }
  887. //----------------------------------------------------------------------------
  888. // File installation helper class.
  889. struct cmFileCopier
  890. {
  891. cmFileCopier(cmFileCommand* command, const char* name = "COPY"):
  892. FileCommand(command),
  893. Makefile(command->GetMakefile()),
  894. Name(name),
  895. Always(false),
  896. MatchlessFiles(true),
  897. FilePermissions(0),
  898. DirPermissions(0),
  899. CurrentMatchRule(0),
  900. UseGivenPermissionsFile(false),
  901. UseGivenPermissionsDir(false),
  902. UseSourcePermissions(true),
  903. Doing(DoingNone)
  904. {
  905. }
  906. virtual ~cmFileCopier() {}
  907. bool Run(std::vector<std::string> const& args);
  908. protected:
  909. cmFileCommand* FileCommand;
  910. cmMakefile* Makefile;
  911. const char* Name;
  912. bool Always;
  913. cmFileTimeComparison FileTimes;
  914. // Whether to install a file not matching any expression.
  915. bool MatchlessFiles;
  916. // Permissions for files and directories installed by this object.
  917. mode_t FilePermissions;
  918. mode_t DirPermissions;
  919. // Properties set by pattern and regex match rules.
  920. struct MatchProperties
  921. {
  922. bool Exclude;
  923. mode_t Permissions;
  924. MatchProperties(): Exclude(false), Permissions(0) {}
  925. };
  926. struct MatchRule;
  927. friend struct MatchRule;
  928. struct MatchRule
  929. {
  930. cmsys::RegularExpression Regex;
  931. MatchProperties Properties;
  932. std::string RegexString;
  933. MatchRule(std::string const& regex):
  934. Regex(regex.c_str()), RegexString(regex) {}
  935. };
  936. std::vector<MatchRule> MatchRules;
  937. // Get the properties from rules matching this input file.
  938. MatchProperties CollectMatchProperties(const char* file)
  939. {
  940. // Match rules are case-insensitive on some platforms.
  941. #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
  942. std::string lower = cmSystemTools::LowerCase(file);
  943. const char* file_to_match = lower.c_str();
  944. #else
  945. const char* file_to_match = file;
  946. #endif
  947. // Collect properties from all matching rules.
  948. bool matched = false;
  949. MatchProperties result;
  950. for(std::vector<MatchRule>::iterator mr = this->MatchRules.begin();
  951. mr != this->MatchRules.end(); ++mr)
  952. {
  953. if(mr->Regex.find(file_to_match))
  954. {
  955. matched = true;
  956. result.Exclude |= mr->Properties.Exclude;
  957. result.Permissions |= mr->Properties.Permissions;
  958. }
  959. }
  960. if(!matched && !this->MatchlessFiles)
  961. {
  962. result.Exclude = !cmSystemTools::FileIsDirectory(file);
  963. }
  964. return result;
  965. }
  966. bool SetPermissions(const char* toFile, mode_t permissions)
  967. {
  968. if(permissions && !cmSystemTools::SetPermissions(toFile, permissions))
  969. {
  970. cmOStringStream e;
  971. e << this->Name << " cannot set permissions on \"" << toFile << "\"";
  972. this->FileCommand->SetError(e.str());
  973. return false;
  974. }
  975. return true;
  976. }
  977. // Translate an argument to a permissions bit.
  978. bool CheckPermissions(std::string const& arg, mode_t& permissions)
  979. {
  980. if(arg == "OWNER_READ") { permissions |= mode_owner_read; }
  981. else if(arg == "OWNER_WRITE") { permissions |= mode_owner_write; }
  982. else if(arg == "OWNER_EXECUTE") { permissions |= mode_owner_execute; }
  983. else if(arg == "GROUP_READ") { permissions |= mode_group_read; }
  984. else if(arg == "GROUP_WRITE") { permissions |= mode_group_write; }
  985. else if(arg == "GROUP_EXECUTE") { permissions |= mode_group_execute; }
  986. else if(arg == "WORLD_READ") { permissions |= mode_world_read; }
  987. else if(arg == "WORLD_WRITE") { permissions |= mode_world_write; }
  988. else if(arg == "WORLD_EXECUTE") { permissions |= mode_world_execute; }
  989. else if(arg == "SETUID") { permissions |= mode_setuid; }
  990. else if(arg == "SETGID") { permissions |= mode_setgid; }
  991. else
  992. {
  993. cmOStringStream e;
  994. e << this->Name << " given invalid permission \"" << arg << "\".";
  995. this->FileCommand->SetError(e.str());
  996. return false;
  997. }
  998. return true;
  999. }
  1000. bool InstallSymlink(const char* fromFile, const char* toFile);
  1001. bool InstallFile(const char* fromFile, const char* toFile,
  1002. MatchProperties const& match_properties);
  1003. bool InstallDirectory(const char* source, const char* destination,
  1004. MatchProperties const& match_properties);
  1005. virtual bool Install(const char* fromFile, const char* toFile);
  1006. virtual std::string const& ToName(std::string const& fromName)
  1007. { return fromName; }
  1008. enum Type
  1009. {
  1010. TypeFile,
  1011. TypeDir,
  1012. TypeLink
  1013. };
  1014. virtual void ReportCopy(const char*, Type, bool) {}
  1015. virtual bool ReportMissing(const char* fromFile)
  1016. {
  1017. // The input file does not exist and installation is not optional.
  1018. cmOStringStream e;
  1019. e << this->Name << " cannot find \"" << fromFile << "\".";
  1020. this->FileCommand->SetError(e.str());
  1021. return false;
  1022. }
  1023. MatchRule* CurrentMatchRule;
  1024. bool UseGivenPermissionsFile;
  1025. bool UseGivenPermissionsDir;
  1026. bool UseSourcePermissions;
  1027. std::string Destination;
  1028. std::vector<std::string> Files;
  1029. int Doing;
  1030. virtual bool Parse(std::vector<std::string> const& args);
  1031. enum
  1032. {
  1033. DoingNone,
  1034. DoingError,
  1035. DoingDestination,
  1036. DoingFiles,
  1037. DoingPattern,
  1038. DoingRegex,
  1039. DoingPermissionsFile,
  1040. DoingPermissionsDir,
  1041. DoingPermissionsMatch,
  1042. DoingLast1
  1043. };
  1044. virtual bool CheckKeyword(std::string const& arg);
  1045. virtual bool CheckValue(std::string const& arg);
  1046. void NotBeforeMatch(std::string const& arg)
  1047. {
  1048. cmOStringStream e;
  1049. e << "option " << arg << " may not appear before PATTERN or REGEX.";
  1050. this->FileCommand->SetError(e.str());
  1051. this->Doing = DoingError;
  1052. }
  1053. void NotAfterMatch(std::string const& arg)
  1054. {
  1055. cmOStringStream e;
  1056. e << "option " << arg << " may not appear after PATTERN or REGEX.";
  1057. this->FileCommand->SetError(e.str());
  1058. this->Doing = DoingError;
  1059. }
  1060. virtual void DefaultFilePermissions()
  1061. {
  1062. // Use read/write permissions.
  1063. this->FilePermissions = 0;
  1064. this->FilePermissions |= mode_owner_read;
  1065. this->FilePermissions |= mode_owner_write;
  1066. this->FilePermissions |= mode_group_read;
  1067. this->FilePermissions |= mode_world_read;
  1068. }
  1069. virtual void DefaultDirectoryPermissions()
  1070. {
  1071. // Use read/write/executable permissions.
  1072. this->DirPermissions = 0;
  1073. this->DirPermissions |= mode_owner_read;
  1074. this->DirPermissions |= mode_owner_write;
  1075. this->DirPermissions |= mode_owner_execute;
  1076. this->DirPermissions |= mode_group_read;
  1077. this->DirPermissions |= mode_group_execute;
  1078. this->DirPermissions |= mode_world_read;
  1079. this->DirPermissions |= mode_world_execute;
  1080. }
  1081. };
  1082. //----------------------------------------------------------------------------
  1083. bool cmFileCopier::Parse(std::vector<std::string> const& args)
  1084. {
  1085. this->Doing = DoingFiles;
  1086. for(unsigned int i=1; i < args.size(); ++i)
  1087. {
  1088. // Check this argument.
  1089. if(!this->CheckKeyword(args[i]) &&
  1090. !this->CheckValue(args[i]))
  1091. {
  1092. cmOStringStream e;
  1093. e << "called with unknown argument \"" << args[i] << "\".";
  1094. this->FileCommand->SetError(e.str());
  1095. return false;
  1096. }
  1097. // Quit if an argument is invalid.
  1098. if(this->Doing == DoingError)
  1099. {
  1100. return false;
  1101. }
  1102. }
  1103. // Require a destination.
  1104. if(this->Destination.empty())
  1105. {
  1106. cmOStringStream e;
  1107. e << this->Name << " given no DESTINATION";
  1108. this->FileCommand->SetError(e.str());
  1109. return false;
  1110. }
  1111. // If file permissions were not specified set default permissions.
  1112. if(!this->UseGivenPermissionsFile && !this->UseSourcePermissions)
  1113. {
  1114. this->DefaultFilePermissions();
  1115. }
  1116. // If directory permissions were not specified set default permissions.
  1117. if(!this->UseGivenPermissionsDir && !this->UseSourcePermissions)
  1118. {
  1119. this->DefaultDirectoryPermissions();
  1120. }
  1121. return true;
  1122. }
  1123. //----------------------------------------------------------------------------
  1124. bool cmFileCopier::CheckKeyword(std::string const& arg)
  1125. {
  1126. if(arg == "DESTINATION")
  1127. {
  1128. if(this->CurrentMatchRule)
  1129. {
  1130. this->NotAfterMatch(arg);
  1131. }
  1132. else
  1133. {
  1134. this->Doing = DoingDestination;
  1135. }
  1136. }
  1137. else if(arg == "PATTERN")
  1138. {
  1139. this->Doing = DoingPattern;
  1140. }
  1141. else if(arg == "REGEX")
  1142. {
  1143. this->Doing = DoingRegex;
  1144. }
  1145. else if(arg == "EXCLUDE")
  1146. {
  1147. // Add this property to the current match rule.
  1148. if(this->CurrentMatchRule)
  1149. {
  1150. this->CurrentMatchRule->Properties.Exclude = true;
  1151. this->Doing = DoingNone;
  1152. }
  1153. else
  1154. {
  1155. this->NotBeforeMatch(arg);
  1156. }
  1157. }
  1158. else if(arg == "PERMISSIONS")
  1159. {
  1160. if(this->CurrentMatchRule)
  1161. {
  1162. this->Doing = DoingPermissionsMatch;
  1163. }
  1164. else
  1165. {
  1166. this->NotBeforeMatch(arg);
  1167. }
  1168. }
  1169. else if(arg == "FILE_PERMISSIONS")
  1170. {
  1171. if(this->CurrentMatchRule)
  1172. {
  1173. this->NotAfterMatch(arg);
  1174. }
  1175. else
  1176. {
  1177. this->Doing = DoingPermissionsFile;
  1178. this->UseGivenPermissionsFile = true;
  1179. }
  1180. }
  1181. else if(arg == "DIRECTORY_PERMISSIONS")
  1182. {
  1183. if(this->CurrentMatchRule)
  1184. {
  1185. this->NotAfterMatch(arg);
  1186. }
  1187. else
  1188. {
  1189. this->Doing = DoingPermissionsDir;
  1190. this->UseGivenPermissionsDir = true;
  1191. }
  1192. }
  1193. else if(arg == "USE_SOURCE_PERMISSIONS")
  1194. {
  1195. if(this->CurrentMatchRule)
  1196. {
  1197. this->NotAfterMatch(arg);
  1198. }
  1199. else
  1200. {
  1201. this->Doing = DoingNone;
  1202. this->UseSourcePermissions = true;
  1203. }
  1204. }
  1205. else if(arg == "NO_SOURCE_PERMISSIONS")
  1206. {
  1207. if(this->CurrentMatchRule)
  1208. {
  1209. this->NotAfterMatch(arg);
  1210. }
  1211. else
  1212. {
  1213. this->Doing = DoingNone;
  1214. this->UseSourcePermissions = false;
  1215. }
  1216. }
  1217. else if(arg == "FILES_MATCHING")
  1218. {
  1219. if(this->CurrentMatchRule)
  1220. {
  1221. this->NotAfterMatch(arg);
  1222. }
  1223. else
  1224. {
  1225. this->Doing = DoingNone;
  1226. this->MatchlessFiles = false;
  1227. }
  1228. }
  1229. else
  1230. {
  1231. return false;
  1232. }
  1233. return true;
  1234. }
  1235. //----------------------------------------------------------------------------
  1236. bool cmFileCopier::CheckValue(std::string const& arg)
  1237. {
  1238. switch(this->Doing)
  1239. {
  1240. case DoingFiles:
  1241. if(arg.empty() || cmSystemTools::FileIsFullPath(arg.c_str()))
  1242. {
  1243. this->Files.push_back(arg);
  1244. }
  1245. else
  1246. {
  1247. std::string file = this->Makefile->GetCurrentDirectory();
  1248. file += "/" + arg;
  1249. this->Files.push_back(file);
  1250. }
  1251. break;
  1252. case DoingDestination:
  1253. if(arg.empty() || cmSystemTools::FileIsFullPath(arg.c_str()))
  1254. {
  1255. this->Destination = arg;
  1256. }
  1257. else
  1258. {
  1259. this->Destination = this->Makefile->GetCurrentOutputDirectory();
  1260. this->Destination += "/" + arg;
  1261. }
  1262. this->Doing = DoingNone;
  1263. break;
  1264. case DoingPattern:
  1265. {
  1266. // Convert the pattern to a regular expression. Require a
  1267. // leading slash and trailing end-of-string in the matched
  1268. // string to make sure the pattern matches only whole file
  1269. // names.
  1270. std::string regex = "/";
  1271. regex += cmsys::Glob::PatternToRegex(arg, false);
  1272. regex += "$";
  1273. this->MatchRules.push_back(MatchRule(regex));
  1274. this->CurrentMatchRule = &*(this->MatchRules.end()-1);
  1275. if(this->CurrentMatchRule->Regex.is_valid())
  1276. {
  1277. this->Doing = DoingNone;
  1278. }
  1279. else
  1280. {
  1281. cmOStringStream e;
  1282. e << "could not compile PATTERN \"" << arg << "\".";
  1283. this->FileCommand->SetError(e.str());
  1284. this->Doing = DoingError;
  1285. }
  1286. }
  1287. break;
  1288. case DoingRegex:
  1289. this->MatchRules.push_back(MatchRule(arg));
  1290. this->CurrentMatchRule = &*(this->MatchRules.end()-1);
  1291. if(this->CurrentMatchRule->Regex.is_valid())
  1292. {
  1293. this->Doing = DoingNone;
  1294. }
  1295. else
  1296. {
  1297. cmOStringStream e;
  1298. e << "could not compile REGEX \"" << arg << "\".";
  1299. this->FileCommand->SetError(e.str());
  1300. this->Doing = DoingError;
  1301. }
  1302. break;
  1303. case DoingPermissionsFile:
  1304. if(!this->CheckPermissions(arg, this->FilePermissions))
  1305. {
  1306. this->Doing = DoingError;
  1307. }
  1308. break;
  1309. case DoingPermissionsDir:
  1310. if(!this->CheckPermissions(arg, this->DirPermissions))
  1311. {
  1312. this->Doing = DoingError;
  1313. }
  1314. break;
  1315. case DoingPermissionsMatch:
  1316. if(!this->CheckPermissions(
  1317. arg, this->CurrentMatchRule->Properties.Permissions))
  1318. {
  1319. this->Doing = DoingError;
  1320. }
  1321. break;
  1322. default:
  1323. return false;
  1324. }
  1325. return true;
  1326. }
  1327. //----------------------------------------------------------------------------
  1328. bool cmFileCopier::Run(std::vector<std::string> const& args)
  1329. {
  1330. if(!this->Parse(args))
  1331. {
  1332. return false;
  1333. }
  1334. std::vector<std::string> const& files = this->Files;
  1335. for(std::vector<std::string>::size_type i = 0; i < files.size(); ++i)
  1336. {
  1337. // Split the input file into its directory and name components.
  1338. std::vector<std::string> fromPathComponents;
  1339. cmSystemTools::SplitPath(files[i].c_str(), fromPathComponents);
  1340. std::string fromName = *(fromPathComponents.end()-1);
  1341. std::string fromDir = cmSystemTools::JoinPath(fromPathComponents.begin(),
  1342. fromPathComponents.end()-1);
  1343. // Compute the full path to the destination file.
  1344. std::string toFile = this->Destination;
  1345. std::string const& toName = this->ToName(fromName);
  1346. if(!toName.empty())
  1347. {
  1348. toFile += "/";
  1349. toFile += toName;
  1350. }
  1351. // Construct the full path to the source file. The file name may
  1352. // have been changed above.
  1353. std::string fromFile = fromDir;
  1354. if(!fromName.empty())
  1355. {
  1356. fromFile += "/";
  1357. fromFile += fromName;
  1358. }
  1359. if(!this->Install(fromFile.c_str(), toFile.c_str()))
  1360. {
  1361. return false;
  1362. }
  1363. }
  1364. return true;
  1365. }
  1366. //----------------------------------------------------------------------------
  1367. bool cmFileCopier::Install(const char* fromFile, const char* toFile)
  1368. {
  1369. if(!*fromFile)
  1370. {
  1371. cmOStringStream e;
  1372. e << "INSTALL encountered an empty string input file name.";
  1373. this->FileCommand->SetError(e.str());
  1374. return false;
  1375. }
  1376. // Collect any properties matching this file name.
  1377. MatchProperties match_properties = this->CollectMatchProperties(fromFile);
  1378. // Skip the file if it is excluded.
  1379. if(match_properties.Exclude)
  1380. {
  1381. return true;
  1382. }
  1383. if(cmSystemTools::SameFile(fromFile, toFile))
  1384. {
  1385. return true;
  1386. }
  1387. else if(cmSystemTools::FileIsSymlink(fromFile))
  1388. {
  1389. return this->InstallSymlink(fromFile, toFile);
  1390. }
  1391. else if(cmSystemTools::FileIsDirectory(fromFile))
  1392. {
  1393. return this->InstallDirectory(fromFile, toFile, match_properties);
  1394. }
  1395. else if(cmSystemTools::FileExists(fromFile))
  1396. {
  1397. return this->InstallFile(fromFile, toFile, match_properties);
  1398. }
  1399. return this->ReportMissing(fromFile);
  1400. }
  1401. //----------------------------------------------------------------------------
  1402. bool cmFileCopier::InstallSymlink(const char* fromFile, const char* toFile)
  1403. {
  1404. // Read the original symlink.
  1405. std::string symlinkTarget;
  1406. if(!cmSystemTools::ReadSymlink(fromFile, symlinkTarget))
  1407. {
  1408. cmOStringStream e;
  1409. e << this->Name << " cannot read symlink \"" << fromFile
  1410. << "\" to duplicate at \"" << toFile << "\".";
  1411. this->FileCommand->SetError(e.str());
  1412. return false;
  1413. }
  1414. // Compare the symlink value to that at the destination if not
  1415. // always installing.
  1416. bool copy = true;
  1417. if(!this->Always)
  1418. {
  1419. std::string oldSymlinkTarget;
  1420. if(cmSystemTools::ReadSymlink(toFile, oldSymlinkTarget))
  1421. {
  1422. if(symlinkTarget == oldSymlinkTarget)
  1423. {
  1424. copy = false;
  1425. }
  1426. }
  1427. }
  1428. // Inform the user about this file installation.
  1429. this->ReportCopy(toFile, TypeLink, copy);
  1430. if(copy)
  1431. {
  1432. // Remove the destination file so we can always create the symlink.
  1433. cmSystemTools::RemoveFile(toFile);
  1434. // Create the symlink.
  1435. if(!cmSystemTools::CreateSymlink(symlinkTarget.c_str(), toFile))
  1436. {
  1437. cmOStringStream e;
  1438. e << this->Name << " cannot duplicate symlink \"" << fromFile
  1439. << "\" at \"" << toFile << "\".";
  1440. this->FileCommand->SetError(e.str());
  1441. return false;
  1442. }
  1443. }
  1444. return true;
  1445. }
  1446. //----------------------------------------------------------------------------
  1447. bool cmFileCopier::InstallFile(const char* fromFile, const char* toFile,
  1448. MatchProperties const& match_properties)
  1449. {
  1450. // Determine whether we will copy the file.
  1451. bool copy = true;
  1452. if(!this->Always)
  1453. {
  1454. // If both files exist with the same time do not copy.
  1455. if(!this->FileTimes.FileTimesDiffer(fromFile, toFile))
  1456. {
  1457. copy = false;
  1458. }
  1459. }
  1460. // Inform the user about this file installation.
  1461. this->ReportCopy(toFile, TypeFile, copy);
  1462. // Copy the file.
  1463. if(copy && !cmSystemTools::CopyAFile(fromFile, toFile, true))
  1464. {
  1465. cmOStringStream e;
  1466. e << this->Name << " cannot copy file \"" << fromFile
  1467. << "\" to \"" << toFile << "\".";
  1468. this->FileCommand->SetError(e.str());
  1469. return false;
  1470. }
  1471. // Set the file modification time of the destination file.
  1472. if(copy && !this->Always)
  1473. {
  1474. // Add write permission so we can set the file time.
  1475. // Permissions are set unconditionally below anyway.
  1476. mode_t perm = 0;
  1477. if(cmSystemTools::GetPermissions(toFile, perm))
  1478. {
  1479. cmSystemTools::SetPermissions(toFile, perm | mode_owner_write);
  1480. }
  1481. if (!cmSystemTools::CopyFileTime(fromFile, toFile))
  1482. {
  1483. cmOStringStream e;
  1484. e << this->Name << " cannot set modification time on \""
  1485. << toFile << "\"";
  1486. this->FileCommand->SetError(e.str());
  1487. return false;
  1488. }
  1489. }
  1490. // Set permissions of the destination file.
  1491. mode_t permissions = (match_properties.Permissions?
  1492. match_properties.Permissions : this->FilePermissions);
  1493. if(!permissions)
  1494. {
  1495. // No permissions were explicitly provided but the user requested
  1496. // that the source file permissions be used.
  1497. cmSystemTools::GetPermissions(fromFile, permissions);
  1498. }
  1499. return this->SetPermissions(toFile, permissions);
  1500. }
  1501. //----------------------------------------------------------------------------
  1502. bool cmFileCopier::InstallDirectory(const char* source,
  1503. const char* destination,
  1504. MatchProperties const& match_properties)
  1505. {
  1506. // Inform the user about this directory installation.
  1507. this->ReportCopy(destination, TypeDir, true);
  1508. // Make sure the destination directory exists.
  1509. if(!cmSystemTools::MakeDirectory(destination))
  1510. {
  1511. cmOStringStream e;
  1512. e << this->Name << " cannot make directory \"" << destination << "\": "
  1513. << cmSystemTools::GetLastSystemError();
  1514. this->FileCommand->SetError(e.str());
  1515. return false;
  1516. }
  1517. // Compute the requested permissions for the destination directory.
  1518. mode_t permissions = (match_properties.Permissions?
  1519. match_properties.Permissions : this->DirPermissions);
  1520. if(!permissions)
  1521. {
  1522. // No permissions were explicitly provided but the user requested
  1523. // that the source directory permissions be used.
  1524. cmSystemTools::GetPermissions(source, permissions);
  1525. }
  1526. // Compute the set of permissions required on this directory to
  1527. // recursively install files and subdirectories safely.
  1528. mode_t required_permissions =
  1529. mode_owner_read | mode_owner_write | mode_owner_execute;
  1530. // If the required permissions are specified it is safe to set the
  1531. // final permissions now. Otherwise we must add the required
  1532. // permissions temporarily during file installation.
  1533. mode_t permissions_before = 0;
  1534. mode_t permissions_after = 0;
  1535. if((permissions & required_permissions) == required_permissions)
  1536. {
  1537. permissions_before = permissions;
  1538. }
  1539. else
  1540. {
  1541. permissions_before = permissions | required_permissions;
  1542. permissions_after = permissions;
  1543. }
  1544. // Set the required permissions of the destination directory.
  1545. if(!this->SetPermissions(destination, permissions_before))
  1546. {
  1547. return false;
  1548. }
  1549. // Load the directory contents to traverse it recursively.
  1550. cmsys::Directory dir;
  1551. if(source && *source)
  1552. {
  1553. dir.Load(source);
  1554. }
  1555. unsigned long numFiles = static_cast<unsigned long>(dir.GetNumberOfFiles());
  1556. for(unsigned long fileNum = 0; fileNum < numFiles; ++fileNum)
  1557. {
  1558. if(!(strcmp(dir.GetFile(fileNum), ".") == 0 ||
  1559. strcmp(dir.GetFile(fileNum), "..") == 0))
  1560. {
  1561. cmsys_stl::string fromPath = source;
  1562. fromPath += "/";
  1563. fromPath += dir.GetFile(fileNum);
  1564. std::string toPath = destination;
  1565. toPath += "/";
  1566. toPath += dir.GetFile(fileNum);
  1567. if(!this->Install(fromPath.c_str(), toPath.c_str()))
  1568. {
  1569. return false;
  1570. }
  1571. }
  1572. }
  1573. // Set the requested permissions of the destination directory.
  1574. return this->SetPermissions(destination, permissions_after);
  1575. }
  1576. //----------------------------------------------------------------------------
  1577. bool cmFileCommand::HandleCopyCommand(std::vector<std::string> const& args)
  1578. {
  1579. cmFileCopier copier(this);
  1580. return copier.Run(args);
  1581. }
  1582. //----------------------------------------------------------------------------
  1583. struct cmFileInstaller: public cmFileCopier
  1584. {
  1585. cmFileInstaller(cmFileCommand* command):
  1586. cmFileCopier(command, "INSTALL"),
  1587. InstallType(cmInstallType_FILES),
  1588. Optional(false),
  1589. DestDirLength(0)
  1590. {
  1591. // Installation does not use source permissions by default.
  1592. this->UseSourcePermissions = false;
  1593. // Check whether to copy files always or only if they have changed.
  1594. this->Always =
  1595. cmSystemTools::IsOn(cmSystemTools::GetEnv("CMAKE_INSTALL_ALWAYS"));
  1596. // Get the current manifest.
  1597. this->Manifest =
  1598. this->Makefile->GetSafeDefinition("CMAKE_INSTALL_MANIFEST_FILES");
  1599. }
  1600. ~cmFileInstaller()
  1601. {
  1602. // Save the updated install manifest.
  1603. this->Makefile->AddDefinition("CMAKE_INSTALL_MANIFEST_FILES",
  1604. this->Manifest.c_str());
  1605. }
  1606. protected:
  1607. cmInstallType InstallType;
  1608. bool Optional;
  1609. int DestDirLength;
  1610. std::string Rename;
  1611. std::string Manifest;
  1612. void ManifestAppend(std::string const& file)
  1613. {
  1614. this->Manifest += ";";
  1615. this->Manifest += file.substr(this->DestDirLength);
  1616. }
  1617. virtual std::string const& ToName(std::string const& fromName)
  1618. { return this->Rename.empty()? fromName : this->Rename; }
  1619. virtual void ReportCopy(const char* toFile, Type type, bool copy)
  1620. {
  1621. std::string message = (copy? "Installing: " : "Up-to-date: ");
  1622. message += toFile;
  1623. this->Makefile->DisplayStatus(message.c_str(), -1);
  1624. if(type != TypeDir)
  1625. {
  1626. // Add the file to the manifest.
  1627. this->ManifestAppend(toFile);
  1628. }
  1629. }
  1630. virtual bool ReportMissing(const char* fromFile)
  1631. {
  1632. return (this->Optional ||
  1633. this->cmFileCopier::ReportMissing(fromFile));
  1634. }
  1635. virtual bool Install(const char* fromFile, const char* toFile)
  1636. {
  1637. // Support installing from empty source to make a directory.
  1638. if(this->InstallType == cmInstallType_DIRECTORY && !*fromFile)
  1639. {
  1640. return this->InstallDirectory(fromFile, toFile, MatchProperties());
  1641. }
  1642. return this->cmFileCopier::Install(fromFile, toFile);
  1643. }
  1644. virtual bool Parse(std::vector<std::string> const& args);
  1645. enum
  1646. {
  1647. DoingType = DoingLast1,
  1648. DoingRename,
  1649. DoingLast2
  1650. };
  1651. virtual bool CheckKeyword(std::string const& arg);
  1652. virtual bool CheckValue(std::string const& arg);
  1653. virtual void DefaultFilePermissions()
  1654. {
  1655. this->cmFileCopier::DefaultFilePermissions();
  1656. // Add execute permissions based on the target type.
  1657. switch(this->InstallType)
  1658. {
  1659. case cmInstallType_SHARED_LIBRARY:
  1660. case cmInstallType_MODULE_LIBRARY:
  1661. if(this->Makefile->IsOn("CMAKE_INSTALL_SO_NO_EXE"))
  1662. {
  1663. break;
  1664. }
  1665. case cmInstallType_EXECUTABLE:
  1666. case cmInstallType_PROGRAMS:
  1667. this->FilePermissions |= mode_owner_execute;
  1668. this->FilePermissions |= mode_group_execute;
  1669. this->FilePermissions |= mode_world_execute;
  1670. break;
  1671. default: break;
  1672. }
  1673. }
  1674. bool GetTargetTypeFromString(const std::string& stype);
  1675. bool HandleInstallDestination();
  1676. };
  1677. //----------------------------------------------------------------------------
  1678. bool cmFileInstaller::Parse(std::vector<std::string> const& args)
  1679. {
  1680. if(!this->cmFileCopier::Parse(args))
  1681. {
  1682. return false;
  1683. }
  1684. if(!this->Rename.empty())
  1685. {
  1686. if(this->InstallType != cmInstallType_FILES &&
  1687. this->InstallType != cmInstallType_PROGRAMS)
  1688. {
  1689. this->FileCommand->SetError("INSTALL option RENAME may be used "
  1690. "only with FILES or PROGRAMS.");
  1691. return false;
  1692. }
  1693. if(this->Files.size() > 1)
  1694. {
  1695. this->FileCommand->SetError("INSTALL option RENAME may be used "
  1696. "only with one file.");
  1697. return false;
  1698. }
  1699. }
  1700. if(!this->HandleInstallDestination())
  1701. {
  1702. return false;
  1703. }
  1704. return true;
  1705. }
  1706. //----------------------------------------------------------------------------
  1707. bool cmFileInstaller::CheckKeyword(std::string const& arg)
  1708. {
  1709. if(arg == "TYPE")
  1710. {
  1711. if(this->CurrentMatchRule)
  1712. {
  1713. this->NotAfterMatch(arg);
  1714. }
  1715. else
  1716. {
  1717. this->Doing = DoingType;
  1718. }
  1719. }
  1720. else if(arg == "FILES")
  1721. {
  1722. if(this->CurrentMatchRule)
  1723. {
  1724. this->NotAfterMatch(arg);
  1725. }
  1726. else
  1727. {
  1728. this->Doing = DoingFiles;
  1729. }
  1730. }
  1731. else if(arg == "RENAME")
  1732. {
  1733. if(this->CurrentMatchRule)
  1734. {
  1735. this->NotAfterMatch(arg);
  1736. }
  1737. else
  1738. {
  1739. this->Doing = DoingRename;
  1740. }
  1741. }
  1742. else if(arg == "OPTIONAL")
  1743. {
  1744. if(this->CurrentMatchRule)
  1745. {
  1746. this->NotAfterMatch(arg);
  1747. }
  1748. else
  1749. {
  1750. this->Doing = DoingNone;
  1751. this->Optional = true;
  1752. }
  1753. }
  1754. else if(arg == "PERMISSIONS")
  1755. {
  1756. if(this->CurrentMatchRule)
  1757. {
  1758. this->Doing = DoingPermissionsMatch;
  1759. }
  1760. else
  1761. {
  1762. // file(INSTALL) aliases PERMISSIONS to FILE_PERMISSIONS
  1763. this->Doing = DoingPermissionsFile;
  1764. this->UseGivenPermissionsFile = true;
  1765. }
  1766. }
  1767. else if(arg == "DIR_PERMISSIONS")
  1768. {
  1769. if(this->CurrentMatchRule)
  1770. {
  1771. this->NotAfterMatch(arg);
  1772. }
  1773. else
  1774. {
  1775. // file(INSTALL) aliases DIR_PERMISSIONS to DIRECTORY_PERMISSIONS
  1776. this->Doing = DoingPermissionsDir;
  1777. this->UseGivenPermissionsDir = true;
  1778. }
  1779. }
  1780. else if(arg == "COMPONENTS" || arg == "CONFIGURATIONS" ||
  1781. arg == "PROPERTIES")
  1782. {
  1783. cmOStringStream e;
  1784. e << "INSTALL called with old-style " << arg << " argument. "
  1785. << "This script was generated with an older version of CMake. "
  1786. << "Re-run this cmake version on your build tree.";
  1787. this->FileCommand->SetError(e.str());
  1788. this->Doing = DoingError;
  1789. }
  1790. else
  1791. {
  1792. return this->cmFileCopier::CheckKeyword(arg);
  1793. }
  1794. return true;
  1795. }
  1796. //----------------------------------------------------------------------------
  1797. bool cmFileInstaller::CheckValue(std::string const& arg)
  1798. {
  1799. switch(this->Doing)
  1800. {
  1801. case DoingType:
  1802. if(!this->GetTargetTypeFromString(arg))
  1803. {
  1804. this->Doing = DoingError;
  1805. }
  1806. break;
  1807. case DoingRename:
  1808. this->Rename = arg;
  1809. break;
  1810. default:
  1811. return this->cmFileCopier::CheckValue(arg);
  1812. }
  1813. return true;
  1814. }
  1815. //----------------------------------------------------------------------------
  1816. bool cmFileInstaller
  1817. ::GetTargetTypeFromString(const std::string& stype)
  1818. {
  1819. if ( stype == "EXECUTABLE" )
  1820. {
  1821. this->InstallType = cmInstallType_EXECUTABLE;
  1822. }
  1823. else if ( stype == "FILE" )
  1824. {
  1825. this->InstallType = cmInstallType_FILES;
  1826. }
  1827. else if ( stype == "PROGRAM" )
  1828. {
  1829. this->InstallType = cmInstallType_PROGRAMS;
  1830. }
  1831. else if ( stype == "STATIC_LIBRARY" )
  1832. {
  1833. this->InstallType = cmInstallType_STATIC_LIBRARY;
  1834. }
  1835. else if ( stype == "SHARED_LIBRARY" )
  1836. {
  1837. this->InstallType = cmInstallType_SHARED_LIBRARY;
  1838. }
  1839. else if ( stype == "MODULE" )
  1840. {
  1841. this->InstallType = cmInstallType_MODULE_LIBRARY;
  1842. }
  1843. else if ( stype == "DIRECTORY" )
  1844. {
  1845. this->InstallType = cmInstallType_DIRECTORY;
  1846. }
  1847. else
  1848. {
  1849. cmOStringStream e;
  1850. e << "Option TYPE given unknown value \"" << stype << "\".";
  1851. this->FileCommand->SetError(e.str());
  1852. return false;
  1853. }
  1854. return true;
  1855. }
  1856. //----------------------------------------------------------------------------
  1857. bool cmFileInstaller::HandleInstallDestination()
  1858. {
  1859. std::string& destination = this->Destination;
  1860. // allow for / to be a valid destination
  1861. if ( destination.size() < 2 && destination != "/" )
  1862. {
  1863. this->FileCommand->SetError("called with inappropriate arguments. "
  1864. "No DESTINATION provided or .");
  1865. return false;
  1866. }
  1867. const char* destdir = cmSystemTools::GetEnv("DESTDIR");
  1868. if ( destdir && *destdir )
  1869. {
  1870. std::string sdestdir = destdir;
  1871. cmSystemTools::ConvertToUnixSlashes(sdestdir);
  1872. char ch1 = destination[0];
  1873. char ch2 = destination[1];
  1874. char ch3 = 0;
  1875. if ( destination.size() > 2 )
  1876. {
  1877. ch3 = destination[2];
  1878. }
  1879. int skip = 0;
  1880. if ( ch1 != '/' )
  1881. {
  1882. int relative = 0;
  1883. if (((ch1 >= 'a' && ch1 <= 'z') || (ch1 >= 'A' && ch1 <= 'Z')) &&
  1884. ch2 == ':' )
  1885. {
  1886. // Assume windows
  1887. // let's do some destdir magic:
  1888. skip = 2;
  1889. if ( ch3 != '/' )
  1890. {
  1891. relative = 1;
  1892. }
  1893. }
  1894. else
  1895. {
  1896. relative = 1;
  1897. }
  1898. if ( relative )
  1899. {
  1900. // This is relative path on unix or windows. Since we are doing
  1901. // destdir, this case does not make sense.
  1902. this->FileCommand->SetError(
  1903. "called with relative DESTINATION. This "
  1904. "does not make sense when using DESTDIR. Specify "
  1905. "absolute path or remove DESTDIR environment variable.");
  1906. return false;
  1907. }
  1908. }
  1909. else
  1910. {
  1911. if ( ch2 == '/' )
  1912. {
  1913. // looks like a network path.
  1914. std::string message = "called with network path DESTINATION. This "
  1915. "does not make sense when using DESTDIR. Specify local "
  1916. "absolute path or remove DESTDIR environment variable."
  1917. "\nDESTINATION=\n";
  1918. message += destination;
  1919. this->FileCommand->SetError(message);
  1920. return false;
  1921. }
  1922. }
  1923. destination = sdestdir + (destination.c_str() + skip);
  1924. this->DestDirLength = int(sdestdir.size());
  1925. }
  1926. if ( !cmSystemTools::FileExists(destination.c_str()) )
  1927. {
  1928. if ( !cmSystemTools::MakeDirectory(destination.c_str()) )
  1929. {
  1930. std::string errstring = "cannot create directory: " + destination +
  1931. ". Maybe need administrative privileges.";
  1932. this->FileCommand->SetError(errstring);
  1933. return false;
  1934. }
  1935. }
  1936. if ( !cmSystemTools::FileIsDirectory(destination.c_str()) )
  1937. {
  1938. std::string errstring = "INSTALL destination: " + destination +
  1939. " is not a directory.";
  1940. this->FileCommand->SetError(errstring);
  1941. return false;
  1942. }
  1943. return true;
  1944. }
  1945. //----------------------------------------------------------------------------
  1946. bool
  1947. cmFileCommand::HandleRPathChangeCommand(std::vector<std::string> const& args)
  1948. {
  1949. // Evaluate arguments.
  1950. const char* file = 0;
  1951. const char* oldRPath = 0;
  1952. const char* newRPath = 0;
  1953. enum Doing { DoingNone, DoingFile, DoingOld, DoingNew };
  1954. Doing doing = DoingNone;
  1955. for(unsigned int i=1; i < args.size(); ++i)
  1956. {
  1957. if(args[i] == "OLD_RPATH")
  1958. {
  1959. doing = DoingOld;
  1960. }
  1961. else if(args[i] == "NEW_RPATH")
  1962. {
  1963. doing = DoingNew;
  1964. }
  1965. else if(args[i] == "FILE")
  1966. {
  1967. doing = DoingFile;
  1968. }
  1969. else if(doing == DoingFile)
  1970. {
  1971. file = args[i].c_str();
  1972. doing = DoingNone;
  1973. }
  1974. else if(doing == DoingOld)
  1975. {
  1976. oldRPath = args[i].c_str();
  1977. doing = DoingNone;
  1978. }
  1979. else if(doing == DoingNew)
  1980. {
  1981. newRPath = args[i].c_str();
  1982. doing = DoingNone;
  1983. }
  1984. else
  1985. {
  1986. cmOStringStream e;
  1987. e << "RPATH_CHANGE given unknown argument " << args[i];
  1988. this->SetError(e.str());
  1989. return false;
  1990. }
  1991. }
  1992. if(!file)
  1993. {
  1994. this->SetError("RPATH_CHANGE not given FILE option.");
  1995. return false;
  1996. }
  1997. if(!oldRPath)
  1998. {
  1999. this->SetError("RPATH_CHANGE not given OLD_RPATH option.");
  2000. return false;
  2001. }
  2002. if(!newRPath)
  2003. {
  2004. this->SetError("RPATH_CHANGE not given NEW_RPATH option.");
  2005. return false;
  2006. }
  2007. if(!cmSystemTools::FileExists(file, true))
  2008. {
  2009. cmOStringStream e;
  2010. e << "RPATH_CHANGE given FILE \"" << file << "\" that does not exist.";
  2011. this->SetError(e.str());
  2012. return false;
  2013. }
  2014. bool success = true;
  2015. cmSystemToolsFileTime* ft = cmSystemTools::FileTimeNew();
  2016. bool have_ft = cmSystemTools::FileTimeGet(file, ft);
  2017. std::string emsg;
  2018. bool changed;
  2019. if(!cmSystemTools::ChangeRPath(file, oldRPath, newRPath, &emsg, &changed))
  2020. {
  2021. cmOStringStream e;
  2022. e << "RPATH_CHANGE could not write new RPATH:\n"
  2023. << " " << newRPath << "\n"
  2024. << "to the file:\n"
  2025. << " " << file << "\n"
  2026. << emsg;
  2027. this->SetError(e.str());
  2028. success = false;
  2029. }
  2030. if(success)
  2031. {
  2032. if(changed)
  2033. {
  2034. std::string message = "Set runtime path of \"";
  2035. message += file;
  2036. message += "\" to \"";
  2037. message += newRPath;
  2038. message += "\"";
  2039. this->Makefile->DisplayStatus(message.c_str(), -1);
  2040. }
  2041. if(have_ft)
  2042. {
  2043. cmSystemTools::FileTimeSet(file, ft);
  2044. }
  2045. }
  2046. cmSystemTools::FileTimeDelete(ft);
  2047. return success;
  2048. }
  2049. //----------------------------------------------------------------------------
  2050. bool
  2051. cmFileCommand::HandleRPathRemoveCommand(std::vector<std::string> const& args)
  2052. {
  2053. // Evaluate arguments.
  2054. const char* file = 0;
  2055. enum Doing { DoingNone, DoingFile };
  2056. Doing doing = DoingNone;
  2057. for(unsigned int i=1; i < args.size(); ++i)
  2058. {
  2059. if(args[i] == "FILE")
  2060. {
  2061. doing = DoingFile;
  2062. }
  2063. else if(doing == DoingFile)
  2064. {
  2065. file = args[i].c_str();
  2066. doing = DoingNone;
  2067. }
  2068. else
  2069. {
  2070. cmOStringStream e;
  2071. e << "RPATH_REMOVE given unknown argument " << args[i];
  2072. this->SetError(e.str());
  2073. return false;
  2074. }
  2075. }
  2076. if(!file)
  2077. {
  2078. this->SetError("RPATH_REMOVE not given FILE option.");
  2079. return false;
  2080. }
  2081. if(!cmSystemTools::FileExists(file, true))
  2082. {
  2083. cmOStringStream e;
  2084. e << "RPATH_REMOVE given FILE \"" << file << "\" that does not exist.";
  2085. this->SetError(e.str());
  2086. return false;
  2087. }
  2088. bool success = true;
  2089. cmSystemToolsFileTime* ft = cmSystemTools::FileTimeNew();
  2090. bool have_ft = cmSystemTools::FileTimeGet(file, ft);
  2091. std::string emsg;
  2092. bool removed;
  2093. if(!cmSystemTools::RemoveRPath(file, &emsg, &removed))
  2094. {
  2095. cmOStringStream e;
  2096. e << "RPATH_REMOVE could not remove RPATH from file:\n"
  2097. << " " << file << "\n"
  2098. << emsg;
  2099. this->SetError(e.str());
  2100. success = false;
  2101. }
  2102. if(success)
  2103. {
  2104. if(removed)
  2105. {
  2106. std::string message = "Removed runtime path from \"";
  2107. message += file;
  2108. message += "\"";
  2109. this->Makefile->DisplayStatus(message.c_str(), -1);
  2110. }
  2111. if(have_ft)
  2112. {
  2113. cmSystemTools::FileTimeSet(file, ft);
  2114. }
  2115. }
  2116. cmSystemTools::FileTimeDelete(ft);
  2117. return success;
  2118. }
  2119. //----------------------------------------------------------------------------
  2120. bool
  2121. cmFileCommand::HandleRPathCheckCommand(std::vector<std::string> const& args)
  2122. {
  2123. // Evaluate arguments.
  2124. const char* file = 0;
  2125. const char* rpath = 0;
  2126. enum Doing { DoingNone, DoingFile, DoingRPath };
  2127. Doing doing = DoingNone;
  2128. for(unsigned int i=1; i < args.size(); ++i)
  2129. {
  2130. if(args[i] == "RPATH")
  2131. {
  2132. doing = DoingRPath;
  2133. }
  2134. else if(args[i] == "FILE")
  2135. {
  2136. doing = DoingFile;
  2137. }
  2138. else if(doing == DoingFile)
  2139. {
  2140. file = args[i].c_str();
  2141. doing = DoingNone;
  2142. }
  2143. else if(doing == DoingRPath)
  2144. {
  2145. rpath = args[i].c_str();
  2146. doing = DoingNone;
  2147. }
  2148. else
  2149. {
  2150. cmOStringStream e;
  2151. e << "RPATH_CHECK given unknown argument " << args[i];
  2152. this->SetError(e.str());
  2153. return false;
  2154. }
  2155. }
  2156. if(!file)
  2157. {
  2158. this->SetError("RPATH_CHECK not given FILE option.");
  2159. return false;
  2160. }
  2161. if(!rpath)
  2162. {
  2163. this->SetError("RPATH_CHECK not given RPATH option.");
  2164. return false;
  2165. }
  2166. // If the file exists but does not have the desired RPath then
  2167. // delete it. This is used during installation to re-install a file
  2168. // if its RPath will change.
  2169. if(cmSystemTools::FileExists(file, true) &&
  2170. !cmSystemTools::CheckRPath(file, rpath))
  2171. {
  2172. cmSystemTools::RemoveFile(file);
  2173. }
  2174. return true;
  2175. }
  2176. //----------------------------------------------------------------------------
  2177. bool cmFileCommand::HandleInstallCommand(std::vector<std::string> const& args)
  2178. {
  2179. cmFileInstaller installer(this);
  2180. return installer.Run(args);
  2181. }
  2182. //----------------------------------------------------------------------------
  2183. bool cmFileCommand::HandleRelativePathCommand(
  2184. std::vector<std::string> const& args)
  2185. {
  2186. if(args.size() != 4 )
  2187. {
  2188. this->SetError("RELATIVE_PATH called with incorrect number of arguments");
  2189. return false;
  2190. }
  2191. const std::string& outVar = args[1];
  2192. const std::string& directoryName = args[2];
  2193. const std::string& fileName = args[3];
  2194. if(!cmSystemTools::FileIsFullPath(directoryName.c_str()))
  2195. {
  2196. std::string errstring =
  2197. "RELATIVE_PATH must be passed a full path to the directory: "
  2198. + directoryName;
  2199. this->SetError(errstring);
  2200. return false;
  2201. }
  2202. if(!cmSystemTools::FileIsFullPath(fileName.c_str()))
  2203. {
  2204. std::string errstring =
  2205. "RELATIVE_PATH must be passed a full path to the file: "
  2206. + fileName;
  2207. this->SetError(errstring);
  2208. return false;
  2209. }
  2210. std::string res = cmSystemTools::RelativePath(directoryName.c_str(),
  2211. fileName.c_str());
  2212. this->Makefile->AddDefinition(outVar,
  2213. res.c_str());
  2214. return true;
  2215. }
  2216. //----------------------------------------------------------------------------
  2217. bool cmFileCommand::HandleRename(std::vector<std::string> const& args)
  2218. {
  2219. if(args.size() != 3)
  2220. {
  2221. this->SetError("RENAME given incorrect number of arguments.");
  2222. return false;
  2223. }
  2224. // Compute full path for old and new names.
  2225. std::string oldname = args[1];
  2226. if(!cmsys::SystemTools::FileIsFullPath(oldname.c_str()))
  2227. {
  2228. oldname = this->Makefile->GetCurrentDirectory();
  2229. oldname += "/" + args[1];
  2230. }
  2231. std::string newname = args[2];
  2232. if(!cmsys::SystemTools::FileIsFullPath(newname.c_str()))
  2233. {
  2234. newname = this->Makefile->GetCurrentDirectory();
  2235. newname += "/" + args[2];
  2236. }
  2237. if(!cmSystemTools::RenameFile(oldname.c_str(), newname.c_str()))
  2238. {
  2239. std::string err = cmSystemTools::GetLastSystemError();
  2240. cmOStringStream e;
  2241. e << "RENAME failed to rename\n"
  2242. << " " << oldname << "\n"
  2243. << "to\n"
  2244. << " " << newname << "\n"
  2245. << "because: " << err << "\n";
  2246. this->SetError(e.str());
  2247. return false;
  2248. }
  2249. return true;
  2250. }
  2251. //----------------------------------------------------------------------------
  2252. bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
  2253. bool recurse)
  2254. {
  2255. std::string message;
  2256. std::vector<std::string>::const_iterator i = args.begin();
  2257. i++; // Get rid of subcommand
  2258. for(;i != args.end(); ++i)
  2259. {
  2260. std::string fileName = *i;
  2261. if(!cmsys::SystemTools::FileIsFullPath(fileName.c_str()))
  2262. {
  2263. fileName = this->Makefile->GetCurrentDirectory();
  2264. fileName += "/" + *i;
  2265. }
  2266. if(cmSystemTools::FileIsDirectory(fileName.c_str()) &&
  2267. !cmSystemTools::FileIsSymlink(fileName.c_str()) && recurse)
  2268. {
  2269. cmSystemTools::RemoveADirectory(fileName.c_str());
  2270. }
  2271. else
  2272. {
  2273. cmSystemTools::RemoveFile(fileName.c_str());
  2274. }
  2275. }
  2276. return true;
  2277. }
  2278. //----------------------------------------------------------------------------
  2279. bool cmFileCommand::HandleCMakePathCommand(std::vector<std::string>
  2280. const& args,
  2281. bool nativePath)
  2282. {
  2283. std::vector<std::string>::const_iterator i = args.begin();
  2284. if(args.size() != 3)
  2285. {
  2286. this->SetError("FILE([TO_CMAKE_PATH|TO_NATIVE_PATH] path result) must be "
  2287. "called with exactly three arguments.");
  2288. return false;
  2289. }
  2290. i++; // Get rid of subcommand
  2291. #if defined(_WIN32) && !defined(__CYGWIN__)
  2292. char pathSep = ';';
  2293. #else
  2294. char pathSep = ':';
  2295. #endif
  2296. std::vector<cmsys::String> path = cmSystemTools::SplitString(i->c_str(),
  2297. pathSep);
  2298. i++;
  2299. const char* var = i->c_str();
  2300. std::string value;
  2301. for(std::vector<cmsys::String>::iterator j = path.begin();
  2302. j != path.end(); ++j)
  2303. {
  2304. if(j != path.begin())
  2305. {
  2306. value += ";";
  2307. }
  2308. if(!nativePath)
  2309. {
  2310. cmSystemTools::ConvertToUnixSlashes(*j);
  2311. }
  2312. else
  2313. {
  2314. *j = cmSystemTools::ConvertToOutputPath(j->c_str());
  2315. // remove double quotes in the path
  2316. cmsys::String& s = *j;
  2317. if(s.size() > 1 && s[0] == '\"' && s[s.size()-1] == '\"')
  2318. {
  2319. s = s.substr(1,s.size()-2);
  2320. }
  2321. }
  2322. value += *j;
  2323. }
  2324. this->Makefile->AddDefinition(var, value.c_str());
  2325. return true;
  2326. }
  2327. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2328. // Stuff for curl download/upload
  2329. typedef std::vector<char> cmFileCommandVectorOfChar;
  2330. namespace {
  2331. size_t
  2332. cmWriteToFileCallback(void *ptr, size_t size, size_t nmemb,
  2333. void *data)
  2334. {
  2335. int realsize = (int)(size * nmemb);
  2336. cmsys::ofstream* fout = static_cast<cmsys::ofstream*>(data);
  2337. const char* chPtr = static_cast<char*>(ptr);
  2338. fout->write(chPtr, realsize);
  2339. return realsize;
  2340. }
  2341. size_t
  2342. cmWriteToMemoryCallback(void *ptr, size_t size, size_t nmemb,
  2343. void *data)
  2344. {
  2345. int realsize = (int)(size * nmemb);
  2346. cmFileCommandVectorOfChar *vec
  2347. = static_cast<cmFileCommandVectorOfChar*>(data);
  2348. const char* chPtr = static_cast<char*>(ptr);
  2349. vec->insert(vec->end(), chPtr, chPtr + realsize);
  2350. return realsize;
  2351. }
  2352. static size_t
  2353. cmFileCommandCurlDebugCallback(CURL *, curl_infotype, char *chPtr,
  2354. size_t size, void *data)
  2355. {
  2356. cmFileCommandVectorOfChar *vec
  2357. = static_cast<cmFileCommandVectorOfChar*>(data);
  2358. vec->insert(vec->end(), chPtr, chPtr + size);
  2359. return size;
  2360. }
  2361. class cURLProgressHelper
  2362. {
  2363. public:
  2364. cURLProgressHelper(cmFileCommand *fc, const char *text)
  2365. {
  2366. this->CurrentPercentage = -1;
  2367. this->FileCommand = fc;
  2368. this->Text = text;
  2369. }
  2370. bool UpdatePercentage(double value, double total, std::string &status)
  2371. {
  2372. int OldPercentage = this->CurrentPercentage;
  2373. if (total > 0.0)
  2374. {
  2375. this->CurrentPercentage = static_cast<int>(value/total*100.0 + 0.5);
  2376. }
  2377. bool updated = (OldPercentage != this->CurrentPercentage);
  2378. if (updated)
  2379. {
  2380. cmOStringStream oss;
  2381. oss << "[" << this->Text << " " << this->CurrentPercentage
  2382. << "% complete]";
  2383. status = oss.str();
  2384. }
  2385. return updated;
  2386. }
  2387. cmFileCommand *GetFileCommand()
  2388. {
  2389. return this->FileCommand;
  2390. }
  2391. private:
  2392. int CurrentPercentage;
  2393. cmFileCommand *FileCommand;
  2394. std::string Text;
  2395. };
  2396. static int
  2397. cmFileDownloadProgressCallback(void *clientp,
  2398. double dltotal, double dlnow,
  2399. double ultotal, double ulnow)
  2400. {
  2401. cURLProgressHelper *helper =
  2402. reinterpret_cast<cURLProgressHelper *>(clientp);
  2403. static_cast<void>(ultotal);
  2404. static_cast<void>(ulnow);
  2405. std::string status;
  2406. if (helper->UpdatePercentage(dlnow, dltotal, status))
  2407. {
  2408. cmFileCommand *fc = helper->GetFileCommand();
  2409. cmMakefile *mf = fc->GetMakefile();
  2410. mf->DisplayStatus(status.c_str(), -1);
  2411. }
  2412. return 0;
  2413. }
  2414. static int
  2415. cmFileUploadProgressCallback(void *clientp,
  2416. double dltotal, double dlnow,
  2417. double ultotal, double ulnow)
  2418. {
  2419. cURLProgressHelper *helper =
  2420. reinterpret_cast<cURLProgressHelper *>(clientp);
  2421. static_cast<void>(dltotal);
  2422. static_cast<void>(dlnow);
  2423. std::string status;
  2424. if (helper->UpdatePercentage(ulnow, ultotal, status))
  2425. {
  2426. cmFileCommand *fc = helper->GetFileCommand();
  2427. cmMakefile *mf = fc->GetMakefile();
  2428. mf->DisplayStatus(status.c_str(), -1);
  2429. }
  2430. return 0;
  2431. }
  2432. }
  2433. namespace {
  2434. class cURLEasyGuard
  2435. {
  2436. public:
  2437. cURLEasyGuard(CURL * easy)
  2438. : Easy(easy)
  2439. {}
  2440. ~cURLEasyGuard(void)
  2441. {
  2442. if (this->Easy)
  2443. {
  2444. ::curl_easy_cleanup(this->Easy);
  2445. }
  2446. }
  2447. inline void release(void)
  2448. {
  2449. this->Easy = 0;
  2450. return;
  2451. }
  2452. private:
  2453. ::CURL * Easy;
  2454. };
  2455. }
  2456. #endif
  2457. #define check_curl_result(result, errstr) \
  2458. if (result != CURLE_OK) \
  2459. { \
  2460. std::string e(errstr); \
  2461. e += ::curl_easy_strerror(result); \
  2462. this->SetError(e); \
  2463. return false; \
  2464. }
  2465. bool
  2466. cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
  2467. {
  2468. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2469. std::vector<std::string>::const_iterator i = args.begin();
  2470. if(args.size() < 3)
  2471. {
  2472. this->SetError("DOWNLOAD must be called with at least three arguments.");
  2473. return false;
  2474. }
  2475. ++i; // Get rid of subcommand
  2476. std::string url = *i;
  2477. ++i;
  2478. std::string file = *i;
  2479. ++i;
  2480. long timeout = 0;
  2481. long inactivity_timeout = 0;
  2482. std::string verboseLog;
  2483. std::string statusVar;
  2484. bool tls_verify = this->Makefile->IsOn("CMAKE_TLS_VERIFY");
  2485. const char* cainfo = this->Makefile->GetDefinition("CMAKE_TLS_CAINFO");
  2486. std::string expectedHash;
  2487. std::string hashMatchMSG;
  2488. cmsys::auto_ptr<cmCryptoHash> hash;
  2489. bool showProgress = false;
  2490. while(i != args.end())
  2491. {
  2492. if(*i == "TIMEOUT")
  2493. {
  2494. ++i;
  2495. if(i != args.end())
  2496. {
  2497. timeout = atol(i->c_str());
  2498. }
  2499. else
  2500. {
  2501. this->SetError("DOWNLOAD missing time for TIMEOUT.");
  2502. return false;
  2503. }
  2504. }
  2505. else if(*i == "INACTIVITY_TIMEOUT")
  2506. {
  2507. ++i;
  2508. if(i != args.end())
  2509. {
  2510. inactivity_timeout = atol(i->c_str());
  2511. }
  2512. else
  2513. {
  2514. this->SetError("DOWNLOAD missing time for INACTIVITY_TIMEOUT.");
  2515. return false;
  2516. }
  2517. }
  2518. else if(*i == "LOG")
  2519. {
  2520. ++i;
  2521. if( i == args.end())
  2522. {
  2523. this->SetError("DOWNLOAD missing VAR for LOG.");
  2524. return false;
  2525. }
  2526. verboseLog = *i;
  2527. }
  2528. else if(*i == "STATUS")
  2529. {
  2530. ++i;
  2531. if( i == args.end())
  2532. {
  2533. this->SetError("DOWNLOAD missing VAR for STATUS.");
  2534. return false;
  2535. }
  2536. statusVar = *i;
  2537. }
  2538. else if(*i == "TLS_VERIFY")
  2539. {
  2540. ++i;
  2541. if(i != args.end())
  2542. {
  2543. tls_verify = cmSystemTools::IsOn(i->c_str());
  2544. }
  2545. else
  2546. {
  2547. this->SetError("TLS_VERIFY missing bool value.");
  2548. return false;
  2549. }
  2550. }
  2551. else if(*i == "TLS_CAINFO")
  2552. {
  2553. ++i;
  2554. if(i != args.end())
  2555. {
  2556. cainfo = i->c_str();
  2557. }
  2558. else
  2559. {
  2560. this->SetError("TLS_CAFILE missing file value.");
  2561. return false;
  2562. }
  2563. }
  2564. else if(*i == "EXPECTED_MD5")
  2565. {
  2566. ++i;
  2567. if( i == args.end())
  2568. {
  2569. this->SetError("DOWNLOAD missing sum value for EXPECTED_MD5.");
  2570. return false;
  2571. }
  2572. hash = cmsys::auto_ptr<cmCryptoHash>(cmCryptoHash::New("MD5"));
  2573. hashMatchMSG = "MD5 sum";
  2574. expectedHash = cmSystemTools::LowerCase(*i);
  2575. }
  2576. else if(*i == "SHOW_PROGRESS")
  2577. {
  2578. showProgress = true;
  2579. }
  2580. else if(*i == "EXPECTED_HASH")
  2581. {
  2582. ++i;
  2583. if(i == args.end())
  2584. {
  2585. this->SetError("DOWNLOAD missing ALGO=value for EXPECTED_HASH.");
  2586. return false;
  2587. }
  2588. std::string::size_type pos = i->find("=");
  2589. if(pos == std::string::npos)
  2590. {
  2591. std::string err =
  2592. "DOWNLOAD EXPECTED_HASH expects ALGO=value but got: ";
  2593. err += *i;
  2594. this->SetError(err);
  2595. return false;
  2596. }
  2597. std::string algo = i->substr(0, pos);
  2598. expectedHash = cmSystemTools::LowerCase(i->substr(pos+1));
  2599. hash = cmsys::auto_ptr<cmCryptoHash>(cmCryptoHash::New(algo.c_str()));
  2600. if(!hash.get())
  2601. {
  2602. std::string err = "DOWNLOAD EXPECTED_HASH given unknown ALGO: ";
  2603. err += algo;
  2604. this->SetError(err);
  2605. return false;
  2606. }
  2607. hashMatchMSG = algo + " hash";
  2608. }
  2609. ++i;
  2610. }
  2611. // If file exists already, and caller specified an expected md5 or sha,
  2612. // and the existing file already has the expected hash, then simply
  2613. // return.
  2614. //
  2615. if(cmSystemTools::FileExists(file.c_str()) && hash.get())
  2616. {
  2617. std::string msg;
  2618. std::string actualHash = hash->HashFile(file);
  2619. if(actualHash == expectedHash)
  2620. {
  2621. msg = "returning early; file already exists with expected ";
  2622. msg += hashMatchMSG;
  2623. msg += "\"";
  2624. if(statusVar.size())
  2625. {
  2626. cmOStringStream result;
  2627. result << (int)0 << ";\"" << msg;
  2628. this->Makefile->AddDefinition(statusVar,
  2629. result.str().c_str());
  2630. }
  2631. return true;
  2632. }
  2633. }
  2634. // Make sure parent directory exists so we can write to the file
  2635. // as we receive downloaded bits from curl...
  2636. //
  2637. std::string dir = cmSystemTools::GetFilenamePath(file);
  2638. if(!cmSystemTools::FileExists(dir.c_str()) &&
  2639. !cmSystemTools::MakeDirectory(dir.c_str()))
  2640. {
  2641. std::string errstring = "DOWNLOAD error: cannot create directory '"
  2642. + dir + "' - Specify file by full path name and verify that you "
  2643. "have directory creation and file write privileges.";
  2644. this->SetError(errstring);
  2645. return false;
  2646. }
  2647. cmsys::ofstream fout(file.c_str(), std::ios::binary);
  2648. if(!fout)
  2649. {
  2650. this->SetError("DOWNLOAD cannot open file for write.");
  2651. return false;
  2652. }
  2653. ::CURL *curl;
  2654. ::curl_global_init(CURL_GLOBAL_DEFAULT);
  2655. curl = ::curl_easy_init();
  2656. if(!curl)
  2657. {
  2658. this->SetError("DOWNLOAD error initializing curl.");
  2659. return false;
  2660. }
  2661. cURLEasyGuard g_curl(curl);
  2662. ::CURLcode res = ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  2663. check_curl_result(res, "DOWNLOAD cannot set url: ");
  2664. // enable HTTP ERROR parsing
  2665. res = ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
  2666. check_curl_result(res, "DOWNLOAD cannot set http failure option: ");
  2667. res = ::curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/" LIBCURL_VERSION);
  2668. check_curl_result(res, "DOWNLOAD cannot set user agent option: ");
  2669. res = ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  2670. cmWriteToFileCallback);
  2671. check_curl_result(res, "DOWNLOAD cannot set write function: ");
  2672. res = ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  2673. cmFileCommandCurlDebugCallback);
  2674. check_curl_result(res, "DOWNLOAD cannot set debug function: ");
  2675. // check to see if TLS verification is requested
  2676. if(tls_verify)
  2677. {
  2678. res = ::curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
  2679. check_curl_result(res, "Unable to set TLS/SSL Verify on: ");
  2680. }
  2681. else
  2682. {
  2683. res = ::curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
  2684. check_curl_result(res, "Unable to set TLS/SSL Verify off: ");
  2685. }
  2686. // check to see if a CAINFO file has been specified
  2687. // command arg comes first
  2688. if(cainfo && *cainfo)
  2689. {
  2690. res = ::curl_easy_setopt(curl, CURLOPT_CAINFO, cainfo);
  2691. check_curl_result(res, "Unable to set TLS/SSL Verify CAINFO: ");
  2692. }
  2693. cmFileCommandVectorOfChar chunkDebug;
  2694. res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&fout);
  2695. check_curl_result(res, "DOWNLOAD cannot set write data: ");
  2696. res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
  2697. check_curl_result(res, "DOWNLOAD cannot set debug data: ");
  2698. res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  2699. check_curl_result(res, "DOWNLOAD cannot set follow-redirect option: ");
  2700. if(verboseLog.size())
  2701. {
  2702. res = ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  2703. check_curl_result(res, "DOWNLOAD cannot set verbose: ");
  2704. }
  2705. if(timeout > 0)
  2706. {
  2707. res = ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout );
  2708. check_curl_result(res, "DOWNLOAD cannot set timeout: ");
  2709. }
  2710. if(inactivity_timeout > 0)
  2711. {
  2712. // Give up if there is no progress for a long time.
  2713. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
  2714. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, inactivity_timeout);
  2715. }
  2716. // Need the progress helper's scope to last through the duration of
  2717. // the curl_easy_perform call... so this object is declared at function
  2718. // scope intentionally, rather than inside the "if(showProgress)"
  2719. // block...
  2720. //
  2721. cURLProgressHelper helper(this, "download");
  2722. if(showProgress)
  2723. {
  2724. res = ::curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
  2725. check_curl_result(res, "DOWNLOAD cannot set noprogress value: ");
  2726. res = ::curl_easy_setopt(curl,
  2727. CURLOPT_PROGRESSFUNCTION, cmFileDownloadProgressCallback);
  2728. check_curl_result(res, "DOWNLOAD cannot set progress function: ");
  2729. res = ::curl_easy_setopt(curl,
  2730. CURLOPT_PROGRESSDATA, reinterpret_cast<void*>(&helper));
  2731. check_curl_result(res, "DOWNLOAD cannot set progress data: ");
  2732. }
  2733. res = ::curl_easy_perform(curl);
  2734. /* always cleanup */
  2735. g_curl.release();
  2736. ::curl_easy_cleanup(curl);
  2737. if(statusVar.size())
  2738. {
  2739. cmOStringStream result;
  2740. result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\"";
  2741. this->Makefile->AddDefinition(statusVar,
  2742. result.str().c_str());
  2743. }
  2744. ::curl_global_cleanup();
  2745. // Explicitly flush/close so we can measure the md5 accurately.
  2746. //
  2747. fout.flush();
  2748. fout.close();
  2749. // Verify MD5 sum if requested:
  2750. //
  2751. if (hash.get())
  2752. {
  2753. std::string actualHash = hash->HashFile(file);
  2754. if (actualHash.size() == 0)
  2755. {
  2756. this->SetError("DOWNLOAD cannot compute hash on downloaded file");
  2757. return false;
  2758. }
  2759. if (expectedHash != actualHash)
  2760. {
  2761. cmOStringStream oss;
  2762. oss << "DOWNLOAD HASH mismatch" << std::endl
  2763. << " for file: [" << file << "]" << std::endl
  2764. << " expected hash: [" << expectedHash << "]" << std::endl
  2765. << " actual hash: [" << actualHash << "]" << std::endl
  2766. << " status: [" << (int)res << ";\""
  2767. << ::curl_easy_strerror(res) << "\"]" << std::endl
  2768. ;
  2769. this->SetError(oss.str());
  2770. return false;
  2771. }
  2772. }
  2773. if(chunkDebug.size())
  2774. {
  2775. chunkDebug.push_back(0);
  2776. if(CURLE_OPERATION_TIMEOUTED == res)
  2777. {
  2778. std::string output = &*chunkDebug.begin();
  2779. if(verboseLog.size())
  2780. {
  2781. this->Makefile->AddDefinition(verboseLog,
  2782. &*chunkDebug.begin());
  2783. }
  2784. }
  2785. this->Makefile->AddDefinition(verboseLog,
  2786. &*chunkDebug.begin());
  2787. }
  2788. return true;
  2789. #else
  2790. this->SetError("DOWNLOAD not supported by bootstrap cmake.");
  2791. return false;
  2792. #endif
  2793. }
  2794. bool
  2795. cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
  2796. {
  2797. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2798. if(args.size() < 3)
  2799. {
  2800. this->SetError("UPLOAD must be called with at least three arguments.");
  2801. return false;
  2802. }
  2803. std::vector<std::string>::const_iterator i = args.begin();
  2804. ++i;
  2805. std::string filename = *i;
  2806. ++i;
  2807. std::string url = *i;
  2808. ++i;
  2809. long timeout = 0;
  2810. long inactivity_timeout = 0;
  2811. std::string logVar;
  2812. std::string statusVar;
  2813. bool showProgress = false;
  2814. while(i != args.end())
  2815. {
  2816. if(*i == "TIMEOUT")
  2817. {
  2818. ++i;
  2819. if(i != args.end())
  2820. {
  2821. timeout = atol(i->c_str());
  2822. }
  2823. else
  2824. {
  2825. this->SetError("UPLOAD missing time for TIMEOUT.");
  2826. return false;
  2827. }
  2828. }
  2829. else if(*i == "INACTIVITY_TIMEOUT")
  2830. {
  2831. ++i;
  2832. if(i != args.end())
  2833. {
  2834. inactivity_timeout = atol(i->c_str());
  2835. }
  2836. else
  2837. {
  2838. this->SetError("UPLOAD missing time for INACTIVITY_TIMEOUT.");
  2839. return false;
  2840. }
  2841. }
  2842. else if(*i == "LOG")
  2843. {
  2844. ++i;
  2845. if( i == args.end())
  2846. {
  2847. this->SetError("UPLOAD missing VAR for LOG.");
  2848. return false;
  2849. }
  2850. logVar = *i;
  2851. }
  2852. else if(*i == "STATUS")
  2853. {
  2854. ++i;
  2855. if( i == args.end())
  2856. {
  2857. this->SetError("UPLOAD missing VAR for STATUS.");
  2858. return false;
  2859. }
  2860. statusVar = *i;
  2861. }
  2862. else if(*i == "SHOW_PROGRESS")
  2863. {
  2864. showProgress = true;
  2865. }
  2866. ++i;
  2867. }
  2868. // Open file for reading:
  2869. //
  2870. FILE *fin = cmsys::SystemTools::Fopen(filename.c_str(), "rb");
  2871. if(!fin)
  2872. {
  2873. std::string errStr = "UPLOAD cannot open file '";
  2874. errStr += filename + "' for reading.";
  2875. this->SetError(errStr);
  2876. return false;
  2877. }
  2878. struct stat st;
  2879. if(::stat(filename.c_str(), &st))
  2880. {
  2881. std::string errStr = "UPLOAD cannot stat file '";
  2882. errStr += filename + "'.";
  2883. this->SetError(errStr);
  2884. fclose(fin);
  2885. return false;
  2886. }
  2887. ::CURL *curl;
  2888. ::curl_global_init(CURL_GLOBAL_DEFAULT);
  2889. curl = ::curl_easy_init();
  2890. if(!curl)
  2891. {
  2892. this->SetError("UPLOAD error initializing curl.");
  2893. fclose(fin);
  2894. return false;
  2895. }
  2896. cURLEasyGuard g_curl(curl);
  2897. // enable HTTP ERROR parsing
  2898. ::CURLcode res = ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
  2899. // enable uploading
  2900. res = ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  2901. check_curl_result(res, "UPLOAD cannot set upload flag: ");
  2902. res = ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  2903. check_curl_result(res, "UPLOAD cannot set url: ");
  2904. res = ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  2905. cmWriteToMemoryCallback);
  2906. check_curl_result(res, "UPLOAD cannot set write function: ");
  2907. res = ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  2908. cmFileCommandCurlDebugCallback);
  2909. check_curl_result(res, "UPLOAD cannot set debug function: ");
  2910. cmFileCommandVectorOfChar chunkResponse;
  2911. cmFileCommandVectorOfChar chunkDebug;
  2912. res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunkResponse);
  2913. check_curl_result(res, "UPLOAD cannot set write data: ");
  2914. res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
  2915. check_curl_result(res, "UPLOAD cannot set debug data: ");
  2916. res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  2917. check_curl_result(res, "UPLOAD cannot set follow-redirect option: ");
  2918. if(logVar.size())
  2919. {
  2920. res = ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  2921. check_curl_result(res, "UPLOAD cannot set verbose: ");
  2922. }
  2923. if(timeout > 0)
  2924. {
  2925. res = ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout );
  2926. check_curl_result(res, "UPLOAD cannot set timeout: ");
  2927. }
  2928. if(inactivity_timeout > 0)
  2929. {
  2930. // Give up if there is no progress for a long time.
  2931. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
  2932. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, inactivity_timeout);
  2933. }
  2934. // Need the progress helper's scope to last through the duration of
  2935. // the curl_easy_perform call... so this object is declared at function
  2936. // scope intentionally, rather than inside the "if(showProgress)"
  2937. // block...
  2938. //
  2939. cURLProgressHelper helper(this, "upload");
  2940. if(showProgress)
  2941. {
  2942. res = ::curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
  2943. check_curl_result(res, "UPLOAD cannot set noprogress value: ");
  2944. res = ::curl_easy_setopt(curl,
  2945. CURLOPT_PROGRESSFUNCTION, cmFileUploadProgressCallback);
  2946. check_curl_result(res, "UPLOAD cannot set progress function: ");
  2947. res = ::curl_easy_setopt(curl,
  2948. CURLOPT_PROGRESSDATA, reinterpret_cast<void*>(&helper));
  2949. check_curl_result(res, "UPLOAD cannot set progress data: ");
  2950. }
  2951. // now specify which file to upload
  2952. res = ::curl_easy_setopt(curl, CURLOPT_INFILE, fin);
  2953. check_curl_result(res, "UPLOAD cannot set input file: ");
  2954. // and give the size of the upload (optional)
  2955. res = ::curl_easy_setopt(curl,
  2956. CURLOPT_INFILESIZE, static_cast<long>(st.st_size));
  2957. check_curl_result(res, "UPLOAD cannot set input file size: ");
  2958. res = ::curl_easy_perform(curl);
  2959. /* always cleanup */
  2960. g_curl.release();
  2961. ::curl_easy_cleanup(curl);
  2962. if(statusVar.size())
  2963. {
  2964. cmOStringStream result;
  2965. result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\"";
  2966. this->Makefile->AddDefinition(statusVar,
  2967. result.str().c_str());
  2968. }
  2969. ::curl_global_cleanup();
  2970. fclose(fin);
  2971. fin = NULL;
  2972. if(logVar.size())
  2973. {
  2974. std::string log;
  2975. if(chunkResponse.size())
  2976. {
  2977. chunkResponse.push_back(0);
  2978. log += "Response:\n";
  2979. log += &*chunkResponse.begin();
  2980. log += "\n";
  2981. }
  2982. if(chunkDebug.size())
  2983. {
  2984. chunkDebug.push_back(0);
  2985. log += "Debug:\n";
  2986. log += &*chunkDebug.begin();
  2987. log += "\n";
  2988. }
  2989. this->Makefile->AddDefinition(logVar, log.c_str());
  2990. }
  2991. return true;
  2992. #else
  2993. this->SetError("UPLOAD not supported by bootstrap cmake.");
  2994. return false;
  2995. #endif
  2996. }
  2997. //----------------------------------------------------------------------------
  2998. void cmFileCommand::AddEvaluationFile(const std::string &inputName,
  2999. const std::string &outputExpr,
  3000. const std::string &condition,
  3001. bool inputIsContent
  3002. )
  3003. {
  3004. cmListFileBacktrace lfbt;
  3005. this->Makefile->GetBacktrace(lfbt);
  3006. cmGeneratorExpression outputGe(lfbt);
  3007. cmsys::auto_ptr<cmCompiledGeneratorExpression> outputCge
  3008. = outputGe.Parse(outputExpr);
  3009. cmGeneratorExpression conditionGe(lfbt);
  3010. cmsys::auto_ptr<cmCompiledGeneratorExpression> conditionCge
  3011. = conditionGe.Parse(condition);
  3012. this->Makefile->GetLocalGenerator()
  3013. ->GetGlobalGenerator()->AddEvaluationFile(inputName,
  3014. outputCge,
  3015. this->Makefile,
  3016. conditionCge,
  3017. inputIsContent);
  3018. }
  3019. //----------------------------------------------------------------------------
  3020. bool cmFileCommand::HandleGenerateCommand(
  3021. std::vector<std::string> const& args)
  3022. {
  3023. if (args.size() < 5)
  3024. {
  3025. this->SetError("Incorrect arguments to GENERATE subcommand.");
  3026. return false;
  3027. }
  3028. if (args[1] != "OUTPUT")
  3029. {
  3030. this->SetError("Incorrect arguments to GENERATE subcommand.");
  3031. return false;
  3032. }
  3033. std::string condition;
  3034. if (args.size() > 5)
  3035. {
  3036. if (args[5] != "CONDITION")
  3037. {
  3038. this->SetError("Incorrect arguments to GENERATE subcommand.");
  3039. return false;
  3040. }
  3041. if (args.size() != 7)
  3042. {
  3043. this->SetError("Incorrect arguments to GENERATE subcommand.");
  3044. return false;
  3045. }
  3046. condition = args[6];
  3047. if (condition.empty())
  3048. {
  3049. this->SetError("CONDITION of sub-command GENERATE must not be empty if "
  3050. "specified.");
  3051. return false;
  3052. }
  3053. }
  3054. std::string output = args[2];
  3055. const bool inputIsContent = args[3] != "INPUT";
  3056. if (inputIsContent && args[3] != "CONTENT")
  3057. {
  3058. this->SetError("Incorrect arguments to GENERATE subcommand.");
  3059. return false;
  3060. }
  3061. std::string input = args[4];
  3062. this->AddEvaluationFile(input, output, condition, inputIsContent);
  3063. return true;
  3064. }
  3065. //----------------------------------------------------------------------------
  3066. bool cmFileCommand::HandleTimestampCommand(
  3067. std::vector<std::string> const& args)
  3068. {
  3069. if(args.size() < 3)
  3070. {
  3071. this->SetError("sub-command TIMESTAMP requires at least two arguments.");
  3072. return false;
  3073. }
  3074. else if(args.size() > 5)
  3075. {
  3076. this->SetError("sub-command TIMESTAMP takes at most four arguments.");
  3077. return false;
  3078. }
  3079. unsigned int argsIndex = 1;
  3080. const std::string& filename = args[argsIndex++];
  3081. const std::string& outputVariable = args[argsIndex++];
  3082. std::string formatString;
  3083. if(args.size() > argsIndex && args[argsIndex] != "UTC")
  3084. {
  3085. formatString = args[argsIndex++];
  3086. }
  3087. bool utcFlag = false;
  3088. if(args.size() > argsIndex)
  3089. {
  3090. if(args[argsIndex] == "UTC")
  3091. {
  3092. utcFlag = true;
  3093. }
  3094. else
  3095. {
  3096. std::string e = " TIMESTAMP sub-command does not recognize option " +
  3097. args[argsIndex] + ".";
  3098. this->SetError(e);
  3099. return false;
  3100. }
  3101. }
  3102. cmTimestamp timestamp;
  3103. std::string result = timestamp.FileModificationTime(
  3104. filename.c_str(), formatString, utcFlag);
  3105. this->Makefile->AddDefinition(outputVariable, result.c_str());
  3106. return true;
  3107. }