cmCPackGenerator.cxx 52 KB

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