cmCPackGenerator.cxx 55 KB

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