cmCPackGenerator.cxx 57 KB

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