cmCPackGenerator.cxx 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  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 "cmCPackGenerator.h"
  11. #include "cmMakefile.h"
  12. #include "cmCPackLog.h"
  13. #include "cmake.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmLocalGenerator.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmCPackComponentGroup.h"
  18. #include "cmXMLSafe.h"
  19. #include <cmsys/SystemTools.hxx>
  20. #include <cmsys/Glob.hxx>
  21. #include <cmsys/FStream.hxx>
  22. #include <algorithm>
  23. #include <list>
  24. #if defined(__HAIKU__)
  25. #include <FindDirectory.h>
  26. #include <StorageDefs.h>
  27. #endif
  28. //----------------------------------------------------------------------
  29. cmCPackGenerator::cmCPackGenerator()
  30. {
  31. this->GeneratorVerbose = cmSystemTools::OUTPUT_NONE;
  32. this->MakefileMap = 0;
  33. this->Logger = 0;
  34. this->componentPackageMethod = ONE_PACKAGE_PER_GROUP;
  35. }
  36. //----------------------------------------------------------------------
  37. cmCPackGenerator::~cmCPackGenerator()
  38. {
  39. this->MakefileMap = 0;
  40. }
  41. //----------------------------------------------------------------------
  42. void cmCPackGeneratorProgress(const char *msg, float prog, void* ptr)
  43. {
  44. cmCPackGenerator* self = static_cast<cmCPackGenerator*>(ptr);
  45. self->DisplayVerboseOutput(msg, prog);
  46. }
  47. //----------------------------------------------------------------------
  48. void cmCPackGenerator::DisplayVerboseOutput(const char* msg,
  49. float progress)
  50. {
  51. (void)progress;
  52. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "" << msg << std::endl);
  53. }
  54. //----------------------------------------------------------------------
  55. int cmCPackGenerator::PrepareNames()
  56. {
  57. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  58. "Create temp directory." << std::endl);
  59. // checks CPACK_SET_DESTDIR support
  60. if (IsOn("CPACK_SET_DESTDIR"))
  61. {
  62. if (SETDESTDIR_UNSUPPORTED==SupportsSetDestdir())
  63. {
  64. cmCPackLogger(cmCPackLog::LOG_ERROR,
  65. "CPACK_SET_DESTDIR is set to ON but the '"
  66. << Name << "' generator does NOT support it."
  67. << std::endl);
  68. return 0;
  69. }
  70. else if (SETDESTDIR_SHOULD_NOT_BE_USED==SupportsSetDestdir())
  71. {
  72. cmCPackLogger(cmCPackLog::LOG_WARNING,
  73. "CPACK_SET_DESTDIR is set to ON but it is "
  74. << "usually a bad idea to do that with '"
  75. << Name << "' generator. Use at your own risk."
  76. << std::endl);
  77. }
  78. }
  79. std::string tempDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  80. tempDirectory += "/_CPack_Packages/";
  81. const char* toplevelTag = this->GetOption("CPACK_TOPLEVEL_TAG");
  82. if ( toplevelTag )
  83. {
  84. tempDirectory += toplevelTag;
  85. tempDirectory += "/";
  86. }
  87. tempDirectory += this->GetOption("CPACK_GENERATOR");
  88. std::string topDirectory = tempDirectory;
  89. const char* pfname = this->GetOption("CPACK_PACKAGE_FILE_NAME");
  90. if(!pfname)
  91. {
  92. cmCPackLogger(cmCPackLog::LOG_ERROR,
  93. "CPACK_PACKAGE_FILE_NAME not specified" << std::endl);
  94. return 0;
  95. }
  96. std::string outName = pfname;
  97. tempDirectory += "/" + outName;
  98. if(!this->GetOutputExtension())
  99. {
  100. cmCPackLogger(cmCPackLog::LOG_ERROR,
  101. "No output extension specified" << std::endl);
  102. return 0;
  103. }
  104. outName += this->GetOutputExtension();
  105. const char* pdir = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  106. if(!pdir)
  107. {
  108. cmCPackLogger(cmCPackLog::LOG_ERROR,
  109. "CPACK_PACKAGE_DIRECTORY not specified" << std::endl);
  110. return 0;
  111. }
  112. std::string destFile = pdir;
  113. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PREFIX", destFile.c_str());
  114. destFile += "/" + outName;
  115. std::string outFile = topDirectory + "/" + outName;
  116. this->SetOptionIfNotSet("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
  117. this->SetOptionIfNotSet("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
  118. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_NAME", outName.c_str());
  119. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PATH", destFile.c_str());
  120. this->SetOptionIfNotSet("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  121. outFile.c_str());
  122. this->SetOptionIfNotSet("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
  123. this->SetOptionIfNotSet("CPACK_NATIVE_INSTALL_DIRECTORY",
  124. cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str());
  125. this->SetOptionIfNotSet("CPACK_TEMPORARY_INSTALL_DIRECTORY",
  126. tempDirectory.c_str());
  127. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  128. "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl);
  129. const char* descFileName
  130. = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE");
  131. if ( descFileName )
  132. {
  133. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  134. "Look for: " << descFileName << std::endl);
  135. if ( !cmSystemTools::FileExists(descFileName) )
  136. {
  137. cmCPackLogger(cmCPackLog::LOG_ERROR,
  138. "Cannot find description file name: ["
  139. << descFileName << "]" << std::endl);
  140. return 0;
  141. }
  142. cmsys::ifstream ifs(descFileName);
  143. if ( !ifs )
  144. {
  145. cmCPackLogger(cmCPackLog::LOG_ERROR,
  146. "Cannot open description file name: " << descFileName << std::endl);
  147. return 0;
  148. }
  149. std::ostringstream ostr;
  150. std::string line;
  151. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  152. "Read description file: " << descFileName << std::endl);
  153. while ( ifs && cmSystemTools::GetLineFromStream(ifs, line) )
  154. {
  155. ostr << cmXMLSafe(line) << std::endl;
  156. }
  157. this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str());
  158. }
  159. if ( !this->GetOption("CPACK_PACKAGE_DESCRIPTION") )
  160. {
  161. cmCPackLogger(cmCPackLog::LOG_ERROR,
  162. "Project description not specified. Please specify "
  163. "CPACK_PACKAGE_DESCRIPTION or CPACK_PACKAGE_DESCRIPTION_FILE."
  164. << std::endl);
  165. return 0;
  166. }
  167. this->SetOptionIfNotSet("CPACK_REMOVE_TOPLEVEL_DIRECTORY", "1");
  168. return 1;
  169. }
  170. //----------------------------------------------------------------------
  171. int cmCPackGenerator::InstallProject()
  172. {
  173. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl);
  174. this->CleanTemporaryDirectory();
  175. std::string bareTempInstallDirectory
  176. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  177. std::string tempInstallDirectoryStr = bareTempInstallDirectory;
  178. bool setDestDir = cmSystemTools::IsOn(this->GetOption("CPACK_SET_DESTDIR"))
  179. | cmSystemTools::IsInternallyOn(
  180. this->GetOption("CPACK_SET_DESTDIR"));
  181. if (!setDestDir)
  182. {
  183. tempInstallDirectoryStr += this->GetPackagingInstallPrefix();
  184. }
  185. const char* tempInstallDirectory = tempInstallDirectoryStr.c_str();
  186. int res = 1;
  187. if ( !cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory.c_str()))
  188. {
  189. cmCPackLogger(cmCPackLog::LOG_ERROR,
  190. "Problem creating temporary directory: "
  191. << (tempInstallDirectory ? tempInstallDirectory : "(NULL)")
  192. << std::endl);
  193. return 0;
  194. }
  195. if ( setDestDir )
  196. {
  197. std::string destDir = "DESTDIR=";
  198. destDir += tempInstallDirectory;
  199. cmSystemTools::PutEnv(destDir);
  200. }
  201. else
  202. {
  203. // Make sure there is no destdir
  204. cmSystemTools::PutEnv("DESTDIR=");
  205. }
  206. // If the CPackConfig file sets CPACK_INSTALL_COMMANDS then run them
  207. // as listed
  208. if ( !this->InstallProjectViaInstallCommands(
  209. setDestDir, tempInstallDirectory) )
  210. {
  211. return 0;
  212. }
  213. // If the CPackConfig file sets CPACK_INSTALL_SCRIPT then run them
  214. // as listed
  215. if ( !this->InstallProjectViaInstallScript(
  216. setDestDir, tempInstallDirectory) )
  217. {
  218. return 0;
  219. }
  220. // If the CPackConfig file sets CPACK_INSTALLED_DIRECTORIES
  221. // then glob it and copy it to CPACK_TEMPORARY_DIRECTORY
  222. // This is used in Source packaging
  223. if ( !this->InstallProjectViaInstalledDirectories(
  224. setDestDir, tempInstallDirectory) )
  225. {
  226. return 0;
  227. }
  228. // If the project is a CMAKE project then run pre-install
  229. // and then read the cmake_install script to run it
  230. if ( !this->InstallProjectViaInstallCMakeProjects(
  231. setDestDir, bareTempInstallDirectory) )
  232. {
  233. return 0;
  234. }
  235. if ( setDestDir )
  236. {
  237. cmSystemTools::PutEnv("DESTDIR=");
  238. }
  239. return res;
  240. }
  241. //----------------------------------------------------------------------
  242. int cmCPackGenerator::InstallProjectViaInstallCommands(
  243. bool setDestDir, const std::string& tempInstallDirectory)
  244. {
  245. (void) setDestDir;
  246. const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
  247. if ( installCommands && *installCommands )
  248. {
  249. std::string tempInstallDirectoryEnv = "CMAKE_INSTALL_PREFIX=";
  250. tempInstallDirectoryEnv += tempInstallDirectory;
  251. cmSystemTools::PutEnv(tempInstallDirectoryEnv);
  252. std::vector<std::string> installCommandsVector;
  253. cmSystemTools::ExpandListArgument(installCommands,installCommandsVector);
  254. std::vector<std::string>::iterator it;
  255. for ( it = installCommandsVector.begin();
  256. it != installCommandsVector.end();
  257. ++it )
  258. {
  259. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << *it
  260. << std::endl);
  261. std::string output;
  262. int retVal = 1;
  263. bool resB = cmSystemTools::RunSingleCommand(
  264. it->c_str(), &output, &output,
  265. &retVal, 0, this->GeneratorVerbose, 0);
  266. if ( !resB || retVal )
  267. {
  268. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  269. tmpFile += "/InstallOutput.log";
  270. cmGeneratedFileStream ofs(tmpFile.c_str());
  271. ofs << "# Run command: " << *it << std::endl
  272. << "# Output:" << std::endl
  273. << output << std::endl;
  274. cmCPackLogger(cmCPackLog::LOG_ERROR,
  275. "Problem running install command: " << *it << std::endl
  276. << "Please check " << tmpFile << " for errors"
  277. << std::endl);
  278. return 0;
  279. }
  280. }
  281. }
  282. return 1;
  283. }
  284. //----------------------------------------------------------------------
  285. int cmCPackGenerator::InstallProjectViaInstalledDirectories(
  286. bool setDestDir, const std::string& tempInstallDirectory)
  287. {
  288. (void)setDestDir;
  289. (void)tempInstallDirectory;
  290. std::vector<cmsys::RegularExpression> ignoreFilesRegex;
  291. const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES");
  292. if ( cpackIgnoreFiles )
  293. {
  294. std::vector<std::string> ignoreFilesRegexString;
  295. cmSystemTools::ExpandListArgument(cpackIgnoreFiles,
  296. ignoreFilesRegexString);
  297. std::vector<std::string>::iterator it;
  298. for ( it = ignoreFilesRegexString.begin();
  299. it != ignoreFilesRegexString.end();
  300. ++it )
  301. {
  302. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  303. "Create ignore files regex for: " << *it << std::endl);
  304. ignoreFilesRegex.push_back(it->c_str());
  305. }
  306. }
  307. const char* installDirectories
  308. = this->GetOption("CPACK_INSTALLED_DIRECTORIES");
  309. if ( installDirectories && *installDirectories )
  310. {
  311. std::vector<std::string> installDirectoriesVector;
  312. cmSystemTools::ExpandListArgument(installDirectories,
  313. installDirectoriesVector);
  314. if ( installDirectoriesVector.size() % 2 != 0 )
  315. {
  316. cmCPackLogger(cmCPackLog::LOG_ERROR,
  317. "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> and "
  318. "<subdirectory>. The <subdirectory> can be '.' to be installed in "
  319. "the toplevel directory of installation." << std::endl);
  320. return 0;
  321. }
  322. std::vector<std::string>::iterator it;
  323. const std::string& tempDir = tempInstallDirectory;
  324. for ( it = installDirectoriesVector.begin();
  325. it != installDirectoriesVector.end();
  326. ++it )
  327. {
  328. std::list<std::pair<std::string,std::string> > symlinkedFiles;
  329. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  330. cmsys::Glob gl;
  331. std::string top = *it;
  332. it ++;
  333. std::string subdir = *it;
  334. std::string findExpr = top;
  335. findExpr += "/*";
  336. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  337. "- Install directory: " << top << std::endl);
  338. gl.RecurseOn();
  339. if ( !gl.FindFiles(findExpr) )
  340. {
  341. cmCPackLogger(cmCPackLog::LOG_ERROR,
  342. "Cannot find any files in the installed directory" << std::endl);
  343. return 0;
  344. }
  345. files = gl.GetFiles();
  346. std::vector<std::string>::iterator gfit;
  347. std::vector<cmsys::RegularExpression>::iterator regIt;
  348. for ( gfit = files.begin(); gfit != files.end(); ++ gfit )
  349. {
  350. bool skip = false;
  351. std::string &inFile = *gfit;
  352. for ( regIt= ignoreFilesRegex.begin();
  353. regIt!= ignoreFilesRegex.end();
  354. ++ regIt)
  355. {
  356. if ( regIt->find(inFile.c_str()) )
  357. {
  358. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Ignore file: "
  359. << inFile << std::endl);
  360. skip = true;
  361. }
  362. }
  363. if ( skip )
  364. {
  365. continue;
  366. }
  367. std::string filePath = tempDir;
  368. filePath += "/" + subdir + "/"
  369. + cmSystemTools::RelativePath(top.c_str(), gfit->c_str());
  370. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: "
  371. << inFile << " -> " << filePath << std::endl);
  372. /* If the file is a symlink we will have to re-create it */
  373. if ( cmSystemTools::FileIsSymlink(inFile))
  374. {
  375. std::string targetFile;
  376. std::string inFileRelative =
  377. cmSystemTools::RelativePath(top.c_str(),inFile.c_str());
  378. cmSystemTools::ReadSymlink(inFile,targetFile);
  379. symlinkedFiles.push_back(std::pair<std::string,
  380. std::string>(targetFile,inFileRelative));
  381. }
  382. /* If it is not a symlink then do a plain copy */
  383. else if (!(
  384. cmSystemTools::CopyFileIfDifferent(inFile.c_str(),filePath.c_str())
  385. &&
  386. cmSystemTools::CopyFileTime(inFile.c_str(),filePath.c_str())
  387. ) )
  388. {
  389. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: "
  390. << inFile << " -> " << filePath << std::endl);
  391. return 0;
  392. }
  393. }
  394. /* rebuild symlinks in the installed tree */
  395. if (!symlinkedFiles.empty())
  396. {
  397. std::list< std::pair<std::string,std::string> >::iterator symlinkedIt;
  398. std::string curDir = cmSystemTools::GetCurrentWorkingDirectory();
  399. std::string goToDir = tempDir;
  400. goToDir += "/"+subdir;
  401. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  402. "Change dir to: " << goToDir <<std::endl);
  403. cmSystemTools::ChangeDirectory(goToDir);
  404. for (symlinkedIt=symlinkedFiles.begin();
  405. symlinkedIt != symlinkedFiles.end();
  406. ++symlinkedIt)
  407. {
  408. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Will create a symlink: "
  409. << symlinkedIt->second << "--> "
  410. << symlinkedIt->first << std::endl);
  411. // make sure directory exists for symlink
  412. std::string destDir =
  413. cmSystemTools::GetFilenamePath(symlinkedIt->second);
  414. if(!destDir.empty() && !cmSystemTools::MakeDirectory(destDir))
  415. {
  416. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create dir: "
  417. << destDir
  418. << "\nTrying to create symlink: "
  419. << symlinkedIt->second << "--> "
  420. << symlinkedIt->first
  421. << std::endl);
  422. }
  423. if (!cmSystemTools::CreateSymlink(symlinkedIt->first,
  424. symlinkedIt->second))
  425. {
  426. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create symlink: "
  427. << symlinkedIt->second << "--> "
  428. << symlinkedIt->first << std::endl);
  429. return 0;
  430. }
  431. }
  432. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Going back to: "
  433. << curDir <<std::endl);
  434. cmSystemTools::ChangeDirectory(curDir);
  435. }
  436. }
  437. }
  438. return 1;
  439. }
  440. //----------------------------------------------------------------------
  441. int cmCPackGenerator::InstallProjectViaInstallScript(
  442. bool setDestDir, const std::string& tempInstallDirectory)
  443. {
  444. const char* cmakeScripts
  445. = this->GetOption("CPACK_INSTALL_SCRIPT");
  446. if ( cmakeScripts && *cmakeScripts )
  447. {
  448. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  449. "- Install scripts: " << cmakeScripts << std::endl);
  450. std::vector<std::string> cmakeScriptsVector;
  451. cmSystemTools::ExpandListArgument(cmakeScripts,
  452. cmakeScriptsVector);
  453. std::vector<std::string>::iterator it;
  454. for ( it = cmakeScriptsVector.begin();
  455. it != cmakeScriptsVector.end();
  456. ++it )
  457. {
  458. std::string installScript = *it;
  459. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  460. "- Install script: " << installScript << std::endl);
  461. if ( setDestDir )
  462. {
  463. // For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX
  464. // underneath the tempInstallDirectory. The value of the project's
  465. // CMAKE_INSTALL_PREFIX is sent in here as the value of the
  466. // CPACK_INSTALL_PREFIX variable.
  467. std::string dir;
  468. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  469. {
  470. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  471. }
  472. this->SetOption("CMAKE_INSTALL_PREFIX", dir.c_str());
  473. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  474. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (this->SetOption)"
  475. << std::endl);
  476. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  477. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" << std::endl);
  478. }
  479. else
  480. {
  481. this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str());
  482. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  483. "- Using non-DESTDIR install... (this->SetOption)" << std::endl);
  484. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  485. "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory
  486. << "'" << std::endl);
  487. }
  488. this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR",
  489. tempInstallDirectory.c_str());
  490. this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
  491. tempInstallDirectory.c_str());
  492. int res = this->MakefileMap->ReadListFile(installScript.c_str());
  493. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  494. {
  495. return 0;
  496. }
  497. }
  498. }
  499. return 1;
  500. }
  501. //----------------------------------------------------------------------
  502. int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
  503. bool setDestDir, const std::string& baseTempInstallDirectory)
  504. {
  505. const char* cmakeProjects
  506. = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
  507. const char* cmakeGenerator
  508. = this->GetOption("CPACK_CMAKE_GENERATOR");
  509. std::string absoluteDestFiles;
  510. if ( cmakeProjects && *cmakeProjects )
  511. {
  512. if ( !cmakeGenerator )
  513. {
  514. cmCPackLogger(cmCPackLog::LOG_ERROR,
  515. "CPACK_INSTALL_CMAKE_PROJECTS is specified, but "
  516. "CPACK_CMAKE_GENERATOR is not. CPACK_CMAKE_GENERATOR "
  517. "is required to install the project."
  518. << std::endl);
  519. return 0;
  520. }
  521. std::vector<std::string> cmakeProjectsVector;
  522. cmSystemTools::ExpandListArgument(cmakeProjects,
  523. cmakeProjectsVector);
  524. std::vector<std::string>::iterator it;
  525. for ( it = cmakeProjectsVector.begin();
  526. it != cmakeProjectsVector.end();
  527. ++it )
  528. {
  529. if ( it+1 == cmakeProjectsVector.end() ||
  530. it+2 == cmakeProjectsVector.end() ||
  531. it+3 == cmakeProjectsVector.end() )
  532. {
  533. cmCPackLogger(cmCPackLog::LOG_ERROR,
  534. "Not enough items on list: CPACK_INSTALL_CMAKE_PROJECTS. "
  535. "CPACK_INSTALL_CMAKE_PROJECTS should hold quadruplet of install "
  536. "directory, install project name, install component, and install "
  537. "subdirectory."
  538. << std::endl);
  539. return 0;
  540. }
  541. std::string installDirectory = *it;
  542. ++it;
  543. std::string installProjectName = *it;
  544. ++it;
  545. std::string installComponent = *it;
  546. ++it;
  547. std::string installSubDirectory = *it;
  548. std::string installFile = installDirectory + "/cmake_install.cmake";
  549. std::vector<std::string> componentsVector;
  550. bool componentInstall = false;
  551. /*
  552. * We do a component install iff
  553. * - the CPack generator support component
  554. * - the user did not request Monolithic install
  555. * (this works at CPack time too)
  556. */
  557. if (this->SupportsComponentInstallation() &
  558. !(this->IsOn("CPACK_MONOLITHIC_INSTALL")))
  559. {
  560. // Determine the installation types for this project (if provided).
  561. std::string installTypesVar = "CPACK_"
  562. + cmSystemTools::UpperCase(installComponent) + "_INSTALL_TYPES";
  563. const char *installTypes = this->GetOption(installTypesVar);
  564. if (installTypes && *installTypes)
  565. {
  566. std::vector<std::string> installTypesVector;
  567. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  568. std::vector<std::string>::iterator installTypeIt;
  569. for (installTypeIt = installTypesVector.begin();
  570. installTypeIt != installTypesVector.end();
  571. ++installTypeIt)
  572. {
  573. this->GetInstallationType(installProjectName,
  574. *installTypeIt);
  575. }
  576. }
  577. // Determine the set of components that will be used in this project
  578. std::string componentsVar
  579. = "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(installComponent);
  580. const char *components = this->GetOption(componentsVar);
  581. if (components && *components)
  582. {
  583. cmSystemTools::ExpandListArgument(components, componentsVector);
  584. std::vector<std::string>::iterator compIt;
  585. for (compIt = componentsVector.begin();
  586. compIt != componentsVector.end();
  587. ++compIt)
  588. {
  589. GetComponent(installProjectName, *compIt);
  590. }
  591. componentInstall = true;
  592. }
  593. }
  594. if (componentsVector.empty())
  595. {
  596. componentsVector.push_back(installComponent);
  597. }
  598. const char* buildConfigCstr = this->GetOption("CPACK_BUILD_CONFIG");
  599. std::string buildConfig = buildConfigCstr ? buildConfigCstr : "";
  600. cmGlobalGenerator* globalGenerator
  601. = this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
  602. cmakeGenerator);
  603. if ( !globalGenerator )
  604. {
  605. cmCPackLogger(cmCPackLog::LOG_ERROR,
  606. "Specified package generator not found. "
  607. "CPACK_CMAKE_GENERATOR value is invalid."
  608. << std::endl);
  609. return 0;
  610. }
  611. // set the global flag for unix style paths on cmSystemTools as
  612. // soon as the generator is set. This allows gmake to be used
  613. // on windows.
  614. cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths());
  615. // Does this generator require pre-install?
  616. if (const char* preinstall = globalGenerator->GetPreinstallTargetName())
  617. {
  618. std::string buildCommand =
  619. globalGenerator->GenerateCMakeBuildCommand(
  620. preinstall, buildConfig, "", false);
  621. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  622. "- Install command: " << buildCommand << std::endl);
  623. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  624. "- Run preinstall target for: " << installProjectName << std::endl);
  625. std::string output;
  626. int retVal = 1;
  627. bool resB =
  628. cmSystemTools::RunSingleCommand(buildCommand.c_str(),
  629. &output, &output,
  630. &retVal,
  631. installDirectory.c_str(),
  632. this->GeneratorVerbose, 0);
  633. if ( !resB || retVal )
  634. {
  635. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  636. tmpFile += "/PreinstallOutput.log";
  637. cmGeneratedFileStream ofs(tmpFile.c_str());
  638. ofs << "# Run command: " << buildCommand << std::endl
  639. << "# Directory: " << installDirectory << std::endl
  640. << "# Output:" << std::endl
  641. << output << std::endl;
  642. cmCPackLogger(cmCPackLog::LOG_ERROR,
  643. "Problem running install command: " << buildCommand
  644. << std::endl
  645. << "Please check " << tmpFile << " for errors"
  646. << std::endl);
  647. return 0;
  648. }
  649. }
  650. delete globalGenerator;
  651. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  652. "- Install project: " << installProjectName << std::endl);
  653. // Run the installation for each component
  654. std::vector<std::string>::iterator componentIt;
  655. for (componentIt = componentsVector.begin();
  656. componentIt != componentsVector.end();
  657. ++componentIt)
  658. {
  659. std::string tempInstallDirectory = baseTempInstallDirectory;
  660. installComponent = *componentIt;
  661. if (componentInstall)
  662. {
  663. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  664. "- Install component: " << installComponent
  665. << std::endl);
  666. }
  667. cmake cm;
  668. cm.AddCMakePaths();
  669. cm.SetProgressCallback(cmCPackGeneratorProgress, this);
  670. cmGlobalGenerator gg;
  671. gg.SetCMakeInstance(&cm);
  672. cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  673. cmMakefile *mf = lg->GetMakefile();
  674. std::string realInstallDirectory = tempInstallDirectory;
  675. if ( !installSubDirectory.empty() && installSubDirectory != "/" )
  676. {
  677. realInstallDirectory += installSubDirectory;
  678. }
  679. if (componentInstall)
  680. {
  681. tempInstallDirectory += "/";
  682. // Some CPack generators would rather chose
  683. // the local installation directory suffix.
  684. // Some (e.g. RPM) use
  685. // one install directory for each component **GROUP**
  686. // instead of the default
  687. // one install directory for each component.
  688. tempInstallDirectory +=
  689. GetComponentInstallDirNameSuffix(installComponent);
  690. if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY"))
  691. {
  692. tempInstallDirectory += "/";
  693. tempInstallDirectory += this->GetOption("CPACK_PACKAGE_FILE_NAME");
  694. }
  695. }
  696. if (!setDestDir)
  697. {
  698. tempInstallDirectory += this->GetPackagingInstallPrefix();
  699. }
  700. if ( setDestDir )
  701. {
  702. // For DESTDIR based packaging, use the *project*
  703. // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
  704. // value of the project's CMAKE_INSTALL_PREFIX is sent in here as
  705. // the value of the CPACK_INSTALL_PREFIX variable.
  706. //
  707. // If DESTDIR has been 'internally set ON' this means that
  708. // the underlying CPack specific generator did ask for that
  709. // In this case we may override CPACK_INSTALL_PREFIX with
  710. // CPACK_PACKAGING_INSTALL_PREFIX
  711. // I know this is tricky and awkward but it's the price for
  712. // CPACK_SET_DESTDIR backward compatibility.
  713. if (cmSystemTools::IsInternallyOn(
  714. this->GetOption("CPACK_SET_DESTDIR")))
  715. {
  716. this->SetOption("CPACK_INSTALL_PREFIX",
  717. this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX"));
  718. }
  719. std::string dir;
  720. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  721. {
  722. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  723. }
  724. mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str());
  725. cmCPackLogger(
  726. cmCPackLog::LOG_DEBUG,
  727. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)"
  728. << std::endl);
  729. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  730. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  731. << std::endl);
  732. // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory
  733. // exists:
  734. //
  735. if (cmSystemTools::StringStartsWith(dir.c_str(), "/"))
  736. {
  737. dir = tempInstallDirectory + dir;
  738. }
  739. else
  740. {
  741. dir = tempInstallDirectory + "/" + dir;
  742. }
  743. /*
  744. * We must re-set DESTDIR for each component
  745. * We must not add the CPACK_INSTALL_PREFIX part because
  746. * it will be added using the override of CMAKE_INSTALL_PREFIX
  747. * The main reason for this awkward trick is that
  748. * are using DESTDIR for 2 different reasons:
  749. * - Because it was asked by the CPack Generator or the user
  750. * using CPACK_SET_DESTDIR
  751. * - Because it was already used for component install
  752. * in order to put things in subdirs...
  753. */
  754. cmSystemTools::PutEnv(
  755. std::string("DESTDIR=")+tempInstallDirectory
  756. );
  757. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  758. "- Creating directory: '" << dir << "'" << std::endl);
  759. if ( !cmsys::SystemTools::MakeDirectory(dir.c_str()))
  760. {
  761. cmCPackLogger(cmCPackLog::LOG_ERROR,
  762. "Problem creating temporary directory: "
  763. << dir << std::endl);
  764. return 0;
  765. }
  766. }
  767. else
  768. {
  769. mf->AddDefinition("CMAKE_INSTALL_PREFIX",
  770. tempInstallDirectory.c_str());
  771. if ( !cmsys::SystemTools::MakeDirectory(
  772. tempInstallDirectory.c_str()))
  773. {
  774. cmCPackLogger(cmCPackLog::LOG_ERROR,
  775. "Problem creating temporary directory: "
  776. << tempInstallDirectory << std::endl);
  777. return 0;
  778. }
  779. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  780. "- Using non-DESTDIR install... (mf->AddDefinition)"
  781. << std::endl);
  782. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  783. "- Setting CMAKE_INSTALL_PREFIX to '"
  784. << tempInstallDirectory
  785. << "'" << std::endl);
  786. }
  787. if (!buildConfig.empty())
  788. {
  789. mf->AddDefinition("BUILD_TYPE", buildConfig.c_str());
  790. }
  791. std::string installComponentLowerCase
  792. = cmSystemTools::LowerCase(installComponent);
  793. if ( installComponentLowerCase != "all" )
  794. {
  795. mf->AddDefinition("CMAKE_INSTALL_COMPONENT",
  796. installComponent.c_str());
  797. }
  798. // strip on TRUE, ON, 1, one or several file names, but not on
  799. // FALSE, OFF, 0 and an empty string
  800. if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES")))
  801. {
  802. mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1");
  803. }
  804. // Remember the list of files before installation
  805. // of the current component (if we are in component install)
  806. const char* InstallPrefix = tempInstallDirectory.c_str();
  807. std::vector<std::string> filesBefore;
  808. std::string findExpr(InstallPrefix);
  809. if (componentInstall)
  810. {
  811. cmsys::Glob glB;
  812. findExpr += "/*";
  813. glB.RecurseOn();
  814. glB.FindFiles(findExpr);
  815. filesBefore = glB.GetFiles();
  816. std::sort(filesBefore.begin(),filesBefore.end());
  817. }
  818. // If CPack was asked to warn on ABSOLUTE INSTALL DESTINATION
  819. // then forward request to cmake_install.cmake script
  820. if (this->IsOn("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION"))
  821. {
  822. mf->AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION",
  823. "1");
  824. }
  825. // If current CPack generator does support
  826. // ABSOLUTE INSTALL DESTINATION or CPack has been asked for
  827. // then ask cmake_install.cmake script to error out
  828. // as soon as it occurs (before installing file)
  829. if (!SupportsAbsoluteDestination() ||
  830. this->IsOn("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION"))
  831. {
  832. mf->AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION",
  833. "1");
  834. }
  835. // do installation
  836. int res = mf->ReadListFile(installFile.c_str());
  837. // forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES
  838. // to CPack (may be used by generators like CPack RPM or DEB)
  839. // in order to transparently handle ABSOLUTE PATH
  840. if (mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES"))
  841. {
  842. mf->AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES",
  843. mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES"));
  844. }
  845. // Now rebuild the list of files after installation
  846. // of the current component (if we are in component install)
  847. if (componentInstall)
  848. {
  849. cmsys::Glob glA;
  850. glA.RecurseOn();
  851. glA.FindFiles(findExpr);
  852. std::vector<std::string> filesAfter = glA.GetFiles();
  853. std::sort(filesAfter.begin(),filesAfter.end());
  854. std::vector<std::string>::iterator diff;
  855. std::vector<std::string> result(filesAfter.size());
  856. diff = std::set_difference (
  857. filesAfter.begin(),filesAfter.end(),
  858. filesBefore.begin(),filesBefore.end(),
  859. result.begin());
  860. std::vector<std::string>::iterator fit;
  861. std::string localFileName;
  862. // Populate the File field of each component
  863. for (fit=result.begin();fit!=diff;++fit)
  864. {
  865. localFileName =
  866. cmSystemTools::RelativePath(InstallPrefix, fit->c_str());
  867. localFileName =
  868. localFileName.substr(localFileName.find_first_not_of('/'),
  869. std::string::npos);
  870. Components[installComponent].Files.push_back(localFileName);
  871. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file <"
  872. <<localFileName<<"> to component <"
  873. <<installComponent<<">"<<std::endl);
  874. }
  875. }
  876. if (NULL !=mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
  877. if (!absoluteDestFiles.empty()) {
  878. absoluteDestFiles +=";";
  879. }
  880. absoluteDestFiles +=
  881. mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES");
  882. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  883. "Got some ABSOLUTE DESTINATION FILES: "
  884. << absoluteDestFiles << std::endl);
  885. // define component specific var
  886. if (componentInstall)
  887. {
  888. std::string absoluteDestFileComponent =
  889. std::string("CPACK_ABSOLUTE_DESTINATION_FILES")
  890. + "_" + GetComponentInstallDirNameSuffix(installComponent);
  891. if (NULL != this->GetOption(absoluteDestFileComponent))
  892. {
  893. std::string absoluteDestFilesListComponent =
  894. this->GetOption(absoluteDestFileComponent);
  895. absoluteDestFilesListComponent +=";";
  896. absoluteDestFilesListComponent +=
  897. mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES");
  898. this->SetOption(absoluteDestFileComponent,
  899. absoluteDestFilesListComponent.c_str());
  900. }
  901. else
  902. {
  903. this->SetOption(absoluteDestFileComponent,
  904. mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"));
  905. }
  906. }
  907. }
  908. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  909. {
  910. return 0;
  911. }
  912. }
  913. }
  914. }
  915. this->SetOption("CPACK_ABSOLUTE_DESTINATION_FILES",
  916. absoluteDestFiles.c_str());
  917. return 1;
  918. }
  919. //----------------------------------------------------------------------
  920. bool cmCPackGenerator::ReadListFile(const char* moduleName)
  921. {
  922. bool retval;
  923. std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
  924. retval = this->MakefileMap->ReadListFile(fullPath.c_str());
  925. // include FATAL_ERROR and ERROR in the return status
  926. retval = retval && (! cmSystemTools::GetErrorOccuredFlag());
  927. return retval;
  928. }
  929. //----------------------------------------------------------------------
  930. void cmCPackGenerator::SetOptionIfNotSet(const std::string& op,
  931. const char* value)
  932. {
  933. const char* def = this->MakefileMap->GetDefinition(op);
  934. if ( def && *def )
  935. {
  936. return;
  937. }
  938. this->SetOption(op, value);
  939. }
  940. //----------------------------------------------------------------------
  941. void cmCPackGenerator::SetOption(const std::string& op, const char* value)
  942. {
  943. if ( !value )
  944. {
  945. this->MakefileMap->RemoveDefinition(op);
  946. return;
  947. }
  948. cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
  949. << "::SetOption(" << op << ", " << value << ")" << std::endl);
  950. this->MakefileMap->AddDefinition(op, value);
  951. }
  952. //----------------------------------------------------------------------
  953. int cmCPackGenerator::DoPackage()
  954. {
  955. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  956. "Create package using " << this->Name << std::endl);
  957. // Prepare CPack internal name and check
  958. // values for many CPACK_xxx vars
  959. if ( !this->PrepareNames() )
  960. {
  961. return 0;
  962. }
  963. // Digest Component grouping specification
  964. if ( !this->PrepareGroupingKind() )
  965. {
  966. return 0;
  967. }
  968. if ( cmSystemTools::IsOn(
  969. this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY")) )
  970. {
  971. const char* toplevelDirectory
  972. = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  973. if ( cmSystemTools::FileExists(toplevelDirectory) )
  974. {
  975. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  976. "Remove toplevel directory: "
  977. << toplevelDirectory << std::endl);
  978. if ( !cmSystemTools::RepeatedRemoveDirectory(toplevelDirectory) )
  979. {
  980. cmCPackLogger(cmCPackLog::LOG_ERROR,
  981. "Problem removing toplevel directory: "
  982. << toplevelDirectory
  983. << std::endl);
  984. return 0;
  985. }
  986. }
  987. }
  988. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  989. "About to install project " << std::endl);
  990. if ( !this->InstallProject() )
  991. {
  992. return 0;
  993. }
  994. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  995. "Done install project " << std::endl);
  996. const char* tempPackageFileName = this->GetOption(
  997. "CPACK_TEMPORARY_PACKAGE_FILE_NAME");
  998. const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  999. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  1000. cmsys::Glob gl;
  1001. std::string findExpr = tempDirectory;
  1002. findExpr += "/*";
  1003. gl.RecurseOn();
  1004. gl.SetRecurseThroughSymlinks(false);
  1005. if ( !gl.FindFiles(findExpr) )
  1006. {
  1007. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1008. "Cannot find any files in the packaging tree" << std::endl);
  1009. return 0;
  1010. }
  1011. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Create package" << std::endl);
  1012. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Package files to: "
  1013. << (tempPackageFileName ? tempPackageFileName : "(NULL)") << std::endl);
  1014. if ( cmSystemTools::FileExists(tempPackageFileName) )
  1015. {
  1016. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove old package file"
  1017. << std::endl);
  1018. cmSystemTools::RemoveFile(tempPackageFileName);
  1019. }
  1020. if ( cmSystemTools::IsOn(this->GetOption(
  1021. "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
  1022. {
  1023. tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  1024. }
  1025. // The files to be installed
  1026. files = gl.GetFiles();
  1027. packageFileNames.clear();
  1028. /* Put at least one file name into the list of
  1029. * wanted packageFileNames. The specific generator
  1030. * may update this during PackageFiles.
  1031. * (either putting several names or updating the provided one)
  1032. */
  1033. packageFileNames.push_back(tempPackageFileName ? tempPackageFileName : "");
  1034. toplevel = tempDirectory;
  1035. if ( !this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag())
  1036. {
  1037. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem compressing the directory"
  1038. << std::endl);
  1039. return 0;
  1040. }
  1041. /*
  1042. * Copy the generated packages to final destination
  1043. * - there may be several of them
  1044. * - the initially provided name may have changed
  1045. * (because the specific generator did 'normalize' it)
  1046. */
  1047. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copying final package(s) ["
  1048. <<packageFileNames.size()
  1049. <<"]:"<<std::endl);
  1050. std::vector<std::string>::iterator it;
  1051. /* now copy package one by one */
  1052. for (it=packageFileNames.begin();it!=packageFileNames.end();++it)
  1053. {
  1054. std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
  1055. tempPackageFileName = it->c_str();
  1056. tmpPF += "/"+cmSystemTools::GetFilenameName(*it);
  1057. const char* packageFileName = tmpPF.c_str();
  1058. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy final package(s): "
  1059. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  1060. << " to "
  1061. << (packageFileName ? packageFileName : "(NULL)")
  1062. << std::endl);
  1063. if ( !cmSystemTools::CopyFileIfDifferent(tempPackageFileName,
  1064. packageFileName) )
  1065. {
  1066. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the package: "
  1067. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  1068. << " to "
  1069. << (packageFileName ? packageFileName : "(NULL)")
  1070. << std::endl);
  1071. return 0;
  1072. }
  1073. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- package: "
  1074. << packageFileName
  1075. << " generated." << std::endl);
  1076. }
  1077. return 1;
  1078. }
  1079. //----------------------------------------------------------------------
  1080. int cmCPackGenerator::Initialize(const std::string& name, cmMakefile* mf)
  1081. {
  1082. this->MakefileMap = mf;
  1083. this->Name = name;
  1084. // set the running generator name
  1085. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  1086. // Load the project specific config file
  1087. const char* config =
  1088. this->GetOption("CPACK_PROJECT_CONFIG_FILE");
  1089. if(config)
  1090. {
  1091. mf->ReadListFile(config);
  1092. }
  1093. int result = this->InitializeInternal();
  1094. if (cmSystemTools::GetErrorOccuredFlag())
  1095. {
  1096. return 0;
  1097. }
  1098. // If a generator subclass did not already set this option in its
  1099. // InitializeInternal implementation, and the project did not already set
  1100. // it, the default value should be:
  1101. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
  1102. return result;
  1103. }
  1104. //----------------------------------------------------------------------
  1105. int cmCPackGenerator::InitializeInternal()
  1106. {
  1107. return 1;
  1108. }
  1109. //----------------------------------------------------------------------
  1110. bool cmCPackGenerator::IsSet(const std::string& name) const
  1111. {
  1112. return this->MakefileMap->IsSet(name);
  1113. }
  1114. //----------------------------------------------------------------------
  1115. bool cmCPackGenerator::IsOn(const std::string& name) const
  1116. {
  1117. return cmSystemTools::IsOn(GetOption(name));
  1118. }
  1119. //----------------------------------------------------------------------
  1120. const char* cmCPackGenerator::GetOption(const std::string& op) const
  1121. {
  1122. const char* ret = this->MakefileMap->GetDefinition(op);
  1123. if(!ret)
  1124. {
  1125. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1126. "Warning, GetOption return NULL for: "
  1127. << op
  1128. << std::endl);
  1129. }
  1130. return ret;
  1131. }
  1132. //----------------------------------------------------------------------
  1133. std::vector<std::string> cmCPackGenerator::GetOptions() const
  1134. {
  1135. return this->MakefileMap->GetDefinitions();
  1136. }
  1137. //----------------------------------------------------------------------
  1138. int cmCPackGenerator::PackageFiles()
  1139. {
  1140. return 0;
  1141. }
  1142. //----------------------------------------------------------------------
  1143. const char* cmCPackGenerator::GetInstallPath()
  1144. {
  1145. if ( !this->InstallPath.empty() )
  1146. {
  1147. return this->InstallPath.c_str();
  1148. }
  1149. #if defined(_WIN32) && !defined(__CYGWIN__)
  1150. const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles");
  1151. const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive");
  1152. if ( prgfiles )
  1153. {
  1154. this->InstallPath = prgfiles;
  1155. }
  1156. else if ( sysDrive )
  1157. {
  1158. this->InstallPath = sysDrive;
  1159. this->InstallPath += "/Program Files";
  1160. }
  1161. else
  1162. {
  1163. this->InstallPath = "c:/Program Files";
  1164. }
  1165. this->InstallPath += "/";
  1166. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  1167. this->InstallPath += "-";
  1168. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  1169. #elif defined(__HAIKU__)
  1170. char dir[B_PATH_NAME_LENGTH];
  1171. if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir)) == B_OK)
  1172. {
  1173. this->InstallPath = dir;
  1174. }
  1175. else
  1176. {
  1177. this->InstallPath = "/boot/system";
  1178. }
  1179. #else
  1180. this->InstallPath = "/usr/local/";
  1181. #endif
  1182. return this->InstallPath.c_str();
  1183. }
  1184. //----------------------------------------------------------------------
  1185. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  1186. {
  1187. cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '"
  1188. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" << std::endl);
  1189. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
  1190. }
  1191. //----------------------------------------------------------------------
  1192. std::string cmCPackGenerator::FindTemplate(const char* name)
  1193. {
  1194. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
  1195. << (name ? name : "(NULL)") << std::endl);
  1196. std::string ffile = this->MakefileMap->GetModulesFile(name);
  1197. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
  1198. << ffile << std::endl);
  1199. return ffile;
  1200. }
  1201. //----------------------------------------------------------------------
  1202. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  1203. std::string& outString)
  1204. {
  1205. this->MakefileMap->ConfigureString(inString,
  1206. outString, true, false);
  1207. return true;
  1208. }
  1209. //----------------------------------------------------------------------
  1210. bool cmCPackGenerator::ConfigureFile(const char* inName,
  1211. const char* outName, bool copyOnly /* = false */)
  1212. {
  1213. return this->MakefileMap->ConfigureFile(inName, outName,
  1214. copyOnly, true, false) == 1;
  1215. }
  1216. //----------------------------------------------------------------------
  1217. int cmCPackGenerator::CleanTemporaryDirectory()
  1218. {
  1219. std::string tempInstallDirectoryWithPostfix
  1220. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  1221. const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str();
  1222. if(cmsys::SystemTools::FileExists(tempInstallDirectory))
  1223. {
  1224. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1225. "- Clean temporary : "
  1226. << tempInstallDirectory << std::endl);
  1227. if(!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory))
  1228. {
  1229. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1230. "Problem removing temporary directory: " <<
  1231. tempInstallDirectory
  1232. << std::endl);
  1233. return 0;
  1234. }
  1235. }
  1236. return 1;
  1237. }
  1238. //----------------------------------------------------------------------
  1239. cmInstalledFile const* cmCPackGenerator::GetInstalledFile(
  1240. std::string const& name) const
  1241. {
  1242. cmake const* cm = this->MakefileMap->GetCMakeInstance();
  1243. return cm->GetInstalledFile(name);
  1244. }
  1245. //----------------------------------------------------------------------
  1246. int cmCPackGenerator::PrepareGroupingKind()
  1247. {
  1248. // find a component package method specified by the user
  1249. ComponentPackageMethod method = UNKNOWN_COMPONENT_PACKAGE_METHOD;
  1250. if(this->GetOption("CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE"))
  1251. {
  1252. method = ONE_PACKAGE;
  1253. }
  1254. if(this->GetOption("CPACK_COMPONENTS_IGNORE_GROUPS"))
  1255. {
  1256. method = ONE_PACKAGE_PER_COMPONENT;
  1257. }
  1258. if(this->GetOption("CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP"))
  1259. {
  1260. method = ONE_PACKAGE_PER_GROUP;
  1261. }
  1262. std::string groupingType;
  1263. // Second way to specify grouping
  1264. if (NULL != this->GetOption("CPACK_COMPONENTS_GROUPING")) {
  1265. groupingType = this->GetOption("CPACK_COMPONENTS_GROUPING");
  1266. }
  1267. if (!groupingType.empty())
  1268. {
  1269. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "["
  1270. << this->Name << "]"
  1271. << " requested component grouping = "<< groupingType <<std::endl);
  1272. if (groupingType == "ALL_COMPONENTS_IN_ONE")
  1273. {
  1274. method = ONE_PACKAGE;
  1275. }
  1276. else if (groupingType == "IGNORE")
  1277. {
  1278. method = ONE_PACKAGE_PER_COMPONENT;
  1279. }
  1280. else if (groupingType == "ONE_PER_GROUP")
  1281. {
  1282. method = ONE_PACKAGE_PER_GROUP;
  1283. }
  1284. else
  1285. {
  1286. cmCPackLogger(cmCPackLog::LOG_WARNING, "["
  1287. << this->Name << "]"
  1288. << " requested component grouping type <"<< groupingType
  1289. << "> UNKNOWN not in (ALL_COMPONENTS_IN_ONE,IGNORE,ONE_PER_GROUP)"
  1290. << std::endl);
  1291. }
  1292. }
  1293. // Some components were defined but NO group
  1294. // fallback to default if not group based
  1295. if(method == ONE_PACKAGE_PER_GROUP &&
  1296. this->ComponentGroups.empty() && !this->Components.empty())
  1297. {
  1298. if(componentPackageMethod == ONE_PACKAGE)
  1299. {
  1300. method = ONE_PACKAGE;
  1301. }
  1302. else
  1303. {
  1304. method = ONE_PACKAGE_PER_COMPONENT;
  1305. }
  1306. cmCPackLogger(cmCPackLog::LOG_WARNING, "["
  1307. << this->Name << "]"
  1308. << " One package per component group requested, "
  1309. << "but NO component groups exist: Ignoring component group."
  1310. << std::endl);
  1311. }
  1312. // if user specified packaging method, override the default packaging method
  1313. if(method != UNKNOWN_COMPONENT_PACKAGE_METHOD)
  1314. {
  1315. componentPackageMethod = method;
  1316. }
  1317. const char* method_names[] =
  1318. {
  1319. "ALL_COMPONENTS_IN_ONE",
  1320. "IGNORE_GROUPS",
  1321. "ONE_PER_GROUP"
  1322. };
  1323. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "["
  1324. << this->Name << "]"
  1325. << " requested component grouping = "
  1326. << method_names[componentPackageMethod]
  1327. << std::endl);
  1328. return 1;
  1329. }
  1330. //----------------------------------------------------------------------
  1331. std::string cmCPackGenerator::GetComponentInstallDirNameSuffix(
  1332. const std::string& componentName) {
  1333. return componentName;
  1334. }
  1335. //----------------------------------------------------------------------
  1336. std::string cmCPackGenerator::GetComponentPackageFileName(
  1337. const std::string& initialPackageFileName,
  1338. const std::string& groupOrComponentName,
  1339. bool isGroupName) {
  1340. /*
  1341. * the default behavior is to use the
  1342. * component [group] name as a suffix
  1343. */
  1344. std::string suffix="-"+groupOrComponentName;
  1345. /* check if we should use DISPLAY name */
  1346. std::string dispNameVar = "CPACK_"+Name+"_USE_DISPLAY_NAME_IN_FILENAME";
  1347. if (IsOn(dispNameVar))
  1348. {
  1349. /* the component Group case */
  1350. if (isGroupName)
  1351. {
  1352. std::string groupDispVar = "CPACK_COMPONENT_GROUP_"
  1353. + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
  1354. const char* groupDispName = GetOption(groupDispVar);
  1355. if (groupDispName)
  1356. {
  1357. suffix = "-"+std::string(groupDispName);
  1358. }
  1359. }
  1360. /* the [single] component case */
  1361. else
  1362. {
  1363. std::string dispVar = "CPACK_COMPONENT_"
  1364. + cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
  1365. const char* dispName = GetOption(dispVar);
  1366. if(dispName)
  1367. {
  1368. suffix = "-"+std::string(dispName);
  1369. }
  1370. }
  1371. }
  1372. return initialPackageFileName + suffix;
  1373. }
  1374. //----------------------------------------------------------------------
  1375. enum cmCPackGenerator::CPackSetDestdirSupport
  1376. cmCPackGenerator::SupportsSetDestdir() const
  1377. {
  1378. return cmCPackGenerator::SETDESTDIR_SUPPORTED;
  1379. }
  1380. //----------------------------------------------------------------------
  1381. bool cmCPackGenerator::SupportsAbsoluteDestination() const
  1382. {
  1383. return true;
  1384. }
  1385. //----------------------------------------------------------------------
  1386. bool cmCPackGenerator::SupportsComponentInstallation() const
  1387. {
  1388. return false;
  1389. }
  1390. //----------------------------------------------------------------------
  1391. bool cmCPackGenerator::WantsComponentInstallation() const
  1392. {
  1393. return (!IsOn("CPACK_MONOLITHIC_INSTALL")
  1394. && SupportsComponentInstallation()
  1395. // check that we have at least one group or component
  1396. && (!this->ComponentGroups.empty() || !this->Components.empty()));
  1397. }
  1398. //----------------------------------------------------------------------
  1399. cmCPackInstallationType*
  1400. cmCPackGenerator::GetInstallationType(const std::string& projectName,
  1401. const std::string& name)
  1402. {
  1403. (void) projectName;
  1404. bool hasInstallationType = this->InstallationTypes.count(name) != 0;
  1405. cmCPackInstallationType *installType = &this->InstallationTypes[name];
  1406. if (!hasInstallationType)
  1407. {
  1408. // Define the installation type
  1409. std::string macroPrefix = "CPACK_INSTALL_TYPE_"
  1410. + cmsys::SystemTools::UpperCase(name);
  1411. installType->Name = name;
  1412. const char* displayName
  1413. = this->GetOption(macroPrefix + "_DISPLAY_NAME");
  1414. if (displayName && *displayName)
  1415. {
  1416. installType->DisplayName = displayName;
  1417. }
  1418. else
  1419. {
  1420. installType->DisplayName = installType->Name;
  1421. }
  1422. installType->Index = static_cast<unsigned>(
  1423. this->InstallationTypes.size());
  1424. }
  1425. return installType;
  1426. }
  1427. //----------------------------------------------------------------------
  1428. cmCPackComponent*
  1429. cmCPackGenerator::GetComponent(const std::string& projectName,
  1430. const std::string& name)
  1431. {
  1432. bool hasComponent = this->Components.count(name) != 0;
  1433. cmCPackComponent *component = &this->Components[name];
  1434. if (!hasComponent)
  1435. {
  1436. // Define the component
  1437. std::string macroPrefix = "CPACK_COMPONENT_"
  1438. + cmsys::SystemTools::UpperCase(name);
  1439. component->Name = name;
  1440. const char* displayName
  1441. = this->GetOption(macroPrefix + "_DISPLAY_NAME");
  1442. if (displayName && *displayName)
  1443. {
  1444. component->DisplayName = displayName;
  1445. }
  1446. else
  1447. {
  1448. component->DisplayName = component->Name;
  1449. }
  1450. component->IsHidden
  1451. = this->IsOn(macroPrefix + "_HIDDEN");
  1452. component->IsRequired
  1453. = this->IsOn(macroPrefix + "_REQUIRED");
  1454. component->IsDisabledByDefault
  1455. = this->IsOn(macroPrefix + "_DISABLED");
  1456. component->IsDownloaded
  1457. = this->IsOn(macroPrefix + "_DOWNLOADED")
  1458. || cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
  1459. const char* archiveFile = this->GetOption(macroPrefix +
  1460. "_ARCHIVE_FILE");
  1461. if (archiveFile && *archiveFile)
  1462. {
  1463. component->ArchiveFile = archiveFile;
  1464. }
  1465. const char* groupName = this->GetOption(macroPrefix + "_GROUP");
  1466. if (groupName && *groupName)
  1467. {
  1468. component->Group = GetComponentGroup(projectName, groupName);
  1469. component->Group->Components.push_back(component);
  1470. }
  1471. else
  1472. {
  1473. component->Group = 0;
  1474. }
  1475. const char* description
  1476. = this->GetOption(macroPrefix + "_DESCRIPTION");
  1477. if (description && *description)
  1478. {
  1479. component->Description = description;
  1480. }
  1481. // Determine the installation types.
  1482. const char *installTypes
  1483. = this->GetOption(macroPrefix + "_INSTALL_TYPES");
  1484. if (installTypes && *installTypes)
  1485. {
  1486. std::vector<std::string> installTypesVector;
  1487. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  1488. std::vector<std::string>::iterator installTypesIt;
  1489. for (installTypesIt = installTypesVector.begin();
  1490. installTypesIt != installTypesVector.end();
  1491. ++installTypesIt)
  1492. {
  1493. component->InstallationTypes.push_back(
  1494. this->GetInstallationType(projectName, *installTypesIt));
  1495. }
  1496. }
  1497. // Determine the component dependencies.
  1498. const char *depends = this->GetOption(macroPrefix + "_DEPENDS");
  1499. if (depends && *depends)
  1500. {
  1501. std::vector<std::string> dependsVector;
  1502. cmSystemTools::ExpandListArgument(depends, dependsVector);
  1503. std::vector<std::string>::iterator dependIt;
  1504. for (dependIt = dependsVector.begin();
  1505. dependIt != dependsVector.end();
  1506. ++dependIt)
  1507. {
  1508. cmCPackComponent *child = GetComponent(projectName,
  1509. *dependIt);
  1510. component->Dependencies.push_back(child);
  1511. child->ReverseDependencies.push_back(component);
  1512. }
  1513. }
  1514. }
  1515. return component;
  1516. }
  1517. //----------------------------------------------------------------------
  1518. cmCPackComponentGroup*
  1519. cmCPackGenerator::GetComponentGroup(const std::string& projectName,
  1520. const std::string& name)
  1521. {
  1522. (void) projectName;
  1523. std::string macroPrefix = "CPACK_COMPONENT_GROUP_"
  1524. + cmsys::SystemTools::UpperCase(name);
  1525. bool hasGroup = this->ComponentGroups.count(name) != 0;
  1526. cmCPackComponentGroup *group = &this->ComponentGroups[name];
  1527. if (!hasGroup)
  1528. {
  1529. // Define the group
  1530. group->Name = name;
  1531. const char* displayName
  1532. = this->GetOption(macroPrefix + "_DISPLAY_NAME");
  1533. if (displayName && *displayName)
  1534. {
  1535. group->DisplayName = displayName;
  1536. }
  1537. else
  1538. {
  1539. group->DisplayName = group->Name;
  1540. }
  1541. const char* description
  1542. = this->GetOption(macroPrefix + "_DESCRIPTION");
  1543. if (description && *description)
  1544. {
  1545. group->Description = description;
  1546. }
  1547. group->IsBold
  1548. = this->IsOn(macroPrefix + "_BOLD_TITLE");
  1549. group->IsExpandedByDefault
  1550. = this->IsOn(macroPrefix + "_EXPANDED");
  1551. const char* parentGroupName
  1552. = this->GetOption(macroPrefix + "_PARENT_GROUP");
  1553. if (parentGroupName && *parentGroupName)
  1554. {
  1555. group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
  1556. group->ParentGroup->Subgroups.push_back(group);
  1557. }
  1558. else
  1559. {
  1560. group->ParentGroup = 0;
  1561. }
  1562. }
  1563. return group;
  1564. }